The means that allows Java to solve both the security and the portability problems is that the output of a Java compiler is not executable code but it is the Bytecode. Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system, which is called the lava Virtual Machine (JVM). JVM is an interpreter for bytecode. The fact that a Java program is executed by JVM helps solve the major problems associated with downloading programs over the Internet. Translating a Java program into bytecode helps makes it much easier to run a program in a wide variety of environments. This is because only the JVM needs to be implemented for each platform.
Once the run-time package exists for a given system, any Java program can run on it. If a Java program is compiled to its subject code, then different versions of the same program would exist for each type of CPU connected to the Internet. This is not a practical solution. Thus, the understanding of bytecode is the most effective way to create strictly portable programs. Now, if a Java program is interpreted, it also helps to make it secure. Since the execution of every Java program is under the control of the JVM, the JVM can contain the program, and prevent it from generating side effects outside of the system. The use of by tee ode enables the Java run-time system to execute programs much faster.
Sun provides a facility called lust In Time (JIT) compiler for bytecode. It is not possible to compile an entire Java program into executable code all at once, because Java performs various run-time checks that can be done only at run time. JIT compiles the code 3.S and when needed.