200 Tricky Java and Spring Boot Questions You Must Know
As I’m preparing for interviews, I’ve been diving into some tricky Java and Spring Boot questions to sharpen my skills. While I’m still learning and not an expert yet, I thought it’d be helpful to share 200 questions that are challenging but useful for anyone who wants to improve or prep for an interview. I’m sharing this journey with you in hopes that it can help others who are in the same boat as me – trying to get better and feel more confident with these topics!
1. What happens if you try to run a Java program without a main() method?
3. Why is String
immutable in Java?
4. What is the difference between ==
and equals()
in Java?
6. What is the purpose of the transient
keyword in Java?
7. Can a static
block throw exceptions? Why or why not?
8. What is the difference between final
, finally
, and finalize()
in Java?
9. How does Java handle integer overflow?
10. Can you store null
in a HashMap
key? If yes, how does it handle it?
11. What is the difference between abstraction and encapsulation?
12. Can an interface have a constructor?
13. What is the role of super
and this
in inheritance?
15. What is method overloading and method overriding? Provide examples.
17. How does the instanceof
operator work?
18. What is a covariant return type?
19. Can you call a superclass method without creating an instance of the subclass?
20. What is the diamond problem in multiple inheritance, and how does Java handle it?
21. What is the difference between throw
and throws
?
22. Can a finally
block skip execution? When?
23. How do you create custom exceptions in Java?
24. What happens if an exception is thrown in a catch
block?
25. What is the difference between Error
and Exception
?
26. What is a checked exception? How is it different from an unchecked exception?
27. Why should we always close resources in a finally
block or use try-with-resources?
28. Can constructors throw exceptions in Java?
29. What happens if a try
block has a return statement? Does the finally
block still execute?
30. Can you use throw
without try-catch
? Why or why not?
31. How does HashMap
handle collisions internally?
33. What is the difference between HashSet
and TreeSet
?
34. Why should you override equals()
and hashCode()
together?
35. How does ConcurrentHashMap
handle thread safety?
36. What is the difference between Enumeration
and Iterator
?
37. What is the difference between Vector
and ArrayList
?
38. How does PriorityQueue
maintain order?
39. Can a TreeMap
store null
keys? Why or why not?
40. What is the difference between fail-fast and fail-safe iterators?
41. What is the difference between synchronized
and volatile
?
42. How does Java handle deadlocks?
44. What is the difference between wait()
and sleep()
?
45. Can you start a thread twice in Java?
46. How do you achieve thread safety in a Java program?
47. What is the purpose of the ThreadLocal
class?
48. How does the ReentrantLock
work?
49. What is the difference between Runnable
and Callable
?
50. What is a daemon thread in Java?
51. What is Spring Boot, and how is it different from Spring Framework?
52. What is the role of @SpringBootApplication
annotation?
54. How does Spring Boot handle dependency injection?
55. What is the difference between @Component
, @Service
, and @Repository
?
56. What is the purpose of @Autowired
?
57. How does Spring Boot implement embedded servers?
58. What is a Bean in Spring, and how do you define it?
59. What is the role of @Configuration
in Spring Boot?
60. How do you handle application configuration profiles in Spring Boot?
61. What is @Transactional
, and why is it important?
62. How does Spring Boot handle circular dependencies?
63. What is the purpose of @PathVariable
and @RequestParam
?
64. How do you secure a Spring Boot application?
65. What is Spring Boot Actuator, and how do you use it?
67. How do you implement pagination in Spring Boot?
68. What is the purpose of @EnableAutoConfiguration
?
69. How do you connect Spring Boot to a database?
70. What is the role of JPA
in Spring Boot?
72. What is the Factory design pattern, and when should you use it?
73. What is the Builder pattern, and how is it different from the Factory pattern?
74. What is Dependency Injection (DI), and why is it important in Spring Boot?
75. What is the difference between Monolithic and Microservices architecture?
76. What are the pros and cons of RESTful APIs?
77. How do you handle API versioning in Spring Boot?
78. What is Circuit Breaker in Microservices?
79. How do you implement distributed tracing in Microservices?
80. What is the purpose of Eureka in a Spring Cloud application?
81. What is a lambda expression, and how do you use it in Java 8?
82. What is the purpose of the Stream
API in Java 8?
83. What is the difference between map()
and flatMap()
in Java Streams?
84. What are default methods in interfaces, and why were they introduced in Java 8?
85. How does the Optional
class help avoid null pointer exceptions?
86. What is the difference between forEach()
and map()
in Streams?
87. How do you sort a list using a lambda expression?
88. What are functional interfaces, and how are they used?
89. What is the purpose of the Collectors
class in Streams?
90. How do you create a custom collector in Java Streams?
91. What is the purpose of the StringBuilder
class in Java?
92. What is the difference between StringBuffer
and StringBuilder
?
93. How do you measure the performance of a Java application?
94. What is Garbage Collection (GC), and how does it work in Java?
95. What are the different types of class loaders in Java?
96. What is a static
nested class, and how is it different from an inner class?
97. What is the purpose of the transient
keyword in Java?
98. How do you serialize and deserialize an object in Java?
99. What is a soft reference in Java?
100. What is the difference between JDK, JRE, and JVM?