MCQ

Spring MCQs – Multiple Choice Questions and Answers – Part 1

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. What is dependency injection?

A It is a design pattern that implements the Inversion of control (IoC) pattern for software applications.

B It is one of the Spring modules.

C It is a technique to get dependencies from any project.

D It is used to promote loose coupling in code.

A
Dependency Injection is a design pattern that implements the Inversion of Control pattern for software applications.

 

 

2. What types of dependency injection does Spring support?

A Based on the constructor and setters

B Based on the constructor, setters, and getters

C Based on setters, getters, and properties

D Based on the constructor, setters, and properties

A
Spring supports constructor-based and setters-based injections.

 

 

3. Which of the following statements is correct regarding the Spring Framework?

A The Spring Framework is a heavy-weight solution.

B The Spring Framework is a light-weight solution.

C Both A and B are true.

D None of the above

B
There are many reasons why spring is a lightweight framework.

  • Spring provides you with different modules and allows you to use whatever works best for you. Ideally, the spring JAR file is only 2-3 MB.
  • If you compare Spring with EJB, you have to write much less code and configurations. The beauty of Spring is that you can focus on the business logic whereas in EJB, you have to write a lot of code along with the business logic which makes it cumbersome and tightly coupled.
  • With Spring, you play with POJO which does not depend on a Framework and improves the testability of your code.
  • Spring offers seamless integration with frameworks, third-party libraries, etc.

 

 

4. AOP is part of Core Container in the Spring Framework?

A True

B False

B
AOP (Aspect-oriented programming) is not part of Core Container, is one of the key components of the Spring Framework, is a programming approach that allows properties of a program to determine how they are compiled into an executable program. AOP complements the OOP rules by also providing modularity. AOP breaks down the logic of the program into distinct parts called “concerns”. This increases modularity by cross-cutting concerns.

 

 

5. The Expression Language is part of the Core Container in the Spring?

A True

B False

A
SpEL stands for Spring Expression Language which is part of Core Container. It is a powerful expression language that supports queries and manipulation of an object graph at bean creation or runtime. It is similar to other expression languages such as JSP EL, OGNL, MVEL and JBoss EL, etc., with some additional features such as method calling and basic string modeling.

 

 

6. Can we integrate spring with struts?

A Yes

B No

A
Spring is a popular web framework for easy integration with many popular web libraries. So the question is: why do we need Spring when we have Struts? Spring is more than an MVC framework: it offers many other benefits that are not available in Struts.
 

7. Spring is a ___________ framework?

A free

B open source

C under license

D proprietary

B
The Spring Framework is open source.

 

 

8. What are the different types of Bean injection?

A constructor and setter

B constructor and getter

C getter and setter

D setter, getter and constructor

A
Spring supports both setter and constructor injection.

 

 

9. Controller in Spring is a(n)_______________?

A abstract class

B concrete class

C final class

D interface

D
Another way to create a controller in Spring framework is to have a class implement the Controller interface. For example:

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
 
public class ControllerExample implements Controller {
 
    @Override
    public ModelAndView handleRequest(HttpServletRequest rq,
            HttpServletResponse rp) throws Exception {
        System.out.println("Welcome to StackHowTo");
        return new ModelAndView("StackHowTo");
    }
}

 

 

10. Which exception class is bound to all the exceptions thrown in Spring applications?

A ArrayIndexOutofBound

B DataAccessException

C NullPointerException

D SpringException

B
DataAccessException is an exception defined by the Spring framework. There are two things to note about DataAccessException. First of all, this is an exception. Therefore, application code that uses a data access object is not required to wrap every call with a try-catch block, as is the case in JDBC entity beans. and EJB 2.x. Second, DataAccessException is useful because it encapsulates the specific exception classes used by the underlying persistence technology and thus keeps the rest of the application independent of the persistence layer.

 

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 *