Java JDK JRE and JVM
Java programs need three parts to build and run: the JDK, the JRE, and the JVM. Each part has one clear job. Beginners often mix up the three names, so this lesson separates them with simple pictures.
A Food Truck Example
Picture a food truck business. A workshop builds the truck and stores every cooking tool. The truck carries equipment and serves customers. A stove inside the truck heats the food.
- JDK works like the workshop
- JRE works like the truck
- JVM works like the stove
The Three Parts Explained
JVM (Java Virtual Machine)
The JVM runs your compiled Java program. It reads bytecode, a middle-level language that sits between your code and the computer, and turns it into instructions that your machine understands. Windows, Mac, and Linux each have their own JVM. Your program stays the same on all three systems. This idea gives Java its famous promise: write once, run anywhere.
JRE (Java Runtime Environment)
The JRE holds the JVM and the ready-made Java libraries. Libraries include classes such as String, ArrayList, and Math. A person who only wants to run a Java application needs the JRE and nothing more.
JDK (Java Development Kit)
The JDK holds the JRE and the tools that developers use. The most important tool is javac, the compiler that converts your source code into bytecode. The JDK ships the java launcher, the jar packaging tool, the javadoc documentation tool, and the jdb debugger. Every Java learner installs the JDK.
Diagram: Boxes Inside Boxes
Each part sits inside the bigger one.
+--------------------------------------------------+ | JDK (Java Development Kit) | | Tools: javac, jar, javadoc, jdb | | | | +------------------------------------------+ | | | JRE (Java Runtime Environment) | | | | Libraries: String, ArrayList, Math | | | | | | | | +----------------------------------+ | | | | | JVM (Java Virtual Machine) | | | | | | Runs bytecode | | | | | +----------------------------------+ | | | +------------------------------------------+ | +--------------------------------------------------+
How a Program Travels
A Java file passes through several stages before it prints anything. The diagram below shows the full trip.
Hello.java (you write this)
|
| javac compiler (part of JDK)
v
Hello.class (bytecode)
|
| JVM (part of JRE)
v
+-----------+ +-----------+ +-----------+
| Windows | | Mac | | Linux |
| Output | | Output | | Output |
+-----------+ +-----------+ +-----------+
The compiler runs once. The JVM runs every time you start the program.
Check Your Installation
Open a terminal or command prompt and type these two commands.
java -version javac -version
The first command shows the runtime version. The second command shows the compiler version. A message like "javac is not recognized" means the JDK is missing or the PATH setting needs a fix.
Which One Should You Install
| Part | Contains | Who Needs It |
|---|---|---|
| JVM | Bytecode runner | Comes inside the JRE and JDK |
| JRE | JVM + libraries | People who only run Java apps |
| JDK | JRE + developer tools | Students and developers |
Recent Java versions ship the runtime inside the JDK, so most learners download a single JDK package and get everything.
Common Mistakes
- Installing only the runtime and wondering why javac fails
- Installing several JDK versions and running the wrong one
- Forgetting to restart the terminal after changing the PATH
Quick Summary
- JVM runs bytecode
- JRE bundles the JVM with libraries
- JDK bundles the JRE with developer tools
- Learners install the JDK
