Java application runs the same bytecodes regardless of any environment (Operating System). To enable a Java application to execute anywhere on the network, the compiler generates an architecture-neutral object file format. An architecture-neutral object file format meaning that compiled Java code (bytecode) can run on many processors given the presence of a JVM. The JVM is the main component of making the java a platform independent language. That is the architectural neutral part.
What is JVM
Java Virtual Machine (JVM) is a specification that provides runtime environment in which java bytecode can be executed. As the name implies, the JVM acts as a “virtual” machine or processor. Java's platform independence consists mostly of its Java Virtual Machine (JVM) . JVM makes this possible because it is aware of the specific instruction lengths and other particularities of the platform. The JVM performs following operation:
- Loads code
- Verifies code
- Executes code
In most cases, other programming languages, the compiler produce code for a particular Operating System but the Java compiler produce Bytecode only for a Java Virtual Machine . When you run a Java program, it runs as a thread within the JVM process. It is the JVM's responsibility to load your class files, verify code, interpret them and execute them. When you issue a command like java , the JVM loads the class definition for that particular class and calls the main method of that class.
It is the JVMs responsibility that makes it possible for the same class file to run on any other Operating Systems. The JVM takes your compiled platform-neutral byte code and interprets it to run platform-specific machine code. It can also compile it into native code with a JIT (a just-in-time compiler that compiles and caches your code, usually one method at a time). Thus, it is in the JVM where your code results, if needed, in native Operating System calls. Therefore, in the JVM , your platform-neutral threading code gets turned into platform-specific threading code.
Credit for JVM: http://net-informations.com/java/intro/jvm.htm