CORE JAVA INTERVIEW PREP — DAY 1 & 2

Java Foundations

History & Editions · JDK vs JRE vs JVM · Bytecode & Compilation
Platform Independence · Java Architecture

Prepared for: Android Java Developer → Core Java Backend Developer

1. History of Java & Java Editions (SE / EE / ME)

1.1 What is it?

Java is a general-purpose, class-based, object-oriented programming language originally developed at Sun Microsystems, first released publicly in 1995. It was designed to let developers write code once and run it on any device without rewriting it for each platform.

Timeline (the version of history interviewers actually expect)

YearEvent
1991Project "Green" started by James Gosling, Mike Sheridan, Patrick Naughton at Sun Microsystems. Original language was called "Oak," aimed at embedded/consumer electronics.
1995Renamed to "Java" and released publicly. Tagline: "Write Once, Run Anywhere" (WORA).
1996JDK 1.0 released.
2004Java 5 (J2SE 5.0) — huge release: generics, enums, autoboxing, annotations, varargs, enhanced for-loop.
2009–2010Sun Microsystems acquired by Oracle. Java becomes an Oracle-stewarded language.
2014Java 8 — biggest modern release: Lambdas, Streams, Optional, new Date/Time API.
2017 onwardOracle moves to a 6-month release cadence (Java 9, 10, 11...) instead of multi-year cycles.
2018Java 11 — first Long Term Support (LTS) release after Java 8.
2021+Java 17 (LTS), Java 21 (LTS) — records, sealed classes, pattern matching, virtual threads (Project Loom).
Why was Java introduced / what problem did it solve?
C/C++ programs had to be compiled separately for every OS/CPU architecture, manual memory management caused frequent memory leaks and crashes, and there was no built-in security sandboxing for code downloaded over a network (this mattered a lot in the early Internet/applet era). Java solved this by introducing a virtual machine layer (the JVM), automatic garbage collection, and a security manager/sandbox model.

1.2 Java Editions — SE, EE, ME

EditionFull FormPurposeTypical Use
Java SEStandard EditionThe core Java platform — language fundamentals, collections, I/O, concurrency, JVM.Desktop apps, foundation for everything else (including Android's Java subset).
Java EE / Jakarta EEEnterprise EditionBuilt on top of SE; adds APIs for large-scale, distributed, web/enterprise apps — Servlets, JSP, EJB, JPA, JMS.Backend enterprise applications (this is the direction you're heading with Spring Boot, which largely replaces/augments raw Java EE).
Java MEMicro EditionA stripped-down subset of SE for resource-constrained devices.Old feature-phones, embedded/IoT devices (mostly historical today).
Interview angle: Note that as of 2018, Oracle donated Java EE to the Eclipse Foundation, and it was renamed Jakarta EE due to trademark reasons. Mentioning this shows you're up to date, not just reciting textbook facts.

1.3 Android Relevance

Android apps written in Java use the Java SE language and a subset of its core libraries, but they do not run on a traditional JVM — they compile to a different bytecode format run by ART (Android Runtime), previously Dalvik. This is a classic interview trap: interviewers will ask "does Android use JVM?" — the correct answer is no, Android uses ART/Dalvik with DEX bytecode, not JVM with .class bytecode, even though the source language is Java.

Interview Questions — History & Editions

Q1. Who created Java and why was it originally called "Oak"?
James Gosling led the team at Sun Microsystems; it was named Oak after a tree outside Gosling's office, later renamed due to a trademark conflict.
Q2. What is the difference between Java SE, EE, and ME?
SE = core language/platform; EE = SE + enterprise APIs (web, distributed systems); ME = a lightweight subset for embedded/constrained devices.
Q3. Is Android's Java runtime the same as the standard JVM?
No — Android uses ART (formerly Dalvik), which executes DEX bytecode, not the JVM's .class bytecode. This is a very common trap question for Android-to-backend candidates specifically.
Q4. What is Jakarta EE?
The renamed continuation of Java EE after Oracle transferred it to the Eclipse Foundation in 2017–2018.
Q5 (Tricky). If Java was designed for embedded consumer electronics, why did it become famous for web/enterprise backend systems?
Its "write once run anywhere" promise, strong standard library, and later Java EE additions made it ideal for portable, secure, server-side software — a different market than originally intended, but the same underlying design goals (portability, safety, robustness) applied.

2. JDK vs JRE vs JVM

2.1 What is each one?

ComponentFull FormContainsUsed For
JVMJava Virtual MachineClass loader, bytecode verifier, execution engine (interpreter + JIT compiler), runtime memory areas (heap, stack, etc.)Actually executes Java bytecode. It's an abstract spec with concrete implementations (HotSpot, OpenJ9, etc.)
JREJava Runtime EnvironmentJVM + core class libraries (java.lang, java.util, java.io, etc.) + supporting filesEverything needed to run a compiled Java program — but no compiler.
JDKJava Development KitJRE + development tools (javac compiler, javadoc, jar, jdb debugger, jshell, etc.)Everything needed to develop and run Java programs.
Simple mental model: JDK ⊃ JRE ⊃ JVM (JDK is a superset containing JRE, which is a superset containing JVM).

2.2 Why does this separation exist?

End users who only need to run Java applications (e.g., running a desktop app) historically only needed the JRE — no need to ship a compiler with every machine. Developers writing/compiling code need the full JDK. This separation kept distribution lean. (Note: since Java 11, Oracle stopped shipping a separate public JRE download — you typically install a JDK even just to run apps now, though the conceptual distinction still matters for interviews.)

2.3 Internal Working / What's inside the JVM

What happens if this separation didn't exist? Without the JVM abstraction layer, Java code would have to be compiled directly to machine code per platform (like C), losing the "write once, run anywhere" guarantee entirely — you'd be back to distributing separate binaries for Windows/Linux/macOS.

Interview Questions — JDK / JRE / JVM

Q1. What is the relationship between JDK, JRE, and JVM?
JDK = JRE + development tools. JRE = JVM + core libraries. JVM is the actual execution engine.
Q2. Can you run a compiled .class file without installing the JDK?
Yes, historically with just the JRE (or the java command from a JDK, since standalone JRE downloads are largely discontinued post Java 11).
Q3. Is the JVM platform-independent?
The JVM specification is platform-independent, but each JVM implementation (e.g., Windows JVM, Linux JVM) is platform-dependent — this is precisely what makes the bytecode above it portable.
Q4 (Tricky). Is JVM a compiler or an interpreter?
Both — it starts by interpreting bytecode, then uses a JIT compiler to convert frequently executed ("hot") code paths into native machine code for performance. This is why it's called a "mixed-mode" execution engine.
Q5 (Scenario). Your company ships a Java desktop tool to clients who only run it, never compile it. What's the minimum they need installed?
Conceptually just a JRE; practically today, a JDK (since standalone JRE distribution has been discontinued by Oracle since Java 11) or a jlink-produced custom minimal runtime image.
Q6. Name two JVM implementations other than Oracle's HotSpot.
Eclipse OpenJ9, Azul Zing/Prime, GraalVM (which also does polyglot + native image compilation).

3. Bytecode, Compilation Process & Execution Process

3.1 What is Bytecode?

Bytecode is an intermediate, platform-neutral instruction set stored in .class files after compilation. It is not native machine code (which is CPU-specific) and not raw source code (which is human-oriented) — it sits in between, designed specifically for the JVM to interpret or JIT-compile.

Why was bytecode introduced? If javac compiled Java source directly to machine code, you'd need a different compiler output for every CPU/OS combination — defeating portability. By compiling to a neutral bytecode format instead, only the JVM implementation needs to be platform-specific; your compiled .class file never changes.

3.2 Compilation Process — Step by Step

  1. Source Code (.java) is written by the developer.
  2. javac (Java Compiler) compiles it into bytecode (.class file) — this step also does static type checking and catches compile-time errors.
  3. The .class file contains bytecode instructions plus metadata (constant pool, method signatures, etc.) understood only by the JVM.
$ javac HelloWorld.java     <-- produces HelloWorld.class (bytecode)
$ java HelloWorld           <-- JVM loads & executes the bytecode

Example

// HelloWorld.java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, Interview!");
    }
}

You can inspect the actual bytecode instructions using javap -c HelloWorld.class — this is an excellent thing to mention in an interview to show hands-on curiosity about internals.

3.3 Execution Process — Step by Step

  1. Class Loading — the ClassLoader subsystem loads the .class file's bytecode into the Method Area of JVM memory.
  2. Bytecode Verification — the Bytecode Verifier checks the code doesn't violate JVM security/structural constraints (no illegal type casts, no stack overflow at a structural level, no access violations) before it's trusted to run.
  3. Execution — the Execution Engine runs the verified bytecode:
  4. Garbage Collection runs concurrently/periodically to reclaim heap memory of unreachable objects.
Real-world analogy: Think of bytecode like sheet music. Any musician (JVM on any OS) who can read standard musical notation can play it, regardless of what instrument (CPU architecture) they own. The composer (javac) only needs to write the notation once.

3.4 JIT Compilation Tiers (deeper detail for senior-level questions)

Interview Questions — Bytecode & Compilation/Execution

Q1. What is bytecode and why does Java use it instead of compiling directly to machine code?
Bytecode is a platform-neutral intermediate representation. It enables portability — the same .class file runs on any OS with a compatible JVM, without recompilation.
Q2. What are the two ways the JVM executes bytecode?
Interpretation (line-by-line, fast to start) and JIT compilation (compiles hot code paths to native machine code for long-term performance).
Q3. What does the Bytecode Verifier check for, and why does it matter for security?
It ensures the bytecode doesn't violate JVM constraints (illegal casts, stack corruption, illegal access) — critical historically for safely running untrusted code like applets downloaded from the web.
Q4 (Tricky). If the JVM interprets bytecode, why is Java sometimes said to run "as fast as C++" in long-running server applications?
Because of JIT compilation — after warm-up, hot code paths run as optimized native machine code, sometimes even outperforming naive C++ compiled ahead-of-time because JIT has access to runtime profiling data (actual branch behavior, actual object shapes) that a static compiler doesn't.
Q5 (Scenario). A short-lived CLI tool and a long-running web server are both written in Java. Which benefits more from JIT, and why might the CLI tool feel "slower" per-invocation despite Java's JIT?
The web server benefits more — JIT needs many repeated invocations ("warm-up") to identify and optimize hot paths. A short-lived CLI process may exit before JIT optimization kicks in, so it runs mostly interpreted, which is why short scripts can feel slower to start in Java (this is also why GraalVM Native Image exists — to AOT-compile for fast-starting CLI-style use cases).
Q6. What tool can you use to view the actual bytecode generated for a class?
javap -c ClassName, or javap -v for verbose output including the constant pool.

4. Platform Independence — "Write Once, Run Anywhere" (WORA)

4.1 What does WORA actually mean?

It means Java source code, once compiled into bytecode, can run unmodified on any device with a compatible JVM installed — Windows, Linux, macOS, etc. — without needing to be recompiled for each platform.

What problem does it solve? Before Java, C/C++ programs required separate compilation (and often separate code branches using preprocessor directives) for each target OS/architecture. This multiplied development, testing, and maintenance effort. WORA collapses this into "compile once."

4.2 How is it actually achieved? (This is the part interviewers really want)

  1. The Java compiler (javac) never targets a specific CPU — it always targets the abstract JVM bytecode format.
  2. Each platform has its own platform-specific JVM implementation that knows how to translate that same bytecode into instructions that specific OS/CPU understands.
  3. So the portability burden shifts from "every program must be recompiled per platform" to "only the JVM itself is written per platform" (by the JVM vendor, not by application developers).
Common Misconception (interview trap): "Write Once, Run Anywhere" does NOT mean there's zero platform dependency at all — file path separators, line endings, native library integrations (JNI), and even subtle floating-point/timezone behaviors can differ. WORA is a strong practical guarantee at the bytecode/JVM level, not an absolute guarantee against every OS-level difference. Good candidates mention this nuance rather than reciting WORA as an absolute truth.

4.3 Advantages

4.4 Disadvantages / Trade-offs

Interview Questions — Platform Independence

Q1. Explain "Write Once, Run Anywhere" in your own words.
Java source compiles to platform-neutral bytecode once; any machine with a matching JVM can run that same bytecode without recompilation, because the JVM (not the application) handles the platform-specific translation.
Q2. Is Java 100% platform-independent with zero exceptions?
No — native library calls via JNI, certain OS-level file/path behaviors, and environment-specific configuration can introduce platform-specific behavior. WORA is a strong guarantee at the bytecode/JVM execution level, not an absolute one.
Q3 (Scenario). Your Java app runs perfectly on your Windows dev machine but a file-handling test fails on the Linux CI server. Does this contradict WORA?
Not necessarily — it likely reflects OS-level differences (path separators \ vs /, case sensitivity of filesystems, line-ending differences) rather than a JVM/bytecode portability failure. This is exactly the nuance interviewers probe for.
Q4. What's a modern technology that trades away some WORA benefit for faster startup, and why would a team choose it?
GraalVM Native Image — it Ahead-Of-Time compiles Java to a platform-specific native binary for near-instant startup and lower memory footprint (great for serverless/microservices), at the cost of building a separate binary per target platform, which is the opposite trade-off from classic WORA.

5. Java Architecture Overview

(Source → Compiler → Bytecode → JVM → Machine Code)

5.1 The Full Pipeline

 [1] MyProgram.java   (Source Code — human readable)
          |
          |  javac (compiler): syntax check, type check
          v
 [2] MyProgram.class  (Bytecode — platform-neutral instructions)
          |
          |  java (launcher) starts the JVM, which:
          v
 [3] Class Loader     -> loads .class into Method Area
          |
          v
 [4] Bytecode Verifier -> checks safety/structural correctness
          |
          v
 [5] Execution Engine
        - Interpreter (executes bytecode directly), and/or
        - JIT Compiler (compiles hot paths to native machine code)
          |
          v
 [6] Native Machine Code executed by the actual CPU

5.2 The Three Big JVM Subsystems (recap, tie-together)

SubsystemResponsibility
Class Loader SubsystemLoading, Linking (Verify → Prepare → Resolve), Initialization of classes
Runtime Data AreasMethod Area/Metaspace, Heap, Java Stacks, PC Registers, Native Stacks
Execution EngineInterpreter, JIT Compiler, Garbage Collector
How to answer "explain Java architecture" in an interview (structure your answer this way):
  1. Start with the pipeline: source → javac → bytecode → JVM → machine code.
  2. Name the 3 JVM subsystems (class loader, runtime data areas, execution engine).
  3. Mention WORA as the outcome/benefit this architecture achieves.
  4. If pushed deeper, go into class loading phases or JIT tiers (shows depth without being asked twice).

Interview Questions — Java Architecture

Q1. Walk me through what happens from the moment you run java MyProgram to the program actually executing.
JVM starts → Class Loader locates and loads MyProgram.class into the Method Area → Bytecode Verifier validates it → Execution Engine begins interpreting bytecode (and JIT-compiles hot methods over time) → output is produced via native machine instructions executed by the CPU, with GC running in the background to manage heap memory.
Q2. Where does compilation end and JVM responsibility begin?
javac's job ends once it produces the .class bytecode file. Everything from loading that bytecode onward (verification, execution, memory management) is the JVM's responsibility at runtime.
Q3 (Tricky). Is there only one compilation step in Java's execution model?
No — there are effectively two: (1) javac compiles source to bytecode ahead-of-time, and (2) the JIT compiler inside the JVM later compiles hot bytecode into native machine code at runtime. Candidates who only mention javac miss half the architecture.
Q4 (Scenario). You're asked to explain to a junior dev why editing a .java file doesn't change the running application's behavior immediately. What do you say?
Because the JVM executes the compiled .class bytecode, not the .java source directly — you must recompile with javac (regenerating the .class file) and restart/reload the JVM (or use a hot-reload tool) for the change to take effect.

Quick-Fire MCQs (Self-Test Before Moving to Day 3)

1. Java bytecode is executed directly by the CPU.
(a) True   (b) False   — Answer: (b) False — it's executed/interpreted or JIT-compiled by the JVM.
2. Which contains the other two: JDK, JRE, JVM?
Answer: JDK (JDK ⊃ JRE ⊃ JVM)
3. Android apps run directly on a standard JVM.
(a) True   (b) False   — Answer: (b) False — Android uses ART/Dalvik with DEX bytecode.
4. What tool converts .java files to .class files?
Answer: javac
5. Name the JVM component responsible for checking bytecode safety before execution.
Answer: Bytecode Verifier
6. Which edition of Java is the foundation that EE is built on top of?
Answer: Java SE
7. True or False: WORA guarantees zero platform-specific behavior under all circumstances.
Answer: False — native calls (JNI) and OS-level differences can still introduce platform-specific behavior.

Mini Assignment

  1. Write a "Hello World" program, compile it with javac, then run javap -c on the resulting .class file. Try to identify at least 3 bytecode instructions and guess what they do.
  2. Write one paragraph (in your own words, no notes) explaining the full journey from source code to program output, as if explaining it to a fellow Android developer who has never seen server-side Java.
  3. Research and note down: which JVM implementation does your current Android Studio / backend JDK use (HotSpot? Something else?), and what Java version it targets.