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: Subject, Target Audience, Topic Core Full size

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.

  1. 1Subject — Computer Science
  2. 2Target Audience — BCA, BTech & MCA Students
  3. 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 (javac \text{javac}\ ) compiles human-readable source code (.java.java) into platform-neutralBytecode(.class.class). 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

  • 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 (rt.jarrt.jar, java .lang\text{java}\ .lang, java .util\text{java}\ .util) + 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 (javac \text{javac}\ compiler, javadoc \text{javadoc}\ , jdb \text{jdb}\ debugger, jar \text{jar}\ 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 (new Object()\text{new}\ Object()) 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. 1

    Source File (.java)

    Human readable Java source code created by developer

  2. 2

    javac Compiler

    Syntactic & semantic analysis compiles source into platform-neutral Bytecode (.class)

  3. 3

    ClassLoader Subsystem

    Loading (Bootstrap/Extension/Application), Linking (Verification/Preparation/Resolution), and Initialization

  4. 4

    JVM Memory Areas

    Heap, Method Area (Metaspace), Stack Frames allocated in RAM

  5. 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

  • 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
Exam tip: A GC Root is an anchor object accessible from outside the heap, including: local variables currently alive on thread call stacks, active Java threads, static variables in loaded classes, and JNI references.

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

  1. Question 1

    In which JVM memory area are local primitive variables created inside a method stored?
  2. Question 2

    What is the role of the Just-In-Time (JIT) compiler within the JVM execution engine?

Read it? Now test it. Timed exam questions on this topic, then a report on what to revise.

Take a test

Want a lesson on another topic? Type any topic or add a photo of your notes — get a lesson like this in seconds.

Learn a topic

More Computer Science explained