Java Backend Interview Q&A← All stacks

Java Language & Platform — Interview Q&A Matrix

Parent stack: Core Java Runtime Technology: Java Language & Platform Levels: Junior · Architect Questions: 4

Each entry contains a Question, the Expected Depth, an Ideal Answer, and Red Flags.

Junior

Q1 — == vs .equals() and the Integer cache

Question: What is the difference between == and .equals() for objects, and why does the following print true then false?

java
Integer a = 100, b = 100;
Integer c = 1000, d = 1000;
System.out.println(a == b); // ?
System.out.println(c == d); // ?

Expected Depth:

Ideal Answer:

java
System.out.println(c.equals(d)); // true, compares value
java
Objects.equals(null, 1000); // false, no exception

Red Flags:


Q2 — Checked vs unchecked exceptions & finally

Question: What is the difference between checked and unchecked exceptions? What does finally guarantee, and what happens if you return inside it?

Expected Depth:

Ideal Answer:

java
int value() {
    try {
        return 1;
    } finally {
        return 2; // always returns 2 and hides the first result
    }
}
java
try (var reader = Files.newBufferedReader(path)) {
    return reader.readLine();
} // reader.close() runs automatically, even on an exception

Red Flags:


Q3 — String immutability, pool, and StringBuilder

Question: Why is String immutable in Java? What is the string pool, and when should you use StringBuilder?

Expected Depth:

Ideal Answer:

java
var builder = new StringBuilder();
for (String part : parts) {
    builder.append(part);
}
String result = builder.toString();
java
String json = """
    { "status": "OK" }
    """;

Red Flags:


Architect

Q4 — Designing for backward/forward compatibility (records, sealed, modules)

Question: You're designing a shared domain library used by 40 services. How do modern Java features (records, sealed types, JPMS) shape an API that must evolve without breaking consumers?

Expected Depth:

Ideal Answer:

java
public record Money(String currency, long amountMinor) {}
java
public sealed interface PaymentEvent
        permits Authorized, Captured, Refunded {}

String describe(PaymentEvent event) {
    return switch (event) {
        case Authorized a -> "auth " + a.amount();
        case Captured c   -> "capture " + c.amount();
        case Refunded r   -> "refund " + r.amount();
    }; // the compiler checks that all types are covered
}

Red Flags:


Scoring Rubric

Level Pass bar
JuniorExplains basic language features and uses standard APIs correctly.
SeniorExplains trade-offs, finds risks, and writes correct code.
ArchitectDefines clear platform guidance and designs APIs that evolve safely.