The Java and Spring Boot questions senior full stack and backend interviews ask, with answers you can say out loud in a minute or two: the language, collections and generics, concurrency, the JVM, Spring, JPA, testing and production, and the questions about coming to Java from Node.js. The "what does this print?" cards were run with Java 25.
How to use this chapter. Each answer links back to the topic that explains it in depth. Read the question, answer it out loud first, then compare. A strong answer has a shape: the direct answer, how it works underneath, the trade-off or gotcha, and a concrete example, ideally from your own work. Interviewers for senior roles listen for judgement ("I'd use X, except when…") more than for definitions.
The language questions check that you know modern Java, not the Java of 2008, and that you understand the few places where Java behaves differently from what a JavaScript developer expects: equality, null, primitives and immutability.
The mental model for this section: every answer should mention a version or a trade-off. "Records (Java 16) give you equals and hashCode for free, but they're shallowly immutable" beats "records are data classes".
Overloads are chosen at compile time from the static types of the arguments, not from the runtime value. A cast to Object picks describe(Object); a cast to String picks describe(String), even though both values are null.
describe(42) boxes the int to Integer, the most specific match, so it prints Integer.
The trap is the version not shown: describe(null) with no cast doesn't compile here, because String and Integer are both more specific than Object and neither is more specific than the other: "reference to describe is ambiguous". With only Object and String overloads it would compile and pick String, the most specific.
?What does this print? finally and return
Finally.java
staticintcompute(){int x =1;try{return x;}finally{
x =2;IO.println("finally ran, x = "+ x);}}voidmain(){IO.println("returned "+compute());}
Show answer
Terminal
$ java Finally.java
finally ran, x = 2
returned 1
What’s happening
return x evaluates the return value first: 1 is saved as the result.
Then the finally block runs, sets the local x to 2 and prints finally ran, x = 2.
The method still returns the saved 1: changing a local primitive in finally doesn't change a value that was already computed. (A return statement insidefinally would replace it, and also swallow any exception; never do that.)
Collections questions are where interviewers check whether you know the cost of the data structure you reach for, and whether you can explain HashMap without hand-waving.
The mental model: name the structure, its big-O for the operation that matters, and its trap (mutable keys, unmodifiable views, iteration while modifying).
?What does this print? A mutable key
MutableKey.java
importjava.util.*;classSku{String code;Sku(String code){this.code = code;}@Overridepublicbooleanequals(Object o){return o instanceofSku other && code.equals(other.code);}@OverridepublicinthashCode(){return code.hashCode();}}voidmain(){Map<Sku,Integer> stock =newHashMap<>();Sku key =newSku("KB-1");
stock.put(key,12);
key.code ="KB-2";IO.println(stock.get(key));IO.println(stock.get(newSku("KB-1")));IO.println(stock.size());}
Show answer
Terminal
$ java MutableKey.java
null
null
1
What’s happening
put stored the entry in the bucket for the hash of "KB-1".
Changing key.code to "KB-2" changes its hash. get(key) now looks in the bucket for "KB-2", finds nothing: null.
get(new Sku("KB-1")) finds the right bucket, but the stored key's equals now compares "KB-2" with "KB-1": no match, null again.
The entry is still there (size is 1) but no key can reach it: a small memory leak. Map keys should be immutable; a record would have made code final.
Concurrency is where Node developers are most exposed, because Node hides threads. Interviewers want to hear that you understand shared mutable state and the tools for it, and that you know what virtual threads changed.
The mental model: every concurrency bug is shared mutable state without a happens-before relationship. Answers get strong when they name the guarantee (atomicity, visibility, ordering) each tool provides.
?What does this print? Lost updates
Two threads each add 1 to a shared counter 100,000 times. Does the plain int end at 200,000? Does the AtomicInteger?
Race.java
importjava.util.concurrent.atomic.AtomicInteger;int plain =0;AtomicInteger atomic =newAtomicInteger();voidmain()throwsInterruptedException{boolean lostAny =false;for(int round =0; round <20&&!lostAny; round++){
plain =0;
atomic.set(0);Runnable work =()->{for(int i =0; i <100_000; i++){
plain++;
atomic.incrementAndGet();}};Thread a =Thread.ofPlatform().start(work);Thread b =Thread.ofPlatform().start(work);
a.join();
b.join();
lostAny = plain <200_000;if(atomic.get()!=200_000){IO.println("atomic lost updates?!");}}IO.println("plain int lost updates: "+ lostAny);IO.println("AtomicInteger total: "+ atomic.get());}
Show answer
Terminal
$ java Race.java
plain int lost updates: true
AtomicInteger total: 200000
What’s happening
plain++ is three steps: read, add, write. When both threads read the same value and both write back value + 1, one increment is lost. So the plain counter ends below 200,000 (the exact number changes every run, which is why the program prints only whether updates were lost, trying up to 20 rounds).
atomic.incrementAndGet() is a single atomic compare-and-set operation, so it never loses one: AtomicInteger total: 200000.
Even volatile int plain wouldn't help: volatile makes each write visible, but the read-add-write is still three steps. Fix it with an atomic, a LongAdder, or synchronized.
JVM questions separate people who've run Java in production from people who've only written it. Interviewers like incident-flavoured questions: "the service's memory keeps growing", "p99 latency spikes every few minutes".
The mental model: heap and GC explain memory and pauses, the JIT explains warm-up, and the tools (jcmd, JFR, heap and thread dumps) are how you prove it.
?What does this print? Static initialisation order
Init.java
publicclassInit{staticclassConfig{staticfinalConfigINSTANCE=newConfig();staticint created =0;finalint number;Config(){
created++;
number = created;}}publicstaticvoidmain(String[] args){System.out.println("number: "+Config.INSTANCE.number);System.out.println("created: "+Config.created);}}
Terminal
$ java Init.java
number: 1
created: 0
What’s happening
Using Config.INSTANCE triggers class initialisation, which runs the static initialisers in source order.
First INSTANCE = new Config(): the constructor runs while created still has its default value 0, so it becomes 1 and number is 1.
Then the next static initialiser runs: static int created = 0;resetscreated to 0.
So it prints number: 1 and created: 0. Order of static fields matters; a singleton declared before the state it uses sees that state half-initialised.
Spring questions test whether you know what the framework does for you, so you can predict and debug it: the container, auto-configuration, proxies, configuration, and what changed in Boot 3 and 4.
The mental model: Spring is a container that builds your object graph and wraps beans in proxies; Boot adds conditional defaults. Almost every Spring puzzle ("why isn't my transaction working?", "why is this bean missing?") is answered by one of those two sentences.
JPA questions are really about what SQL your code produces and where the transaction boundary is. Interviewers like the N+1 problem, lazy loading and transactions because they cause real outages.
The mental model: Hibernate turns object navigation into SQL, lazily, inside a persistence context that lives as long as the transaction. Everything below follows from that.
These questions check whether you can ship and run a service: what you test and how, and what you watch once it's live.
The mental model: fast, focused tests for logic; a few real-infrastructure tests for the edges; and production signals (health, metrics, logs, traces) for everything tests can't predict.
#Coming from Node.js: questions about your background
Added
If your recent work is Node.js and TypeScript, expect questions about it. They aren't traps: the interviewer wants to know whether you understand the differences and whether you'll be productive. Be honest about where your Java experience is from, and specific about what transfers. The answers below are illustrative structures, not scripts and not claims about your history: fill them with your own projects and numbers.
The mental model: turn "less Java recently" into "I know two ecosystems and why each makes its choices". Comparing them well is a senior skill.