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® i. 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 are part of the Java runtime, insulate code that comes from another platform. They can also restrict which system resources are allowed to be accessed by each class that is loaded.

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.

In addition to loading and running the bytecodes, the Java virtual machine includes a garbage collector that manages memory. Java 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 IBM i 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 IBM i 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 performs the corresponding operation.