Judgment drills for backend interviews: Java Core, Spring Boot and the web
Memorised answers break at the next question: what would you do. How to answer through the failure mode and the evidence, which defaults to pick (equals, pass-by-value, interfaces, constructor injection, idempotency), and drills on reviewing AI-written code, choosing designs and reading incidents.
On this page
1. The problem
A candidate answers "POST isn't idempotent" in five seconds. Next question: "The gateway retries after a 2-second timeout and 1.8% of bookings are duplicated. What do you do?" Silence. Memorisation stops exactly where the interviewer starts scoring.
2. Key idea
Every fundamental has a specific failure point, and interviewers ask about it. Answer in four steps: one sentence of definition, where it breaks (which input goes wrong), evidence (a red test, a log, a number), the default and when you'd change it.
| Fundamental | Where it breaks | In other languages |
|---|---|---|
== compares identity, equals content |
Integer 128 and above compared with == is false |
Python is on numbers outside -5..256 |
equals goes with hashCode |
a HashSet holding two "equal" elements |
Python sets __hash__ to None when you define __eq__ |
| Pass by value | reassigning a parameter isn't seen by the caller | Go, Python, JavaScript too |
| POST isn't idempotent | retry after timeout creates duplicates | every HTTP API with retries |
2.1 Defaults to pick, and when to change them
The last column is where you score.
| Default | Use when | Don't use when (switch to) |
|---|---|---|
| Interfaces for contracts | you need mocks, several providers | subclasses share state and an algorithm skeleton: abstract class |
ArrayList |
index access, sequential scans | adds/removes at both ends: ArrayDeque |
Constructor injection, final fields |
required dependencies | optional dependencies: setter injection |
Path variable /users/1 |
identifying one resource | filtering, sorting, paging: query params |
PUT with a client-generated id |
operations that must retry safely | server-generated ids: POST + idempotency key |
Tell project stories in six points: name, role, team size, features, the problem and how you solved it, results with numbers you measured. Every number on a CV gets "how did you measure that?".
3. In Java
Integer reserved = 200, requested = 200;
System.out.println(reserved == requested); // false: outside the -128..127 cache
System.out.println(reserved.equals(requested)); // true
static void print(Object o) { System.out.println("Object"); }
static void print(String s) { System.out.println("String"); }
Object o = "hello";
print(o); // "Object": overloads pick by DECLARED type, at compile time
static void rename(List<String> names) { names.add("B"); } // changes the shared object
static void replace(List<String> names) { names = new ArrayList<>(); } // only changes the copy
List<String> names = new ArrayList<>(List.of("A"));
rename(names); replace(names);
System.out.println(names); // [A, B]Other languages: C# has ReferenceEquals and Equals; Node.js compares objects with === by identity.
Common fundamentals, answered by where they break
- JDK, JRE, JVM: the JVM runs bytecode (JIT, GC); the JDK adds
javac,jcmd. Since Java 11 Oracle ships no separate JRE; usejlinkor a Temurin image. - Encapsulation: getters/setters for every field aren't encapsulation; the object guards its own invariants (
Wallet.withdrawchecks the balance). Prefer composition over inheritance (fragile base class). finalon a reference: no reassignment, but the object inside can still change.finalfields are guaranteed visible after the constructor by the Java Memory Model.- Overloading is chosen at compile time by declared type; overriding at runtime by actual type. Static methods can't be overridden.
- Spring DI: constructor injection for
finalfields, tests without Spring; field injection hides dependencies. - HTTPS: TLS 1.3 handshakes in 1 RTT, the certificate proves the server; HSTS forces browsers onto HTTPS.
4. Working with AI
Delegate to AI: generating questions from your CV, playing an interviewer who digs deeper, grading answers against the four steps.
Check AI-drafted answers:
- There's a concrete failure point (an input, a number), not just a definition.
- There's a way to prove it: a test, a command, a metric.
- It says when to change the default.
- Every number is one you measured and can explain.
5. Exercises
Exercise 1: Review an Integer refactor with "unchanged behaviour"
AI changed int qty to Integer qty to allow null, noting "just a refactor, tests still green". Tests use quantities 2 and 5. Find the bug, name a test, fix it.
record Line(String sku, Integer qty) {}
boolean sameQuantity(Line ordered, Line shipped) {
return ordered.qty() == shipped.qty();
}Solution to Exercise 1
==on twoIntegers compares identity. From -128 to 127,Integer.valueOfreturns cached objects, so tests pass; from 128, each boxing creates a new object:128givesfalse.- Test: a
@ParameterizedTestwith 127, 128, 1000 andnull. - Fix:
return Objects.equals(ordered.qty(), shipped.qty());. The cache's upper bound can be changed with-XX:AutoBoxCacheMax, so a test that passes on one machine can fail on another.
Exercise 2: Read the duplicate-booking incident
After enabling gateway retries (2-second timeout, 1 retry), one hour shows 12,400 POST /bookings, 3.1% timeouts, 220 duplicate bookings (same customer, room and dates, ~2 seconds apart). The app logs no errors. Diagnose, act within 15 minutes, fix the root cause.
Solution to Exercise 2
- Diagnosis: the first request is slow but succeeds; after 2 seconds the gateway resends and the server creates a second booking. The ~2-second gap and clean logs are the giveaway.
- 15 minutes: turn off retries for
POSTat the gateway (keep them for GET); query the duplicates to cancel or refund; tell customer support. - Root fix: the client sends an
Idempotency-Key(a UUID per click), the server stores the key with the result and returns the old result on a repeat;UNIQUE (user_id, idempotency_key)as the final net. Find out why the first request took over 2 seconds.
Summary
- Answer in four steps: definition, failure point, evidence, default.
- Compare wrappers with
equals; overrideequalsand overridehashCode. - Java passes by value; overloads at compile time, overrides at runtime.
- POST needs an idempotency key before you turn on retries.
- Tell projects through problems solved and numbers you measured.
Comments
Community rules