Difference Between JDK, JRE and JVM

Naveen AnamaneniUpdated · 7 min read

Think of a restaurant. The kitchen is where food is made: it has chefs, tools and ingredients. The dining hall is where food is served and eaten, and it needs only tables and waiters. The kitchen also contains a serving counter, so you could eat there too. Java's three letters work the same way: the JDK is the kitchen for building programs, the JRE is what you need to run them, and the JVM is the engine at the center of both.

Three Boxes, One Inside the Other

JDK = JRE + development tools; JRE = JVM + class library
JVMJREJDK
Full nameJava Virtual MachineJava Runtime EnvironmentJava Development Kit
What it isThe engine that runs bytecodeEverything needed to run Java programsEverything needed to write and run Java programs
ContainsClass loader, memory areas, execution engineThe JVM + the Java class libraryThe JRE + development tools
Tools you getNone you run directlyjavajava, javac, jshell, javap, jar, jdb and more
Who needs itComes inside the other twoUsers who only run Java programsDevelopers: you

The JVM: The Engine

The JVM is the part that actually runs your program. It loads .class files, checks the bytecode, runs it with the interpreter and the JIT compiler, and frees memory with the garbage collector.

On its own, the JVM can't do much: it doesn't know what a String or an ArrayList is. Those come from the class library. That's why you never download "just a JVM". The next two lessons look inside it.

The JRE: Enough to Run Programs

The JRE is the JVM plus the Java class library: the thousands of ready-made classes in packages such as java.lang, java.util, java.io and java.time. With a JRE you can run any compiled Java program, but you can't compile one, because it has no javac.

Here's a program that uses only a few of those library classes, and asks the running JVM about itself:

WhatRunsMe.java▶ Try it
public class WhatRunsMe {
    public static void main(String[] args) {
        String vm = System.getProperty("java.vm.name");
        String spec = System.getProperty("java.specification.version");
        String classVersion = System.getProperty("java.class.version");
 
        System.out.println("JVM: " + vm);
        System.out.println("Java SE version: " + spec);
        System.out.println("Class file version: " + classVersion);
    }
}
Output
JVM: OpenJDK 64-Bit Server VM
Java SE version: 25
Class file version: 69.0

How it works

  1. Line 3 asks for the name of the JVM. "OpenJDK 64-Bit Server VM" is HotSpot, the JVM inside almost every JDK.
  2. Line 4 asks which Java SE version this runtime implements.
  3. Line 5 asks for the newest class file version it can run: 69 means Java 25. The lesson "Bytecode and Platform Independence" explains these numbers.

Try it yourself: run it with a different JDK if you have one installed, for example Java 17. Which of the three lines change?

The JDK: Everything for Developers

The JDK is the JRE plus the tools you use to build programs. You've already met several of them:

ToolWhat it doesLesson
javacCompiles .java files to bytecodeCompiling and Running from the Command Line
javaStarts the JVM and runs a programJava Hello World Program
jshellRuns Java one line at a timeJShell (Interactive Java)
javapShows the bytecode inside a .class fileBytecode and Platform Independence
jarPacks classes into one .jar filePackaging, later in the course
jdbA command-line debuggerUsing the Debugger
jlinkBuilds a small custom runtime for one applicationPackaging, later in the course

As a developer, always install the JDK. It contains everything the JRE has, so you can both build and run.

What Happened to the JRE?

Until Java 8, Oracle offered two downloads: a JDK for developers and a smaller JRE for everyone else. Since Java 11, Oracle no longer ships a separate JRE. Today, applications are usually delivered with their own runtime, built with jlink, or run inside a container image. Some distributions, such as Eclipse Temurin, still offer JRE downloads for convenience.

The idea of a JRE, "the JVM plus the class library", is still exactly how Java is organized. That's why interviewers still ask about it.

Common Mistakes

Saying the JVM compiles Java code. javac, part of the JDK, compiles source code to bytecode. The JVM runs the bytecode, using its JIT compiler to turn hot bytecode into machine code.

Thinking the JDK and JRE run code differently. A program behaves the same whether it runs from a JDK or a JRE; both contain the same JVM and class library.

Saying "JVM is platform independent". The bytecode is platform independent. Each operating system needs its own JVM, JRE and JDK.

Interview Corner

What is the difference between JDK, JRE and JVM?

The JVM runs bytecode: it loads, verifies and executes classes and manages memory. The JRE is the JVM plus the Java class library, so it can run Java programs. The JDK is the JRE plus development tools such as javac, jshell and javap, so it can build and run them. In short: JDK = JRE + tools, JRE = JVM + libraries.

Can you run a Java program with only a JRE? Can you compile one?

You can run a compiled program, because the JRE has the JVM and the class library. You can't compile, because javac is only in the JDK.

Is the JVM platform independent?

No. Each operating system and processor needs its own JVM. The bytecode is what's platform independent: the same .class file runs on every JVM.

Practice

  1. Easy: Without looking, draw the three nested boxes and write two things that belong in each layer.
  2. Harder: Open the bin folder of your JDK and find three tools that aren't in the table above. Run each with --help and write one sentence about what it does.

Quick check: JDK, JRE and JVM

4 questions
1Which one contains javac?
2What is the JRE made of?
3Which part actually executes bytecode?
4Which statement is true today?

Key Takeaways

Was this tutorial helpful?

Lesson 22 of 482