🚀 Java Architecture (Step-by-Step)

jvm Architecture

1. What is Java?

👉Example:
If you write a Java program on Windows, the same program can run on Linux or Mac without changes.

2. Java Program Execution Flow

Java works in these main steps:

  1. Write code in .java file (human-readable).
    Example:
    class Hello {
        public static void main(String[] args) {
            System.out.println("Hello World");
        }
    }
  2. Compile code with javac (Java Compiler).
    • Converts .java → .class (bytecode).
    • Bytecode is platform-independent.
  3. Run code with java command.
    • JVM loads .class file.
    • JVM executes bytecode using Execution Engine + JIT.

3. Main Components of Java Architecture

Java Architecture has 3 core parts:

(A) JVM (Java Virtual Machine)

👉Interview Point:

(B) JRE (Java Runtime Environment)

👉Interview Tip:
If you only need to run Java programs (not write/compile), you just need JRE.

(C) JDK (Java Development Kit)

👉Interview Tip:

4. Detailed JVM Architecture

JVM itself has sub-components:

jvm Architecture

1. ClassLoader

👉Example:
When you write System.out.println, java.lang.System is loaded by Bootstrap ClassLoader.

2. Memory Areas in JVM

JVM divides memory into parts when running a program:

👉Example Flow:
Student s = new Student();

3. Execution Engine

👉Example:
If a method is called 1000 times, JIT compiles it into native code so JVM doesn't re-interpret every time.

4. Garbage Collector (GC)

👉Example:
Student s1 = new Student();
s1 = null; // old object becomes unreachable → Garbage Collector cleans it

5. Step-by-Step Flow of Program Execution

  1. Source Code (.java) → written by developer.
  2. Compiler (javac) → converts to Bytecode (.class).
  3. ClassLoader → loads .class file into JVM.
  4. Bytecode Verifier → checks security (no illegal code).
  5. Execution Engine (Interpreter + JIT) → executes code.
  6. Garbage Collector → cleans unused objects.


7. Key Interview Questions

1. Why is Java platform independent?

2. Why is JVM platform dependent?

3. What is the role of JIT?

4. Difference between JVM, JRE, JDK?

5. What happens when you run a Java program?