← Back to Chapters

JDK vs JRE vs JVM

☕ JDK vs JRE vs JVM

? Quick Overview

In Java, JDK, JRE, and JVM are closely related components that work together to develop and run Java applications. Understanding their roles is essential for every Java developer.

? Key Concepts

  • JVM executes Java bytecode
  • JRE provides runtime environment
  • JDK provides development tools
  • Java follows Write Once, Run Anywhere

? Syntax / Theory

When you write a Java program, the source code (.java) is compiled into bytecode (.class) using the Java compiler. This bytecode is then executed by the JVM inside the JRE. The JDK includes everything needed to develop, compile, and run Java programs.

? Code Example(s)

? View Code Example
// Simple Java program demonstrating compilation and execution
class HelloJava {
public static void main(String[] args) {
System.out.println("Hello, Java World!");
}
}
? View Code Example
// Command-line steps showing JDK, JRE, and JVM interaction
javac HelloJava.java
java HelloJava

? Live Output / Explanation

? What Happens Internally?

javac (part of JDK) compiles the source code into bytecode. The java command starts the JVM, which loads the bytecode, verifies it, and executes it using the JRE libraries.

? Tips & Best Practices

  • Install JDK if you want to develop Java programs
  • Only JRE is needed to run Java applications
  • Keep your JDK version consistent across projects
  • Understand JVM memory for better performance tuning

? Try It Yourself

  • Write and compile a simple Java program using JDK
  • Locate JVM files inside your JDK installation
  • Run the same .class file on another OS