Home/Learn/Java A–Z/JVM, JDK & JRE

JVM, JDK & JRE

Beginner
Java Fundamentals

Understand the three pillars of Java: JRE runs programs, JDK develops them, and the JVM executes bytecode on any platform.

Overview

Java's "Write Once, Run Anywhere" promise is powered by three components. The JDK (Java Development Kit) contains everything needed to write and compile code. The JRE (Java Runtime Environment) provides the libraries and JVM to run compiled programs. The JVM (Java Virtual Machine) is the engine that interprets or JIT-compiles bytecode into native instructions — and it's why the same .class file runs on Windows, macOS, and Linux without recompilation.

JDK, JRE & JVM — The Hierarchy

Think of them as nested sets: JDK ⊃ JRE ⊃ JVM.

The JDK ships with the Java compiler (javac), debugger (jdb), documentation generator (javadoc), and a full JRE. The JRE bundles the standard class libraries (java.lang, java.util, java.io, etc.) plus the JVM itself. The JVM alone loads and executes .class bytecode files.

From Java 9 onward, Oracle stopped shipping a standalone JRE. Instead, use jlink to package a minimal custom runtime containing only the modules your application needs.

HelloWorld.java
// Step 1: Compile source to bytecode
//   javac HelloWorld.java  →  produces HelloWorld.class

// Step 2: JVM executes the bytecode
//   java HelloWorld

public class HelloWorld {
    public static void main(String[] args) {
        // Print JVM details at runtime
        System.out.println("Java version : " + System.getProperty("java.version"));
        System.out.println("JVM name     : " + System.getProperty("java.vm.name"));
        System.out.println("Running on   : " + System.getProperty("os.name"));
    }
}

JVM Architecture

The JVM has three major subsystems:

1. ClassLoader Subsystem — loads, links, and initialises .class files. Follows parent-delegation: Bootstrap ClassLoader (core Java classes from rt.jar / jmods) → Extension/Platform ClassLoader → Application ClassLoader (your classpath).

2. Runtime Data Areas — Method Area stores class metadata and static fields (shared). Heap stores all objects (shared). Each thread owns a JVM Stack (stack frames for method calls), a PC Register (current instruction pointer), and a Native Method Stack (JNI calls).

3. Execution Engine — Interpreter runs bytecode line by line initially. JIT Compiler profiles "hot" code and compiles it to optimised native machine code. Garbage Collector reclaims unreachable heap objects automatically.

JvmMemoryInfo.java
public class JvmMemoryInfo {
    public static void main(String[] args) {
        Runtime rt = Runtime.getRuntime();
        long mb = 1024L * 1024L;

        System.out.printf("Available CPUs : %d%n",   rt.availableProcessors());
        System.out.printf("Max heap       : %d MB%n", rt.maxMemory()   / mb);
        System.out.printf("Total heap     : %d MB%n", rt.totalMemory() / mb);
        System.out.printf("Free heap      : %d MB%n", rt.freeMemory()  / mb);

        // Suggest a GC cycle — not guaranteed to run immediately
        System.gc();
    }
}

JIT Compilation & Bytecode

javac compiles your .java source into platform-neutral bytecode stored in .class files. Every compliant JVM (on any OS or CPU) understands the same bytecode instruction set — that's platform independence.

The JIT (Just-In-Time) compiler monitors execution and, after a method is called enough times (default threshold: 10 000), compiles it straight to native machine code. After warm-up, JIT-compiled Java routinely matches C/C++ throughput on server workloads.

Use javap -c ClassName to disassemble bytecode and see the raw opcodes.

javap bytecode output
// Inspect bytecode: javap -c HelloWorld
//
// public static void main(java.lang.String[]);
//   Code:
//      0: getstatic     #7   // Field java/lang/System.out
//      3: ldc           #13  // String "Hello"
//      5: invokevirtual #15  // Method println:(Ljava/lang/String;)V
//      8: return
//
// These opcodes are IDENTICAL regardless of whether you run
// on Windows x64, macOS ARM, or Linux on a mainframe.

Interactive Visualization

Class Loading
ClassLoader
Bootstrap CL
Platform CL
App CL
Method Area
Class metadata
Static fields
Constant pool
Heap
Young Gen (Eden)
Old Gen
Objects
JVM Stack
main() frame
Local vars
Operand stack
PC Register
Instruction ptr
JVM starts: ClassLoader loads .class bytecode into the Method Area.
1 / 6

Key Points to Remember

  • JDK ⊃ JRE ⊃ JVM — JDK for developing, JRE for running, JVM for executing bytecode
  • Java bytecode is platform-neutral; the JVM translates it to native code per platform
  • JIT compilation converts frequently-executed bytecode to native code for peak performance
  • Heap is shared across threads; each thread has its own Stack, PC Register, and Native Method Stack
  • Class loading uses parent delegation: Bootstrap → Platform → Application ClassLoader
  • From Java 9+, use jlink to create lean custom runtimes instead of shipping a full JRE

Practice JVM, JDK & JRE in the Playground

Run and modify code directly in your browser - no setup needed.

Interview Questions

Sign in to ask Aria
1

What is the difference between JDK, JRE, and JVM?

EasyTCS
2

How does the JIT compiler improve Java performance over a pure interpreter?

MediumAmazon
3

Explain the class loading mechanism and the parent delegation model

MediumOracle
4

What is the difference between stack memory and heap memory in the JVM?

MediumGoogle
5

How does Java achieve platform independence?

EasyInfosys

Ask Aria about JVM, JDK & JRE

Your personal AI tutor — ask anything about this concept