This is a list of compiled question asked in recent interviews. This collection of questions should cover a wide range of essential Java topics, from foundational concepts to advanced Spring and microservices topics. Each question serves as a basis for deeper exploration during interviews
- Explain how Java achieves platform independence.
- What are JVM, JRE, and JDK? How do they differ?
- What is a ClassLoader? How is it utilized in Java?
- Explain the difference between
ClassNotFoundExceptionandNoClassDefFoundError. - Why is
ClassNotFoundExceptionencountered only at runtime?
- What is the String Pool, and where is it located?
- Describe the
intern()function in Java. - What is the difference between
==andequals()for string literals? - How do
==andequals()behave differently for String objects?
- Define encapsulation in Java.
- What is the
Serializableinterface, and when is it used? - Can a Java class be static, final, or private? Explain each.
- Explain Object-Oriented Programming (OOP) and its principles.
- How does OOP differ from scripting languages?
- What is the superclass of all exceptions?
- Explain the difference between errors and exceptions.
- What are checked and unchecked exceptions?
- What is the
try-with-resourcesblock? - Explain exception propagation in Java.
- What is autoboxing in Java?
- Describe some key Java 8 features.
- What is a lambda function, and how is it useful?
- How does indexing work internally in Java collections?
- Can a constructor be present in an interface? Why not?
- Performance difference between a traditional
forloop and an enhancedfor-eachloop?
- Write code to make 5 threads print data one after the other.
- What is the difference between
volatileand atomic operations?
- Explain the Builder Pattern and provide code for it.
- Write code for the Singleton Pattern.
- Describe the Factory Pattern and any issues you’ve encountered with it.
- Why are design patterns needed?
- How do design patterns simplify programming?
- What design patterns are you familiar with?
- How would you invent a new design pattern?
- What is Spring Boot, and why is it popular?
- Explain the purpose of annotations like
@Qualifier,@Value,@Bean,@Component. - Difference between
@Controllerand@RestController. - Difference between
@Mockand@InjectMock.
- How does OAuth work?
- Explain how to implement role-based access control using Spring Security.
- Name and describe the three main interfaces of Spring Data JPA.
- How do you handle exceptions in a controller to return proper status codes?
- What is transaction propagation in Spring Boot?
- What is the
application.propertiesfile? - How does Spring/Hibernate generate SQL queries automatically?
- Describe MVC architecture and the differences between Controller, Service, and Repository layers.
- How is pagination implemented in Spring Boot with an SQL database?
- How do you create unique constraints in a database entity class?
- How does
HashMapwork? - Difference between
HashMapandHashTable. - Compare
HashMapandConcurrentHashMap. - Differences between
List,Set, andMap. When to choose each? - What is a
LinkedList? - What is the
Comparableinterface? - How is
hashCodegenerated for an object? - How many collection implementations are you aware of?
- What is the
Iterableinterface?
- What is the Streams API?
- How many ways are there to create streams in Java?
- Difference between Streams and Collections.
- What are the two types of operations in the Stream API?
- Mention some methods you use in Streams.
- Difference between
map()andflatMap(). - What does the
collect()method do in Streams? - Difference between
findFirst()andfindAny()in Streams? - How to handle exceptions in Streams?
- How to convert a Stream into a Collection?
- Difference between sequential and parallel streams? Any performance effects?
- What is a functional interface?
- Can a functional interface contain default and static methods?
- Provide an example of a functional interface.
- Differences between microservices and monolithic architecture.
- What is the CAP theorem? Which trade-offs are important for distributed systems?
- Write pseudo-code for a Singleton Pattern.
- Refine code for the Factory Pattern.
- How do you make a class immutable?
- Differences between
PUT,POST, andPATCH. - REST API URL naming conventions.
- Explain Maven scopes (e.g., compile, runtime, test).
- What Java versions are you familiar with?
- Key differences between Java versions.
- Sort a list of employees by highest salary.
- Find employees with salaries greater than a specific value.
- Calculate the average age of employees earning above a certain salary.
- Find the top 3 highest-paid employees.
- Count the number of employees from a specific city.
- Calculate the total salary of a given list of employees.
- Extract the addresses from an employee list.
- Group employees by city.
- Describe your troubleshooting steps if a backend service is inaccessible after deployment.