Blog/Java Programming/Java Architecture/Java Architecture Interview Questions

Java Architecture Interview Questions

This chapter is a focused interview bank based on the notes we created today and the most repeated interview topics across common Java interview prep sources.

How to Use This File

  • Start with Top 20 Must-Prepare.
  • Then revise Rapid Fire before interview.
  • For depth, map each question to previous chapters in this module.

Top 20 Must-Prepare Questions

1) Why is Java platform independent?

Java source code is compiled into platform-independent bytecode (.class), and JVM (which is platform-specific) executes that bytecode on each OS.

2) What is bytecode in Java?

Bytecode is intermediate instruction set generated by javac from .java files. JVM understands and executes it.

3) What is the role of javac compiler?

It performs syntax/type checks and converts Java source code into bytecode.

4) What happens in Java compilation phase?

Syntax validation, type checking, semantic checks, comment ignoring, and .class bytecode generation.

5) What happens in Java execution phase?

Class loading, bytecode verification, memory allocation in runtime areas, and execution via interpreter/JIT.

6) Differentiate JVM, JRE, and JDK.

  • JVM: Executes bytecode.
  • JRE: JVM + runtime libraries.
  • JDK: JRE + development tools (javac, javadoc, debugger, etc.).

7) What is JVM?

An abstract runtime machine that executes Java bytecode and provides memory management, GC, and runtime services.

8) Is JVM process-based or system-based VM?

JVM is an application/process-based virtual machine.

9) What are main components of JVM architecture?

Class Loader, Runtime Memory Areas, Execution Engine, JNI, Native Method Libraries.

10) What are JVM memory areas?

Method Area, Heap, Stack, PC Register, Native Method Stack.

11) What is stored in Method Area?

Class metadata, runtime constant pool, method information, static variables.

12) What is stored in Heap?

Objects and arrays (including instance state of objects).

13) What is stored in Stack?

Per-thread stack frames: local variables, operand stack, method call/return data.

14) What is PC Register?

Per-thread register containing address of current JVM instruction.

15) What are Class Loader phases?

Loading, Linking (Verify + Prepare + Resolve), Initialization.

16) What happens in Linking phase?

  • Verify: Bytecode checks.
  • Prepare: Memory for static fields with default values.
  • Resolve: Symbolic to direct references.

17) Why is bytecode verifier important?

It prevents invalid or unsafe bytecode execution and improves runtime safety/security.

18) Interpreter vs JIT compiler?

  • Interpreter: Executes bytecode instruction-by-instruction.
  • JIT: Compiles hot bytecode paths to native machine code for performance.

19) Why does JVM use both interpreter and JIT?

Fast startup from interpreter + long-run performance from JIT optimization.

20) What is JNI?

Java Native Interface is a bridge that allows Java code to call native code/libraries (C/C++ and OS-level APIs).

High-Frequency Follow-Up Questions

21) What is Bootstrap, Extension/Platform, and Application ClassLoader?

They are layered class loaders: core Java classes, platform extension classes, and app classpath classes.

22) What is Java's "Write Once, Run Anywhere" practically?

Compile once to bytecode; run anywhere with compatible JVM implementation.

23) Why does Java need JRE to run programs?

Because runtime requires JVM + Java class libraries and support files available in JRE.

24) Can you run Java code with only JRE and no JDK?

You can run already compiled .class files, but you cannot compile new .java files without JDK.

25) Which memory is cleaned by garbage collector?

Primarily heap memory (unreachable objects).

26) Is stack memory garbage-collected like heap?

Stack frames are auto-released on method return; GC mainly targets heap objects.

27) What is a hot spot in JIT context?

A frequently executed code path/method selected by JVM for JIT compilation.

28) When are static variables assigned explicit values?

During class initialization phase after loading/linking.

29) Why are local variables thread-safe by default?

They live in thread-specific stack frames, not shared heap state.

30) Common misconception: Is Java interpreted or compiled?

Both. Java is compiled to bytecode and then interpreted/JIT-compiled at runtime.

Rapid-Fire (One-Liners)

  • JDK formula: JDK = JRE + Dev Tools
  • JRE formula: JRE = JVM + Runtime Libraries
  • Heap scope: Shared across threads
  • Stack scope: Per thread
  • Method Area scope: Shared
  • Class Loader output: Runtime class representation in JVM
  • JIT full form: Just-In-Time compiler
  • Main job of GC: Reclaim unreachable heap objects
  • Java entry command for execution: java ClassName
  • Java compile command: javac FileName.java

Interview Strategy for This Module

  1. Explain execution flow first (.java -> .class -> JVM).
  2. Then explain architecture blocks (ClassLoader, Memory, Engine).
  3. Then answer performance/safety with JIT + verifier + GC.
  4. End with JVM/JRE/JDK difference in one crisp table.

Suggested Self-Test Prompts

  • Draw JVM architecture from memory in 60 seconds.
  • Explain heap vs stack with one code example.
  • Explain class loading phases without notes.
  • Explain why Java is platform independent in 3 lines.
  • Explain interpreter + JIT together in under 45 seconds.