Computer Science · College · BCA, BTech & MCA
Java Architecture: JVM, JRE, JDK, Memory Areas & Garbage Collection
In-depth guide to Java runtime internals: JDK vs JRE vs JVM, the ClassLoader subsystem, JVM Memory Areas (Heap, Stack, Metaspace), and Generational Garbage Collection.
1JDK vs JRE vs JVM & The "Write Once, Run Anywhere" Philosophy
Java Architecture: JVM, JRE, JDK, Memory Areas & Garbage Collection
In-depth guide to Java runtime internals: JDK vs JRE vs JVM, the ClassLoader subsystem, JVM Memory Areas (Heap, Stack, Metaspace), and Generational Garbage Collection.
- 1Subject — Computer Science
- 2Target Audience — BCA, BTech & MCA Students
- 3Topic Core — JDK vs JRE vs JVM, Memory Areas & Garbage Collection
Java’s platform independence stems from its two-stage execution architecture. The Java Compiler () compiles human-readable source code () into platform-neutralBytecode(). TheJava Virtual Machine (JVM)interprets and compiles this bytecode into native machine instructions on the target host hardware.
Architecture Hierarchy: JDK vs JRE vs JVM
| Component | Full Name | Contents / Inclusions | Primary Target Audience |
|---|---|---|---|
| JVM | Java Virtual Machine | Virtual execution engine: ClassLoader, Execution Engine (Interpreter + JIT Compiler), Garbage Collector | Abstract specification implemented by OS-specific binaries (HotSpot, OpenJ9) |
| JRE | Java Runtime Environment | JVM + Core Java Class Libraries (, , ) + Supporting native binaries | End users running compiled Java applications without authoring code |
| JDK | Java Development Kit | JRE + Development Tools ( compiler, , debugger, packager) | Software engineers writing, debugging, and compiling Java software |
JVM
- Full Name
- Java Virtual Machine
- Contents / Inclusions
- Virtual execution engine: ClassLoader, Execution Engine (Interpreter + JIT Compiler), Garbage Collector
- Primary Target Audience
- Abstract specification implemented by OS-specific binaries (HotSpot, OpenJ9)
JRE
- Full Name
- Java Runtime Environment
- Contents / Inclusions
- JVM + Core Java Class Libraries (, , ) + Supporting native binaries
- Primary Target Audience
- End users running compiled Java applications without authoring code
JDK
- Full Name
- Java Development Kit
- Contents / Inclusions
- JRE + Development Tools ( compiler, , debugger, packager)
- Primary Target Audience
- Software engineers writing, debugging, and compiling Java software
2JVM Internal Memory Architecture (Runtime Data Areas)
When a Java application boots, the OS allocates process memory which the JVM partitions intofive distinct runtime data areas:
- Heap Area (Shared across all threads):Where all objects () and instance variables are allocated.
- Method Area / Metaspace (Shared across all threads):Stores class metadata, bytecode instructions, static variables, and runtime constant pool.
- JVM Stack (Thread-isolated):Created per thread; holds stack frames for active method calls (local variables, operand stack, return references).
- Program Counter (PC) Register (Thread-isolated):Holds memory address of the bytecode instruction currently being executed by the thread.
- Native Method Stack (Thread-isolated):Manages native C/C++ method invocations via Java Native Interface (JNI).
Java Execution & Compilation Pipeline
- 1
Source File (.java)
Human readable Java source code created by developer
- 2
javac Compiler
Syntactic & semantic analysis compiles source into platform-neutral Bytecode (.class)
- 3
ClassLoader Subsystem
Loading (Bootstrap/Extension/Application), Linking (Verification/Preparation/Resolution), and Initialization
- 4
JVM Memory Areas
Heap, Method Area (Metaspace), Stack Frames allocated in RAM
- 5
Execution Engine & JIT
Interpreter executes bytecode line-by-line; Just-In-Time (JIT) compiler compiles frequently executed "hotspots" into native machine code
3Generational Garbage Collection (GC) Mechanics
Definition
Garbage Collection (GC) — The automated background process in the JVM that identifies and deallocates memory occupied by unreferenced objects on the Heap that can no longer be reached from any active GC Root.
Generational Heap Memory Layout
| Heap Generation | Sub-Regions | Object Lifespan | Garbage Collector Action |
|---|---|---|---|
| Young Generation | Eden Space, Survivor 0 (S0), Survivor 1 (S1) | Short-lived objects (over 90% die young) | Minor GC (fast, frequent stop-the-world pauses) |
| Old / Tenured Generation | Single contiguous Old Space | Long-lived objects that survived multiple Minor GC age thresholds (e.g. 15 tenuring cycles) | Major GC / Full GC (more intensive, compacts memory to prevent fragmentation) |
| Metaspace (Off-Heap since Java 8) | Native system memory | Loaded class metadata, annotations, method bytecode | Replaced PermGen; automatically resizes to prevent java.lang.OutOfMemoryError: PermGen space |
Young Generation
- Sub-Regions
- Eden Space, Survivor 0 (S0), Survivor 1 (S1)
- Object Lifespan
- Short-lived objects (over 90% die young)
- Garbage Collector Action
- Minor GC (fast, frequent stop-the-world pauses)
Old / Tenured Generation
- Sub-Regions
- Single contiguous Old Space
- Object Lifespan
- Long-lived objects that survived multiple Minor GC age thresholds (e.g. 15 tenuring cycles)
- Garbage Collector Action
- Major GC / Full GC (more intensive, compacts memory to prevent fragmentation)
Metaspace (Off-Heap since Java 8)
- Sub-Regions
- Native system memory
- Object Lifespan
- Loaded class metadata, annotations, method bytecode
- Garbage Collector Action
- Replaced PermGen; automatically resizes to prevent java.lang.OutOfMemoryError: PermGen space
Remember
- Bytecode (.class) provides platform neutrality; the JVM translates it into host-specific machine code.
- JDK contains JRE and development tools; JRE contains JVM and runtime class libraries.
- JVM Heap and Metaspace are shared across all threads; Stack, PC Register, and Native Stack are strictly per-thread.
- Generational Garbage Collection splits heap into Young and Old generations to maximize deallocation throughput.
Check yourself
Question 1
In which JVM memory area are local primitive variables created inside a method stored?Question 2
What is the role of the Just-In-Time (JIT) compiler within the JVM execution engine?