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 (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
💻 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 (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:
📝 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 (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:
📝 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.
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 |
Java Version Compatibility
Understanding the relationship between JDK versions and their corresponding JRE versions is important for compatibility:
Note: LTS (Long-Term Support) versions receive updates for several years and are recommended for enterprise applications.
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
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.java→HelloWorld.class) - JRE provides libraries and environment to run it (
java HelloWorld) - JVM executes the bytecode on your specific operating system