JVM:
The use of the JVM is simple : – To change the byte code into the machine specific code. So the JVM converts the byte code(ie the code which we get when we compile the .java class) into the code that your machine/OS understands.
JVM is machine specific. So JVM for windows will be different from JVM for Mac or Unix. JVM is one of the most crucial part in the java engine. It is due to JVM only that we say java code is “Compile Once, Run Anywhere” programming language.
The byte code generated when we compile the code will be THE SAME doesn’t matter we compiled the code in Windows OS or some other. However, JVM makes sure that the byte code should be interpreted properly in the OS under concerned so interpret the byte code differently for different OS
JRE:
JRE = JVM + Java Packages Classes(like util, math, lang, awt,swing etc) + runtime libraries.
Bytecode will be understood by the JRE with the help of JVM.
A JVM is just the thing that executes .class files. A JRE includes libraries and APIs (i.e., all the java.* and javax.* Java classes, plus things like the native libaries needed for the AWT to function.) So a JRE is a JVM plus more stuff. You can’t actually run a program on a bare JVM; there are a few APIs (the java.lang package, in particular) which the JVM can’t function without.
JDK:
Java Developer Kit contains tools needed to develop the Java programs, and JRE to run the programs. The tools include compiler (javac.exe), Java application launcher (java.exe), Appletviewer, etc…
JDK = JVM + JRE
Compiler(javasc.exe) converts java code into byte code. Java application launcher(java.exe) opens a JRE, loads the class, and invokes its main method.
You need JDK, if at all you want to write your own programs, and to compile them. For running java programs, JRE is sufficient.
To conclude,
In the Java programming language, all source code is first written in plain text files ending with the .java extension. Those source files are then compiled into .class files by the javac compiler. A .class file does not contain code that is native to your processor; it instead contains bytecodesthe machine language of the Java Virtual Machine (Java VM).[2] The java launcher tool then runs your application with an instance of the Java Virtual Machine.