JDK vs JRE vs JVM - Differences Explained with Examples
Introduction
JDK vs JRE vs JVM is one of the first things that confuses anyone starting with Java - and one of the most common Java interview questions. This tutorial explains what each of the three is, what it contains, and how they fit inside each other. We will start with the JVM, then look at the JRE and the JDK. We will then see all three at work by compiling and running a small program, and look at the bytecode which the JVM actually runs. Lastly, we will compare the three side by side and see which one you need to install.(Note - This tutorial is part of the Java Fundamentals series. If you are new to Java, start with What is Java?Click to read the first tutorial in the Java Fundamentals series, which explains bytecode and "Write Once, Run Anywhere".)
The short answer
The three are nested inside each other, like boxes inside boxes -- JVM (Java Virtual Machine): Runs Java bytecode.
- JRE (Java Runtime Environment): The JVM plus the Java class libraries - everything needed to run a Java program.
- JDK (Java Development Kit): The JRE plus development tools such as the compiler - everything needed to write, compile and run Java programs.
JDK = JRE + development tools
javac, jar, javadoc, jshell, jdb, javap, jlink ...
JRE = JVM + class libraries
java.lang, java.util, java.io, java.time ...
JVM
class loader · runtime memory areas · execution engine (interpreter, JIT compiler, garbage collector)
What is the JVM (Java Virtual Machine)?
The Java Virtual Machine is the program which runs Java bytecode. It is called a virtual machine because it behaves like a computer of its own - it has its own instruction set (bytecode), and its own way of managing memory. The JVM translates that bytecode into instructions for the real processor and operating system underneath.The JVM is the reason Java programs are platform independent. Bytecode is the same everywhere, but the JVM is not - there is a separate JVM for Windows, Linux and macOS, on each type of processor. The JVM has three main parts -
- Class loader subsystem: Finds
.classfiles, loads them into memory, and verifies that the bytecode is valid and safe before it runs. - Runtime data areas: The memory the JVM manages while a program runs - the heap, where all objects live; a stack for every thread, which holds method calls and local variables; and the method area (called Metaspace in HotSpot), which holds class definitions.
- Execution engine: Runs the bytecode. An interpreter runs the bytecode instruction by instruction, and the JIT (Just-In-Time) compiler compiles frequently used methods into native machine code for speed. The garbage collector, also part of the execution engine, frees memory used by objects which are no longer needed.
What is the JRE (Java Runtime Environment)?
The JVM on its own cannot do much. Almost every Java program uses ready-made classes from the Java class library -String and System from java.lang, collections such as ArrayList from java.util, file handling from java.io and java.nio, dates from java.time (see the overview of the java.time APIClick to read the overview of Java 8's Date and Time API), and many more.The Java Runtime Environment is the JVM packaged together with these class libraries and the supporting files they need, such as configuration and security files. In other words - JRE = JVM + class libraries. A JRE is all you need to run a Java program, but it has no compiler, so you cannot use it to develop one.
Note - Since Java 11, Oracle no longer ships a separate JRE download. The JDK itself contains the runtime, and applications are expected to ship their own runtime, which can be built with the JDK's
jlink tool to contain only the modulesClick to read tutorial on Java 9 Modules they need. Some vendors, such as Eclipse Temurin, still offer JRE downloads for convenience. So you will still hear the term JRE, but in practice you install a JDK.
What is the JDK (Java Development Kit)?
The Java Development Kit is the full kit for Java developers. It contains a complete Java runtime - the JVM and the class libraries - plus the tools needed to develop Java programs. In other words - JDK = JRE + development tools. The most commonly used tools in the JDK'sbin folder are -javac- the Java compiler, which compiles.javasource files into.classbytecode files.java- the launcher, which starts a JVM and runs a program.jar- packages classes and resources into a single.jararchive.javadoc- generates HTML documentation from comments in the source code.jshell- an interactive shell for trying out Java code line by line.jdb- a command-line debugger.javap- disassembles.classfiles, showing the bytecode inside.jlink- builds a custom, smaller Java runtime containing only the modules an application needs.jcmd,jconsoleandjfr- monitor and troubleshoot running JVMs.
JDK, JRE and JVM in action
Let us now see the three at work. Below is a small program which prints a greeting.A simple Java program to compile and run
//Greeting.java
public class Greeting {
public static void main(String[] args) {
String name = "JavaBrahman";
System.out.println("Hello, " + name + "!");
}
}
javac, to compile Greeting.java into Greeting.class. Then we use the java launcher to start a JVM and run it -
javac Greeting.java java Greeting
Hello, JavaBrahman!
Explanation of the steps
- The JDK did the compiling.
javacis a JDK tool - it is not part of a JRE. - The JRE provided the class library -
String,SystemandPrintStream, whoseprintln()method printed the line, are all classes fromjava.langandjava.io. - The JVM loaded
Greeting.class, verified its bytecode, and ran itsmain()method.
Looking at the bytecode the JVM runs
What exactly is insideGreeting.class? The JDK's javap tool can show us. The -c option prints the bytecode instructions of each method -
javap -c Greeting
Compiled from "Greeting.java"
public class Greeting {
public Greeting();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: ldc #7 // String JavaBrahman
2: astore_1
3: getstatic #9 // Field java/lang/System.out:Ljava/io/PrintStream;
6: aload_1
7: invokedynamic #15, 0 // InvokeDynamic #0:makeConcatWithConstants:(Ljava/lang/String;)Ljava/lang/String;
12: invokevirtual #19 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
15: return
}
Explanation of the bytecode
- This is the bytecode - the instruction set of the JVM. These are the instructions that the same
Greeting.classfile carries to every operating system. ldcloads the constant string"JavaBrahman", andastore_1stores it in the local variablename.getstaticfetchesSystem.out,invokedynamicjoins the strings together, andinvokevirtualcallsprintln().- Notice the constructor
Greeting(). We never wrote it - the compiler added a default constructor for us. We will learn about constructors later in this series.
You can check which JDK you have installed, and the version of its compiler, with these commands -
java --version javac --version
java 24.0.1 2025-04-15 Java(TM) SE Runtime Environment (build 24.0.1+9-30) Java HotSpot(TM) 64-Bit Server VM (build 24.0.1+9-30, mixed mode, sharing) javac 24.0.1
javac, which is only present because this is a full JDK. If java works but javac is not recognized, you have only a runtime installed, or the JDK's bin folder is not on your PATH.
JDK vs JRE vs JVM - side-by-side comparison
| JVM | JRE | JDK | |
| Full form | Java Virtual Machine | Java Runtime Environment | Java Development Kit |
| What it is | The engine which runs bytecode | JVM + class libraries | JRE + development tools |
| Main job | Load, verify and execute bytecode; manage memory | Provide everything needed to run Java programs | Provide everything needed to develop and run Java programs |
| Can compile code? | No | No | Yes - javac |
| Can run code? | Yes - it is what runs it | Yes | Yes |
| Platform dependent? | Yes - one per OS and processor | Yes | Yes |
| Who needs it? | Comes inside the JRE and JDK | Users who only run Java programs | Java developers |
| Download separately? | No | Only from some vendors since Java 11 | Yes |
Note - Bytecode is platform independent, but the JVM, the JRE and the JDK are all platform dependent. That is why the download pages list a separate JDK for Windows, Linux and macOS, while the
.class files you compile run on all of them.
Which one should you install?
Install a JDK. If you are learning Java or developing in Java, you need the compiler and tools, and a modern JDK already contains everything a JRE has. Choose a recent Long-Term Support release, such as Java 21 or Java 25, from a vendor such as Eclipse Temurin or Oracle. If you are only running a Java application someone else built, check its instructions - many applications now ship with their own runtime built usingjlink, so you may not need to install Java at all.
Summary
In this tutorial we first saw that the JVM, the JRE and the JDK are nested inside each other. We then looked at the JVM - the engine which loads, verifies and runs bytecode, with its class loader, memory areas and execution engine. Next we saw that the JRE adds the Java class libraries to the JVM, and that it is no longer offered separately by Oracle since Java 11. We then saw that the JDK adds development tools such asjavac, jar, jshell and javap. We then compiled and ran a program to see all three at work, and used javap to look at the bytecode the JVM runs. Lastly, we compared the three side by side and saw that, as a developer, you should install a JDK.Continue Reading Java Tutorials
What is Java? History, Features, Editions and UsesClick to read the first tutorial in the Java Fundamentals series New Features in Java 8Click to read the list of new features in Java 8 Java Wrapper Classes TutorialClick to read tutorial on Java Wrapper Classes The Complete Java Enums TutorialClick to read tutorial on Java Enums
What is Java? History, Features, Editions and UsesClick to read the first tutorial in the Java Fundamentals series New Features in Java 8Click to read the list of new features in Java 8 Java Wrapper Classes TutorialClick to read tutorial on Java Wrapper Classes The Complete Java Enums TutorialClick to read tutorial on Java Enums