Java sovles the problem of platform independence by usingbyte code.Java complier does not produce native executablecode.
Instead it produces a special format called byte code.Byte code is a highly optimized set of instructionsdesigned to executed by a java runtime system called JavaVirtual Machine(JVM).JVM is an interpreter for byte code.
This interpreter reads or understands the bytecode andexecutes the corresponding native machine instructions.Thus to port java programs to a new platform ,all thatneeded is to port the interperter and some of the libraryroutines.
Even the complier is written in java.The bytecodes are precisely defined and remain the same on allplatforms.The use of byte code enables the java runtime system toexecute programs much faster.
The JVM is the core of the Java platform and is responsible for:
1. Loading bytecodes from the class files
2. Verifying the loaded byte codes
3. Linking the program with the necessary libraries
4. Memory Management by Garbage Collection
5. Managing calls between the program and the host environment.