JDK vs JRE vs JVM

Understanding the Java Development Kit, Runtime Environment, and Virtual Machine

← Back to Index

The Three Key Components

Java's architecture consists of three main components that work together to enable Java development and execution:

Quick Summary
  • JDK (Java Development Kit) - Complete development environment (includes JRE + development tools)
  • JRE (Java Runtime Environment) - Runtime environment for executing Java applications (includes JVM + libraries)
  • JVM (Java Virtual Machine) - Abstract machine that executes Java bytecode

The Relationship

JDK = JRE + Development Tools

JRE = JVM + Libraries

JVM = Bytecode Executor

JDK (Java Development Kit)

The JDK is a complete software development kit required for developing Java applications. It includes everything you need to write, compile, and run Java programs.

What's Included in the JDK?

Common JDK Tools

# Compile Java source code
javac MyProgram.java

# Run Java application
java MyProgram

# Create JAR file
jar cf myapp.jar *.class

# Generate documentation
javadoc -d docs MyProgram.java

# View class file contents
javap -c MyProgram.class

# Monitor JVM
jconsole

When Do You Need the JDK?

For Developers

If you're a Java developer, you always need the JDK. The JRE alone is not sufficient for development work.

JRE (Java Runtime Environment)

The JRE provides the minimum requirements for executing a Java application. It's designed for end-users who need to run Java programs but don't need development tools.

What's Included in the JRE?

When Do You Need the JRE?

Important Note (Java 11+)

Starting with Java 11, Oracle no longer provides a separate JRE download. The JDK is now the primary distribution. For deployment, you can create custom runtime images using jlink.

JVM (Java Virtual Machine)

The JVM is an abstract computing machine that enables a computer to run Java programs. It's the core component that provides the "write once, run anywhere" capability.

What Does the JVM Do?

JVM Architecture

1. Class Loader Subsystem

Loads .class files into memory

2. Runtime Data Areas

  • Heap - Object memory (shared among all threads)
  • Stack - Method calls and local variables (per thread)
  • Method Area - Class structures, constant pool
  • PC Register - Current instruction address (per thread)
  • Native Method Stack - Native method calls

3. Execution Engine

  • Interpreter - Executes bytecode line by line
  • JIT Compiler - Compiles frequently used code to native code
  • Garbage Collector - Automatically reclaims memory

Platform Independence

// Java source code (.java)
public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

// Compile to bytecode (.class) - Platform Independent
// javac Hello.java

// JVM executes bytecode on ANY platform
// Windows JVM, Linux JVM, Mac JVM all understand the same bytecode
Write Once, Run Anywhere

Java code is compiled to platform-independent bytecode. The JVM translates this bytecode to native machine instructions specific to the underlying operating system and hardware.

Side-by-Side Comparison

Feature JDK JRE JVM
Full Name Java Development Kit Java Runtime Environment Java Virtual Machine
Purpose Development Running applications Executing bytecode
Includes JRE + Dev Tools JVM + Libraries Execution engine
Contains Compiler Yes (javac) No No
Can Run Programs Yes Yes Yes
Can Compile Code Yes No No
Target Users Developers End users Internal component
Size Largest (~150-300 MB) Medium (~50-100 MB) Part of JRE

Practical Scenarios

Scenario 1: Java Developer

You need: JDK

Why: You need to write, compile, and test Java code. The JDK includes the compiler (javac) and all development tools.

# Download and install JDK
# Write code
MyApp.java

# Compile with JDK's javac
javac MyApp.java

# Run with JDK's java
java MyApp

Scenario 2: Production Server

You need: JRE (or custom runtime with jlink)

Why: You only need to run compiled Java applications. No development or compilation happens on production servers.

# Production server setup
# Install JRE or use Docker with JRE base image

# Run your compiled JAR
java -jar myapp.jar

Scenario 3: End User Running Desktop App

They need: JRE

Why: They just want to run the Java application, not develop it.

JDK Distributions and Vendors

Multiple vendors provide JDK distributions, all implementing the same Java specifications:

Major JDK Distributions

Checking Your Java Version

# Check JDK/JRE version
java -version

# Output example:
# openjdk version "17.0.2" 2022-01-18
# OpenJDK Runtime Environment (build 17.0.2+8-86)
# OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode)

# Check compiler version
javac -version

# Output example:
# javac 17.0.2

Common Questions

Q: Can I have multiple JDKs installed?

A: Yes! You can have multiple JDK versions installed simultaneously. Use environment variables (JAVA_HOME) or tools like SDKMAN! or jEnv to manage them.

Q: Do I need both JDK and JRE?

A: No. The JDK includes the JRE. If you have the JDK, you don't need a separate JRE installation.

Q: Can I run Java applications without installing anything?

A: No. At minimum, you need the JRE (or JDK) to run Java applications. However, you can bundle a JRE with your application using tools like jpackage.

Q: Is the JVM the same across all operating systems?

A: The JVM specification is the same, but implementations are platform-specific. Oracle provides different JVM implementations for Windows, Linux, and macOS.

Q: What's the difference between JRE and JVM?

A: JVM is just the execution engine. JRE = JVM + Java class libraries + supporting files. You can't run Java with just the JVM; you need the complete JRE.

Why Understanding These Differences Matters