JDK, JRE, and JVM – Complete Guide with Architecture, Examples, and Differences
Learn the difference between JDK, JRE, and JVM, their roles in Java development, how Java code executes, and understand the Java execution hierarchy with examples and diagrams.
JDK, JRE, and JVM – Complete Detailed Tutorial
Understanding JDK, JRE, and JVM is essential for every Java developer. These three components define how Java code is written, compiled, and executed.
1. What is JVM (Java Virtual Machine)?
JVM is the engine that executes Java bytecode. It is platform-dependent but runs bytecode on any OS through its runtime environment.
Key Roles of JVM
- Loads class files (
.class) - Verifies the bytecode
- Executes bytecode
1.1 JVM Architecture
JVM consists of several components:
- Class Loader Subsystem
- Loads
.classfiles at runtime. - Supports dynamic class loading.
- Runtime Data Areas
- Method Area: Stores class structures, constants, method info
- Heap: Stores objects
- Stack: Stores frames for method calls
- PC Register: Points to current instruction
- Native Method Stack: Stores native method information
- Execution Engine
- Interpreter: Reads bytecode line by line
- JIT Compiler: Converts bytecode to native machine code for faster execution
- Garbage Collector: Frees unused memory automatically
1.2 JVM Bytecode Execution Flow
Key Points:
- JVM is platform-dependent.
- Bytecode is platform-independent.
- Enables WORA (Write Once, Run Anywhere).
2. What is JRE (Java Runtime Environment)?
JRE provides the environment to run Java applications.
Components of JRE
- JVM → Executes bytecode
- Core Libraries → Predefined Java classes (
java.lang,java.util) - Runtime Environment → Supports Java program execution
Key Point
- JRE cannot compile Java programs.
- Required only for running Java applications, not developing.
3. What is JDK (Java Development Kit)?
JDK is a full software development kit for Java.
It contains:
- JRE → To run Java programs
- JVM → To execute bytecode
- Development Tools:
javac→ Compilerjava→ Launcherjavadoc→ Documentationjar→ Packaging tooljdb→ Debugger
Use Case
- Developers need JDK to write, compile, and run Java programs.
- Users only need JRE to run Java programs.
4. Relationship Between JDK, JRE, and JVM
- JDK → Tools for developers (compile + run)
- JRE → Runtime environment (run programs only)
- JVM → Executes bytecode
Example Analogy: Making Tea
| ComponentAnalogy | |
| JVM | Stove that executes the tea-making process |
| JRE | Stove + ingredients + utensils (ready environment to make tea) |
| JDK | Everything in JRE + tools to prepare tea (for development) |
5. Key Differences – JDK vs JRE vs JVM
| FeatureJDKJREJVM | |||
| Full Form | Java Development Kit | Java Runtime Environment | Java Virtual Machine |
| Purpose | Development + Execution | Execution only | Executes bytecode |
| Contains | JRE + Tools | JVM + Libraries | Bytecode interpreter & execution engine |
| Tools | javac, jar, javadoc | None | None |
| Who Uses | Developers | End users | Both |
6. Example of Compilation & Execution
Step 1: Write Java Code
Step 2: Compile with JDK
- Creates
Hello.class(bytecode)
Step 3: Run with JRE/JVM
- JVM executes bytecode and prints output.
7. Summary
- JVM: Executes bytecode (platform-dependent)
- JRE: Provides environment to run Java programs
- JDK: Contains JRE + tools to develop Java programs
Key Concept:
- JDK → Development + Runtime
- JRE → Runtime
- JVM → Execution