HeadlinesBriefing favicon HeadlinesBriefing.com

How the JVM Works: From Code to Execution

ByteByteGo •
×

The Java Virtual Machine transforms human-readable code into running programs through a multi-stage process. Starting with javac compilation, Java source code becomes platform-independent bytecode stored in .class files, JARs, or modules. This bytecode serves as the universal intermediary that allows Java's 'write once, run anywhere' promise to function across different operating systems and hardware architectures.

Loading begins when the class loader subsystem brings classes into memory using parent delegation. The bootstrap loader handles core JDK classes, platform loader manages extensions, and system loader processes application code. During linking, bytecode verification ensures safety, static fields are allocated with default values, and symbolic references convert to direct memory addresses. Initialization assigns actual values to static variables and executes static blocks.

Execution involves both interpretation and compilation. The interpreter runs bytecode directly for fast startup, while the JIT compiler converts frequently called methods into native machine code stored in the code cache. This hybrid approach balances startup speed with peak performance. The JVM manages memory through shared heap and method areas across threads, while maintaining per-thread stacks, program counters, and native method stacks. Garbage collection automatically reclaims unused heap memory, completing the environment that makes Java applications portable and efficient.