JDK vs JRE vs JVM
Newcomers often blur the lines between the JVM, JRE, and JDK. They are three nested layers of the Java platform, each with a distinct role. Getting them straight clarifies how Java code is built, distributed, and executed.
The Big Picture
These three components form a containment hierarchy: the JDK contains the JRE, which contains the JVM.
┌─────────────────────────────────────────────┐
│ JDK (Java Development Kit) │
│ Compiler (javac), debugger, javadoc, jar │
│ ┌───────────────────────────────────────┐ │
│ │ JRE (Java Runtime Environment) │ │
│ │ Core libraries, class loader │ │
│ │ ┌─────────────────────────────────┐ │ │
│ │ │ JVM (Java Virtual Machine) │ │ │
│ │ │ Executes bytecode, JIT, GC │ │ │
│ │ └─────────────────────────────────┘ │ │
│ └───────────────────────────────────────┘ │
└─────────────────────────────────────────────┘
JDK ⊃ JRE ⊃ JVM
The JVM: Java Virtual Machine
The JVM is an abstract computing machine — a specification that any vendor can implement — that executes Java bytecode. It is the component responsible for the “Run Anywhere” half of Java’s promise: the same .class file runs on any compliant JVM.
Key JVM responsibilities:
- Class loading — locating and loading
.classfiles into memory. - Bytecode verification — ensuring code is safe before running it.
- Execution — interpreting bytecode and, via the JIT compiler, compiling hot paths to native code.
- Garbage collection — reclaiming unused memory automatically.
Note: The JVM is platform-specific even though bytecode is platform-independent. There is a different JVM build for Windows, macOS, and Linux — each translates the same bytecode to its host’s native instructions.
The JRE: Java Runtime Environment
The JRE is what you need to run an existing Java application. It bundles the JVM together with the core class libraries (java.lang, java.util, java.io, and so on) and supporting files.
If you only want to execute a Java program someone else built — and not compile any code — the JRE is sufficient.
Tip: Since Java 11, Oracle and most distributions no longer ship a standalone JRE download. Instead you install a full JDK, and tools like
jlinklet you build a slim custom runtime image when you need a minimal footprint.
The JDK: Java Development Kit
The JDK is the full toolkit for developing Java applications. It is a superset of the JRE, adding the tools that turn source code into runnable bytecode.
Tools included with the JDK:
| Tool | Purpose |
|---|---|
javac | Compiles .java source into .class bytecode |
java | Launches the JVM to run a program |
jar | Packages classes into .jar archives |
javadoc | Generates HTML API documentation from comments |
jdb | Command-line debugger |
jshell | Interactive REPL for evaluating Java snippets |
jlink | Builds custom runtime images |
Side-by-Side Comparison
| Aspect | JVM | JRE | JDK |
|---|---|---|---|
| Full name | Java Virtual Machine | Java Runtime Environment | Java Development Kit |
| Primary purpose | Executes bytecode | Runs Java applications | Develops Java applications |
| Contains | — | JVM + libraries | JRE + dev tools |
| Includes compiler? | No | No | Yes (javac) |
| Who needs it | Underlies the others | End users running apps | Developers writing apps |
From Source to Execution
The flow that ties all three together:
HelloWorld.java --[javac, from JDK]--> HelloWorld.class (bytecode)
HelloWorld.class --[java launcher]--> JVM loads, verifies, JIT-compiles, runs
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Built by the JDK, run by the JVM!");
}
}
Output:
Built by the JDK, run by the JVM!
Interview Questions
What is the difference between the JDK and the JRE?
The JRE provides everything needed to run Java programs (JVM plus core libraries). The JDK is a superset that also includes development tools like the javac compiler, so it is what you need to build programs.
Is the JVM platform independent? The bytecode it runs is platform independent, but the JVM itself is platform specific — each operating system requires its own JVM implementation.
Can you run a Java program with only the JVM?
Not in practice. The JVM needs the core class libraries (provided by the JRE) to do anything useful, since even System.out.println depends on them.