Java and Object-Oriented Design Fundamentals
Company: Antra
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
## Java and Object-Oriented Design Fundamentals
This is a rapid-fire fundamentals round covering core Java language and collection semantics, the Spring Boot/Spring framework stereotypes, and general object-oriented design principles. The interviewer expects crisp, precise definitions, correct mechanics, and an awareness of the trade-offs behind each choice — the kind of answers a backend Java engineer should be able to give without hesitation.
### Constraints & Assumptions
- Answers should target the standard Java SE collections framework (`java.util`) and the Spring Framework / Spring Boot ecosystem.
- Assume a typical layered Spring Boot web application (controller → service → repository) when discussing the Spring stereotypes.
- "ArrayList" and "HashSet" refer to `java.util.ArrayList` and `java.util.HashSet`.
### Clarifying Questions to Ask
- Should the comparisons focus on conceptual/interface-level differences, or on concrete implementation details (memory layout, resizing, hashing)?
- For the Spring annotations, should the answer cover only behavior, or also how Spring's component scanning and exception translation use these stereotypes?
- Is the target audience a generalist or specifically a backend engineer who will own service-layer code?
- For "Java vs Python", is the interviewer looking for language-design contrasts (typing, concurrency, runtime) or ecosystem/use-case fit?
### Part 1
Explain the SOLID principles. For each of the five, give a one-line definition and a short example of a violation and how to fix it.
```hint What the acronym stands for
SOLID is five separate design principles: **S**ingle Responsibility, **O**pen/Closed, **L**iskov Substitution, **I**nterface Segregation, and **D**ependency Inversion. Anchor each letter to "what change should *not* ripple."
```
#### What This Part Should Cover
```premium-lock What This Part Should Cover
```
### Part 2
What is the difference between an **interface** and an **abstract class** in Java? When would you choose one over the other?
```hint Axes to compare
Contrast on: state/fields, constructors, multiple inheritance, default/concrete methods, access modifiers, and the "is-a" vs "can-do" relationship. Note what changed with Java 8 default methods.
```
#### What This Part Should Cover
```premium-lock What This Part Should Cover
```
### Part 3
Compare **Java** and **Python** as languages. Highlight the differences that matter for backend engineering.
```hint Pick a few high-leverage axes
Compare typing (static vs dynamic), compilation/runtime (JVM bytecode + JIT vs CPython interpreter), concurrency (real threads vs the GIL), and performance/ecosystem trade-offs. Avoid a laundry list.
```
#### What This Part Should Cover
```premium-lock What This Part Should Cover
```
### Part 4
What is `ArrayList` in Java? Describe its backing structure and the cost of its core operations.
```hint Backing structure
It is backed by a dynamically-resized array. Think about which operations are $O(1)$ amortized vs $O(n)$, and what happens when capacity is exceeded.
```
#### What This Part Should Cover
```premium-lock What This Part Should Cover
```
### Part 5
What is `HashSet` in Java? How does it work internally, and what are its performance characteristics?
```hint What backs it
A `HashSet` is backed by a `HashMap`. The key insight is how `hashCode()` and `equals()` together provide uniqueness and expected $O(1)$ lookup.
```
#### What This Part Should Cover
```premium-lock What This Part Should Cover
```
### Part 6
In Spring, what Spring Boot/Spring annotations are you familiar with, and specifically what is the difference between `@Repository` and `@Service`?
```hint The stereotype hierarchy
`@Repository`, `@Service`, and `@Controller` are all specializations of `@Component`. The interesting difference is not "which layer" but the extra behavior Spring attaches to `@Repository`.
```
#### What This Part Should Cover
```premium-lock What This Part Should Cover
```
### What a Strong Answer Covers
```premium-lock What a Strong Answer Covers
```
### Follow-up Questions
- For `ArrayList` (Part 4): how does the default growth policy work, and what concurrent alternatives exist (`CopyOnWriteArrayList`, `Collections.synchronizedList`, `Vector`) and when would you use each?
- For `HashSet` (Part 5): what happens if you mutate an object after adding it to a `HashSet` such that its `hashCode()` changes?
- For Spring (Part 6): if `@Repository` and `@Service` are functionally interchangeable for component scanning, why not just annotate everything with `@Component`?
- For SOLID (Part 1): give an example where rigidly applying the Single Responsibility Principle led to over-engineering, and how you'd balance it.
Quick Answer: This question assesses mastery of software engineering fundamentals across object-oriented design, Java collections, and the Spring framework. It tests practical knowledge of SOLID principles, Java type system mechanics, and backend framework conventions commonly evaluated in Java software engineer interviews.