JDK JRE JVM Explained Example in Java
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
| Component | Role |
|---|---|
| JDK | Full development kit — compiler (javac), tools, JRE |
| JRE | Runtime environment — libraries + JVM (execute only) |
| JVM | Virtual 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
- You write
.javasource and compile withjavac(part of the JDK). - The compiler produces platform-independent bytecode in
.classfiles. - The JVM (inside the JRE) interprets or JIT-compiles bytecode and runs
main. System.getPropertyqueries runtime details exposed by the JVM.
Best Practices
- Install the JDK (not JRE alone) on development machines.
- Set
JAVA_HOMEand add%JAVA_HOME%\binto 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.