Java Developer Interview Questions (5+ Years)
Core Java & Concurrency
1. How do you detect a deadlock in your code?
2. What are different ways to create a thread, and which one is better?
3. What is locking in terms of threads?
4. Difference between sleep() and wait()?
5. Have you used Executor framework?
6. What are ways to avoid deadlocks in Java?
7. Difference between Runnable and Callable interface?
8. Explain the producer-consumer problem and how to handle it?
9. Difference between starvation and deadlock in Java threads?
10. What is a reentrant lock?
11. What is type erasure in generics?
12. What is the entry point in Java?
13. Difference between stack and heap memory?
14. How do Java classloaders work?
Spring Boot & Microservices
1. How does Spring Boot support the development of RESTful web services?
2. How do you secure REST APIs in Spring Boot?
3. What is service discovery and service registration?
4. How does client-side load balancing differ from server-side load balancing?
5. How does request mapping work in AWS (from domain to IP address)?
6. Explain the working functionality of Kubernetes?
7. How does a load balancer work?
8. How have you implemented Spring Security in your project?
9. How do you handle session management and authentication in Spring Security?
10. Explain Spring MVC architecture?
11. How do you handle form validation in Spring MVC?
12. How do RestController and RequestMapping annotations support RESTful web service
development?
Database & Hibernate
1. What are different Hibernate mappings?
2. Difference between Map and FlatMap?
3. How do you write database-related test cases and mock them?
4. What are views? Can we perform CRUD operations on views?
5. What is a Cartesian product in SQL?
6. Difference between clustered and non-clustered indexes?
7. How do you detect a memory leak in your application?
8. What are the reasons for memory leaks?
9. How do you store sensitive information like passwords in properties files?
10. Which scenarios require ORM (Hibernate) vs direct JDBC connections?
Kafka & Messaging Systems
1. How do you write test cases for Apache Kafka?
2. How do you set up Kafka?
3. What happens if a producer sends 100 messages per second, but the consumer can only
process 20 per second?
4. Have you worked with Kafka stream topologies?
5. What are you using to read data from a Kafka topic in Spring Boot?
Performance & Optimization
1. Why is Stream API faster than Iterator?
2. What is the time complexity for common operations in HashMap?
3. Difference between weak and soft references?
4. Advanced use cases of ArrayList, LinkedList, and HashMap?
5. How do you implement multithreading in Java for a data processing application?
Testing & Code Quality
1. How do you use Mockito to create mocks in tests?
2. Difference between mock and spy in Mockito?
3. What parameters do you verify during code reviews?
4. What will happen if you override hashCode() but not equals()?
5. What will happen if you override equals() but not hashCode()?
6. What happens if the hashCode method always returns the same value?
Design Patterns & Best Practices
1. How does the Builder design pattern help when creating objects with multiple parameters?
2. When would you use Comparator vs Comparable?
3. In which scenarios have you written a Singleton class?
4. Difference between interfaces with default methods vs abstract classes?
5. Explain a scalable Notification microservice design (supporting Email, SMS, multiple providers).
DevOps & Security
1. How do you manage logging in your application? Which version of Log4j do you use?
2. What was the recent Log4j vulnerability?
3. How do you prevent JAR files from being decompiled (Obfuscation)?
4. How do you convert an existing Spring Boot application into a serverless architecture?
5. What are Maven lifecycles and how do you use them?
6. Difference between mvn clean install and mvn clean package?
7. How do you handle merge conflicts in Git?
Java 17 & New Features
1. What are the new features in Java 17?