JDK vs JRE vs JVM - Differences Explained with Examples

Introduction

JDK vs JRE vs JVM is one of the first things that confuses anyone starting with Java - and one of the most common Java interview questions. This tutorial explains what each of the three is, what it contains, and how they fit inside each other. We will start with the JVM, then look at the JRE and the JDK. We will then see all three at work by compiling and running a small program, and look at the bytecode which the JVM actually runs. Lastly, we will compare the three side by side and see which one you need to install.

(Note - This tutorial is part of the Java Fundamentals series. If you are new to Java, start with What is Java?Click to read the first tutorial in the Java Fundamentals series, which explains bytecode and "Write Once, Run Anywhere".)

The short answer

The three are nested inside each other, like boxes inside boxes -
  • JVM (Java Virtual Machine): Runs Java bytecode.
  • JRE (Java Runtime Environment): The JVM plus the Java class libraries - everything needed to run a Java program.
  • JDK (Java Development Kit): The JRE plus development tools such as the compiler - everything needed to write, compile and run Java programs.
JDK = JRE + development tools
javac, jar, javadoc, jshell, jdb, javap, jlink ...
JRE = JVM + class libraries
java.lang, java.util, java.io, java.time ...
JVM
class loader · runtime memory areas · execution engine (interpreter, JIT compiler, garbage collector)
Let us now look at each of them, starting from the innermost box.

What is the JVM (Java Virtual Machine)?

The Java Virtual Machine is the program which runs Java bytecode. It is called a virtual machine because it behaves like a computer of its own - it has its own instruction set (bytecode), and its own way of managing memory. The JVM translates that bytecode into instructions for the real processor and operating system underneath.

The JVM is the reason Java programs are platform independent. Bytecode is the same everywhere, but the JVM is not - there is a separate JVM for Windows, Linux and macOS, on each type of processor. The JVM has three main parts -
  • Class loader subsystem: Finds .class files, loads them into memory, and verifies that the bytecode is valid and safe before it runs.
  • Runtime data areas: The memory the JVM manages while a program runs - the heap, where all objects live; a stack for every thread, which holds method calls and local variables; and the method area (called Metaspace in HotSpot), which holds class definitions.
  • Execution engine: Runs the bytecode. An interpreter runs the bytecode instruction by instruction, and the JIT (Just-In-Time) compiler compiles frequently used methods into native machine code for speed. The garbage collector, also part of the execution engine, frees memory used by objects which are no longer needed.
Note - "JVM" is both a specification and an implementation. The JVM Specification describes how any JVM must behave. HotSpot, which comes with OpenJDK and Oracle's JDK, is by far the most widely used implementation. Others include Eclipse OpenJ9 and GraalVM.

What is the JRE (Java Runtime Environment)?

The JVM on its own cannot do much. Almost every Java program uses ready-made classes from the Java class library - String and System from java.lang, collections such as ArrayList from java.util, file handling from java.io and java.nio, dates from java.time (see the overview of the java.time APIClick to read the overview of Java 8's Date and Time API), and many more.

The Java Runtime Environment is the JVM packaged together with these class libraries and the supporting files they need, such as configuration and security files. In other words - JRE = JVM + class libraries. A JRE is all you need to run a Java program, but it has no compiler, so you cannot use it to develop one.

Note - Since Java 11, Oracle no longer ships a separate JRE download. The JDK itself contains the runtime, and applications are expected to ship their own runtime, which can be built with the JDK's jlink tool to contain only the modulesClick to read tutorial on Java 9 Modules they need. Some vendors, such as Eclipse Temurin, still offer JRE downloads for convenience. So you will still hear the term JRE, but in practice you install a JDK.

What is the JDK (Java Development Kit)?

The Java Development Kit is the full kit for Java developers. It contains a complete Java runtime - the JVM and the class libraries - plus the tools needed to develop Java programs. In other words - JDK = JRE + development tools. The most commonly used tools in the JDK's bin folder are -
  • javac - the Java compiler, which compiles .java source files into .class bytecode files.
  • java - the launcher, which starts a JVM and runs a program.
  • jar - packages classes and resources into a single .jar archive.
  • javadoc - generates HTML documentation from comments in the source code.
  • jshell - an interactive shell for trying out Java code line by line.
  • jdb - a command-line debugger.
  • javap - disassembles .class files, showing the bytecode inside.
  • jlink - builds a custom, smaller Java runtime containing only the modules an application needs.
  • jcmd, jconsole and jfr - monitor and troubleshoot running JVMs.
The JDK is built from the open-source OpenJDK project. Several vendors provide free builds of it, such as Eclipse Temurin, Oracle OpenJDK, Amazon Corretto, Microsoft Build of OpenJDK and Azul Zulu, along with Oracle's own Oracle JDK. They are all built from the same source code, so for learning Java any of them will do.

JDK, JRE and JVM in action

Let us now see the three at work. Below is a small program which prints a greeting.
A simple Java program to compile and run
//Greeting.java
public class Greeting {
  public static void main(String[] args) {
    String name = "JavaBrahman";
    System.out.println("Hello, " + name + "!");
  }
}
First, we use the JDK's compiler, javac, to compile Greeting.java into Greeting.class. Then we use the java launcher to start a JVM and run it -
javac Greeting.java
java Greeting
 OUTPUT of the above commands
Hello, JavaBrahman!

Explanation of the steps

  • The JDK did the compiling. javac is a JDK tool - it is not part of a JRE.
  • The JRE provided the class library - String, System and PrintStream, whose println() method printed the line, are all classes from java.lang and java.io.
  • The JVM loaded Greeting.class, verified its bytecode, and ran its main() method.

Looking at the bytecode the JVM runs

What exactly is inside Greeting.class? The JDK's javap tool can show us. The -c option prints the bytecode instructions of each method -
javap -c Greeting
 OUTPUT of the above command
Compiled from "Greeting.java"
public class Greeting {
  public Greeting();
    Code:
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: return

  public static void main(java.lang.String[]);
    Code:
         0: ldc           #7                  // String JavaBrahman
         2: astore_1
         3: getstatic     #9                  // Field java/lang/System.out:Ljava/io/PrintStream;
         6: aload_1
         7: invokedynamic #15,  0             // InvokeDynamic #0:makeConcatWithConstants:(Ljava/lang/String;)Ljava/lang/String;
        12: invokevirtual #19                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
        15: return
}

Explanation of the bytecode

  • This is the bytecode - the instruction set of the JVM. These are the instructions that the same Greeting.class file carries to every operating system.
  • ldc loads the constant string "JavaBrahman", and astore_1 stores it in the local variable name.
  • getstatic fetches System.out, invokedynamic joins the strings together, and invokevirtual calls println().
  • Notice the constructor Greeting(). We never wrote it - the compiler added a default constructor for us. We will learn about constructors later in this series.
You will never need to write bytecode yourself, but knowing that it exists explains what the compiler produces, and what the JVM runs.

You can check which JDK you have installed, and the version of its compiler, with these commands -
java --version
javac --version
 OUTPUT of the above commands
java 24.0.1 2025-04-15
Java(TM) SE Runtime Environment (build 24.0.1+9-30)
Java HotSpot(TM) 64-Bit Server VM (build 24.0.1+9-30, mixed mode, sharing)
javac 24.0.1
The output names all three - the Java SE Runtime Environment (the JRE part of the JDK), the HotSpot 64-Bit Server VM (the JVM), and javac, which is only present because this is a full JDK. If java works but javac is not recognized, you have only a runtime installed, or the JDK's bin folder is not on your PATH.

JDK vs JRE vs JVM - side-by-side comparison

JVMJREJDK
Full formJava Virtual MachineJava Runtime EnvironmentJava Development Kit
What it isThe engine which runs bytecodeJVM + class librariesJRE + development tools
Main jobLoad, verify and execute bytecode; manage memoryProvide everything needed to run Java programsProvide everything needed to develop and run Java programs
Can compile code?NoNoYes - javac
Can run code?Yes - it is what runs itYesYes
Platform dependent?Yes - one per OS and processorYesYes
Who needs it?Comes inside the JRE and JDKUsers who only run Java programsJava developers
Download separately?NoOnly from some vendors since Java 11Yes

Note - Bytecode is platform independent, but the JVM, the JRE and the JDK are all platform dependent. That is why the download pages list a separate JDK for Windows, Linux and macOS, while the .class files you compile run on all of them.

Which one should you install?

Install a JDK. If you are learning Java or developing in Java, you need the compiler and tools, and a modern JDK already contains everything a JRE has. Choose a recent Long-Term Support release, such as Java 21 or Java 25, from a vendor such as Eclipse Temurin or Oracle. If you are only running a Java application someone else built, check its instructions - many applications now ship with their own runtime built using jlink, so you may not need to install Java at all.

Summary

In this tutorial we first saw that the JVM, the JRE and the JDK are nested inside each other. We then looked at the JVM - the engine which loads, verifies and runs bytecode, with its class loader, memory areas and execution engine. Next we saw that the JRE adds the Java class libraries to the JVM, and that it is no longer offered separately by Oracle since Java 11. We then saw that the JDK adds development tools such as javac, jar, jshell and javap. We then compiled and ran a program to see all three at work, and used javap to look at the bytecode the JVM runs. Lastly, we compared the three side by side and saw that, as a developer, you should install a JDK.