MCQ

Spring MCQs – Multiple Choice Questions and Answers – Part 2

Multiple choice questions and answers (MCQs) on Spring to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are taken from an interview. So you will find questions on basic techniques such as Spring Data, JPA, Spring MVC, XML, Hibernate, and more. This quiz will easily prepare anyone to pass their online test.
 

1. Dependency injection or IOC is a _____________?

A Design Pattern

B Framework

C Java Module

D ORM Framework

A
In software engineering, dependency injection is a technique by which one object provides dependencies to another object. A dependency is a usable object (a service). An injection is the passage of a dependency to a dependent object (a client) that would use it.

 

 

2. Beans defined in the spring framework are by default ______?

A Abstract

B Singleton

C Final

D Initialized

B
The word “Singleton” in Spring is used for a bean scope, which means that the bean will only be created once for the entire application. Singleton usually stands for the GOF (Gang of Four) pattern. It is an object oriented model ensuring that there will only be one instance of a class.

 

 

3. Which of the following is not a Spring module?

A AOP

B O/R Integration

C Spring MVC

D HTML/JSP

D
Spring framework includes many modules such as core, beans, context, expression language, AOP, Aspects, JDBC, ORM, OXM, JMS, Transaction, Web, Servlet, Struts, etc.

Source : docs.spring.io

 

 

4. Which of the following statements is true?

A ApplicationContext implements the BeanFactory

B ApplicationContext inherits from BeanFactory

C BeanFactory inherits from ApplicationContext

D BeanFactory implements ApplicationContext

B
  • ApplicationContext is a more preferred way than BeanFactory
  • In newer versions of Spring, BeanFactory is replaced by ApplicationContext. But BeanFactory still exists for backward compatibility
  • ApplicationContext extends BeanFactory has the following advantages:
    1. It supports internationalization of text messages
    2. It supports event publishing for registered listeners
    3. Access to resources such as URLs and files

 

 

5. How to get the DAO object in the spring framework?

A Use the “new” keyword

B Using Spring Dependency Injection

C Both A and B are true.

D None of the above

B
If a class A expects a data access object (DAO) to receive data from a database, you can easily create another test object(mock) for a database connection and inject that object into A to test A without having a database connection. Dependency injection based design is possible with the Java standard. Spring simply simplifies the use of dependency injection by providing a standard way to provide the configuration and by managing the references of the created objects.

 

 

6. In which version of spring have the features of Java 5 been introduced?

A Spring 1.0

B Spring 2.0

C Spring 2.5

D Spring 3.0

D
The main API of the Spring 3.0 framework uses Java 5; therefore, Java5 or later is required to run Spring 3.0 applications. Java 5 features, such as generic types, annotations, etc, can be used in Spring 3.0 framework applications. Spring 3.0 is fully compatible with JEE1.4 and JEE5 models.

 

 

7. In which version of spring has Spring Expression Language been supported?

A Spring 1.0

B Spring 2.0

C Spring 2.5

D Spring 3.0

D
Spring 3.0 introduces Spring Expression Language (SpEL), a powerful expression language that supports querying and manipulating object graph at runtime. With SpEL, Spring applications can overcome the limitation of using only fixed values in configuration files. It can be used for bean definitions in XML-based and annotation-based configurations.

 

 

8. Which class does the IoC container represent?

A ApplicationContext

B ServletContext

C RootContext

D WebApplicationContext

A
The IoC (Inversion of Control) container is responsible for instantiating, configuring, and aggregating objects. The IoC container obtains information from the XML file and operates accordingly. The main tasks performed by the IoC container are as follows:

  • Instantiate the application class
  • Configure the object
  • Aggregate dependencies between objects

 

 

9.How to use “idref” in the spring framework?

A With setter method

B With getter method

C With setter method and constructor argument

D With getter method and constructor argument

C
In the Spring framework, idref consists of transmitting the identifier of a bean to another bean. Example: <idref bean="PointA">. idrefs can be considered of type Strings.

When using “idref”, the parameters of the Setter method or the constructor that we define/inject must be of type Strings.

 

 

10. What component is part of the data access layer in the Spring Framework?

A Aspects

B JMS

C Beans

D Core

E Web

F Servelet

G Expression language

B
Java applications that use Java Message Service (JMS) are called JMS clients. A JMS client can create, send, receive, and read messages. The clients who send messages are called producers and those who receive messages are called consumers.

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *