Java in order to support security and portability, does not compile the source code to executable code. It is translated into bytecode, which is highly optimized set of instructions designed to be executed by the Java run-time system, which is called Java Virtual Machine (JVM). JVM is an interpreter of bytecode.
Converting the Java program to bytecode instead of compiled code, offers a great ability to run those programs on multiple platforms. Once we have the run-time package for a given system, then any Java program can run on it. Instead, if Java programs were to be compiled to the native code, then it would be very difficult since the same program has to be compiled for every CPU type.
Using JVM also offers a protected environment which helps in enhanced safety for the system. This reduces any side effects caused by the programs.