go to previous page   go to home page   go to next page hear noise highlighting

Answer:

  1. Translation (into machine instructions, which are then directly executed by the processor)
  2. Interpretation (by an interpreter program running on the processor)

Bytecodes

source program translated into bytecodes

Java combines these ideas in a way that will take some explaining. To run a Java program the source file is first translated into a file of bytecodes.

A Java bytecode is a machine instruction for a Java processor. A file of bytecodes is a machine language program for a Java processor.

Conceptually, a Java processor is a silicon processor chip that directly executes a machine language called Java bytecodes. This is like an Intel processor that directly executes Intel machine language.

The picture shows the Java compiler translating the sample Java program Hello.java into bytecodes. The file of bytecodes is called Hello.class.

The file Hello.java is not changed. An entierly new file Hello.class containing bytecodes is created by the compiler. (If there already is a file named Hello.class, it will be replaced by a new one. Usually, this is what you want.)

In this picture, the source program Hello.java is examined by a program called javac running on your computer. The javac program is a compiler (a translator) that translates the source program into a bytecode file called Hello.class.

Important Idea: The bytecode file will contain exactly the same bytecodes no matter what computer the javac compiler runs on.

The architecture of the processor that executes Java bytecodes is well-documented and is available to anyone. The Java compiler on a Macintosh will produce the same bytecodes as the Java compiler on an Intel system.


QUESTION 3:

Could a processor chip be built that executes Java bytecodes directly, just as an Intel processor chip executes its machine language directly?


go to previous page   go to home page   go to next page