Skip to main content

JDK JRE JVM Explained Example in Java

1 min read Updated May 29, 2026
Share:
On this page (9sections)

Introduction

Before writing advanced Java programs, it helps to understand how source code becomes running output. Three terms appear constantly: JDK, JRE and JVM.

Comparison

ComponentRole
JDKFull development kit — compiler (javac), tools, JRE
JRERuntime environment — libraries + JVM (execute only)
JVMVirtual machine that runs bytecode on any supported OS

Execution Flow

Hello.java  --javac-->  Hello.class (bytecode)  --JVM-->  Program Output
     ^                        ^                          ^
   JDK tool                 JRE/JVM                   Running process

Example Program

public class JdkDemo {
    public static void main(String[] args) {
        System.out.println("Java Version : " + System.getProperty("java.version"));
        System.out.println("JVM Name     : " + System.getProperty("java.vm.name"));
        System.out.println("JRE Vendor   : " + System.getProperty("java.vendor"));
        System.out.println("OS Name      : " + System.getProperty("os.name"));

        int a = 10, b = 20;
        System.out.println("Sum = " + (a + b));
    }
}

Sample Output

Java Version : 21.0.2
JVM Name     : OpenJDK 64-Bit Server VM
JRE Vendor   : Oracle Corporation
OS Name      : Windows 11
Sum = 30

How It Works

  1. You write .java source and compile with javac (part of the JDK).
  2. The compiler produces platform-independent bytecode in .class files.
  3. The JVM (inside the JRE) interprets or JIT-compiles bytecode and runs main.
  4. System.getProperty queries runtime details exposed by the JVM.

Best Practices

  • Install the JDK (not JRE alone) on development machines.
  • Set JAVA_HOME and add %JAVA_HOME%\bin to PATH on Windows.
  • Match your project’s Java version with the JDK used in CI and production.

Common Mistakes

  • Confusing JRE with JDK and failing to find javac.
  • Mixing bytecode compiled with a newer JDK than the runtime JVM supports.

Frequently Asked Questions

What is the difference between JDK and JRE?
JRE provides the runtime (JVM + libraries) to execute Java programs. JDK includes the JRE plus development tools such as javac, jar and javadoc needed to write and build programs.
What does the JVM do?
The JVM loads bytecode (.class files), verifies it, executes it and manages memory through garbage collection.

Related Tutorials

Search tutorials