JDK vs JRE vs JVM in Java
In this lesson: Understand JDK, JRE and JVM — what each does, how they fit together and which one you need — with diagram and table.
Three key pieces
To understand Java, you need three names: JVM, JRE and JDK. They sound similar but do different jobs. In short: the JVM runs your code, the JRE lets you run Java, and the JDK lets you write Java. They are nested inside each other.
JVM — the engine
The Java Virtual Machine is the engine that runs Java bytecode (the compiled form of your code). It reads bytecode and executes it on your device. Because each operating system has its own JVM, the same bytecode runs on Windows, Mac and Linux — the heart of "write once, run anywhere".
JRE — to run Java
The Java Runtime Environment is everything needed to run a Java program. It includes the JVM plus the standard libraries your program uses. If you only want to run finished Java apps and not write them, the JRE is enough.
JDK — to write Java
The Java Development Kit is everything needed to write and compile Java. It includes the JRE plus developer tools — most importantly the compiler javac, which turns your .java code into bytecode. Learners and developers install the JDK.
javac Hello.java // JDK's compiler makes bytecode java Hello // JRE's JVM runs it
How they fit together
Think of them as boxes inside boxes:
JDK (write + compile + run)
└── JRE (run)
└── JVM (execute bytecode)
The JDK is the biggest — it contains the JRE, which contains the JVM. So installing the JDK automatically gives you the JRE and the JVM too.
Quick comparison
| Part | Purpose | Contains | Who needs it |
|---|---|---|---|
| JVM | Runs bytecode | The engine | Everyone (inside JRE) |
| JRE | Run Java apps | JVM + libraries | Users running Java |
| JDK | Write + compile | JRE + tools | Developers, learners |
Common mistakes
- Installing only the JRE to code. You need the JDK to compile with
javac. - Thinking they are separate downloads to combine. The JDK already includes JRE and JVM.
- Confusing the JVM with the whole of Java. The JVM is just the execution engine.
- Expecting bytecode to run without a JVM. Every device needs a JVM to run Java.
Summary
- JVM runs Java bytecode and makes Java platform-independent.
- JRE = JVM + libraries, enough to run Java programs.
- JDK = JRE + tools (like the compiler), needed to write Java.
- They nest: JDK contains JRE contains JVM.
- Install the JDK to get all three for development.
Next, set up the JDK in the Java setup guide, or write your first program in Hello World.
