Lec1_Intro_to_java (1)-6-21
Lec1_Intro_to_java (1)-6-21
7
Programming Languages
• Programming languages are a set of instructions written in a way that
a computer could understand
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:
10
Levels of Programming Languages
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
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.)
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