Complete Final Assessment (Qns & Ans)
2025
Question 1 (Multiple Choice)
Case:
A development team is building an enterprise application using
the Spring Framework. In order to reduce tight coupling and
improve testability, they plan to use dependency injection (DI)
throughout the application.
Question:
Which DI approach is generally considered best practice in Spring
to ensure immutability and mandatory dependency provision?
A. Field injection
B. Setter injection
©2025
,C. Constructor injection
D. Interface injection
Correct ANS: C. Constructor injection
Rationale:
Constructor injection ensures that required dependencies are
provided when an object is created, promoting immutability and
making unit testing easier. Field injection and setter injection are
more prone to hidden dependencies and potential
NullPointerExceptions if not managed carefully.
---
Question 2 (Fill in the Blank)
Case:
While configuring Spring beans, a developer needs to delay the
instantiation of a resource‑heavy bean until it is first needed.
Statement:
Configuring a bean to be created only when it is first requested is
called ______.
©2025
, Correct ANS: lazy initialization
Rationale:
Lazy initialization (often configured via the `lazy-init` attribute or
the `@Lazy` annotation) defers bean creation until it is actually
needed, which can help reduce startup time and resource usage in
large applications.
---
Question 3 (True/False)
Case:
A software engineer is applying declarative transaction
management in a Spring-based application by annotating service
methods.
Statement:
Annotating a method with `@Transactional` in Spring ensures
that the method’s execution is wrapped within a database
transaction.
Correct ANS: True
©2025
, Rationale:
The `@Transactional` annotation instructs Spring to manage
transactions declaratively. This means that, when the annotated
method is invoked, Spring will begin a transaction, commit it on
successful completion, or roll it back if an exception occurs.
---
Question 4 (Multiple Response)
Case:
A security specialist is securing a web application using Spring
Security. The team wishes to leverage Spring Security’s built‑in
authentication and authorization mechanisms.
Question:
Which of the following features are provided by Spring Security?
(Select all that apply.)
A. URL-based security
B. Method-level security
C. CSRF protection
D. Automatic XSS sanitization
©2025