Java Programming
Java OOP, collections, multithreading
958 Questions 10 Topics Take Test
Advertisement
Showing 51–60 of 958 questions
Which of the following best describes IoC (Inversion of Control) in Spring?
A Control of object creation is transferred from application to Spring Container
B Application controls all object creation
C Objects cannot be created dynamically
D Spring eliminates the need for object-oriented programming
Correct Answer:  A. Control of object creation is transferred from application to Spring Container
EXPLANATION

IoC is a principle where the Spring Container manages object creation and lifecycle, not the application code itself.

Take Test
What is the default scope of a Spring Bean?
A prototype
B request
C singleton
D session
Correct Answer:  C. singleton
EXPLANATION

By default, Spring creates beans as singletons - one instance per application context, shared across the entire application.

Take Test
A Spring application requires constructor-based dependency injection for a mandatory dependency. Which approach is best?
A @Autowired on setter method
B @Autowired on constructor
C @Resource annotation
D Manual object creation
Correct Answer:  B. @Autowired on constructor
EXPLANATION

Constructor-based DI ensures mandatory dependencies are provided at object creation time and is considered a best practice for required dependencies.

Take Test
Which XML element is used to define a bean in Spring XML configuration?
A
B
C
D
Correct Answer:  B.
EXPLANATION

The <bean> element is the standard XML element used in applicationContext.xml to define Spring beans.

Take Test
What does @Autowired annotation do in Spring?
A Automatically injects dependencies by type
B Creates a new bean instance
C Marks a class as deprecated
D Enables auto-scanning of packages
Correct Answer:  A. Automatically injects dependencies by type
EXPLANATION

@Autowired performs type-based dependency injection. Spring looks for a bean of the required type and injects it automatically.

Take Test
Advertisement
Which of the following is NOT a valid Spring bean scope in Spring 5.x+?
A singleton
B prototype
C request
D eternal
Correct Answer:  D. eternal
EXPLANATION

Valid scopes are singleton, prototype, request, session, application, and websocket. 'eternal' is not a valid scope.

Take Test
What is the primary purpose of Dependency Injection (DI) in Spring Framework?
A To increase code complexity
B To reduce coupling between classes and improve testability
C To replace all design patterns
D To automatically generate SQL queries
Correct Answer:  B. To reduce coupling between classes and improve testability
EXPLANATION

DI reduces coupling by injecting dependencies rather than creating them internally, making code more testable and maintainable.

Take Test
Which annotation is used to mark a class as a Spring Bean in the latest Spring Framework?
A @Bean
B @Component
C @Service
D @Controller
Correct Answer:  B. @Component
EXPLANATION

@Component is a generic stereotype annotation for any Spring-managed component. @Bean is used on methods, while @Service and @Controller are specialized versions of @Component.

Take Test
What is the return type of a lambda expression used with IntStream.range(1, 5).map(x -> x * 2)?
A void
B int
C IntStream
D Function
Correct Answer:  C. IntStream
EXPLANATION

map() is an intermediate operation that returns an IntStream. The lambda expression (x -> x * 2) transforms each int, but map() itself returns IntStream, not the transformed value type.

Take Test
Q.60 Medium Lambda Expressions
Consider the following code:
List fruits = Arrays.asList("apple", "banana", "cherry");
fruits.removeIf(s -> s.length() > 5);

What will be the contents of 'fruits' list after execution?
A ["apple", "banana", "cherry"]
B ["apple"]
C ["apple", "cherry"]
D []
Correct Answer:  B. ["apple"]
EXPLANATION

removeIf() removes all elements that satisfy the lambda predicate. Strings with length > 5 are "banana" (6 chars) and "cherry" (6 chars). Only "apple" (5 chars) remains as its length is not greater than 5.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips