Home › Interview questions
Java & Spring Boot interview questions — Level II · Junior
71 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).
How Java Runs — JDK, JRE, JVM & Your First Program · Java Foundations — Zero to Basics
Variables, Data Types & Operators · Java Foundations — Zero to Basics
- Java is often described as 'pass-by-value' even for objects. Explain what that actually means and a bug it commonly causes.II
- Why can comparing two Integer objects with == sometimes return true and sometimes false?II
- When would you choose BigDecimal over double, and what is the one mistake people make constructing it?II
Control Flow — Loops, Conditionals & Switch · Java Foundations — Zero to Basics
- Compare a traditional switch statement with a switch expression (Java 14+). When would you reach for the new form?II
- What is the difference between break, labeled break, and continue, and when is a labeled break actually justified?II
- Why can an enhanced for-each loop throw ConcurrentModificationException, and how do you remove elements correctly?II
- What pitfalls come from comparing floating-point or wrapper values in loop conditions and switch?II
- Why does fall-through exist in switch at all, and how do you exploit it deliberately versus accidentally?II
OOP I — Classes, Objects, Constructors · Java Foundations — Zero to Basics
- Explain what a record is, what it generates, and where a record is the wrong choice.II
- What is the difference between shallow and deep copying, and how does it interact with a copy constructor?II
OOP II — Inheritance, Polymorphism, Interfaces · Java Foundations — Zero to Basics
- Compare composition and inheritance. Why is 'favor composition over inheritance' such a strong rule?II
- Explain method overriding versus overloading, including how the rules differ at compile time versus runtime.II
- Since Java 8 interfaces can have default methods. Why were they added, and how is the diamond conflict resolved?II
- When should you use an abstract class versus an interface in a modern (Java 8+) codebase?II
OOP III — Encapsulation, Abstraction, Enums · Java Foundations — Zero to Basics
- Encapsulation is more than private fields. What does proper encapsulation actually protect, and how do getters leak it?II
- Explain the difference between abstraction and encapsulation, since interviewers often conflate them.II
- Why should you prefer EnumMap and EnumSet over HashMap and HashSet when keys are enums?II
- How do access modifiers (private, package-private, protected, public) shape API design, and what's the danger of protected?II
Strings, StringBuilder & String Pool · Java Foundations — Zero to Basics
- Why is repeated String concatenation in a loop a performance problem, and what does the compiler do for non-loop concatenation?II
- Why must String be immutable, and what would break if it weren't?II
- Compare equals(), ==, equalsIgnoreCase(), and compareTo() for Strings, and what's the locale gotcha?II
- What's the difference between StringBuilder and StringBuffer, and when does capacity tuning matter?II
Exception Handling & Custom Exceptions · Java Foundations — Zero to Basics
- Explain checked versus unchecked exceptions and the modern argument for preferring unchecked in many designs.II
- Walk through how try-with-resources works and why it's strictly better than finally-based cleanup.II
- What does it mean to 'swallow' an exception, and what are the correct patterns for translation and chaining?II
Generics — Wildcards, Bounded Types, PECS · Java Foundations — Zero to Basics
Efficiency & Big-O — Measuring Speed From Zero · Java Foundations — Zero to Basics
- How do you find the Big-O of a piece of code by reading it?II
- Why do we usually quote the worst case, and what are best/average cases?II
- Why is building a String in a loop with + considered O(n^2)?II
- Give an example where choosing the right data structure changes the Big-O.II
Collections Deep Dive — List, Set, Map, Queue · Java Foundations — Zero to Basics
- Compare ArrayList and LinkedList honestly. Why is LinkedList almost never the right choice in practice?II
- What exactly is the contract between equals() and hashCode(), and what breaks when you violate it?II
- When would you choose a TreeMap or LinkedHashMap over a plain HashMap?II
- Compare ArrayDeque, Stack, and the various queue choices. What should you actually use for a stack or queue today?II
- How does a HashMap find a value in O(1) on average instead of scanning every entry?II
- What is a hash collision and how does Java's HashMap resolve it?II
- What is the load factor, and what happens when a HashMap exceeds it?II
- Why must equal objects have equal hash codes, and what breaks if they don't?II
Java 8 — Optional, Date/Time API, Method Refs · Java Foundations — Zero to Basics
- What is Optional actually for, and what are the anti-patterns interviewers want you to avoid?II
- Why was java.time introduced to replace Date and Calendar, and what are its key design wins?II
- Distinguish the four method reference forms and when each applies.II
- Why is the old SimpleDateFormat dangerous, and what replaced it?II
File I/O — java.io, NIO2 & Files API · Java Foundations — Zero to Basics
- Compare the old java.io streams with NIO.2 (java.nio.file). When do you still reach for streams?II
- Why is buffering critical for I/O performance, and what does a BufferedReader actually save you?II
- What's the difference between Files.lines(), Files.readAllLines(), and Files.readString() for reading a file?II
JVM Architecture · JVM Internals & Runtime
Collections & Equals/HashCode Contracts · Core & Modern Java (8 -> 21)
- Walk through how HashMap stores and finds an entry, and why a bad hashCode degrades it to O(n).II
- Why must hashCode be consistent with equals, and what breaks if you override one but not the other?II
- What goes wrong if you mutate an object after using it as a HashMap key or HashSet element?II
- Why prefer ArrayDeque over Stack and LinkedList, and List.of over Collections.unmodifiableList?II
IoC, DI & Bean Lifecycle · Spring & Spring Boot
- Walk me through constructor vs setter vs field injection and which you'd use in production.II
- What's the difference between @Component, @Service, @Repository, and @Controller? Does the framework treat them differently?II
- How does Spring resolve a dependency when multiple beans implement the same interface, and what are @Primary, @Qualifier, and parameter-name matching doing?II
- Why is @PostConstruct preferred over doing initialization work in the constructor, and what can go wrong if you don't?II
SQL Mastery & Joins · Databases & Persistence
- What's the difference between WHERE and HAVING, and how does that relate to the logical order of query evaluation?II
- How do GROUP BY and aggregate functions handle NULLs, and what surprises people about COUNT?II
Scalability Fundamentals · System Design
- When would you scale vertically instead of horizontally, and what makes horizontal scaling harder?II
Docker & Containers · DevOps: Docker, Kubernetes & Helm
- Why does ordering of Dockerfile instructions matter, and how do you exploit layer caching for a Java build?II
- When should you use a named volume vs a bind mount, and why are containers themselves a bad place to keep data?II
Linux Essentials & Shell · Linux, Networking & Observability
Creational Design Patterns · Design Patterns in Java
- In a Spring application, how often do you actually write GoF creational patterns by hand, and why?II
Strings — Practice Programs · Practice Programs — Master Every Pattern
- Why should you never compare strings with == , and when is it a subtle trap?II
- How do you check if two strings are anagrams efficiently?II
- How do you find the first non-repeating character in a string?II
JVM Internals — Top Interview Q&A · Interview Rapid-Fire — Top Q&A
- What are Bootstrap, Platform, and Application ClassLoaders?II
- How does the JIT Compiler improve performance?II
Start Here — Build Your First AI Feature · Build AI Features as a Java Backend Engineer
- In one or two sentences, what actually happens when an LLM 'answers' a question, and why does that mental model matter for backend design?II
- What is a token, and why do engineers care about tokenization when they are just trying to ship a feature?II
- What is a context window, and how do you design around it when your data is bigger than it?II
- What is the difference between a system prompt and a user prompt, and how do you reliably get structured output like JSON out of a model?II
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