0% found this document useful (0 votes)
11 views16 pages

Lec1 - Intro - To - Java (1) - 6-21

Uploaded by

appleid8738
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views16 pages

Lec1 - Intro - To - Java (1) - 6-21

Uploaded by

appleid8738
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Programs

• A program is a set of instructions for a computer to follow that directs the


computer to do the tasks you want it to do and produce the results you
want.
• A program is like a recipe. It contains a list of variables (called ingredients)
and a list of statements (called directions) that tell the computer what to
do with the variables.
• Following the instructions is called running or executing the program
• We use programs almost daily (email, word processors, video games, bank
ATMs, etc.).
• Programmers tell a computer what to do through programs. Without
programs, a computer is an empty machine.
• Computers do not understand human languages, so we need to use
computer languages to communicate with them
• Programs are written using programming languages
6
Running a Program
• Normally, a computer receives two kinds of input:
• The program
• The data needed by the program.

• The output is the result(s) produced by following the instructions in the


program.

7
Programming Languages
• Programming languages are a set of instructions written in a way that
a computer could understand

• Why do we need programming languages?


• All computer components: Central Processing Unit(CPU), memory,
and Input/Output (I/O) understands a machine code called a
binary.
• Binary is a long string of 0’s and 1’s that human cannot
understand!
• So how can we make the computer to perform a certain task?
• Programming languages helps us in doing so by providing an intermediate
solution between the human and the machine
• Each language has a unique set of keywords (words that it
understands) and a special syntax for organizing program instructions.

8
Syntax and Semantics of programming
languages
• Syntax and Semantics provide a language's definition.

• The grammar rules for a programming language are called the syntax of the language
(detected by the compiler). Different languages have different syntax.
• e.g., while statement in java
• while (boolean_expression) statement

• The interpretation or the meaning of the statements is called the semantic of the
language.
• e.g., Array index out of range:
int[] v = new int[10];
v[10] = 100; // 10 is not a legal index for an array of 10 elements
• e.g., Use of a non-initialized variable:
int i;
i++; // the variable i is not initialized

More details:
https://newtutorial2012.blogspot.com/2012/07/differentced-between-synataxsemantic.html
https://www.inf.unibz.it/~calvanese/teaching/ip/lecture-notes/uni10/node2.html 9
Programming Languages (cont.)
Programming languages could be Assembly High-level
categorized into:

• Low-level languages (machine


language): they are close to the
machine language e.g. assembly
language
• High-level languages: they are
closer to the programmers'
language (more friendly!) e.g.
Java

10
Levels of Programming Languages

• High-level languages are relatively easy


Natural Language
to use (i.e., more flexibility, easier to
be Implemented, maintained)
Very High-Level
Language
• Unfortunately, computer hardware does
(e.g., Java, C++, C#)
not understand high-level languages!
• Therefore, a high-level language High Level Language
program must be translated into a (e.g., Fortran, Cobol)
low-level language.
Assembly Language
(Intel:8086, Sun
Sparc)

Speed Machine Language


(e.g., 01001110000)
11
Choosing A Language

• Depends on your tasks:


• Satellite communication (speed) à Assembly
• Educationà Basic, Pascal
• Business à Cobol
• Web developmentà JavaScript, JSP, .NET
• Scientific calculationà Fortran, Matlab
• Embedded and Operating Systemsà C
• Enterprise applications à Java

12
Translating/Converting High-level to
Low-level
• A source program must be translated into a machine code.
• An application program called a translator which transforms code
from High Level Language to Low Level Language, making it
machine understandable code.
• Compilers and interpreters are simply language translators in
computer programming.
• The program is run by loading machine code into main memory. The
processor directly executes these machine language instructions

13
Compilers

• A compiler is a program that takes a high-level language program and


translates the entire program into machine code all at one time
• All instructions are compiled before any are executed by the CPU
• The Java compiler (javac) translates Java source code (Hello.java) into a
special representation called bytecode (object program)
• When a Java program is translated into bytecodes, the bytecodes are
exactly the same no matter what computer system is used
• Compilation process occurs only once and the resulting object program
could be run as often as needed without re-compiling the source
program

14
Interpreters
• An interpreter reads through a source program written in a high level
language and performs the instructions that the source program asks
for one by one.
• Once a given instruction has been translated and executed, the next
one then will follow, and son on
• The Java Virtual Machine (JVM) uses an interpreter, to translate
bytecode into machine language and executes it

15
Java Programming Language

16
Java History
• Java is a high-level object-oriented programming
language developed by James Gosling at Sun
Microsystems in the early 1990s.
• He was unhappy using c++ programming language so
he developed java.
• Java Old name was “Oak”
• 1995 “Oak” was renamed as Java as a core
components of Sun microsystems java platform
• Java is a consolidation language, designed to absorb
the strengths of earlier languages and ignore their
weakness

17
Java Features

• Simple
• Platform-Independent (portable)
• Object-Oriented
• Robust and Secure
• Compiled and interpreted
• Distributed
• Multithreaded
• Architecture-Neutral
• High-performance

18
Java Features (Cont.)
• Simple
• Java syntax is based on C++ (greatly simplified and improved).
• Java has removed many complicated and rarely-used features, for example,
explicit pointers, operator overloading, etc.
• There is no need to remove unreferenced objects because there is an
Automatic Garbage Collection in Java.
• Platform-Independent (portable)
• Write once run anywhere
• Java is completely portable; the same Java code will run identically on
different platforms, regardless of hardware compatibility or operating
systems.
• Object oriented
• OOP is a popular programming approach that is replacing traditional
procedural programming which offers great flexibility, modularity, clarity,
and reusability
• All coding and data reside within objects and classes

19
Java Features (Cont.)

• Robust and secure


• Exception handling built-in strong type checking
• automatic garbage collection so all memory corruptions or unauthorized
memory accesses are impossible
• strong memory management (no-pointers).
• Programs run inside the virtual machine sandbox
• Compiled and interpreted
• Code is complied to bytecode that are interpreted by a JVM
• Distributed
• Creating applications on networks.
• Multiple programmers can work together on a single project from multiple
remote locations and share data and programs.

20
Java Features (Cont.)

• Multithreaded
• It allows to handle multiple tasks simultaneously (run multiple threads )
• Architecture-Neutral
• no implementation dependent features e.g. size of primitive types is fixed.
• High-performance
• The new JVM uses the technology known as just-in-time (JIT) compilation.
• With JIT complier the interpreted code gives almost the native code speed.

21

You might also like