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.
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.
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.
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
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
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.