JVM Architecture
Every Java program runs on the Java Virtual Machine (JVM). Understanding the JVM is what separates a Java user from a Java expert. When your application has memory leaks, GC pauses, or performance issues, JVM knowledge is what helps you diagnose and fix them.
In this chapter, you’ll learn the JVM’s architecture — the components that make Java’s “Write Once, Run Anywhere” promise possible.
JDK vs JRE vs JVM
┌─────────────────────────────────────────────┐
│ JDK (Java Development Kit) │
│ ┌────────────────────────────────────────┐ │
│ │ JRE (Java Runtime Environment) │ │
│ │ ┌─────────────────────────────────┐ │ │
│ │ │ JVM (Java Virtual Machine) │ │ │
│ │ │ • Class Loader │ │ │
│ │ │ • Runtime Data Areas │ │ │
│ │ │ • Execution Engine │ │ │
│ │ └─────────────────────────────────┘ │ │
│ │ + Core Libraries (java.lang, etc.) │ │
│ └────────────────────────────────────────┘ │
│ + Dev Tools (javac, jdb, jconsole, etc.) │
└─────────────────────────────────────────────┘
- JVM — runs bytecode
- JRE — JVM + standard libraries (enough to run Java apps)
- JDK — JRE + development tools (needed to develop Java apps)
JVM Components
1. Class Loader Subsystem
Loads .class files into memory. Three phases: Loading → Linking → Initialization.
2. Runtime Data Areas
Memory areas used during execution:
- Heap — object storage (shared across all threads)
- Stack — per-thread method call frames and local variables
- Method Area / Metaspace — class metadata, constant pool
- Program Counter — per-thread, tracks current instruction
- Native Method Stack — for native (C/C++) method calls
3. Execution Engine
Executes bytecode:
- Interpreter — executes bytecode line by line (slow but starts fast)
- JIT Compiler — compiles hot methods to native code (fast execution)
- Garbage Collector — reclaims unused memory automatically
How Java Achieves Platform Independence
javac JVM
Source Code ──────────────▶ Bytecode ──────────────▶ Native Code
(Hello.java) (Hello.class) (platform-specific)
Same .class file runs on:
├── Windows JVM
├── macOS JVM
└── Linux JVM
You write code once. The compiler (javac) produces bytecode — a platform-neutral intermediate format. The JVM on each platform translates bytecode to native machine code.
What’s Next?
In the next chapter, you’ll learn how the Class Loading mechanism works — bootstrap, extension, and application class loaders.