Java virtual machine

The Java™ virtual machine is a runtime environment that you can add into a web browser or any operating system, such as IBM® i5/OS™. The Java virtual machine runs instructions that a Java compiler generates. It consists of a bytecode interpreter and runtime that allow Java class files to run on any platform, regardless of the platform on which they were originally developed.

The class loader and security manager, which is part of the Java runtime, insulate code that comes from another platform. They also can restrict which system resources each class that is loaded accesses.

Note: Java applications are not restricted; only applets are restricted. Applications can freely access system resources and use native methods. Most IBM Developer Kit for Java programs are applications.

You can use the Create Java Program (CRTJVAPGM) command to ensure that the code meets the safety requirements that the Java runtime imposes to verify the bytecodes. This includes enforcing type restrictions, checking data conversions, ensuring that parameter stack overflows or underflows do not occur, and checking for access violations. However, you do not need to explicitly verify the bytecodes. If you do not use the CRTJVAPGM command in advance, then the checks occur during the first use of a class. Once the bytecodes are verified, the interpreter decodes the bytecodes and runs the machine instructions that are needed to carry out the desired operations.

Note: The Java interpreter is only used if you specify OPTIMIZE(*INTERPRET) or INTERPRET(*YES).

In addition to loading and running the bytecodes, the Java virtual machine includes a garbage collector that manages memory. Garbage collection runs at the same time as the loading and interpretation of the bytecodes.

Java runtime environment

The Java runtime environment starts whenever you enter the Run Java (RUNJVA) command or JAVA command on the iSeries™ command line. Because the Java environment is multithreaded, it is necessary to run the Java virtual machine in a job that supports threads, such as a batch immediate (BCI) job. As illustrated in the following figure, after the Java virtual machine starts, additional threads may start in the job in which the garbage collector runs.

Figure 1: The typical Java environment when using the RUNJVA or JAVA CL command
This graphic shows
an example of starting the Java runtime environment by using the RUNJVA or
JAVA CL command on the iSeries command line.

It is also possible to start the Java runtime environment by using the java command in Qshell from the Qshell Interpreter. In this environment, the Qshell Interpreter is running in a BCI job that is associated with an interactive job. The Java runtime environment starts in the job that is running the Qshell Interpreter.

Figure 2: The Java environment when using the java command in Qshell
This graphic shows
an example of starting the Java runtime environment by using the java command
in Qshell from the Qshell Interpreter.

When the Java runtime environment starts from an interactive job, the Java Shell Display is shown. This display provides an input line for entering data into the System.in stream, as well as displaying data that is written to the System.out stream and System.err stream.

Java interpreter

The Java interpreter is the part of the Java virtual machine that interprets Java class files for a particular hardware platform. The Java interpreter decodes each bytecode and runs a series of machine instructions for that bytecode.

Related topics:
Related concepts
Java applets and applications
Java JAR and class files
Java threads
Sun Microsystems, Inc. Java Development Kit