Explain core Java and Spring fundamentals
Company: Antra
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: easy
Interview Round: Technical Screen
## Java and Spring fundamentals
You are interviewing for a backend Java/Spring role. Answer the following conceptual questions:
1. **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.
2. **Object-oriented design**
- Explain the SOLID design principles and give a short example for each principle.
3. **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.
4. **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.
5. **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?
6. **Exception handling**
- How should exceptions be handled in Java? Explain checked vs unchecked exceptions and discuss best practices for exception handling in real applications.
7. **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?
8. **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.
Quick Answer: This question evaluates core competencies in Java and Spring, covering data structures and collections, object-oriented design (SOLID), hash-based collections and concurrency primitives, immutability and string handling, exception handling, Spring IoC/DI and AOP, bean lifecycle and annotations, and functional collection processing via the Stream API. Commonly asked in Software Engineering Fundamentals interviews for backend Java/Spring roles, it checks both conceptual understanding and practical application by assessing architectural reasoning, concurrency and thread-safety knowledge, and familiarity with framework conventions and APIs.