Java and Spring fundamentals
You are interviewing for a backend Java/Spring role. Answer the following conceptual questions:
-
Collections & data structures
-
Compare
ArrayList
and
LinkedList
in Java in terms of internal implementation, time complexity for common operations (access, insertion, deletion), and typical use cases.
-
Object-oriented design
-
Explain the SOLID design principles and give a short example for each principle.
-
Hash-based collections & concurrency
-
Compare
Hashtable
and
HashSet
: what does each store, how are keys/values handled, and what about thread safety?
-
Explain what
ConcurrentHashMap
is, how it differs from
HashMap
and
Hashtable
, and in what situations you would use it.
-
Strings and immutability
-
Compare
String
,
StringBuilder
, and
StringBuffer
in Java, including mutability and thread safety, and when you would use each.
-
What does it mean for an object to be immutable? Why can immutability be useful?
-
Describe how you would design and implement an immutable class in Java.
-
Concurrency primitives
-
Explain the purpose and behavior of the
volatile
keyword in Java. What problems does it solve and what are its limitations?
-
Explain what synchronization (the
synchronized
keyword) does in Java. How does it provide thread safety and what are the trade-offs?
-
Describe the
java.util.concurrent.atomic
package: what problem does it solve, and how do classes like
AtomicInteger
and
AtomicReference
work conceptually?
-
Exception handling
-
How should exceptions be handled in Java? Explain checked vs unchecked exceptions and discuss best practices for exception handling in real applications.
-
Spring core concepts
-
Explain Inversion of Control (IoC) and Dependency Injection (DI) in the context of the Spring framework, with an example of how dependencies are wired.
-
Explain Aspect-Oriented Programming (AOP) in Spring and give common use cases (for example, logging, transactions).
-
Describe how to define and use beans in Spring (for example, via annotations, Java configuration, or XML). How are beans created, managed, and injected?
-
Compare the stereotype annotations
@Component
,
@Service
, and
@Repository
in Spring. What do they have in common and when would you use each?
-
What other common Spring annotations do you know (such as
@Controller
,
@RestController
,
@Autowired
,
@Qualifier
,
@Configuration
,
@Bean
,
@Transactional
, etc.), and what are they used for?
-
Stream API
-
Explain how to use the Java Stream API to process collections (for example, filtering, mapping, grouping, and aggregation) in a functional style. Give a few examples of typical operations you would implement with streams.