Java & Spring Interview Questions
Complete question bank — deduplicated & organized by topic
99 questions across 12 topics
IoC & Dependency Injection
1. What is the IoC (Inversion of Control) principle?
2. What is the IoC container?
3. How many types of IoC containers are there in Spring?
4. What is BeanFactory and how does it differ from ApplicationContext?
5. What is Dependency Injection (DI)?
6. Which type of DI is preferred and why?
7. What is the difference between constructor injection and setter injection?
8. What is field injection?
9. What is dependency pulling?
10. What is cyclic dependency in Spring and how do you resolve it?
Java Object Class Methods
1. Which methods do you know from the Object class?
2. What is the equals() method and when should you override it?
3. What is the hashCode() method?
4. What is the toString() method?
5. What is the instanceof operator?
6. What is the contract between equals() and hashCode()?
7. Can two objects have the same hashCode()?
8. What happens if you override equals() but not hashCode()?
9. What happens if you override hashCode() but not equals()?
10. What happens if you haven't overridden equals() and hashCode() at all?
Java Collections Framework
1. What is the Java Collections Framework?
2. What is the difference between List and Set interfaces?
3. What is the difference between Set and Map?
4. What is the difference between ArrayList and LinkedList?
5. What is the difference between HashSet and LinkedHashSet?
6. What is the difference between HashMap and LinkedHashMap?
7. Explain the internal working of HashMap.
8. What is a hash collision and how does HashMap handle it?
9. What are the Comparable and Comparator interfaces?
10. Explain IdentityHashMap.
11. What is a concurrent collection?
12. What is the difference between fail-fast and fail-safe iterators?
13. What is ConcurrentModificationException and how do you resolve it?
14. How many types of concurrent collections exist in Java?
15. How does ConcurrentHashMap work?
Collections — Use Cases
1. Which collection gives thread safety AND good performance?
2. Which collection maintains sorting order and removes duplicates?
3. Which collection removes duplicates and maintains insertion order?
4. Which collection only removes duplicates (no order guarantee)?
5. I have a list of custom objects with the same content — how do I remove duplicates?
6. If I want to sort a custom object by salary, which collection/interface should I use?
7. What happens when two different objects have the same hash code?
Multithreading & Stream API
1. What is multithreading in Java?
2. What are the different ways to create a thread in Java?
3. What is the difference between wait() and sleep()?
4. What is the use of the join() method?
5. What is inter-thread communication in Java?
6. Can you call start() on the same thread twice? What happens?
7. What is the Stream API?
8. What are the features of lambda expressions?
9. What are predefined functional interfaces in Java?
10. What is the difference between map() and flatMap() in Stream API?
11. How do you sum a list [1,2,3,4,5] using the Stream API?
12. How do you count character occurrences in a string using the Stream API?
13. Write code to find vowels and special characters in a given string.
Exception Handling
1. What is an exception?
2. What is the difference between checked (compile-time) and unchecked (runtime) exceptions?
3. What is the difference between an Error and an Exception?
4. What is the difference between throw and throws?
5. What is the try block?
6. What is the catch block?
7. What is the finally block and how can you stop its execution?
8. What is exception propagation?
9. How do you handle exceptions in your project?
10. What is global exception handling (e.g., @ControllerAdvice)?
11. How do you create and use custom exceptions?
Design Patterns
1. What is the Singleton design pattern?
2. How can the Singleton pattern be broken (reflection, serialization, cloning)?
3. How do you write a thread-safe Singleton class in Java?
4. What is the Template Method design pattern?
5. What is the Factory design pattern?
6. Explain the SOLID principles.
Cloning, Immutability & Serialization
1. What is object cloning?
2. How does the Cloneable interface work?
3. What is shallow cloning?
4. What is deep cloning?
5. What is a marker interface?
6. How do you create an immutable class in Java?
7. What is serialization and how does it work?
8. What is type casting in Java?
Spring & Microservices
1. How do Microservices work?
2. What is an API Gateway and what problems does it solve?
3. What are the Spring Cloud configurations for microservices?
4. How do you convert a monolithic application to microservices?
5. What is the difference between authentication and authorisation?
6. What are common memory leak scenarios in Java?
Hibernate & JPA
1. What is Hibernate?
2. What is caching in Hibernate (first-level vs second-level)?
3. What is the difference between first-level and second-level cache?
4. What is a Hibernate Session?
5. What is the difference between [Link]() and [Link]()?
6. What is a bidirectional relationship in JPA/Hibernate?
7. What are JUnit annotations and what does each do?
8. What is the significance of @Mock in JUnit/Mockito?
SQL & Databases
1. What is normalization in databases?
2. What are the types of joins in SQL?
3. Write a SQL query to find the second highest salary in an employee table.
4. What is the difference between DELETE and TRUNCATE?
REST API
1. Write an end-to-end RESTful web service example (Controller -> Service -> Repository).
Generated for interview preparation | Java + Spring Boot + Hibernate + SQL