JDK vs JRE vs JVM – Differences Explained with Examples
When you start with Java you quickly meet three abbreviations: JDK, JRE and JVM. They are nested parts of the same platform. The JVM runs Java programs, the JRE is the JVM plus the libraries a program needs, and the JDK is the JRE plus the tools to write and build programs.
This tutorial explains each one, how a program travels from source code to running code, and what has changed in modern Java versions.
1. How JDK, JRE and JVM Are Related
Swipe sideways to see the whole diagram.
JDK = JRE + development tools (javac, jar, javadoc, jdb, jshell, jlink ...)
JRE = JVM + class libraries (java.lang, java.util, java.io ...) + supporting files
JVM = the engine that loads, verifies and runs bytecode
Think of a car factory: the JVM is the engine, the JRE is the complete car you can drive, and the JDK is the whole workshop with the tools to build cars.
2. What Is the JVM?
The Java Virtual Machine is a program that executes Java bytecode. It is called "virtual" because it behaves like a computer with its own instruction set, but it is implemented in software on top of the real operating system.
The JVM is responsible for:
- Loading
.classfiles when they are first needed. - Verifying bytecode so it cannot break type or memory rules.
- Executing bytecode with an interpreter and a JIT compiler.
- Managing memory, including garbage collection.
- Providing threads, security checks and exception handling.
The JVM itself is platform-specific: there is a different JVM build for Windows, macOS and Linux on each processor type. That is what allows the same bytecode to run everywhere. The most widely used JVM is HotSpot, part of OpenJDK.
3. What Does Bytecode Look Like?
Here is a tiny program and the bytecode javac produces for it, shown with the JDK's javap -c disassembler:
public class Calculator {
static int add(int a, int b) {
return a + b;
}
public static void main(String[] args) {
System.out.println("2 + 3 = " + add(2, 3));
}
}
2 + 3 = 5
static int add(int, int);
Code:
0: iload_0 // push a
1: iload_1 // push b
2: iadd // add them
3: ireturn // return the result
public static void main(java.lang.String[]);
Code:
0: getstatic #7 // Field java/lang/System.out
3: iconst_2
4: iconst_3
5: invokestatic #13 // Method add:(II)I
8: invokedynamic #19 // build the string "2 + 3 = ..."
13: invokevirtual #23 // Method PrintStream.println
16: return
Bytecode is a simple stack-based language: values are pushed onto a stack, and instructions such as iadd work on the top of the stack. The JVM turns these instructions into real machine code for the processor it is running on.
4. Inside the JVM
1. Class loader subsystem
Classes are loaded on demand through a hierarchy of class loaders, then linked (verified, prepared and resolved) and initialized (static fields set and static blocks run).
public class ClassLoaderDemo {
public static void main(String[] args) {
// Bootstrap loader (shown as null): core classes such as String
System.out.println("String -> " + String.class.getClassLoader());
// Platform loader: other Java SE modules such as java.sql
System.out.println("java.sql.Date -> " + java.sql.Date.class.getClassLoader().getName());
// Application loader: your own classes from the class path
System.out.println("ClassLoaderDemo -> " + ClassLoaderDemo.class.getClassLoader().getName());
}
}
String -> null java.sql.Date -> platform ClassLoaderDemo -> app
- Bootstrap loader (shown as
null): loads core classes such asjava.lang.String. - Platform loader: loads other Java SE modules.
- Application loader: loads your classes from the class path or module path.
2. Runtime data areas
| Area | Shared? | Holds |
|---|---|---|
| Heap | All threads | Every object and array; managed by the garbage collector. |
| Metaspace (method area) | All threads | Class metadata, method code, the constant pool. |
| Java stack | One per thread | A frame per method call with local variables and partial results. |
| PC register | One per thread | The address of the current bytecode instruction. |
| Native method stack | One per thread | Frames for native (C/C++) methods. |
3. Execution engine
- Interpreter: runs bytecode instruction by instruction, so the program starts quickly.
- JIT compiler: compiles frequently executed methods into optimised native code (HotSpot uses the C1 and C2 compilers).
- Garbage collector: reclaims memory from unreachable objects (G1 is the default on most machines, although the JVM picks the Serial collector on machines with very few CPUs or little memory; ZGC, Parallel and others are available).
5. What Is the JRE?
The Java Runtime Environment is everything needed to run a Java program: the JVM plus the Java class libraries (java.lang, java.util, java.io, java.net and so on) and supporting configuration files. It does not include the compiler.
jlink.6. What Is the JDK?
The Java Development Kit is what developers install. It contains the runtime plus the tools to write, build, debug and package Java programs:
| Tool | Purpose |
|---|---|
javac | Compiles .java source files into .class bytecode. |
java | Launches the JVM to run a program. |
jar | Packages classes and resources into a JAR file. |
javadoc | Generates HTML documentation from comments. |
jshell | Interactive console for trying Java code (Java 9+). |
javap | Shows the contents and bytecode of class files. |
jdb | Command-line debugger. |
jlink | Builds a custom, minimal runtime image. |
jpackage | Creates native installers (.exe, .dmg, .deb). |
jcmd, jstack, jfr | Diagnose and profile running JVMs. |
Popular JDK distributions, all built from OpenJDK, include Eclipse Temurin, Oracle JDK, Amazon Corretto, Microsoft Build of OpenJDK, Azul Zulu and GraalVM.
7. From Source Code to Running Program
- You write
Calculator.java. - JDK:
javac Calculator.javacreatesCalculator.class. - JRE / JVM:
java Calculatorstarts the JVM. - The class loader loads
Calculatorand the library classes it uses. - The verifier checks the bytecode.
- The interpreter starts running
main; hot code is JIT-compiled. - The garbage collector cleans up unused objects while the program runs.
javac Calculator.java # JDK tool: compile
java Calculator # JVM: run
javap -c Calculator # JDK tool: show bytecode
java -version # which JDK/JVM is installed
8. JDK vs JRE vs JVM: Comparison
| Aspect | JDK | JRE | JVM |
|---|---|---|---|
| Full form | Java Development Kit | Java Runtime Environment | Java Virtual Machine |
| Purpose | Develop and run Java programs | Run Java programs | Execute bytecode |
| Contains | JRE + development tools | JVM + class libraries | Class loader, memory areas, execution engine |
Includes compiler (javac) | Yes | No | No (contains the JIT compiler only) |
| Who needs it | Developers | Users running Java apps | Part of both |
| Platform-specific | Yes | Yes | Yes |
9. Building a Small Runtime with jlink
Instead of installing a full JDK on a server, you can create a trimmed runtime that contains only the modules your application uses:
# Which modules does my app need?
jdeps --print-module-deps app.jar
# Build a runtime with just those modules
jlink --add-modules java.base,java.sql --output my-runtime --strip-debug --no-header-files --no-man-pages
# Run the app with the custom runtime
my-runtime/bin/java -jar app.jar
This is how modern container images keep Java applications small.
10. Java Version Improvements and Java 25 Updates
The JDK, JRE and JVM roles are unchanged, but recent releases improved how the JVM starts, uses memory and is packaged. All items below are standard features:
| Feature | Java version | What it changes |
|---|---|---|
jlink and the module system | Java 9 | Build custom runtimes instead of shipping a full JRE. |
| Single-file source launcher | Java 11 | java Hello.java compiles in memory and runs. |
| AOT class loading and linking | Java 24 | An AOT cache from a training run lets the JVM start faster. |
| AOT command-line ergonomics | Java 25 | Create the cache in one step with -XX:AOTCacheOutput. |
| AOT method profiling | Java 25 | The cache also stores method profiles, so the JIT compiler warms up sooner. |
| Compact object headers | Java 25 | Product feature (off by default): -XX:+UseCompactObjectHeaders shrinks object headers to reduce heap use. |
Example: Faster Start-up with an AOT Cache
An AOT (ahead-of-time) cache stores classes that the JVM has already loaded and linked during a training run. Later runs read them from the cache instead of repeating that work:
javac -d classes Calculator.java
jar --create --file calc.jar --main-class Calculator -C classes .
# 1. Training run: runs the app, then writes the AOT cache (Java 25 one-step form)
java -XX:AOTCacheOutput=app.aot -jar calc.jar
# 2. Later runs: load and link classes from the cache for a faster start
java -XX:AOTCache=app.aot -jar calc.jar
2 + 3 = 5
The training run prints the program's output and a few lines about creating app.aot. Both runs must use the same JDK version and the same class path, and the class path must contain JAR files only; a folder of .class files is rejected when the cache is created. The time saved is small for a tiny program but grows with the number of classes an application loads.
11. Summary
- The JVM loads, verifies and runs bytecode, manages memory and JIT-compiles hot code.
- The JRE is the JVM plus the class libraries needed to run programs.
- The JDK is the JRE plus development tools such as
javac,jar,jshellandjlink. - All three are platform-specific; the bytecode they run is not.
- Since Java 11, Oracle ships only the JDK; use
jlinkto build a small runtime (some vendors still offer JRE packages).
Related Tutorials
12. Official Java Documentation References
- The Java Virtual Machine Specification, Java SE 25 Edition
- JVMS §2.5: Run-Time Data Areas
- JVMS §4.10: Verification of class Files
- JVMS §5.3: Creation and Loading
- Java Virtual Machine Guide (Java SE 25)
- HotSpot Virtual Machine Garbage Collection Tuning Guide (Java SE 25)
- The java Command (Java SE 25)
- The javap Command (Java SE 25)
- The jlink Command (Java SE 25)
- The jdeps Command (Java SE 25)
- java.lang.ClassLoader (Java SE 25 API)
- JEP 483: Ahead-of-Time Class Loading & Linking
- JEP 514: Ahead-of-Time Command-Line Ergonomics
- JEP 515: Ahead-of-Time Method Profiling
- JEP 519: Compact Object Headers