1.2 Java Architecture
How Java turns your source code into platform-independent bytecode and then into machine instructions using the JVM and JRE.

From Source Code to Bytecode
Java follows a two-step compilation model. Instead of compiling directly to machine code for one operating system, the compiler first produces an intermediate, platform-neutral format called bytecode.
- Source code: You write Java programs in
.javafiles. - Compiler: The Java compiler checks your code for errors and translates it into bytecode.
- Bytecode: The compiled instructions are stored in
.classfiles and are understood by the JVM, not directly by the operating system.
Execution: JRE, JVM and JIT
Once bytecode is generated, the Java Runtime Environment (JRE) provides everything needed to run it on a particular machine.
1. Class Loader
Loads all the required .class files into memory when your program starts so that the JVM can use them.
2. Bytecode Verifier
Checks the loaded bytecode to ensure it is safe and follows JVM rules, preventing illegal memory access or corrupted instructions.
3. JVM and JIT Compiler
The Java Virtual Machine (JVM) interprets or compiles bytecode into native machine code. The Just-In-Time (JIT) compiler detects frequently executed sections and compiles them once for faster reuse.