Java source (.java) is compiled by javac into bytecode (.class), which the JVM executes. This two-step model gives Java its portability and its automatic memory management. Everything lives inside a class, and execution begins at a very specific entry-point method.
JVM, JRE, JDK and the entry point
JVM executes bytecode and manages memory (garbage collection). JRE = JVM + standard libraries (enough to run Java). JDK = JRE + development tools like the javac compiler (to build Java). Every program starts at public static void main(String[] args).
A minimal Java program
public class Main {
public static void main(String[] args) {
System.out.println("Hello");
}
}
// compile: javac Main.java -> Main.class (bytecode)
// run: java Main -> JVM executes the bytecode⚡ The edge
- JDK ⊃ JRE ⊃ JVM. You develop with the JDK (it has the compiler), you run with the JRE (it has the JVM plus libraries), and the JVM is the engine that actually executes bytecode and does garbage collection.
- main must be public static void main(String[] args). It's static so the JVM can call it without creating an object first, public so the JVM can access it, and takes a String[] for command-line arguments.
Worked example
Explain the difference between JDK, JRE and JVM.
- The JVM is the virtual machine that executes Java bytecode and manages memory.
- The JRE bundles the JVM with the standard class libraries — everything needed to run a Java program.
- The JDK bundles the JRE with development tools (compiler, debugger), so it's what you need to write and build Java.
Answer: JVM runs bytecode; JRE = JVM + libraries (to run); JDK = JRE + tools like the compiler (to develop).
Worked example
Why is the main method static?
- Execution starts at main before any objects exist.
- A static method belongs to the class, not to an instance, so the JVM can call it without first creating an object.
- If main weren't static, the JVM would need an object to call it on — but creating that object is itself program logic that hasn't run yet.
Answer: Because it's static, the JVM can invoke main on the class without creating an object first — the program's starting point.
⚠ Watch out
- The main signature is exact: public static void main(String[] args) — a wrong signature compiles but won't run as an entry point.
- Java is case-sensitive and conventionally one public class per file, named after the file.
- Don't conflate JDK/JRE/JVM — a precise answer is expected.