Difference Between JDK, JRE and JVM
Think of a restaurant. The kitchen is where food is made: it has chefs, tools and ingredients. The dining hall is where food is served and eaten, and it needs only tables and waiters. The kitchen also contains a serving counter, so you could eat there too. Java's three letters work the same way: the JDK is the kitchen for building programs, the JRE is what you need to run them, and the JVM is the engine at the center of both.
Three Boxes, One Inside the Other
| JVM | JRE | JDK | |
|---|---|---|---|
| Full name | Java Virtual Machine | Java Runtime Environment | Java Development Kit |
| What it is | The engine that runs bytecode | Everything needed to run Java programs | Everything needed to write and run Java programs |
| Contains | Class loader, memory areas, execution engine | The JVM + the Java class library | The JRE + development tools |
| Tools you get | None you run directly | java | java, javac, jshell, javap, jar, jdb and more |
| Who needs it | Comes inside the other two | Users who only run Java programs | Developers: you |
The JVM: The Engine
The JVM is the part that actually runs your program. It loads .class files, checks the bytecode, runs it with the interpreter and the JIT compiler, and frees memory with the garbage collector.
On its own, the JVM can't do much: it doesn't know what a String or an ArrayList is. Those come from the class library. That's why you never download "just a JVM". The next two lessons look inside it.
The JRE: Enough to Run Programs
The JRE is the JVM plus the Java class library: the thousands of ready-made classes in packages such as java.lang, java.util, java.io and java.time. With a JRE you can run any compiled Java program, but you can't compile one, because it has no javac.
Here's a program that uses only a few of those library classes, and asks the running JVM about itself:
public class WhatRunsMe {
public static void main(String[] args) {
String vm = System.getProperty("java.vm.name");
String spec = System.getProperty("java.specification.version");
String classVersion = System.getProperty("java.class.version");
System.out.println("JVM: " + vm);
System.out.println("Java SE version: " + spec);
System.out.println("Class file version: " + classVersion);
}
}JVM: OpenJDK 64-Bit Server VM
Java SE version: 25
Class file version: 69.0How it works
- Line 3 asks for the name of the JVM. "OpenJDK 64-Bit Server VM" is HotSpot, the JVM inside almost every JDK.
- Line 4 asks which Java SE version this runtime implements.
- Line 5 asks for the newest class file version it can run: 69 means Java 25. The lesson "Bytecode and Platform Independence" explains these numbers.
Try it yourself: run it with a different JDK if you have one installed, for example Java 17. Which of the three lines change?
The JDK: Everything for Developers
The JDK is the JRE plus the tools you use to build programs. You've already met several of them:
| Tool | What it does | Lesson |
|---|---|---|
javac | Compiles .java files to bytecode | Compiling and Running from the Command Line |
java | Starts the JVM and runs a program | Java Hello World Program |
jshell | Runs Java one line at a time | JShell (Interactive Java) |
javap | Shows the bytecode inside a .class file | Bytecode and Platform Independence |
jar | Packs classes into one .jar file | Packaging, later in the course |
jdb | A command-line debugger | Using the Debugger |
jlink | Builds a small custom runtime for one application | Packaging, later in the course |
As a developer, always install the JDK. It contains everything the JRE has, so you can both build and run.
What Happened to the JRE?
Until Java 8, Oracle offered two downloads: a JDK for developers and a smaller JRE for everyone else. Since Java 11, Oracle no longer ships a separate JRE. Today, applications are usually delivered with their own runtime, built with jlink, or run inside a container image. Some distributions, such as Eclipse Temurin, still offer JRE downloads for convenience.
The idea of a JRE, "the JVM plus the class library", is still exactly how Java is organized. That's why interviewers still ask about it.
Common Mistakes
Saying the JVM compiles Java code. javac, part of the JDK, compiles source code to bytecode. The JVM runs the bytecode, using its JIT compiler to turn hot bytecode into machine code.
Thinking the JDK and JRE run code differently. A program behaves the same whether it runs from a JDK or a JRE; both contain the same JVM and class library.
Saying "JVM is platform independent". The bytecode is platform independent. Each operating system needs its own JVM, JRE and JDK.
Interview Corner
What is the difference between JDK, JRE and JVM?
The JVM runs bytecode: it loads, verifies and executes classes and manages memory. The JRE is the JVM plus the Java class library, so it can run Java programs. The JDK is the JRE plus development tools such as javac, jshell and javap, so it can build and run them. In short: JDK = JRE + tools, JRE = JVM + libraries.
Can you run a Java program with only a JRE? Can you compile one?
You can run a compiled program, because the JRE has the JVM and the class library. You can't compile, because javac is only in the JDK.
Is the JVM platform independent?
No. Each operating system and processor needs its own JVM. The bytecode is what's platform independent: the same .class file runs on every JVM.
Practice
- Easy: Without looking, draw the three nested boxes and write two things that belong in each layer.
- Harder: Open the
binfolder of your JDK and find three tools that aren't in the table above. Run each with--helpand write one sentence about what it does.
Key Takeaways
Was this tutorial helpful?