JDK vs JRE vs JVM

When you start learning Java, three terms appear again and again: JDK, JRE, and JVM. These three components are closely related, but they do different jobs. Understanding their purpose is important because they explain how Java programs are developed, compiled, and executed.

A simple Java program may look very small, but several components work behind the scenes to execute it. When you write Java source code, the code is first compiled into bytecode. The bytecode is then loaded and executed by the Java Virtual Machine. The tools required to create and compile that program are provided by the Java Development Kit.

The easiest way to remember their primary roles is:

ComponentMain Purpose
JDKUsed to develop Java applications
JREProvides the traditional environment required to run Java applications
JVMExecutes Java bytecode

A simple relationship can be represented as:

JDK
 │
 ├── Development Tools
 │
 └── Runtime Components
        │
        ├── JVM
        │
        └── Java Class Libraries

The exact packaging of these components has evolved in modern Java releases, but their roles remain important for understanding the Java platform.

What is JDK?

JDK stands for Java Development Kit. It is the software development kit used to create Java applications. If you want to write, compile, test, debug, package, and run Java programs, the JDK provides the tools required for these tasks.

When you install a modern Java Development Kit, you get the Java compiler and many other development tools along with the runtime components needed to run Java applications. This is why the JDK is normally what a Java developer installs on a development computer.

For example, consider the following Java program:

public class Main {

    public static void main(String[] args) {
        System.out.println("Hello Java");
    }
}

You save this program in a file named:

Main.java

The .java file contains the source code written by the developer. Before the computer can execute the program, the source code needs to be compiled.

The JDK provides the Java compiler called javac.

You can compile the program using:

javac Main.java

After successful compilation, a bytecode file is produced:

Main.class

The .class file contains Java bytecode. This bytecode is not the same as the original Java source code, and it is not simply the machine code of one specific operating system. It is an intermediate representation designed to be executed by the JVM.

What does the JDK contain?

The JDK contains a collection of tools and components used during Java development. Some of the important tools include the following:

ToolPurpose
javacCompiles Java source code
javaStarts a Java application
jarCreates and manages JAR files
javadocGenerates documentation
jdbProvides debugging support
jshellProvides an interactive Java shell

The JDK also provides the Java APIs and runtime components required by Java applications.

Why do Java developers need the JDK?

Suppose you are building a Java application. You will need to write source code, compile that code, run it, test it, debug problems, and eventually package the application.

The JDK provides tools for these development activities.

For example:

javac Main.java

compiles the source code.

Then:

java Main

starts the application.

Without the development tools provided by the JDK, creating a Java application would not be practical.

JDK example

Consider this program:

public class Calculator {

    public static void main(String[] args) {

        int firstNumber = 20;
        int secondNumber = 10;

        int result = firstNumber + secondNumber;

        System.out.println("Result: " + result);
    }
}

Save the file as:

Calculator.java

Compile it using:

javac Calculator.java

The compiler produces:

Calculator.class

You can then run the application using:

java Calculator

The JDK provides the tools required to perform these development steps.

What is JRE?

JRE stands for Java Runtime Environment. Traditionally, the JRE represents the environment required to run Java applications. It provides the JVM along with the Java class libraries and other runtime components needed by an application.

The word runtime is important here. A runtime environment is concerned with running an already-developed application rather than providing all the tools needed to develop that application.

The traditional relationship can be represented as:

JRE
 │
 ├── JVM
 │
 └── Java Class Libraries

For example, a Java application might use classes such as:

String
ArrayList
Math
System

These classes come from the Java platform libraries. The JVM provides the environment in which the application’s bytecode is executed.

What is the purpose of JRE?

The traditional purpose of the JRE is to provide everything needed to run a Java application.

Imagine that a developer has already created and compiled an application:

ShoppingApplication.class

A user does not need the Java compiler to simply execute that application. The user needs a Java runtime environment capable of running the application’s bytecode.

This is where the concept of the JRE comes in.

The JRE traditionally consists of:

  • JVM
  • Java class libraries
  • Other runtime components

It does not provide the complete collection of development tools included in the JDK.

JRE and modern Java versions

There is an important point that beginners should understand.

The JRE is still an important concept, but modern Java distributions are generally installed and distributed as JDKs rather than as a separate JRE package.

In older Java releases, it was common to see separate JDK and JRE installations. Modern Java development has moved away from that model.

Therefore, when you install Java today as a developer, you will normally install a JDK.

You should still understand the JRE because the term appears frequently in Java books, documentation, interviews, tutorials, and older Java architecture diagrams.

What is JVM?

JVM stands for Java Virtual Machine. It is the component responsible for executing Java bytecode.

When you compile a Java program, the Java compiler converts the source code into bytecode.

For example:

public class Main {

    public static void main(String[] args) {
        System.out.println("Hello Java");
    }
}

The compiler converts this:

Main.java

into:

Main.class

The .class file contains bytecode.

The JVM loads this bytecode and executes it.

The basic process is:

Java Source Code
       │
       │ javac
       ↓
Java Bytecode
       │
       │
       ↓
      JVM
       │
       ↓
Operating System
       │
       ↓
Program Output

The JVM is therefore one of the most important parts of the Java platform.

Why is the JVM important?

The JVM plays a major role in Java’s platform-independent design.

Suppose you write a Java program on Windows. The Java source code is compiled into bytecode.

That bytecode can be executed on another operating system if that operating system has a compatible JVM.

The same basic idea applies to Linux and macOS.

                Java Source Code
                       │
                       ↓
                    Compiler
                       │
                       ↓
                    Bytecode
                       │
          ┌────────────┼────────────┐
          ↓            ↓            ↓
       Windows       Linux        macOS
          │            │            │
         JVM          JVM          JVM
          │            │            │
          ↓            ↓            ↓
       Execute       Execute      Execute

The JVM implementation is platform-specific, but the Java bytecode is designed to be portable across compatible JVM implementations.

This is the foundation behind the well-known Java idea:

Write Once, Run Anywhere.

What does the JVM do?

The JVM performs several important tasks while a Java application is running.

Loading classes

The JVM loads the required Java classes into memory when they are needed.

This is handled by the Java class-loading mechanism.

Verifying bytecode

Before executing bytecode, the JVM performs checks to ensure that the bytecode follows required rules.

This helps provide a safer execution environment.

Executing bytecode

The primary job of the JVM is to execute the bytecode produced by the Java compiler.

The JVM can interpret bytecode and can also use Just-In-Time compilation techniques to improve performance during execution.

Managing memory

The JVM manages important areas of memory used by Java applications.

This includes memory used for objects and method execution.

Garbage collection

Java uses automatic garbage collection.

The JVM can identify objects that are no longer reachable by the application and reclaim memory associated with them.

For example:

public class Main {

    public static void main(String[] args) {

        String message = new String("Hello");

        message = null;
    }
}

After message is assigned null, the previously created String object may become eligible for garbage collection if no other references point to it.

The JVM manages the garbage collection process.

How Java Code Runs

Understanding the complete execution process makes JDK, JRE, and JVM much easier to understand.

Consider the following Java program:

public class Main {

    public static void main(String[] args) {

        int number = 10;

        System.out.println(number);
    }
}

The source code is saved as:

Main.java

Compilation

The JDK provides the javac compiler.

Run:

javac Main.java

The compiler checks the Java source code.

If there are no compilation errors, it produces:

Main.class

This file contains bytecode.

Execution

Now run:

java Main

The Java launcher starts the Java runtime.

The JVM loads the required classes and executes the bytecode.

The output is:

10

The complete flow can be represented as:

             Developer
                 │
                 ↓
            Main.java
                 │
                 ↓
             JDK / javac
                 │
                 ↓
            Main.class
                 │
             Bytecode
                 │
                 ↓
                JVM
                 │
                 ↓
          Program Execution
                 │
                 ↓
              Output

JDK vs JRE vs JVM

Now we can clearly compare all three.

FeatureJDKJREJVM
Full formJava Development KitJava Runtime EnvironmentJava Virtual Machine
Main purposeDevelop Java applicationsRun Java applications in the traditional modelExecute Java bytecode
Compiler includedYesNoNo
Development toolsYesNoNo
JVM includedRuntime components include JVMTraditionally includes JVMIt is the JVM
Java librariesYesYesUses them
Compiles source codeYesNoNo
Executes bytecodeThrough its runtimeThrough its JVMYes
Used mainly byDevelopersApplication users/runtime environmentsJava runtime

The most important distinction is:

JDK → Development
JRE → Runtime Environment
JVM → Bytecode Execution

Relationship Between JDK, JRE, and JVM

A traditional Java architecture diagram is often shown like this:

                 JDK
                  │
                  ↓
                 JRE
                  │
                  ↓
                 JVM

This diagram is useful for understanding the roles of the three components.

A more detailed conceptual diagram is:

JDK
│
├── Development Tools
│      ├── javac
│      ├── jar
│      ├── javadoc
│      └── jdb
│
└── Runtime Components
       │
       ├── JVM
       │
       └── Java Class Libraries

However, remember that this is a conceptual model. Modern Java distributions do not necessarily package a separately installable JRE inside the JDK in the same way older Java releases did.

What is the Difference Between JDK and JRE?

The main difference is their purpose.

The JDK is intended for Java development.

The traditional JRE is intended for running Java applications.

For example, if you are a Java developer writing:

public class Main {

    public static void main(String[] args) {
        System.out.println("Hello Java");
    }
}

you need development tools to compile this program.

Therefore, you need a JDK.

If you only need a Java runtime to execute an already-built application, the development tools are not required.

The distinction can be summarized as:

JDKJRE
Used to develop applicationsTraditionally used to run applications
Contains development toolsDoes not contain development tools
Contains runtime componentsProvides runtime components
Used by developersUsed by applications/users

What is the Difference Between JRE and JVM?

JRE and JVM are not the same thing.

The JVM is responsible for executing Java bytecode.

The traditional JRE provides the JVM along with the Java libraries and other components required to run Java applications.

Think of it this way:

JRE
│
├── JVM
├── Java Libraries
└── Other Runtime Components

So:

JVM = execution engine

JRE = complete traditional runtime environment

What is the Difference Between JDK and JVM?

The JDK is much larger in purpose than the JVM.

The JDK is used to develop Java applications.

The JVM is responsible for executing bytecode.

For example, when you use:

javac Main.java

you are using a JDK development tool.

When you use:

java Main

the Java runtime starts the JVM to execute the compiled bytecode.

Therefore:

JDK → Creates the bytecode
JVM → Executes the bytecode

Why Can’t JVM Compile Java Source Code?

A common beginner mistake is thinking that the JVM directly compiles .java source files.

The Java compiler, javac, is responsible for compiling Java source code into bytecode.

For example:

Main.java
   │
   │ javac
   ↓
Main.class
   │
   │ JVM
   ↓
Execution

The JVM’s primary responsibility is executing the resulting bytecode.

Modern JVM implementations may also compile bytecode into native machine code at runtime through Just-In-Time compilation, but this is different from the initial Java source compilation performed by javac.

Why Does Java Need the JVM?

Without the JVM concept, Java’s platform-independent execution model would be very different.

A Java compiler produces bytecode that follows a common format.

Different operating systems can provide JVM implementations that understand and execute that bytecode.

For example:

                 Java Bytecode
                       │
          ┌────────────┼────────────┐
          ↓            ↓            ↓
       Windows       Linux        macOS
          ↓            ↓            ↓
         JVM          JVM          JVM
          ↓            ↓            ↓
       Execute       Execute      Execute

This approach allows developers to avoid creating completely different Java source programs for every operating system.

Do You Need JDK, JRE, and JVM Separately?

If you are a beginner learning Java, you normally install a JDK.

You do not normally need to separately install a JRE and JVM.

The JDK provides the development environment and the runtime components needed for Java development.

For example, after installing a JDK, you can check your Java installation with:

java -version

You can also check the Java compiler with:

javac -version

If both commands work, your JDK installation is available from the command line.

JDK, JRE, and JVM in Simple Terms

Imagine you are building a Java application.

You write your program using Java source code.

The JDK gives you the tools to develop and compile the application.

The traditional JRE provides the environment needed to run the compiled application.

The JVM is the component that actually executes the Java bytecode.

So the simplified process is:

Write Java Code
      ↓
      JDK
      ↓
Compile Source Code
      ↓
Java Bytecode
      ↓
      JVM
      ↓
Execute Program

A Simple Real-World Analogy

Imagine a movie production system.

The JDK is like the complete production studio. It provides the tools required to create and prepare the movie.

The JRE is like the environment in which the finished movie can be played.

The JVM is like the player that actually processes and plays the movie.

This is only an analogy, but it can help beginners remember the difference.

The technical relationship is more accurately represented as:

JDK
│
├── Development Tools
│
└── Runtime
      │
      ├── JVM
      └── Java Libraries

Common Beginner Questions

Is Java the same as JDK?

No. Java is the programming language and platform. The JDK is the development kit used to create Java applications.

Is JVM software?

Yes. The JVM is a software implementation of the Java Virtual Machine specification that runs Java bytecode.

Is JRE still important?

Yes, as a concept. It is important for understanding Java’s traditional runtime architecture. However, modern Java distributions are generally installed as JDKs rather than separate JRE packages.

Can I run Java without JVM?

A Java bytecode application requires a compatible JVM implementation to execute its bytecode.

Does JDK contain the compiler?

Yes. The JDK provides the Java compiler, javac.

What converts Java source code into bytecode?

The Java compiler, javac, converts Java source code into Java bytecode.

What executes Java bytecode?

The JVM executes Java bytecode.

Which one should I install to learn Java?

You should normally install a JDK because you need the compiler and other development tools.

Frequently Asked Questions

What is the full form of JDK?

JDK stands for Java Development Kit.

What is the full form of JRE?

JRE stands for Java Runtime Environment.

What is the full form of JVM?

JVM stands for Java Virtual Machine.

What is the main purpose of JDK?

The JDK provides the tools and components required to develop Java applications.

What is the main purpose of JRE?

Traditionally, the JRE provides the runtime environment required to run Java applications.

What is the main purpose of JVM?

The JVM loads and executes Java bytecode.

Which one contains javac?

The JDK contains javac, the Java compiler.

Which one executes bytecode?

The JVM executes Java bytecode.

Is JDK required for Java development?

Yes. A JDK provides the compiler and development tools needed for normal Java development.

2 thoughts on “JDK vs JRE vs JVM”

  1. Pingback: Java vs C -

Comments are closed.