Java Program Structure, JVM Execution Pipeline & Top-Level Main
1Concept
Java programs run on the JVM (Java Virtual Machine). Source code (.java) is compiled by javac into platform-independent bytecode (.class files), which the JVM JIT (HotSpot Just-In-Time) compiler converts into native machine code. In Java 21, main() can be declared with instance main methods or standard public static void main(String[] args).
2Architecture Diagram
[App.java] ──► (javac) ──► [App.class Bytecode] ──► [JVM ClassLoader] ──► [JIT HotSpot] ──► Native CPU Code
3Code Example
Stage 0 Language Foundations
public class Application {
public static void main(String[] args) {
System.out.println("=== Java 21 LTS Runtime Pipeline ===");
System.out.println("Java Version: " + System.getProperty("java.version"));
System.out.println("Available CPU Cores: " + Runtime.getRuntime().availableProcessors());
System.out.println("Max Heap Memory: " + (Runtime.getRuntime().maxMemory() / (1024 * 1024)) + " MB");
}
}4Expected Output
=== Java 21 LTS Runtime Pipeline === Java Version: 21.0.2 Available CPU Cores: 8 Max Heap Memory: 4096 MB
5Key Takeaways
- ✓Java source filename must match the public class name (e.g. Application.java).
- ✓Bytecode enables 'Write Once, Run Anywhere' (WORA) across all OS platforms.
- ✓The JVM JIT compiler dynamically optimizes frequently executed bytecode into native assembly.