Java Virtual Machine
How Java achieves architecture neutrality ?
The task of a compiler is to convert the source code to a machine dependent code. Java compiler also does the same thing but instead of producing a platform specific object code, it produces byte code for a virtual machine known as JVM. The real machine/platform specific code is produced by Java Interpreter which is a part of Java Runtime Environment ( JRE ). Thus, the compiled bytecode can be easily distributed across internet and it can be executed on any machine on which JRE is installed. Basically, JVMs are available for different hardware and software platforms and it takes care of producing machine dependent code.
What is a platform ?
We have been using the terms platform / machine interchangeably to illustrate how Java is architecture neutral. To keep things simple, examples of platforms may be a Macintosh machine or an IBM machine. These platforms have implemented different architectures and the concept of JVM makes it possible to compile a Java program on a Macintosh platform and run on an IBM platform.
Following figure visualizes the concept illustrated above :
Difference between JVM, JDK AND JRE
JVM is an abstract machine which provides the runtime environment in which Java bytecode can be executed.
JRE is an implementation of JVM and it consists of a set of libraries and other files which are used by Java programs at runtime.
JDK consists of JRE and the tools required for developing Java softwares.
Note :- JRE is sufficient on a system in which Java programs are to be executed but JDK must be installed on a system on which Java programs are developed.