Home › Interview questions
Java & Spring Boot interview questions — Level III · Mid
74 questions with a short answer, a full explanation and the mistakes interviewers listen for. Every question has a difficulty level from I (Beginner) to V (Expert).
Variables, Data Types & Operators · Java Foundations — Zero to Basics
- What is integer overflow in Java, why is it silent, and how do you guard against it in production?III
- Why is char a numeric type in Java, and what breaks when you treat a String as a sequence of chars for non-Latin text?III
Control Flow — Loops, Conditionals & Switch · Java Foundations — Zero to Basics
- Explain switch pattern matching (Java 21) and how it changes the way you'd write type-dispatch code.III
OOP I — Classes, Objects, Constructors · Java Foundations — Zero to Basics
- Walk through the exact order of initialization when 'new SubClass()' runs, including static and instance initializers.III
- Why is it dangerous to call an overridable method from a constructor?III
- When would you make a class immutable, and what does it take to do it correctly?III
- What problem do static factory methods solve that constructors cannot, and what's the trade-off?III
OOP II — Inheritance, Polymorphism, Interfaces · Java Foundations — Zero to Basics
- What are covariant return types, and what rules constrain an overriding method's signature, exceptions, and visibility?III
- What is the Liskov Substitution Principle, and give a concrete way code violates it.III
OOP III — Encapsulation, Abstraction, Enums · Java Foundations — Zero to Basics
- Why are Java enums the recommended way to implement a singleton, and what else makes enums more than named constants?III
- What is constant-specific behavior in an enum, and when would you use it instead of a switch?III
Strings, StringBuilder & String Pool · Java Foundations — Zero to Basics
Exception Handling & Custom Exceptions · Java Foundations — Zero to Basics
- How should you design a custom exception hierarchy, and what belongs in the exception itself?III
- What are the performance and correctness costs of exceptions, and why shouldn't you use them for control flow?III
- What is a suppressed exception and when do you encounter one in practice?III
Generics — Wildcards, Bounded Types, PECS · Java Foundations — Zero to Basics
- Explain PECS (Producer Extends, Consumer Super) with a concrete example of choosing the right wildcard.III
- What is type erasure, what does it cost you at runtime, and how do you work around it?III
- Compare a bounded type parameter <T extends Number> with a wildcard <? extends Number>. When do you need each?III
- What is a recursive generic bound like <T extends Comparable<T>>, and where does it show up?III
Collections Deep Dive — List, Set, Map, Queue · Java Foundations — Zero to Basics
- Walk through how HashMap works internally, including resizing and the treeification introduced in Java 8.III
- Why is ConcurrentModificationException best-effort, and how do concurrent collections differ from synchronized wrappers?III
Java 8 — Optional, Date/Time API, Method Refs · Java Foundations — Zero to Basics
- Why is using the wrong temporal type (e.g., LocalDateTime for a timestamp) a production hazard?III
- Compare Duration and Period, and why does adding a Duration of '24 hours' differ from adding '1 day'?III
File I/O — java.io, NIO2 & Files API · Java Foundations — Zero to Basics
- How do you walk a directory tree safely, and what are the pitfalls of Files.walk versus Files.walkFileTree?III
- Why should you prefer Path.resolve and avoid string concatenation for file paths, and what's the security angle?III
- What does StandardCopyOption.ATOMIC_MOVE give you, and why does it matter for safe file writes?III
JVM Architecture · JVM Internals & Runtime
- Walk me through the difference between class loading, linking, and initialization, and why the JVM separates them.III
- What is the parent-delegation model and what concrete problems does it prevent?III
- Why does PermGen's removal in Java 8 matter, and what changed operationally with Metaspace?III
- Which runtime data areas are per-thread versus shared, and why does that distinction matter?III
Collections & Equals/HashCode Contracts · Core & Modern Java (8 -> 21)
- Why is implementing compareTo as a.value - b.value a bug, and what should you do instead?III
- When should you reach for a concurrent or copy-on-write collection instead of synchronizing a plain one?III
IoC, DI & Bean Lifecycle · Spring & Spring Boot
- Explain the Spring bean lifecycle from instantiation to destruction, and where AOP proxies appear.III
- You @Autowire a prototype-scoped bean into a singleton service. Why does each call return the same instance, and how do you fix it?III
- How does Spring handle circular dependencies, and why is a constructor cycle a design smell rather than something to patch with @Lazy?III
SQL Mastery & Joins · Databases & Persistence
- When would you use a correlated subquery versus a JOIN or a window function, and what's the performance concern?III
- Explain window functions and how they differ from GROUP BY, with a concrete example.III
- How do CTEs and self-joins help, and when is a recursive CTE the right tool?III
Scalability Fundamentals · System Design
- A user adds an item to their cart, refreshes, and the cart is empty. What's the likely cause and the fix?III
- Why prefer Least Connections over Round Robin, and when do sticky sessions hurt you?III
- You add read replicas and a user reports they don't see their own write. What's happening and how do you fix it?III
- What makes a bad shard key, and why is resharding so painful?III
Microservice Patterns & Architecture · Distributed Systems & Messaging
- Explain circuit breaker states and the specific failure it prevents.III
- How do you handle a request that needs data from five services without killing tail latency?III
- How do you migrate a monolith to microservices with the strangler-fig pattern, and which piece do you extract first?III
Docker & Containers · DevOps: Docker, Kubernetes & Helm
- What does a multi-stage build buy you for a Spring Boot service beyond a smaller image?III
- Your container is PID 1 and doesn't shut down cleanly on a Kubernetes rolling update. What's wrong?III
- Why must you set JVM heap relative to the container memory limit, and what's the failure if you don't?III
- Why run as non-root and what other hardening do you apply to a production image?III
Linux Essentials & Shell · Linux, Networking & Observability
- A Java service is pegging CPU in production. Walk me through diagnosing it on the box with command-line tools.III
- Explain load average versus CPU utilization and why the distinction matters.III
- What is a file descriptor, and how does the 'too many open files' error happen and get fixed?III
- Why is structured pipeline analysis better than grep alone, and show a couple of one-liners you'd actually use.III
- How do you run a Spring Boot app as a managed service and read its logs without a custom PID script?III
Multi-Module Maven Project Design · Real-World Java Backend Architecture
- Why split a backend into a multi-module Maven build instead of one module, and what's the typical layout?III
- Explain dependencyManagement versus dependencies in a parent POM and why it matters.III
- What is a Maven BOM and how does importing the Spring Boot BOM help?III
- Should the domain module depend on Spring, and why do people insist it shouldn't?III
Creational Design Patterns · Design Patterns in Java
- Walk me through implementing a thread-safe Singleton, and why is the GoF Singleton often called an anti-pattern?III
- Compare Factory Method, Abstract Factory, and Builder — when would you pick each?III
- Someone asks you to 'implement clone()' for an object with a mutable list field. How do you respond?III
- When is Prototype the right choice, and how does Spring's @Scope('prototype') relate to it?III
- You're choosing between an object pool and just allocating fresh objects. How do you decide?III
JVM Internals — Top Interview Q&A · Interview Rapid-Fire — Top Q&A
- How does the JVM memory model work?III
- Explain the Class Loading lifecycle.III
- How does Garbage Collection work internally?III
- G1 GC vs ZGC vs Serial GC?III
- What triggers a Full GC?III
- What is Escape Analysis?III
- What is Metaspace and how is it different from PermGen?III
- How do you troubleshoot OutOfMemoryError?III
Start Here — Build Your First AI Feature · Build AI Features as a Java Backend Engineer
- Explain time-to-first-token versus total latency, and why streaming responses to the client is worth the extra complexity.III
- How do you evaluate an LLM feature, and why don't ordinary unit tests work?III
- When should you NOT use an LLM, and how do you defend that decision to a product manager who wants AI everywhere?III
Reading answers is not the same as giving them. Practise out loud with a timed mock interview, flashcards and an AI interviewer — free to start.
Start practising