Java Reference
In-Depth Information
errors
errors
Edit and
save program
Translate program
into executable form
Execute program and
evaluate results
FIGURE 1.20
Editing and running a program
Figure 1.20 shows a very basic view of the program development process. After
editing and saving your program, you attempt to translate it from high-level code
into a form that can be executed. That translation may result in errors, in which
case you return to the editor to make changes to the code to fix the problems.
Once the translation occurs successfully, you can execute the program and evalu-
ate the results. If the results are not what you want, or if you want to enhance
your existing program, you again return to the editor to make changes.
The translation of source code into (ultimately) machine language for a par-
ticular type of CPU can occur in a variety of ways. A
compiler is a program that
translates code in one language to equivalent code in another language. The origi-
nal code is called source code, and the language into which it is translated is called
the target language. For many traditional compilers, the source code is translated
directly into a particular machine language. In that case, the translation process
occurs once (for a given version of the program), and the resulting executable
program can be run whenever needed.
An interpreter is similar to a compiler but has an important difference. An
interpreter interweaves the translation and execution activities. A small part of
the source code, such as one statement, is translated and executed. Then another
statement is translated and executed, and so on. One advantage of this technique
is that it eliminates the need for a separate compilation phase. However, the pro-
gram generally runs more slowly because the translation process occurs during
each execution.
The process generally used to translate and execute Java programs
combines the use of a compiler and an interpreter. This process is
pictured in Figure 1.21. The Java compiler translates Java source
code into Java bytecode, which is a representation of the program in
a low-level form similar to machine language code. The Java inter-
preter reads Java bytecode and executes it on a specific machine.
Another compiler could translate the bytecode into a particular machine language
for efficient execution on that machine.
The difference between Java bytecode and true machine language code is that
Java bytecode is not tied to any particular processor type. This approach has the
KEY CONCEPT
A Java compiler translates Java
source code into Java bytecode, a
low-level, architecture-neutral repre-
sentation of the program.
 
Search WWH ::




Custom Search