Flashcards

Quick study sessions to strengthen memory and retain key concepts.

Flashcard Study

Java: Defensive Copying

Front

Why should internal collections not be exposed directly?

Exposing internal collections breaks encapsulation and allows external modification. If internal collections like a list of orders are…

View Card →
Flashcard Study

Java: Defensive Copying

Front

What are the risks of shared mutable state in multi-threaded applications?

Shared mutable state can lead to race conditions and data inconsistency. In a multi-threaded environment, if multiple threads…

View Card →
Flashcard Study

Java: Defensive Copying

Front

How do List.copyOf and unmodifiable views differ?

List.copyOf creates an immutable copy; unmodifiable view wraps the original list. List.copyOf creates a new, immutable list that…

View Card →
Flashcard Study

Java: Defensive Copying

Front

Why is encapsulation critical in object-oriented programming?

Encapsulation hides internal state and requires all interaction to occur through methods. Encapsulation helps protect an object's state…

View Card →
Flashcard Study

Java: Defensive Copying

Front

Why is returning a raw internal collection dangerous?

Callers can mutate the object's internals without permission. Encapsulation is not only about single fields. If a cart…

View Card →
Flashcard Study

Java: Default Methods and Multiple Inheritance Rules

Front

How would you explain the key default-method precedence rule in a Java interview?

A class method takes precedence over an interface default method. Java resolves many default-method conflicts with a simple…

View Card →
Flashcard Study

Java: Controlled Mutation

Front

How does immutability benefit concurrency?

It prevents race conditions. Frame the concept in practical terms so you can explain it during interview discussion.…

View Card →
Flashcard Study

Java: Controlled Mutation

Front

Why prioritize business operations over direct field manipulation?

They encapsulate logic and protect state. Frame the concept in practical terms so you can explain it during…

View Card →
Flashcard Study

Java: Controlled Mutation

Front

What are common mistakes with encapsulation?

Exposing too much of the internal state. Frame the concept in practical terms so you can explain it…

View Card →
Flashcard Study

Java: Controlled Mutation

Front

How do safe change paths benefit domain objects?

They maintain object integrity. Frame the concept in practical terms so you can explain it during interview discussion.…

View Card →