Here are 1000 MCQs on Spring (Chapterwise).
1. What is the Spring Framework?
a) A framework for building mobile applications
b) A library for creating desktop applications
c) A framework for building Java-based enterprise applications
d) A tool for writing JavaScript applications
View Answer
Explanation: The Spring Framework is a powerful framework for building Java-based enterprise applications, providing comprehensive infrastructure support.
2. How to inject a Spring bean into domain objects?
a) Java Based
b) AspectJ
c) XML
d) AOP
View Answer
Explanation: To inject a Spring bean into domain objects created outside Spring, you need the help of AOP.
3. Scripting languages supported by Spring?
a) All of the mentioned
b) BeanShell
c) JRuby
d) Groovy
View Answer
Explanation: Spring supports the three above-mentioned scripting languages.
4. Servlet filter registered in web deployment descriptor, which filters request in spring application context.
a) DelegatingFilterProxy
b) DelegatingProxy
c) DelegatingFilter
d) None of the mentioned
View Answer
Explanation: As servlet filters must be registered in the web deployment descriptor to take effect, you have to register a DelegatingFilterProxy instance in the web deployment descriptor, which is a servlet filter that delegates request filtering to a filter in Spring’s application context.
5. Which module of the Spring Framework is used for building web applications?
a) Spring Boot
b) Spring ORM
c) Spring AOP
d) Spring MVC
View Answer
Explanation: The Spring MVC module is specifically designed for building web applications following the Model-View-Controller (MVC) design pattern.
6. Which of the following property editors are registered by Spring?
a) CustomNumberEditor
b) CustomDateEditor
c) FileEditor
d) CustomNetEditor
View Answer
Explanation: ClassEditor, FileEditor, LocaleEditor, and URLEditor are pre-registered by Spring, so you don’t need to register them again.
7. Which of the following is a Spring project designed to simplify building microservices?
a) Spring Data
b) Spring Cloud
c) Spring MVC
d) Spring Boot
View Answer
Explanation: Spring Cloud is a project that provides tools for building cloud-native applications and simplifies the development of microservices.
8. How does an Introduction advice do this in Spring?
a) web proxy
b) dynamic proxy
c) implements org.springframework.net.bundle interface
d) none of the mentioned
View Answer
Explanation: Introduction works by adding an interface to the dynamic proxy.
9. Which method is used to gracefully shut down all the bean processes after closing the spring container?
a) destroy method
b) shutdownHook
c) none of the mentioned
d) all of the mentioned
View Answer
Explanation: ShutdownHook method gracefully shuts down each bean process before closing the container.
10. Spring Security algorithms to secure passwords.
a) MD5
b) SHA
c) None of the mentioned
d) All of the mentioned
View Answer
Explanation: Spring Security supports several algorithms for encoding passwords (including MD5 and SHA) and provides built-in password encoders for these algorithms.
11. Session scope attribute to display error message.
a) SPRING_SECURITY_LAST_ERROR
b) SPRING_SECURITY_FIRST_EXCEPTION
c) SPRING_SECURITY_LAST_EXCEPTION
d) SPRING_SECURITY_EXCEPTION
View Answer
Explanation: If an error has occurred, you will have to display the error message by accessing the session scope attribute SPRING_SECURITY_LAST_EXCEPTION, which stores the last exception for the current user.
12. What does Spring Boot provide to simplify application development?
a) A built-in web server
b) Starter dependencies
c) Automatic configuration
d) All of the mentioned
View Answer
Explanation: Spring Boot provides features such as built-in web servers, automatic configuration, and starter dependencies to simplify application development.
13. Which of the following annotations is used to indicate a controller in Spring MVC?
a) @Component
b) @Controller
c) @Service
d) @Repository
View Answer
Explanation: The @Controller annotation is used in Spring MVC to indicate that a class serves as a controller, handling web requests and responses.
14. Which of the following is a characteristic of Spring’s Bean Lifecycle?
a) Beans are created at runtime only
b) All beans are created as singletons
c) Beans can be configured to execute custom initialization methods
d) Beans are destroyed when the application shuts down only
View Answer
Explanation: Spring allows configuring custom initialization methods for beans, which can be executed during the bean lifecycle.
15. Which Spring annotation is used to mark a class as a repository?
a) @Service
b) @Repository
c) @Component
d) @Controller
View Answer
Explanation: The @Repository annotation is used to indicate that a class is a Data Access Object (DAO) and is responsible for interacting with the database.
16. Integration of JSF with Spring Application Context.
a) SpringBeanFacesELResolver
b) DelegatingVariableResolver
c) ContextLoaderListener
d) All of the mentioned
View Answer
Explanation: Due to the similarity between Spring and JSF bean models, it’s very easy to integrate them by registering the Spring-provided JSF variable resolver DelegatingVariableResolver (for JSF 1.1) or the SpringBeanFacesELResolver (for JSF 1.2 and greater).
17. Class which assists Spring Web flow in handling forms.
a) FormHandler
b) Form
c) Form-Handler
d) FormAction
View Answer
Explanation: Spring Web Flow provides a FormAction class to assist you in handling forms.
18. To use JSF Validation components provided by Spring Faces.
a) Facelets
b) Spring Javascript
c) Faces
d) None of the mentioned
View Answer
Explanation: To use the JSF validation components provided by Spring Faces, you have to use Facelets to create your JSF views.
19. To publish a REST service with Spring.
a) accessing data from third-party REST services
b) publishing an application’s data as a REST service
c) none of the mentioned
d) all of the mentioned
View Answer
Explanation: One involves publishing an application’s data as a REST service, while the other involves accessing data from third-party REST services to be used in an application.
20. The service, which will simply fetch all the items that are for auction and return the description.
a) EventSpring
b) SpringBlaze DS
c) SpringFlex
d) All of the mentioned
View Answer
Explanation: Use Spring BlazeDS to set up a simple service and demonstrate its invocation from the client—a simple auction application that we’ll build on in subsequent recipes.
21. How does the Spring JDBC framework know that state 23505 should be mapped to DuplicateKeyException?
a) error code
b) SQL state
c) all of the mentioned
d) none of the mentioned
View Answer
Explanation: The error code and SQL state are database-specific, meaning different database products may return different codes for the same kind of error.
22. Spring EJB Support Classes for Different Types of EJB:
a) AbstractMessageDrivenBean
b) AbstractStatelessSessionBean
c) AbstractStatefulSessionBean
d) All of the mentioned
View Answer
Explanation: Spring EJB Support Classes for Different Types of EJB
EJB Support Class | EJB Type
AbstractStatelessSessionBean | Stateless session bean
AbstractStatefulSessionBean | Stateful session bean
AbstractMessageDrivenBean | General message-driven bean that may not use JMS
AbstractJmsMessageDrivenBean | Message-driven bean that uses JMS.
23. Which annotation is used to define a Spring configuration class?
a) @Service
b) @Component
c) @Repository
d) @Configuration
View Answer
Explanation: The @Configuration annotation is used to indicate that a class can be used by the Spring IoC container as a source of bean definitions.
24. What is the purpose of Aspect-Oriented Programming (AOP) in Spring?
a) To separate cross-cutting concerns from business logic
b) To handle user input in web applications
c) To improve performance of the application
d) To manage database transactions
View Answer
Explanation: AOP in Spring is used to separate cross-cutting concerns (like logging and security) from business logic, enhancing modularity and maintainability.
25. Which of the following is NOT a feature provided by the Spring Framework?
a) Aspect-Oriented Programming
b) Automatic Memory Management
c) Dependency Injection
d) Simplified Data Access
View Answer
Explanation: Automatic Memory Management is a feature of Java’s Garbage Collection, not specifically provided by the Spring Framework.
26. Proxying Spring services with EJB3s, injecting custom resources configured in Spring, or even using Spring to isolate your EJBs from acquiring references to other distributed resources such as a REST endpoint or an RMI endpoint.
a) SpringBeanAutowiring
b) SpringBeanAutowiringInterceptor
c) SpringBeanInterceptor
d) SpringBean
View Answer
Explanation: To do this, use Spring’s SpringBeanAutowiringInterceptor class to provide configuration for the EJB.
27. Spring-WS provides various abstract endpoint classes for you to process the request.
a) org.springframework.*
b) org.springframework.ws.server.endpoint
c) org.springframework.ws.server
d) none of the mentioned
View Answer
Explanation: Spring-WS provides various abstract endpoint classes for you to process the request and response XML messages using different XML processing technologies and APIs. These classes are all located in the org.springframework.ws.server.endpoint package.
28. Which of the following is a feature of Spring Security?
a) Authentication
b) Method security
c) Authorization
d) All of the above
View Answer
Explanation: Spring Security provides comprehensive security services including method security, authentication, and authorization capabilities.
29. Integration of Spring which has each application produce files of shared data for others to consume.
a) Messaging
b) File transfer
c) Shared Database
d) Remote Procedure Invocation
View Answer
Explanation: File transfer: Have each application produce files of shared data for others to consume and consume files that others have produced.
30. Which of the following is used to handle exceptions globally in Spring MVC?
a) @ExceptionHandler
b) @ResponseStatus
c) @ControllerAdvice
d) @RestController
View Answer
Explanation: The @ControllerAdvice annotation is used to handle exceptions globally in Spring MVC, allowing you to define a single exception handling component for multiple controllers.
31. To take an input file or a payload and reliably, and systematically, decompose it into events that an ESB can work with:
a) Splitter
b) Spring Batch
c) All of the mentioned
d) None of the mentioned
View Answer
Explanation: You have a file with a million records in it. This file’s too big to handle as one event; it’s far more natural to react to each row as an event. Spring Batch works very well with these types of solutions. It allows you to take an input file or a payload and reliably, and systematically, decompose it into events that an ESB can work with.
32. Spring core framework provides first-class support for transactions.
a) TransactionManager
b) None of the mentioned
c) Transaction
d) All of the mentioned
View Answer
Explanation: You simply wire up a TransactionManager and give Spring Batch a reference, just as you would in any regular JdbcTemplate or HibernateTemplate solution.
33. Spring Batch provides a mechanism to offload processing to another process.
a) remote chunking
b) chunking
c) remote
d) none of the mentioned
View Answer
Explanation: Spring Batch provides a mechanism to offload processing to another process. This feature, called remote chunking, is new in Spring Batch 2.x.
34. Spring Dynamic Modules was, while powerful for those already invested in an OSGi platform, not the most natural accommodations for those trying to migrate large code into the OSGi environment, SpringSource created.
a) SpringSource dm Server
b) Spring Tooling
c) Spring Dynamic Modules
d) All of the mentioned
View Answer
Explanation: SpringSource dm Server is a robust solution. There are several editions available.
35. Which of the following principles does the Spring Framework primarily rely on?
a) Inversion of Control (IoC)
b) Polymorphism
c) Encapsulation
d) Inheritance
View Answer
Explanation: The Spring Framework primarily relies on Inversion of Control (IoC), allowing the framework to manage the lifecycle of application objects (beans).
36. What is the purpose of the @Component annotation in Spring?
a) To specify a configuration class
b) To define a bean in the application context
c) To enable AOP support
d) To create a controller in Spring MVC
View Answer
Explanation: The @Component annotation is used to define a bean in the application context, indicating that a class is a Spring-managed component.
37. Which interface is used to create a Spring application context?
a) ApplicationListener
b) BeanFactory
c) WebApplicationContext
d) ApplicationContext
View Answer
Explanation: ApplicationContext is a central interface to provide configuration for an application, and it is used to create Spring application contexts.
38. To start using Spring to smooth over some of the minutiae of resource acquisition and to help build more reliable systems in an OSGi environment.
a) Spring Dynamic Modules
b) Spring DM server
c) All of the mentioned
d) None of the mentioned
View Answer
Explanation: Use Spring Dynamic Modules to provide the integration. Spring Dynamic Modules is a framework on top of OSGi that works with any OSGi environment.
39. Spring-WS supports annotating an arbitrary class as a service endpoint by:
a) @Point
b) @End
c) @Endpoint
d) None of the mentioned
View Answer
Explanation: Spring-WS supports annotating an arbitrary class as a service endpoint by the @Endpoint annotation, without extending a framework-specific class.
40. The core interface of Spring email support is:
a) MailSender
b) EMail
c) All of the mentioned
d) None of the mentioned
View Answer
Explanation: Spring email support makes it easier to send email by providing an abstract and implementation-independent API for sending email. The core interface of Spring email support is MailSender.
41. Spring Batch works with a system scheduler:
a) autosys
b) cron
c) none of the mentioned
d) all of the mentioned
View Answer
Explanation: Spring Batch works with a system scheduler such as cron or autosys, or from a web application.
Chapterwise Multiple Choice Questions on Spring
- Spring Basics and Advanced Spring IoC Container
- Spring AOP and AspectJ Support and Scripting in Spring
- Spring Security and Integrating Spring with Other Web Frameworks
- Spring Web Flow, Spring @MVC, Spring REST and Spring and Flex
- Grails, Spring Roo, Spring Testing and Spring Portlet MVC Framework
- Data Access, Transaction Management in Spring and EJB, Spring Remoting and Web Services
- Spring in the Enterprise, Messaging, Spring Integration and Spring Batch
- Spring on the Grid, jBPM and Spring, OSGi and Spring and Advanced Java
1. Spring Basics and Advanced Spring IoC Container
The section contains multiple choice questions and answers on creation and declaration of beans, scope of beans, bean processors, property editors and spring taskexecutors.
|
|
2. Spring AOP and AspectJ Support and Scripting in Spring
The section contains questions and answers on annotation of aspectJ, definition of pointcut, basics of behaviour and beans state, implementation,injection, refreshing and defining beans with scripting languages.
3. Spring Security and Integrating Spring with Other Web Frameworks
The section contains MCQs on URL security, web security, view security, domain object security, integrating and accessing springs with frameworks, web flow management and security.
4. Spring Web Flow, Spring @MVC, Spring REST and Spring and Flex
The section contains multiple choice questions and answers on integration of spring with JSF, MVC applications, mapping and handling of views, bean validation, REST with spring, JSON with REST, flex, sandbox and blazeDS.
5. Grails, Spring Roo, Spring Testing and Spring Portlet MVC Framework
The section contains questions and answers on grails, application domain classes, message and storage properties, unit testing and logging, integration testing, spring roo, portlet and tool suite, custom layouts, tags and templates.
6. Data Access, Transaction Management in Spring and EJB, Spring Remoting and Web Services
The section contains MCQs on JDBC templates, exception handling, ORM frameworks, session, hibernate, EJB, web services and transaction management.
7. Spring in the Enterprise, Messaging, Spring Integration and Spring Batch
The section contains multiple choice questions and answers on email and spring scheduling, JMX MBeans, system integration, error handling, splitters, aggregators, spring gateways and batch and controlling of step execution.
8. Spring on the Grid, jBPM and Spring, OSGi and Spring and Advanced Java
The section contains questions and answers on object clustering, process parallization, load balancing, OSGi, serialization and email API.
Wish you the best in your endeavor to learn and master Spring!