What is the Difference Between JDK, JRE and JVM in Java?

Learn the key differences between JDK, JRE, and JVM in Java. This guide explains what each component does, includes a hands-on code example, and shows how they work together in the Java ecosystem.

October 15, 20257 min read

Prerequisites

  • A basic understanding that Java code needs to be compiled and run.
  • No prior deep knowledge of Java's architecture is required.
  • JDK 17+

Key Terms We'll Use

  • JDK (Java Development Kit): The full toolkit for creating Java programs.
  • JRE (Java Runtime Environment): The package needed to run Java programs.
  • JVM (Java Virtual Machine): The engine that executes your Java code.
  • JSE (Java Platform, Standard Edition): The core Java platform for desktop and server applications.
  • Bytecode: The platform-independent, compiled Java code.
  • Compiler (javac): The tool that turns your .java files into .class (bytecode) files.
  • Maven/Gradle: Build automation tools that manage dependencies and compilation.

If you've ever felt overwhelmed by the JDK, JRE, and JVM, well worrry no more you are in good company. These three "J-acronyms" are the pillars of the Java universe, and understanding their relationship is the first step to truly mastering the language.

Let's break down what each one does and how they work together, using a simple house building analogy.

A House-Building Analogy

  • The JDK is the entire construction company. It has all the tools, architects, and workers.
  • The JRE is the finished house. It's ready for someone to live in (run the program).
  • The JVM is the foundation and utilities. It's what makes the house livable on any piece of land (any operating system).

Now, let's look at each one in detail.

Try Kodaschool for free

Click below to sign up and get access to free web, android and iOs challenges.

Sign Up

1. The JVM (Java Virtual Machine): The "The Foundation"

What it is: The JVM is an abstract computing machine. It's the reason for Java's famous "Write Once, Run Anywhere" (WORA) capability.

What it does:

  • Loads your compiled bytecode (.class files).
  • Verifies the code for security.
  • Interprets the bytecode into machine-specific instructions.
  • Manages memory (garbage collection) and provides the runtime environment.

The Key Insight: The JVM is what makes Java cross-platform. You write code once, and the JVM for Windows, Mac, or Linux handles the translation for its specific operating system.

# You run your program by calling the JVM
java MyProgram

2. The JRE (Java Runtime Environment): The "Move-In Ready House"

What it is: The JRE is a software package. If you only want to run Java applications (like a downloaded .jar file), you only need the JRE installed.

What it contains:

  • The JVM (to execute the program).
  • The Java Class Libraries (like java.util, java.io) that the program needs to run.

When you use it: End-users who need to run Java applications but won't be writing any code themselves.

Important: The JRE does NOT include the compiler (javac) or development tools. You can't create Java programs with just the JRE.

3. JSE (Java Platform, Standard Edition): "The Neighborhood"

What it is: JSE is the core Java platform that defines the specifications for the JDK, JRE, and the standard Java libraries.

What it includes:

  • Specifications for the Java language and virtual machine
  • Core libraries (collections, I/O, networking, etc.)
  • Development tools specification
  • Deployment technologies

The Relationship: JSE is the standard that Oracle and other vendors implement when they create their JDK and JRE distributions.

Note: You'll often see "Java SE" in documentation and download pages—this is what most developers use for general-purpose Java development.

Build Tools: Maven and Gradle - "Your Construction Managers"

While you can compile Java programs manually with javac, real-world projects use build tools to automate the process.

Maven uses a declarative approach with XML configuration:

<!-- pom.xml -->
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>my-app</artifactId>
    <version>1.0.0</version>
    
    <dependencies>
        <dependency>
            <groupId>org.junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

Gradle uses a more flexible Groovy or Kotlin DSL:

// build.gradle
plugins {
    id 'java'
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'junit:junit:4.13.2'
}

4. The JDK (Java Development Kit): The "Full Construction Company"

What it is: The JDK is the complete toolkit for Java developers. If you want to create Java applications, you must install the JDK.

What it contains:

  • The JRE (which contains the JVM and libraries), so you can run your code.
  • The Compiler (javac) to transform your .java files into .class files.
  • Development Tools like debuggers (jdb), documentation tools (javadoc), and archivers (jar).
# You compile your code using the JDK's compiler
javac MyProgram.java

# Then you run it using the JRE's JVM (included in the JDK)
java MyProgram

Let's Build: See the "J's" in Action

Let's create a simple program that demonstrates the entire workflow from writing code to execution. We'll build a mini calculator.

Step 1: Write the Java Code (Using JDK Tools)

Create a file called SimpleCalculator.java:

public class SimpleCalculator {
    
    public int add(int a, int b) {
        return a + b;
    }
    
    public int multiply(int a, int b) {
        return a * b;
    }
    
    public static void main(String[] args) {
        SimpleCalculator calc = new SimpleCalculator();
        
        System.out.println("=== Simple Calculator ===");
        System.out.println("5 + 3 = " + calc.add(5, 3));
        System.out.println("5 * 3 = " + calc.multiply(5, 3));
        System.out.println("Calculation complete!");
    }
}

Step 2: Compile with JDK's javac

Open your terminal/command prompt and navigate to where you saved the file:

# This uses the JDK's compiler to create bytecode
javac SimpleCalculator.java

What happens: The JDK's compiler (javac) converts your human-readable .java file into platform-independent bytecode in a new file called SimpleCalculator.class

Step 3: Run with JRE's java command

# This uses the JRE's JVM to execute the bytecode
java SimpleCalculator

What You should see

=== Simple Calculator ===
5 + 3 = 8
5 * 3 = 15
Calculation complete!

What Just Happened Behind the Scenes?

  1. JDK's Compiler (javac) took your SimpleCalculator.java and created SimpleCalculator.class (bytecode)
  2. JRE's JVM loaded the bytecode and:
    • Verified the code was safe to run
    • Interpreted the bytecode for your specific operating system
    • Managed memory for the SimpleCalculator object
    • Handled the output to your console

Are you curious lets have a look at the bytecode

# On Unix/Linux/Mac:
ls -la SimpleCalculator.class

# On Windows:
dir SimpleCalculator.class

How They Fit Together

This relationship is the most important part to understand. It's not three separate things, but a set of nested components.

Image

The workflow in practice:

  1. You, the developer, write MyProgram.java.
  2. The JDK's compiler (javac) turns it into MyProgram.class (bytecode).
  3. You run the program. The JRE (which is part of your JDK) takes over.
  4. The JVM (which is part of the JRE) loads the bytecode, interprets it, and runs it on your machine.


Key Takeaways

  • JVM = The engine that runs your code, enabling cross-platform compatibility.
  • JRE = JVM + Libraries. It's for running Java programs.
  • JDK = JRE + Compiler & Tools. It's for developing Java programs.
  • The relationship is nested: JDK contains JRE, and JRE contains JVM.

What's Next?

  • Install the JDK: If you're learning Java, download and install the latest JDK from Oracle or OpenJDK.
  • Try it yourself: Write a simple "Hello World" program, compile it with javac, and run it with java.
  • Explore the tools: Run jconsole (included with the JDK) to see a simple monitoring tool in action.

Further Learning:


Happy Coding :)

Barack Ouma

About Barack Ouma

Software Engineer
Building and scaling cloud infrastructures.