Java Reference
In-Depth Information
different compiler for each type of computer. Java, however, uses a slightly different
and much more versatile approach to compiling.
The Java compiler does not translate your program into the machine language for
your particular computer. Instead, it translates your Java program into a language
called byte-code . Byte-code is not the machine language for any particular computer.
Byte-code is the machine language for a fictitious computer called the Java Virtual
Machine . The Java Virtual Machine is very similar to all typical computers. Thus, it is
easy to translate a program written in byte-code into a program in the machine lan-
guage for any particular computer. The program that does this translation is called an
interpreter . An interpreter combines the translation of the byte-code and the execu-
tion of the corresponding machine-language instructions. The interpreter works by
translating an instruction of byte-code into instructions expressed in your computer's
machine language and then executing those instructions on your computer. It does
this one byte-code instruction at a time. Thus, an interpreter translates and executes
the instructions in the byte-code one after the other, rather than translating the entire
byte-code program at once. 2
To run a Java program, you proceed as follows. First, you use the compiler to trans-
late the Java program into byte-code. Then, you use the byte-code interpreter for your
computer to translate each byte-code instruction to machine language and to run the
machine-language instructions.
It sounds as though Java byte-code just adds an extra step in the process. Why not
write compilers that translate directly from Java to the machine language for your par-
ticular computer? That is what is done for most other programming languages. How-
ever, Java byte-code makes your Java program very portable. After you compile your
Java program into byte-code, you can use that byte-code on any computer. When you
run your program on another type of computer, you do not need to recompile it. This
means that you can send your byte-code over the Internet to another computer and
have it easily run on that computer. This is one of the reasons Java is good for Internet
applications. Of course, every kind of computer must have its own byte-code inter-
preter, but these interpreters are simple programs when compared to a compiler.
byte-code
Java Virtual
Machine
interpreter
Byte-Code
The Java compiler translates your Java program into a language called byte-code , which is
the machine language for a fictitious computer. It is easy to translate this byte-code into the
machine language of any particular computer. Each type of computer will have its own inter-
preter that translates and executes byte-code instructions.
2 Sometimes people use the term Java Virtual Machine (JVM) to refer to the Java byte-code inter-
preter (as well as to refer to the underlying hypothetical machine that the interpreter is based on).
Search WWH ::




Custom Search