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.
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.
// Simple Java program demonstrating compilation and execution
class HelloJava {
public static void main(String[] args) {
System.out.println("Hello, Java World!");
}
}
// Command-line steps showing JDK, JRE, and JVM interaction
javac HelloJava.java
java HelloJava
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.
.class file on another OS