Flashcards

Quick study sessions to strengthen memory and retain key concepts.

Flashcard Study

Java: Constructor vs Field Injection

Front

How would you explain a common pitfall of using self-invocation in transaction management in an interview?

Self-invocation bypasses proxies, causing transactional annotations to be ignored. In Spring, transactional proxies are created around bean methods.…

View Card →
Flashcard Study

Java: Constructor vs Field Injection

Front

How does using 'final' fields in constructor injection aid in development?

'Final' fields prevent reassignment after construction, ensuring immutability. Marking dependencies as 'final' when using constructor injection communicates that…

View Card →
Flashcard Study

Java: Constructor vs Field Injection

Front

Why is constructor injection considered safer than field injection?

Constructor injection ensures all dependencies are provided at object creation. Constructor injection requires all necessary dependencies to be…

View Card →
Flashcard Study

Java: Constructor vs Field Injection

Front

What impact does lazy initialization have on constructor injection?

Delays bean creation until needed. Frame the concept in practical terms so you can explain it during interview…

View Card →
Flashcard Study

Java: Constructor vs Field Injection

Front

How does using @Primary affect bean selection?

It designates a default bean for autowiring. @Primary is used when multiple beans of the same type exist,…

View Card →
Flashcard Study

Java: Constructor vs Field Injection

Front

What are the risks of using field injection with private fields?

It complicates code readability and testing. Field injection hides dependencies and makes testing difficult, as fields are inaccessible…

View Card →
Flashcard Study

Java: Constructor vs Field Injection

Front

Which bean scope in Spring Boot is the default in Java?

Singleton. Frame the concept in practical terms so you can explain it during interview discussion. By default, Spring…

View Card →
Flashcard Study

Java: Constructor vs Field Injection

Front

Why prefer constructor injection for encapsulation in Spring Boot?

It keeps dependencies explicit and immutable. Constructor injection supports encapsulation by making dependencies visible only through constructors, preventing…

View Card →
Flashcard Study

Java: Constructor vs Field Injection

Front

How does constructor injection enhance testability?

It allows easy mocking of dependencies. Frame the concept in practical terms so you can explain it during…

View Card →
Flashcard Study

Java: Constructor vs Field Injection

Front

How does Spring Boot handle bean instantiation with constructor injection?

It resolves dependencies before instantiating beans. Spring Boot uses constructor injection to ensure all bean dependencies are available…

View Card →