← Back to Home

JVM vs JRE vs JDK

Understanding JVM, JRE, and JDK is foundational to Core Java and a very common interview topic. They represent execution, runtime, and development layers of Java.

High-Level Difference (One-Line)

  • JVM → Runs Java bytecode
  • JRE → Provides runtime environment
  • JDK → Provides tools to develop Java applications

JVM (Java Virtual Machine)

What Is JVM?

The JVM is an abstract machine that executes Java bytecode. It enables platform independence by converting bytecode into native machine instructions.

Responsibilities

  • Loads bytecode (ClassLoader)
  • Verifies bytecode (Bytecode Verifier)
  • Executes bytecode (Interpreter / JIT Compiler)
  • Manages memory (Heap, Stack, Metaspace)
  • Handles Garbage Collection

Key Point

  • JVM is platform-dependent
  • JVM exists inside JRE
.java → javac → .class (bytecode) → JVM → OS
          

JRE (Java Runtime Environment)

What Is JRE?

The JRE provides the runtime environment required to run Java applications, but not to develop them.

What JRE Contains

  • JVM
  • Core Java libraries (java.lang, java.util, etc.)
  • Supporting files

Can You Compile Code with JRE?

  • ❌ No
  • ✔ You can run Java programs
  • ❌ You cannot compile Java programs

Use Case

  • End users
  • Production servers (runtime only)

JDK (Java Development Kit)

What Is JDK?

The JDK is a complete Java development package that includes tools for developing, compiling, debugging, and running Java applications.

What JDK Contains

  • JRE
  • Development tools:
    • javac (compiler)
    • java (launcher)
    • javadoc
    • javap
    • jshell
    • Debuggers and profilers

Can You Run Java Programs with JDK?

  • ✔ Yes
  • ✔ Can compile and run

Relationship Between JVM, JRE, and JDK

JDK
 └── JRE
      └── JVM
          
  • ✔ JVM is part of JRE
  • ✔ JRE is part of JDK

JVM vs JRE vs JDK (Interview Table)

Aspect JVM JRE JDK
Full form Java Virtual Machine Java Runtime Environment Java Development Kit
Purpose Executes bytecode Runs Java programs Develops Java programs
Contains JVM
Contains libraries
Contains compiler
Used by OS End users Developers

Compilation & Execution Flow (Interview Favorite)

Developer
  ↓
Write .java file
  ↓
javac (JDK)
  ↓
.class (bytecode)
  ↓
JVM (inside JRE)
  ↓
Machine code (OS)
          

Platform Dependency Clarification (Common Trap)

  • Java language → Platform independent
  • Bytecode → Platform independent
  • JVM → Platform dependent
  • JRE/JDK → Platform dependent

✔ This is how Java achieves Write Once, Run Anywhere

Common Interview Traps

  • ❌ JVM ≠ JRE
  • ❌ JRE cannot compile code
  • ❌ JDK is not just a compiler
  • ✔ JVM is not a physical machine

Interview-Ready Answers

Short Answer

JVM runs bytecode, JRE provides the runtime environment, and JDK provides development tools.

Detailed Answer

In Java, JVM is responsible for executing bytecode and managing memory, JRE provides the runtime environment including JVM and core libraries, and JDK is a complete development kit that includes JRE along with tools like the compiler and debugger used to develop Java applications.

Key Takeaway

JVM executes. JRE runs. JDK develops. Mastering this distinction is essential for Core Java interviews and real-world Java development.