Topic 1 of 30 · Beginner
Java, JDK, JRE & JVM
How Java code is compiled and run anywhere.
Concept
Java source (.java) is compiled by javac into bytecode (.class). The JVM runs that bytecode on any operating system — 'write once, run anywhere'.
The JDK (development kit) contains the compiler and tools; the JRE contains the JVM and libraries needed to run programs; the JVM is the engine itself.
The JIT (Just-In-Time) compiler turns frequently used bytecode into native machine code at run time for speed.
Cheat sheet
| Part | Contains | Needed for |
|---|---|---|
| JDK | JRE + javac, jar, jdb | Writing code |
| JRE | JVM + core libraries | Running code |
| JVM | Class loader, memory, JIT, GC | Executing bytecode |
Code (Java 21)
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, AICodeDost!");
}
}
// javac Hello.java -> Hello.class
// java HelloRemember
- main must be public static void main(String[] args).
- File name must match the public class name.
- Bytecode is platform independent; the JVM is not.
Interview questions
Why is Java platform independent?
It compiles to bytecode, not machine code. Each platform has its own JVM that runs the same bytecode.
Why is main static?
So the JVM can call it without creating an object of the class first.
Lesson test
Take an 8-question test on “Java, JDK, JRE & JVM” — concepts, output prediction, bug spotting and interview questions.