Flashcards

Quick study sessions to strengthen memory and retain key concepts.

Flashcard Study

Java: Invariants and Validation

Front

Why validate method inputs?

To ensure the method's logic operates on valid data. Validating inputs in methods prevents errors and unexpected behavior…

View Card →
Flashcard Study

Java: Invariants and Validation

Front

How does immutability help maintain invariants?

Immutability prevents state changes, ensuring invariants are maintained. Immutable objects do not allow changes to their state once…

View Card →
Flashcard Study

Java: Invariants and Validation

Front

How would you explain an invariant in OOP in an interview?

An invariant is a condition that must always hold true for an object. Invariants are rules that define…

View Card →
Flashcard Study

Java: Invariants and Validation

Front

Why is constructor validation important?

Constructor validation ensures an object is created in a valid state. When creating an object, constructor validation checks…

View Card →
Flashcard Study

Java: Invariants and Validation

Front

How would you explain an invariant in an interview?

A rule that should always remain true for a valid object. Examples include 'price cannot be negative' or…

View Card →
Flashcard Study

Java: Interfaces

Front

Why are interfaces crucial for testability and substitution in Java applications?

Interfaces support testing and substitution by defining contracts. Interfaces define a contract that can be implemented by any…

View Card →
Flashcard Study

Java: Interfaces

Front

How do interfaces enable multiple capabilities in Java?

Interfaces allow a class to inherit multiple capabilities. In Java, a class can implement multiple interfaces, enabling it…

View Card →
Flashcard Study

Java: Interfaces

Front

How would you explain a functional interface in a Java interview?

An interface with a single abstract method, used for lambda expressions. Functional interfaces contain exactly one abstract method…

View Card →
Flashcard Study

Java: Interfaces

Front

Why might you use a marker interface in Java?

To provide metadata to classes without defining methods. Marker interfaces in Java are used to indicate that a…

View Card →
Flashcard Study

Java: Interfaces

Front

Why do teams use interfaces over abstract classes in production code?

Interfaces provide multiple inheritance capabilities and focus on defining behavior. Interfaces allow multiple inheritance, meaning a class can…

View Card →