1.
Explain Java program execution flow
Java source code (.java) is compiled by the javac compiler into bytecode (.class).
This bytecode is platform-independent.
The JVM then loads this bytecode and either interprets it line by line or uses the JIT compiler to
convert it into machine code, which is executed by the CPU to produce output.
Java code → Compiler (javac) → Bytecode → JVM (Interpreter + JIT) → Machine code → Execution
→ Output
2. What is bytecode? Why is it important?
Bytecode is the intermediate code generated by the Java compiler.
It is platform-independent, meaning it can run on any system that has a JVM.
This is the main reason Java follows the principle: Write Once, Run Anywhere (WORA)
3. What is JVM?
JVM (Java Virtual Machine) is a runtime environment that executes Java bytecode.
It converts bytecode into machine code using an interpreter and JIT compiler.
It also handles memory management, garbage collection, and security.
4. Difference between JDK, JRE, JVM
JVM → Executes bytecode
JRE (Java Runtime Environment) → JVM + libraries to run programs
JDK (Java Development Kit) → JRE + tools like compiler (javac)
5. What is JIT compiler?
JIT (Just-In-Time) compiler is part of the JVM that converts frequently used bytecode into machine code at
runtime, improving performance compared to interpretation.
6. Interpreter vs JIT
Interpreter → Executes code line by line (slower)
JIT Compiler → Converts code into machine code (faster execution)
7. Why Java is platform independent?
Because Java code is compiled into bytecode, which is not machine-specific.
This bytecode runs on any system that has a JVM.