Skip to main content

JDK vs JRE vs JVM

Reading Time: 7 Minutes
Difficulty: Beginner


Topic Summaryโ€‹

JDK, JRE, and JVM are three key components of the Java ecosystem. Every Java program needs all three to work. Understanding the difference helps you know what to install and how Java programs actually run on your computer.


What You'll Learnโ€‹

  • What JVM is and what it does
  • What JRE is and what it contains
  • What JDK is and what extras it provides
  • How JDK, JRE, and JVM relate to each other
  • When you need each one

Prerequisitesโ€‹

  • Lesson 001 โ€” What is Java
  • Lesson 003 โ€” Features of Java (platform independence concept)

Explanationโ€‹

JVM โ€” Java Virtual Machineโ€‹

The JVM (Java Virtual Machine) is the most fundamental piece. It is a virtual computer inside your real computer. Its job is to:

  1. Load the compiled Java bytecode (.class files)
  2. Verify the bytecode is safe to run
  3. Execute the bytecode โ€” running your Java program
  4. Manage memory โ€” garbage collection happens here

The JVM is what makes Java platform independent. Each operating system has its OWN version of JVM (Windows JVM, Mac JVM, Linux JVM), but they all understand the same bytecode. So you write once, the JVM runs it everywhere.

Key point: The JVM does NOT understand Java source code (.java files). It only understands bytecode (.class files).

What's inside JVM?โ€‹

  • Class Loader โ€” loads your .class files into memory
  • Bytecode Verifier โ€” checks the code is valid and safe
  • Interpreter โ€” executes bytecode instructions
  • JIT Compiler โ€” compiles hot bytecode to native machine code for speed
  • Garbage Collector โ€” frees unused memory automatically

JRE โ€” Java Runtime Environmentโ€‹

The JRE (Java Runtime Environment) is everything you need to RUN a Java program. It contains:

  • โœ… The JVM (to execute bytecode)
  • โœ… Java standard libraries (pre-written classes like String, Math, ArrayList)
  • โœ… Supporting files and configuration

If you just want to RUN Java programs (not write them), you install the JRE. For example, a user who just wants to play a Java game โ€” they need JRE, not JDK.

Note: Since Java 11, Oracle no longer ships a standalone JRE download. The JDK includes the JRE functionality. For Java 11+, just install the JDK.


JDK โ€” Java Development Kitโ€‹

The JDK (Java Development Kit) is everything you need to WRITE, COMPILE, AND RUN Java programs. It contains:

  • โœ… Everything in JRE (which includes JVM)
  • โœ… javac โ€” the Java compiler (turns .java โ†’ .class)
  • โœ… javadoc โ€” generates documentation from comments
  • โœ… jar โ€” creates JAR archive files
  • โœ… jdb โ€” Java debugger
  • โœ… jshell โ€” interactive Java REPL (since Java 9)
  • โœ… Other development tools

If you want to WRITE Java programs, you need the JDK. Always install JDK as a developer.


The Relationship โ€” Nested Like Boxesโ€‹

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ JDK โ”‚
โ”‚ (Java Development Kit) โ”‚
โ”‚ โ”‚
โ”‚ javac, javadoc, jar, jdb, jshell... โ”‚
โ”‚ โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ JRE โ”‚ โ”‚
โ”‚ โ”‚ (Java Runtime Environment) โ”‚ โ”‚
โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ Java Standard Libraries โ”‚ โ”‚
โ”‚ โ”‚ (java.lang, java.util, etc.) โ”‚ โ”‚
โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚
โ”‚ โ”‚ โ”‚ JVM โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ โ”‚ (Java Virtual Machine) โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ โ”‚ Class Loader โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ โ”‚ Bytecode Verifier โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ โ”‚ Interpreter + JIT โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ โ”‚ Garbage Collector โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Think of it as nested Russian dolls โ€” JVM is inside JRE, JRE is inside JDK.


Quick Comparison Tableโ€‹

JVMJREJDK
Full NameJava Virtual MachineJava Runtime EnvironmentJava Development Kit
PurposeExecute bytecodeRun Java programsDevelop Java programs
ContainsInterpreter, JIT, GCJVM + LibrariesJRE + javac + tools
Who needs it?(part of JRE)End usersDevelopers
Can compile Java?โŒ NoโŒ Noโœ… Yes
Can run Java?โœ… Yesโœ… Yesโœ… Yes

How They Work Togetherโ€‹

When you write and run a Java program:

Step 1: You write HelloWorld.java
Step 2: JDK's javac compiles it โ†’ HelloWorld.class (bytecode)
Step 3: JRE's class loader loads HelloWorld.class
Step 4: JVM executes the bytecode โ†’ Output appears!

Real-World Analogyโ€‹

Imagine you're in the film industry:

  • ๐ŸŽฌ JVM = The movie projector. It knows how to play films (bytecode). But it needs the right film reel format. It can't CREATE films, only show them.

  • ๐ŸŽž๏ธ JRE = The cinema (projector + screen + seats + sound system). Everything needed to watch a movie. Audiences (end users) need this.

  • ๐ŸŽฅ JDK = The full film studio (cinema + cameras + editing tools + scriptwriting software). Directors (developers) need this to CREATE films and show them too.

A moviegoer just needs the cinema (JRE). A filmmaker needs the full studio (JDK).


Code Exampleโ€‹

// This program demonstrates what the JDK, JRE, and JVM do

public class JdkJreJvm {
public static void main(String[] args) {

// The JDK compiled this file using javac
// The JRE loaded Java standard libraries like System, String
// The JVM is executing THIS line right now!

System.out.println("=== Understanding JDK, JRE, JVM ===\n");

System.out.println("JVM โ†’ Executes bytecode (this program runs ON the JVM)");
System.out.println("JRE โ†’ JVM + Standard Libraries (String, System, Math...)");
System.out.println("JDK โ†’ JRE + javac + javadoc + jar + dev tools");

// Using JRE's standard library (Math class)
double result = Math.sqrt(144);
System.out.println("\nMath.sqrt(144) = " + result);
// Math is part of JRE's standard library!

// JVM information at runtime
System.out.println("\n--- Your JVM Info ---");
System.out.println("Java Version: " + System.getProperty("java.version"));
System.out.println("JVM Name: " + System.getProperty("java.vm.name"));
System.out.println("OS: " + System.getProperty("os.name"));
}
}

Outputโ€‹

=== Understanding JDK, JRE, JVM ===

JVM โ†’ Executes bytecode (this program runs ON the JVM)
JRE โ†’ JVM + Standard Libraries (String, System, Math...)
JDK โ†’ JRE + javac + javadoc + jar + dev tools

Math.sqrt(144) = 12.0

--- Your JVM Info ---
Java Version: 21.0.1
JVM Name: OpenJDK 64-Bit Server VM
OS: Windows 11

Common Mistakesโ€‹

  • โŒ Mistake: Installing JRE to write Java programs โ†’ โœ… Fix: Developers always need the JDK. JRE alone doesn't include javac (the compiler).
  • โŒ Mistake: Thinking JVM is the same on all platforms โ†’ โœ… Fix: Each OS has a different JVM implementation, but they all execute the same bytecode (that's the magic!).
  • โŒ Mistake: Confusing bytecode with machine code โ†’ โœ… Fix: Bytecode is an intermediate format only the JVM understands. Machine code is what your CPU directly executes.

Best Practicesโ€‹

  • As a developer, always install the JDK โ€” it includes everything
  • Use the latest LTS version of the JDK (currently JDK 21)
  • When deploying an app to a server, you might only need the JRE (or JDK โ€” both work)
  • Use java -version to check your Java version and javac -version to verify the compiler

Interview Questionsโ€‹

Q: What is the difference between JDK, JRE, and JVM?
A: JVM (Java Virtual Machine) executes bytecode. JRE (Java Runtime Environment) = JVM + standard libraries โ€” needed to run Java programs. JDK (Java Development Kit) = JRE + compiler (javac) + dev tools โ€” needed to develop Java programs.

Q: Is JVM platform dependent or independent?
A: The JVM itself is platform dependent (there's a Windows JVM, Mac JVM, etc.). But the bytecode that runs ON the JVM is platform independent. That's why "Write Once, Run Anywhere" works.

Q: Can you run Java without JDK?
A: Yes โ€” if you only want to run (not develop) Java programs, you need only the JRE (which contains the JVM). However, to compile and develop, you need the full JDK.

Q: What is the JIT compiler?
A: JIT (Just-In-Time) compiler is part of the JVM. It monitors which bytecode is executed frequently (hot code) and compiles that to native machine code for faster execution, giving Java near-native performance.


Quick Revisionโ€‹

โœ” JVM = Java Virtual Machine โ€” executes bytecode, inside JRE
โœ” JRE = JVM + standard libraries โ€” runs Java programs
โœ” JDK = JRE + javac + dev tools โ€” develops Java programs
โœ” JVM is platform dependent, bytecode is platform independent
โœ” Developers install JDK; end users (historically) needed JRE
โœ” JDK 11+ bundles everything โ€” just install the JDK


  • Java Program Execution Flow (Lesson 005)
  • Installing Java (Lesson 006)
  • Features of Java โ€” Platform Independence (Lesson 003)

Next Lessonโ€‹

Lesson 005 โ€” Java Program Execution Flow