Java Reference
In-Depth Information
You may notice that the programs written in a high-level language are easier and more intuitive to write, read,
understand, and modify than the programs written in machine and assembly languages. You might have realized
that computers do not understand programs written in high-level languages, as they understand only sequences of
0s and 1s. So there's a need for a way to translate a program written in a high-level language to machine language.
The translation is accomplished by a compiler, an interpreter, or a combination of both. A compiler is a program that
translates programs written in a high-level programming language into machine language. Compiling a program is an
overloaded phrase. Typically, it means translating a program written in a high-level language into machine language.
Sometimes it is used to mean translating a program written in a high-level programming language into a lower-level
programming language, which is not necessarily the machine language. The code that is generated by a compiler is
called compiled code. The compiled program is executed by the computer.
Another way to execute a program written in high-level programming language is to use an interpreter. An
interpreter does not translate the whole program into machine language at once. Rather, it reads one instruction
written in a high-level programming language at a time, translates it into machine language, and executes it. You
can view an interpreter as a simulator. Sometimes a combination of a compiler and an interpreter may be used to
compile and run a program written in a high-level language. For example, a program written in Java is compiled into
an intermediate language called bytecode. An interpreter, specifically called a Java Virtual Machine (JVM) for the
Java platform, is used to interpret the bytecode and execute it. An interpreted program runs slower than a compiled
program. Most of the JVMs today use just-in-time compilers (JIT), which compile the entire Java program into
machine language as needed. Sometimes another kind of compiler, which is called an ahead-of-time (AOT) compiler,
is used to compile a program in an intermediate language (e.g. Java bytecode) to machine language. Figure 1-2 shows
the relationship between the source code, a compiler, and the machine code.
Figure 1-2. The relationship between source code, a compiler, and machine code
Components of a Programming Language
A programming language is a system of notations that are used to write instructions for computers. It can be described
using three components:
Syntax
Semantics
Pragmatics
The syntax part deals with forming valid programming constructs using available notations. The semantics part
deals with the meaning of the programming constructs. The pragmatics part deals with the use of the programming
language in practice.
Like a written language (e.g. English), a programming language has a vocabulary and grammar. The vocabulary
of a programming language consists of a set of words, symbols, and punctuation marks. The grammar of a
programming language defines rules on how to use the vocabulary of the language to form valid programming
constructs. You can think of a valid programming construct in a programming language like a sentence in a written
language. A sentence in a written language is formed using the vocabulary and grammar of the language. Similarly,
a programming construct is formed using the vocabulary and the grammar of the programming language. The
vocabulary and the rules to use that vocabulary to form valid programming constructs are known as the syntax of the
programming language.
 
Search WWH ::




Custom Search