Java backend interviews cover core language semantics, collections, concurrency, Spring, and how you reason about the JVM. Below are the questions asked most often, each with a model answer. Senior: architecture, trade-offs, mentoring, and decision-making.
1
What is the difference between checked and unchecked exceptions?
Answer
Checked exceptions extend Exception and must be declared or handled — they represent recoverable conditions the caller should plan for, like IOException. Unchecked exceptions extend RuntimeException and signal programming errors such as NullPointerException or IllegalArgumentException. The practical guidance is to use unchecked for bugs and checked sparingly, because forcing every caller to handle an exception often produces empty catch blocks.
2
What is Dependency Injection in Spring and which injection types exist?
Answer
DI means an object receives its dependencies from the container instead of constructing them, which decouples classes and makes them testable. Spring supports constructor, setter, and field injection. Constructor injection is preferred: dependencies become final, the object is never in a half-built state, and the class cannot hide an ever-growing dependency list the way field injection can.
3
What is the difference between @Component, @Service, @Repository and @Controller?
Answer
All four register the class as a Spring bean and are technically interchangeable for scanning. They differ in intent and in the extras Spring attaches: @Repository translates persistence exceptions into Spring's DataAccessException hierarchy, @Controller and @RestController take part in request mapping, and @Service is a semantic marker for business logic. Using the specific annotation documents the layer and enables the right behaviour.
4
What is a transaction? Explain isolation levels.
Answer
A transaction is a unit of work that satisfies ACID: it either commits entirely or rolls back. Isolation levels trade consistency against concurrency — Read Uncommitted allows dirty reads, Read Committed prevents them, Repeatable Read also prevents non-repeatable reads, and Serializable prevents phantom reads at the cost of throughput. Most systems run Read Committed and handle the remaining anomalies with optimistic locking.
5
What is the difference between ArrayList and LinkedList? When do you use each?
Answer
ArrayList is backed by a resizable array: indexed access is O(1), but inserting or removing in the middle shifts elements. LinkedList is a doubly linked list: insertion and removal at a known node is O(1), but indexed access is O(n) and every element carries node overhead. In practice ArrayList wins almost always because CPU cache locality beats theoretical complexity; LinkedList is mainly useful as a Deque.
6
What are volatile and synchronized? When do you use each?
Answer
volatile guarantees visibility — a write is immediately visible to other threads and reads are never cached — but it does not provide atomicity, so volatile counters still lose increments. synchronized provides both visibility and mutual exclusion, so only one thread executes the block at a time. Use volatile for a simple flag read by many threads, synchronized or an Atomic class when the operation is read-modify-write.
7
Explain the N+1 problem in Hibernate and how to avoid it.
Answer
N+1 happens when you load N parent entities with one query, then lazily access a collection on each, producing N additional queries. It usually appears as a page that is fast in tests with three rows and unusable with three thousand. Fixes are a JOIN FETCH in JPQL, an entity graph, batch fetching via @BatchSize, or a projection that selects exactly the fields the view needs.
8
What is the difference between String, StringBuilder and StringBuffer?
Answer
String is immutable, so every concatenation allocates a new object — building a string in a loop with + is quadratic. StringBuilder is a mutable buffer and is the right tool for that loop. StringBuffer is the same as StringBuilder but with synchronized methods; it is essentially legacy, since sharing a mutable buffer across threads is rare and usually needs coarser locking anyway.
9
What is the Java Stream API and when should you not use it?
Answer
Streams express operations on collections declaratively as a pipeline of intermediate operations that are lazy and a terminal operation that triggers execution. They shine for filtering, mapping, and aggregation because intent stays readable. Avoid them for very hot loops where the abstraction costs measurable time, for logic with side effects, and for anything where a plain for loop would read more clearly.
🦎
Reading answers is not enough
In a real interview you speak under pressure. Cam asks these same questions, scores every answer, and shows exactly what to fix.
Practice a Senior Java Backend interview →Free · 3 interviews per month