Java: Constructor vs Field Injection
Why does Spring IoC container in DI matter in this design?
It manages object creation and wiring. Frame the concept in practical terms so you can explain it during…
View Card →Quick study sessions to strengthen memory and retain key concepts.
Why does Spring IoC container in DI matter in this design?
It manages object creation and wiring. Frame the concept in practical terms so you can explain it during…
View Card →How does self-invocation affect transactional methods?
It prevents proxies from managing transactions. Self-invocation bypasses Spring's proxy mechanism, so transactional annotations are ignored. In an…
View Card →Why use 'final' with constructor-injected dependencies?
It enforces immutability of dependencies. Frame the concept in practical terms so you can explain it during interview…
View Card →How does constructor injection prevent partially constructed objects?
It ensures all dependencies are set before use. Constructor injection guarantees that all required dependencies are provided when…
View Card →Why avoid @Autowired on private fields?
It hides dependencies, making code less maintainable. Using @Autowired on private fields makes dependencies invisible to anyone reading…
View Card →How would you explain the design downside of field injection in an interview?
It hides dependencies and makes direct testing and reasoning harder. Field injection can work, but it obscures what…
View Card →Why is constructor injection preferred for required dependencies?
It makes collaborators visible and ensures the bean is valid when created. Constructor injection forces the class to…
View Card →Why is using '==' with cached Integer values sometimes misleading?
Cached values may give false impressions of equality with '=='. Java caches Integer objects in the range of…
View Card →What hidden costs can autoboxing introduce?
Autoboxing can lead to increased memory usage and CPU overhead. When primitives are autoboxed, Java creates new objects,…
View Card →How would you explain a common mistake when using wrapper classes in an interview?
Confusing '==' with 'equals()' for equality checks. A frequent error is using '==' to compare wrapper objects, which…
View Card →