ReviseAlgo Logo

Introduction to Java

JDK, JRE, and JVM

A comprehensive breakdown of the Java Platform architecture, detailing the exact role of JDK, JRE, and the internals of the JVM.

Interview: Classic interview topic. Interviewers expect deep understanding of ClassLoaders, JIT compiler, Garbage Collection roots, and memory areas (Heap vs Stack).

Last Updated: June 13, 2026 12 min read

The execution of a Java application depends on three layered software structures: the JVM (Java Virtual Machine) which runs bytecode, the JRE (Java Runtime Environment) which packages the JVM with core class libraries, and the JDK (Java Development Kit) which adds dev tools.

Core Idea

JDK is for compiling and debugging; JRE is for running code; JVM is the engine that actually executes bytecodes.

Why It Matters

A developer needs to configure these environments, manage paths, inspect bytecode, and debug memory limits correctly in CI/CD.

Interview Lens

Frequently tested via JIT questions, ClassLoader hierarchies, and memory area divisions (Heap vs Stack).

Architectural Layers

To understand the Java runtime platform, analyze the nesting of the three major layers:

  • JDK (Java Development Kit): A software bundle that includes development tools like javac (compiler), jar (archiver), javadoc, jdb (debugger), and the JRE.
  • JRE (Java Runtime Environment): The minimum runtime dependencies. It consists of the JVM, core Java class libraries (like java.base), and resource configuration files. Note: stand-alone JREs are discontinued since JDK 11. Custom JREs are now generated using jlink.
  • JVM (Java Virtual Machine): An abstract specification that runs bytecode. It is the engine that executes compiled code.

In-Depth Relationship & JVM Subsystem Internals

The diagram depicts how the JDK, JRE, and JVM are nested. The JVM is the inner engine. JRE wraps this engine with the standard class library runtime files. JDK is the outer kit packaging everything with compile tools.

Within the JVM itself, execution relies on three core areas: the ClassLoader subsystem (which dynamically loads classes), the JVM memory layout (storing methods, stack frames, and heaps), and the execution engine. Understanding this hierarchy allows developers to configure memory bounds and troubleshoot class-loading conflicts effectively.

Deep Dive: JVM Architecture Internals

The JVM is broken into three main subsystems:

1. ClassLoader Subsystem

Handles loading of compiled .class files into memory. It follows a delegation hierarchy:

  • Bootstrap ClassLoader: Loads core APIs from the JDK library runtime.
  • Platform/Extension ClassLoader: Loads platform classes and JDK extension directories.
  • Application/System ClassLoader: Loads classes from the program's ClassPath or ModulePath.

Loading goes through three stages: Loading (reading byte stream), Linking (Verify bytecode, Prepare memory allocation for static fields, Resolve symbolic addresses), and Initialization (executing static initializers and assigning values to static variables).

2. JVM Memory Areas

  • Method Area (Metaspace): Stores class structures, metadata, constant pool, and static field values. Shared across threads.
  • Heap Area: Stores all allocated objects and arrays. Target of the Garbage Collector. Shared across threads.
  • JVM Stack: Thread-local memory storing Stack Frames. Each frame represents a method invocation containing local variables, parameters, and return locations.
  • PC Registers: Thread-local register storing the address of the bytecode instruction currently executing.
  • Native Method Stack: Thread-local stack to support native operations (written in C/C++ via JNI).

3. Execution Engine

Contains the Interpreter (translates bytecode line-by-line), the JIT Compiler (compiles active hotspots directly to machine code for speed), and the Garbage Collector (GC).

Common Pitfalls

  • StackOverflowError vs OutOfMemoryError:
    • StackOverflowError occurs when the JVM Stack runs out of space, typically due to infinite recursion.
    • OutOfMemoryError occurs when the Heap Area runs out of space, typically because your program keeps references to unused objects.
  • Setting Wrong Classpaths: If target classes or dependency jars are missing on the JVM launch classpath, the application will fail at runtime with a ClassNotFoundException.

Best Practices

  • Configure Memory Limits: Explicitly set memory options (-Xms for initial size, -Xmx for maximum size) on production JVMs to prevent applications from crashing the host container.
  • Use standard diagnostic tools: Leverage built-in utilities like jcmd, jstack, and jmap to analyze running JVM thread states and heap usage.

Interview-Relevant Information

Q1: What is Metaspace, and how is it different from the older PermGen?
Answer: Prior to Java 8, class metadata was stored in Permanent Generation (PermGen), which was of fixed size and caused frequent OutOfMemoryErrors. Metaspace replaced PermGen in Java 8; it dynamically allocates from local system memory, reducing metadata exhaustion issues.

Q2: Explain delegation hierarchy in ClassLoaders.
Answer: When a classloader receives a request to load a class, it delegates the search up to its parent classloader before searching its own path. Only if the parent cannot find the class does the child attempt to load it, preventing duplicate class loading and protecting core classes.

Q3: Stack vs Heap allocation. Where do local variables and objects live?
Answer: Local variables of primitive types and object reference addresses live on the JVM Stack (bound to a thread frame). The actual objects themselves reside in the Heap Area.

Quick Checklist

Can you draw the relationships between JDK, JRE, and JVM, describe the five JVM memory areas, and explain the delegation model of class loading? If yes, you have mastered this foundational architectural topic.

Use Cases

Configuring server start scripts with tailored JVM flags (-Xms, -Xmx, -XX:+UseG1GC).

Debugging OutOfMemoryError issues by analyzing heap dump files using profiling tools.

Creating lightweight deployment images using jlink to bundle a custom, minimal JRE.

Common Mistakes

Confusing JVM Stack (which stores method calls and local variables) with Heap Area (which stores objects).

Running applications on production without configuring container memory limits.