BhauAutomation

JDK, JRE and JVM

In Java, JDK (Java Development Kit), JRE (Java Runtime Environment), and JVM (Java Virtual Machine) are the three key components that form the backbone of the Java programming platform. Understanding their differences and relationships is essential for every Java developer.

📘 Topic: Core Java / Environment
Read time: 7 min
📊 Level: Beginner
⚙️ Focus: Java Architecture
📖 Overview

What are JDK, JRE and JVM?

JVM (Java Virtual Machine), JRE (Java Runtime Environment), and JDK (Java Development Kit) are the fundamental parts of the Java platform. They work together to develop, run, and execute Java applications efficiently. The relationship can be summarized as:

    ┌─────────────────────────────────────────┐
    │              JDK (Java Development Kit)  │
    │  ┌───────────────────────────────────┐  │
    │  │        JRE (Java Runtime)          │  │
    │  │  ┌─────────────────────────────┐  │  │
    │  │  │        JVM (Java VM)        │  │  │
    │  │  └─────────────────────────────┘  │  │
    │  │  + Core Libraries                 │  │
    │  └───────────────────────────────────┘  │
    │  + Development Tools (javac, jar, etc.) │
    └─────────────────────────────────────────┘
⚙️ JVM

JVM (Java Virtual Machine)

The Java Virtual Machine (JVM) is an abstract machine responsible for running Java bytecode. It translates compiled Java code (.class files) into machine-specific instructions. JVM provides memory management, security, garbage collection, and platform independence – enabling Java's famous "Write Once, Run Anywhere" capability.

🔧 JVM Architecture Components

Class Loader Runtime Data Areas Execution Engine Garbage Collector Just-In-Time Compiler

💻 Example:

public class Demo { public static void main(String[] args) { System.out.println("Java Program Running..."); } }

When you run this program, the JVM loads the compiled Demo.class file, verifies bytecode, allocates memory, and executes the main method, producing output:

Java Program Running...
📦 JRE

JRE (Java Runtime Environment)

The Java Runtime Environment (JRE) contains the JVM along with the essential class libraries (rt.jar, core APIs) and other files required to execute Java applications. It does not include development tools such as compilers or debuggers. JRE is used primarily to run existing Java applications.

📚 JRE Components:

JVM Core Libraries Java API Classes Deployment Technologies Java Web Start

📝 Example:

When a user installs Java to play a Minecraft game or run a banking application, they are installing the JRE, which provides the runtime environment to execute the compiled Java program without needing development tools.

🛠️ JDK

JDK (Java Development Kit)

The Java Development Kit (JDK) includes the JRE, compiler (javac), debugger, and development tools needed to create Java applications. It provides everything required for Java development, debugging, and monitoring. Developers use the JDK to write, compile, and debug Java programs.

🛠️ JDK Components:

JRE javac (Compiler) java (Launcher) jar (Archiver) javadoc (Documentation) jdb (Debugger) javap (Disassembler)

📝 Example:

When you write a Java program in an IDE like IntelliJ, Eclipse, or VS Code, you are using the JDK.

// Compile Java program javac HelloWorld.java // Run compiled Java program java HelloWorld

Here, javac compiles the source code into bytecode, and java runs it using the JRE and JVM.

📊 Comparison

Differences Between JDK, JRE, and JVM

Component Full Form Includes Purpose
JVM Java Virtual Machine Execution engine only Runs Java bytecode
JRE Java Runtime Environment JVM + Core Libraries Runs Java applications
JDK Java Development Kit JRE + Development Tools Develops and runs Java programs
📅 Versions

Java Version Compatibility

Understanding the relationship between JDK versions and their corresponding JRE versions is important for compatibility:

Java 8 (LTS) - 1.8 Java 11 (LTS) - 11 Java 17 (LTS) - 17 Java 21 (LTS) - 21

Note: LTS (Long-Term Support) versions receive updates for several years and are recommended for enterprise applications.

🏆 Best Practices

Best Practices for JDK, JRE, JVM Management

Install the JDK if you are developing Java applications (includes compiler and tools)

Use the JRE when you only need to run existing Java applications (no development)

Always match your Java version (e.g., Java 8, 11, 17, 21) with your project requirements and dependencies

Keep your JDK/JRE updated for the latest compiler improvements, bug fixes, and security updates

Set JAVA_HOME environment variable to point to JDK installation for development tools to work properly

Use version managers like SDKMAN or jabba to manage multiple JDK versions on the same machine

📝 Summary

Quick Summary Example

Suppose you write a simple program HelloWorld.java:

class HelloWorld { public static void main(String[] args) { System.out.println("Hello Java"); } }
  • JDK compiles it into bytecode (javac HelloWorld.javaHelloWorld.class)
  • JRE provides libraries and environment to run it (java HelloWorld)
  • JVM executes the bytecode on your specific operating system