Bytecodes

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

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

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.

Here is a picture of the sample Java program Hello.java being translated into bytecodes. The file of bytecodes (machine language for the Java processor) is called Hello.class.

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 system is used.

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 exact 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 a Pentium executes its machine language directly?