250+ TOP MCQs on Bean Scopes and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “Bean Scopes”.

1. A bean can be requested by:-
a) getBean method
b) reference from another bean using autowiring, property etc
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: When a bean is requested by the getBean() method or a reference from other beans, Spring will decide which bean instance should be returned according to the bean scope.

2. Which attribute is used to set the scope of the bean?
a) setScope
b) scope
c) getScope
d) none of the mentioned
Answer: b
Clarification: Scope attribute defines the scope of a bean.

3. Which one is the default scope of the beans?
a) Prototype
b) Session
c) Request
d) Singleton
Answer: d
Clarification: This unique bean instance will be returned for all subsequent getBean() calls and bean references.

4. Which scope creates a new bean instance each time when requested?
a) Singleton
b) Prototype
c) Session
d) Request
Answer: b
Clarification: Creates a new bean instance each time when requested.

5. Session Creates a single bean instance per HTTP request, only valid in the context of a web application?
a) True
b) False
Answer: b
Clarification: Session Creates a single bean instance per HTTP session, only valid in the context of a web application.

6. Which of the following are considered valid beans?
a) Singleton
b) Prototype
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: In Spring 1.x, singleton and prototype are the only two valid bean scopes, and they are specified by the singleton attribute (i.e., singleton=”true” or singleton=”false”), not the scope attribute.

7. What will be the output?

public class ShoppingCart 
{
    private List<Product> items = new ArrayList<Product>();
    public void addItem(Product item) 
    {
       items.add(item);
    }
    public List<Product> getItems() 
    {
       return items;
    }
}
 
   <beans ...>
	<bean id="aaa" class="com.shop.Battery">
	<property name="name" value="AAA" />
	<property name="price" value="2.5" />
	bean>
	<bean id="cdrw" class="com.shop.Disc">
	<property name="name" value="CD-RW" />
	<property name="price" value="1.5" />
	bean>
	<bean id="dvdrw" class="com.shop.Disc">
	<property name="name" value="DVD-RW" />
	<property name="price" value="3.0" />
	bean>
	<bean id="shoppingCart" class="com.shop.ShoppingCart" />
   beans>
 
   import org.springframework.context.ApplicationContext;
   import org.springframework.context.support.ClassPathXmlApplicationContext;
   public class Main 
   {
	public static void main(String[] args) {
	ApplicationContext context =
	new ClassPathXmlApplicationContext("beans.xml");
	Product aaa = (Product) context.getBean("aaa");
	Product cdrw = (Product) context.getBean("cdrw");
	Product dvdrw = (Product) context.getBean("dvdrw");
	ShoppingCart cart1 = (ShoppingCart) context.getBean("shoppingCart");
	cart1.addItem(aaa);
	cart1.addItem(cdrw);
	System.out.println("Shopping cart 1 contains " + cart1.getItems());
	ShoppingCart cart2 = (ShoppingCart) context.getBean("shoppingCart");
	cart2.addItem(dvdrw);
	System.out.println("Shopping cart 2 contains " + cart2.getItems());
	}
   }

a) Shopping cart 1 contains (AAA 2.5, CD-RW 1.5)
Shopping cart 2 contains (AAA 2.5, CD-RW 1.5, DVD-RW 3.0)
b) Shopping cart 1 contains (AAA 2.5, CD-RW 1.5)
Shopping cart 2 contains (DVD-RW 3.0)
c) BeanCreationException
d) None of the mentioned
Answer: a
Clarification: Since the default scope is singleton, so items added by first bean instantiated will be used again by same bean if instantiated again.

8. In above question if scope of shoppingCart named bean is prototype, then what will be the output?
What will be the output?
a) Shopping cart 1 contains (AAA 2.5, CD-RW 1.5)
Shopping cart 2 contains (AAA 2.5, CD-RW 1.5, DVD-RW 3.0)
b) Shopping cart 1 contains (AAA 2.5, CD-RW 1.5)
Shopping cart 2 contains (DVD-RW 3.0)
c) BeanCreationException
d) None of the mentioned
Answer: b
Clarification: Since the default scope is prototype, so items added by first bean instantiated will be removed by same bean if instantiated again, and will add new items listed.

9. Which interface is used to perform initialization of beans?
a) InitializingBean
b) Disposablebean
c) None of the mentioned
d) All of the mentioned
Answer: a
Clarification: Spring allows your bean to perform initialization callback methods afterPropertiesSet() by implementing the InitializingBean and interfaces.

10. Which interface is used to perform destruction of beans?
a) InitializingBean
b) Disposablebean
c) None of the mentioned
d) All of the mentioned
Answer: b
Clarification: Spring allows your bean to perform destroy callback methods destroy() by implementing the DisposableBean and interfaces.

11. Alternate way of initialization method is:-
a) init-method attribute
b) afterPropertiesSet
c) destroy-method attribute
d) none of the mentioned
Answer: a
Clarification: A better approach of specifying the initialization callback methods is by setting the init-method attributes in your bean declaration.

12. Alternate way of destruction method is:-
a) init-method attribute
b) afterPropertiesSet
c) destroy-method attribute
d) none of the mentioned
Answer: c
Clarification: A better approach of specifying the destroy callback methods is by setting the destroy-method attributes in your bean declaration.

13. Which annotation is used as a substitute of initialization method?
a) @PostConstruct
b) @PreDestroy
c) None of the mentioned
d) All of the mentioned
Answer: a
Clarification: Using JSR annotation.

14.Which annotation is used as a substitute of destroy method?
a) @PostConstruct
b) @PreDestroy
c) None of the mentioned
d) All of the mentioned
Answer: b
Clarification: Using JSR annotation.

15. Which configuration can be used for Dependency Injection?
a) XML Configuration
b) Annotation Configuration
c) Java Based Configuration
d) All of the mentioned
Answer: d
Clarification: All of the above mentioned can be used for Dependency Injection.

250+ TOP MCQs on Spring MVC Web Applications and Requests handlers and Answers

Java Spring Questions and Answers for freshers on “Spring MVC Web Applications and Requests handlers”.

1. Design pattern implemented by Dispatcher Servlet.
a) jsp
b) tiles
c) front controller
d) none of the mentioned
Answer: c
Clarification: A Spring MVC controller—often referred to as a Dispatcher Servlet—implements one of Sun’s core Java EE design patterns called front controller.

2. Class used to give a class behavior of a Dispatcher Servlet.
a) AbstractController
b) Controller
c) Abstract Class
d) AbstractAction
Answer: a
Clarification: Prior to Spring 3.0 one of a series of classes, such as AbstractController, were used to give a class the behavior of a Dispatcher Servlet.

3. Annotation for Controller Class.
a) @Before
b) @Controller
c) @After
d) @Exception
Answer: b
Clarification: When a @Controller annotated class (i.e., a controller class) receives a request, it looks for an appropriate handler method to handle the request.

4. Handler method annotation.
a) @Before
b) @Controller
c) @After
d) @RequestMapping
Answer: d
Clarification: In order to do so, a controller class’s methods are decorated with the @RequestMapping annotation, making them handler methods.

5. Method arguments that can be used in handler methods using the @RequestMapping annotation.
a) HttpServletRequest or HttpServleResponse
b) @RequestParam
c) @ModelAttribute
d) All of the mentioned
Answer: d
Clarification: The above mentioned is only a partial list of valid argument types, just to give you an idea.

6. Annotation which represents cookie values of requests.
a) HttpServletRequest or HttpServleResponse
b) @RequestParam
c) @Cookie
d) None of the mentioned
Answer: d
Clarification: Cookie values included in an incoming request, annotated with @CookieValue.

7. To add attributes to the model.
a) Map
b) ModelMap
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: Map or ModelMap, for the handler method to add attributes to the model.

8. To access the binding and validation result for the command object.
a) Errors
b) BindingResult
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: Errors or BindingResult, for the handler method to access the binding and validation result for the command object.

9. To notify its completion of session processing.
a) Errors
b) BindingResult
c) SessionStatus
d) None of the mentioned
Answer: c
Clarification: SessionStatus, for the handler method to notify its completion of session processing.

10. Controller Class renders the objects passed by the controller’s handler method.
a) True
b) False
Answer: a
Clarification: Once the controller class has resolved a view name into a view implementation, per the view implementation design, it renders the objects (e.g., HttpServletRequest, Map, Errors, or SessionStatus) passed by the controller’s handler method.

11. Parameter used to specify a configuration file.
a) contextConfigLocation
b) contextConfigure
c) contextLocation
d) none of these
Answer: a
Clarification: By default, a look is made for a file by joining the servlet name with -servlet.xml as the file name. You can explicitly specify a configuration file in the contextConfigLocation servlet parameter.

12. The @RequestMapping annotation can be applied to the class level only.
a) True
b) False
Answer: b
Clarification: The @RequestMapping annotation can be applied to the class level or the method level.

13. Bean classes pre-registered in the web application context by default.
a) DefaultAnnotationHandlerMapping
b) AnnotationMethodHandlerAdapter
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: Next, the DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter bean classes are pre-registered in the web application context by default.

14. By default, @RequestMapping gets all the POST Requests.
a) True
b) False
Answer: b
Clarification: By default, @RequestMapping annotations assume all incoming requests are of the HTTP GET kind, which is the most common in web applications.

15. Callback methods provided by HandlerInterceptor to implement.
a) preHandle()
b) postHandle()
c) afterCompletion()
d) all of the mentioned
Answer: d
Clarification: Each handler interceptor must implement the HandlerInterceptor interface, which contains three callback methods for you to implement: preHandle(), postHandle(), and afterCompletion().


Java Spring for Freshers,

250+ TOP MCQs on Integration Testing and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “Integration Testing”.

1. Base class to access the managed application context through the inherited getApplicationContext() method.
a) AbstractSingleSpringContextTests
b) AbstractSingleSpring
c) Test context listener
d) Test execution listener

Answer: a
Clarification: With Spring JUnit 3 legacy support in releases prior to 2.5, your test class can extend the AbstractSingleSpringContextTests base class to access the managed application context through the inherited getApplicationContext() method.

2. The TestContext framework provides two test execution listeners related to context management:-
a) DependencyInjectionTestExecutionListener
b) DirtiesContextTestExecutionListener
c) All of the mentioned
d) None of the mentioned

Answer: c
Clarification: They will be registered with a test context manager by default if you don’t specify your own explicitly.
• DependencyInjectionTestExecutionListener: This injects dependencies, including
the managed application context, into your tests.
• DirtiesContextTestExecutionListener: This handles the @DirtiesContext
annotation and reloads the application context when necessary.

3. Interface which can provide access to the managed application context through the protected field applicationContext
a) ApplicationContextAware
b) ApplicationContext
c) ApplicationContextAwareContext
d) None of the mentioned

Answer: a
Clarification: These classes integrate with a test context manager and implement the ApplicationContextAware interface, so they can provide access to the managed application context through the protected field applicationContext.

4. In JUnit 4, you can simply run your test with the test runner SpringJUnit4ClassRunner.
a) True
b) False

Answer: a
Clarification: In JUnit 4, you can simply run your test with the test runner SpringJUnit4ClassRunner to have a test context manager integrated. However, in TestNG, you have to integrate with a test context manager manually.

5. Method to indicate that the application context is dirty.
a) getDirty()
b) setDirty()
c) all of the mentioned
d) none of the mentioned

Answer: b
Clarification: You can call the setDirty() method to indicate that the application context is dirty so that it will be reloaded automatically for the next test method.

6. In JUnit4, to explicitly specify a Spring-specific test runner for running your test.
a) SpringJUnit4ClassRunner
b) SpringJUnit4Class
c) SpringJUnit4
d) None of the mentioned

Answer: a
Clarification: You have to explicitly specify a Spring-specific test runner for running your test—SpringJUnit4ClassRunner.

7. Annotation for SpringJUnit4ClassRunner:-
a) @Run
b) @RunWith
c) All of the mentioned
d) None of the mentioned

Answer: b
Clarification: For this option, you have to explicitly specify a Spring-specific test runner for running your test—SpringJUnit4ClassRunner. You can specify this in the @RunWith annotation at the class level.

8. This class implements the ApplicationContextAware interface, so you can get access to the managed application context:-
a) AbstractJUnit38SpringContext
b) AbstractJUnit38Spring
c) AbstractJUnit38SpringContextTests
d) None of the mentioned

Answer: c
Clarification: This class implements the ApplicationContextAware interface, so you can get access to the managed application context via the protected field applicationContext.

9. AbstractJUnit38SpringContext class also implements the ApplicationContextAware interface.
a) True
b) False

Answer: b
Clarification: AbstractTestNGSpringContextTests class also implements the ApplicationContextAware interface.

10. Spring JUnit 3 legacy support in releases prior to 2.5, your test class can extend the:-
a) AbstractDependencyInjectionSpringContextTests
b) AbstractSingleSpringContextTests
c) All of the mentioned
d) None of the mentioned

Answer: a
Clarification: When using Spring JUnit 3 legacy support in releases prior to 2.5, your test class can extend the AbstractDependencyInjectionSpringContextTests base class, which is a subclass of AbstractSingleSpringContextTests, to have its test fixtures injected automatically.

11. AbstractDependencyInjectionSpringContextTests supports dependency injection.
a) auto-wires beans by type via setter methods
b) auto-wires beans by name via protected fields
c) none of the mentioned
d) all of the mentioned

Answer: c
Clarification: When using Spring JUnit 3 legacy support in releases prior to 2.5, your test class can extend the AbstractDependencyInjectionSpringContextTests base class, which is a subclass of AbstractSingleSpringContextTests, to have its test fixtures injected automatically.

12. Test fixtures injected from the managed application context by annotating:-
a) @Autowired
b) @Resource
c) All of the mentioned
d) None of the mentioned

Answer: c
Clarification: When using the TestContext framework to create tests, you can have their test fixtures injected from the managed application context by annotating a field or setter method with the @Autowired or @Resource annotations.

13. TestContext support class AbstractJUnit4SpringContextTests, you can also have test fixtures injected from the managed application context.
a) True
b) False

Answer: a
Clarification: By extending the TestContext support class AbstractJUnit4SpringContextTests, you can also have test fixtures injected from the managed application context. In this case, you don’t need to specify SpringJUnit4ClassRunner for your test, as it is inherited from the parent.

14. Starting from Spring 2.5, the TestContext framework provides a test execution listener related to transaction management:-
a) TransactionalTestExecutionListener
b) TransactionalTestExecution
c) All of the mentioned
d) None of the mentioned

Answer: a
Clarification: It will be registered with a test context manager by default if you don’t specify your own explicitly.

15. Annotation for TransactionalTestExecutionListener:-
a) @Transactional
b) @RunWith
c) @Run
d) None of the mentioned

Answer: a
Clarification: TransactionalTestExecutionListener: This handles the @Transactional annotation at the class or method level and has the methods run within transactions automatically.

250+ TOP MCQs on JMS Messages and Transactions and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “JMS Messages and Transactions”.

1. Template which can send and receive JMS messages with much less code
a) JmsTemplate
b) EMail
c) All of the mentioned
d) None of the mentioned
Answer: a
Clarification: With a JMS template (Spring framework class JmsTemplate), you can send and receive JMS messages with much less code.

2. The template handles the boilerplate tasks for you and also converts the JMS API JMSException hierarchy into Spring runtime exception:-
a) org.springframework.jms.Jms
b) org.springframework.jms.JmsException
c) org.springframework.jms.JmsTemplate
d) none of the mentioned
Answer: b
Clarification: The translation converts exceptions to a mirrored hierarchy of unchecked exceptions.

3. To address different JMS APIs, Spring provides :-
a) JmsTemplate
b) JmsTemplate102
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: To address different JMS APIs, Spring provides two JMS template classes, JmsTemplate and JmsTemplate102, for these two versions of JMS.

4. Before you can send and receive JMS messages, you need to install a JMS message broker:-
a) Apache ActiveM
b) Apache Active
c) Apache MQ
d) Apache ActiveMQ
Answer: d
Clarification: Before you can send and receive JMS messages, you need to install a JMS message broker. For simplicity’s sake, we have chosen Apache ActiveMQ (http://activemq.apache.org/) as our message broker, which is very easy to install and configure.

5. In the preceding sendMail() method, you first create JMS-specific ConnectionFactory.

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
public class FrontDeskImpl implements FrontDesk {
	public void sendMail(Mail mail) {
		ConnectionFactory cf =
		new ActiveMQConnectionFactory("tcp://localhost:61616");
		Destination destination = new ActiveMQQueue("mail.queue");
		Connection conn = null;
		try {
			conn = cf.createConnection();
			Session session =
			conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
			MessageProducer producer = session.createProducer(destination);
			MapMessage message = session.createMapMessage();
			message.setString("mailId", mail.getMailId());
			message.setString("country", mail.getCountry());
			message.setDouble("weight", mail.getWeight());
			producer.send(message);
			session.close();
			} catch (JMSException e) {
				throw new RuntimeException(e);
			} finally {
				if (conn != null) {
				try {
				conn.close();
				} catch (JMSException e) {
				}
			}
		}
	}
}

a) True
b) False
Answer: a
Clarification: In the preceding sendMail() method, you first create JMS-specific ConnectionFactory and Destination objects with the classes provided by ActiveMQ.

6.In JMS, there are two types of destinations:-

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
public class FrontDeskImpl implements FrontDesk {
	public void sendMail(Mail mail) {
		ConnectionFactory cf =
		new ActiveMQConnectionFactory("tcp://localhost:61616");
		Destination destination = new ActiveMQQueue("mail.queue");
		Connection conn = null;
		try {
			conn = cf.createConnection();
			Session session =
			conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
			MessageProducer producer = session.createProducer(destination);
			MapMessage message = session.createMapMessage();
			message.setString("mailId", mail.getMailId());
			message.setString("country", mail.getCountry());
			message.setDouble("weight", mail.getWeight());
			producer.send(message);
			session.close();
			} catch (JMSException e) {
				throw new RuntimeException(e);
			} finally {
				if (conn != null) {
				try {
				conn.close();
				} catch (JMSException e) {
				}
			}
		}
	}
}

a) topic
b) queue
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: The message broker URL is the default for ActiveMQ if you run it on localhost. In JMS, there are two types of destinations: queue and topic. As explained before, a queue is for the point-to-point communication model, while topic is for the publish-subscribe communication model.

7. There are several types of messages defined in the JMS API, including:-
a) TextMessage
b) MapMessage
c) BytesMessage
d) All of the mentioned
Answer: d
Clarification: There are several types of messages defined in the JMS API, including TextMessage, MapMessage, BytesMessage, ObjectMessage, and StreamMessage.

8. To send a JMS message with this template, you simply call:-
a) send
b) sendTo
c) all of the mentioned
d) none of the mentioned
Answer: a
Clarification: To send a JMS message with this template, you simply call the send() method and provide a message destination, as well as a MessageCreator object, which creates the JMS message you are going to send.

9. The MessageCreator interface declares method:-
a) createMessage()
b) create()
c) createMsg()
d) none of the mentioned
Answer: a
Clarification: The MessageCreator interface declares only a createMessage() method for you to implement.

10. A JMS template helps you to obtain and release the JMS connection and session.
a) True
b) False
Answer: a
Clarification: A JMS template helps you to obtain and release the JMS connection and session, and it sends the JMS message created by your MessageCreator object.

11. JMS sender and receiver classes can also extend to retrieve a JMS template:-
a) JmsGatewaySupport
b) JmsGateway
c) All of the mentioned
d) None of the mentioned
Answer: a
Clarification: Just like your DAO class can extend JdbcDaoSupport to retrieve a JDBCtemplate, your JMS sender and receiver classes can also extend JmsGatewaySupport to retrieve a JMS template.

12. When you need access to the JMS template.
a) setJmsTemplate
b) getJmsTemplate
c) getJms
d) none of the mentioned
Answer: b
Clarification: When you need access to the JMS template, you just make a call to getJmsTemplate().

13. Spring provides an implementation of SimpleMessageConvertor to handle the translation of a JMS message received.
a) True
b) False
Answer: a
Clarification: Spring provides an implementation of SimpleMessageConvertor to handle the translation of a JMS message received to a business object and the translation of a business object to a JMS message.

14. By default, the JMS template uses SimpleMessageConverter for converting TextMessage to or from a string.
a) True
b) False
Answer: a
Clarification: By default, the JMS template uses SimpleMessageConverter for converting TextMessage to or from a string, BytesMessage to or from a byte array, MapMessage to or from a map, and ObjectMessage to or from a serializable object.

15. For your front desk and back office classes, you can send and receive a map using the:-
a) convertAndSend()
b) receiveAndConvert()
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: For your front desk and back office classes, you can send and receive a map using the convertAndSend() and receiveAndConvert() methods, and the map will be converted to/from MapMessage.

250+ TOP MCQs on SpringSource dm Server and Toolings and Answers

Tough JavaSpring questions and answers on “Spring Source dm Server and Toolings”.

1. Support for deployment of traditional .war artifacts, enable use of some of the standard Java EE libraries, provide useful defaults for many de facto standard libraries, and provide fully integrated support for Spring Dynamic Modules.
a) Spring Dynamic Modules
b) Spring dm Server
c) Spring Tooling
d) All of the mentioned
Answer: b
Clarification: Use Spring dm Server, SpringSource’s tried and true OSGi–oriented server built on many technologies including Equinox and the Spring framework itself.

2. OSGi doesn’t solve framework concerns, instead focusing on infrastructure requirements for Java applications.
a) True
b) False
Answer: a
Clarification: Spring Dynamic Modules provides functionality that sits on top of those implementations, providing very powerful runtime sophistication for developers looking to produce and consume OSGi services in a Spring-friendly fashion.

3 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) Spring Dynamic Modules
b) Spring dm Server
c) Spring Tooling
d) All of the mentioned
Answer: b
Clarification: SpringSource dm Server is a robust solution. There are several editions available.

4. SpringSource dm Server many advances focus on delivering a solution, and not just a framework, for delivering:-
a) Spring Tooling
b) Spring dm
c) OSGi
d) None of the mentioned
Answer: c
Clarification: SpringSource dm Server many advances focus on delivering a solution, and not just a framework, for delivering OSGi–based enterprise applications.

5. SpringSource dm Server provides value above and beyond a regular OSGi solution.
a) True
b) False
Answer: a
Clarification: It’s already well integrated.

6 OSGi–enabling all of these interwoven dependencies via the granular use of the Import-Package header would be tedious.
a) True
b) False
Answer: a
Clarification: Spring dm Server provides the ability to wholesale import an entire library and all packages therein to expedite the process.

7. SpringSource dm Server also allows you to bend the rules where necessary.
a) True
b) False
Answer: a
Clarification: For example, consider the application of an aspect using Spring’s AOP. This might require weaving of classes, which in the case of a pointcut that matches classes deployed across multiple bundles, would prove cumbersome. SpringSource dm Server can intervene on Spring’s behalf, propagating such changes across multiple bundles where necessary.

8. SpringSource dm Server works with several types of deployment formats:-
a) bundle
b) Java EE .war
c) platform archive
d) all of the mentioned
Answer: d
Clarification: SpringSource dm Server works with four types of deployment formats.

9. Application isolation is critical because it allows you to solve the issue of reconciliation of two services whose interfaces collide. You can use:-
a) .WAR
b) .XML
c) .PAR
d) All of the mentioned
Answer: c
Clarification: You can use a .PAR to isolate services within the deployment unit.

10. SpringSource dm Server provides the robustness needed to commoditize enterprise application development in an OSGi environment.
a) True
b) False
Answer: a
Clarification: For a really good reference, specifically on SpringSource dm Server, I (Josh Long) would humbly recommend you investigate my co-author in-depth treatment of the subject, Pro SpringSource dm Server, by Gary Mak and Daniel Rubio (Apress, 2009).

11. To begin with SpringSource dm Server but need a way to rapidly turnaround development.
a) Spring Dynamic Module
b) Spring Dynamic Server
c) SpringSource dm Server
d) None of the mentioned
Answer: c
Clarification: Use the SpringSource dm Server tooling available as part of SpringSource Tool Suite (STS).

12. SpringSource has provided solid tooling for Eclipse, called :-
a) Spring Dynamic Module
b) dm Server Tools
c) SpringSource dm Server
d) None of the mentioned
Answer: b
Clarification: SpringSource has provided solid tooling for Eclipse, called dm Server Tools, which facilitate executing applications directly in a development environment.

13. These tools—part of the broader SpringSource Tool Suite—are available as :-
a) plug-in
b) stand-alone environment
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: These tools—part of the broader SpringSource Tool Suite—are available as either a plug-in or as a stand-alone environment.


To practice tough questions and answers on all areas of Java Spring,

250+ TOP MCQs on Bean Post Processors and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “Bean Post Processors”.

1. Method used to process bean before initialization callback
a) scope
b) postProcessAfterInitialization()
c) postProcessBeforeInitialization()
d) it’s own constructor
Answer: c
Clarification: You can process every bean before initialization callback method by implementing the postProcessBeforeInitialization() and methods.

2. Method used to process bean after initialization callback
a) scope
b) getBean
c) postProcessAfterInitialization()
d) it’s own constructor
Answer: c
Clarification: You can process every bean after initialization callback method by implementing the postProcessAfterInitialization() and methods.

3. Which method is used to gracefully shutdown all the bean processes after closing the spring container?
a) shutdownHook
b) destroy method
c) none of the mentioned
d) all of the mentioned
Answer: a
Clarification: ShutdownHook method gracefully shuts down each bean process before closing the container.

4. Which method is used to register BeanPostProcessor?
a) addBeanPostProcessors
b) registerBeanPostProcessors
c) addBeanProcessors
d) none of the mentioned
Answer: a
Clarification: When using a bean factory as your IoC container, bean post processors can only be registered programmatically, or more accurately, via the addBeanPostProcessor() method.

5. In application context, BeanPost Processors are registered using addBeanPostProcessors method
a) True
b) False
Answer: b
Clarification: Using an application context, the registration will be as simple as declaring an instance of the processor in the bean configuration file.

6. Which Interface for bean Post Processor is used to distinguish between checked beans
a) StorageConfig
b) Marker
c) None of the mentioned
d) All of the mentioned
Answer: a
Clarification: First of all, for the bean post processor to distinguish which beans should be checked, you create a marker interface, StorageConfig, for your target beans to implement.

7. Which method of bean post processors is used to check path existence
a) getPath
b) setPath
c) value
d) auto-wiring
Answer: a
Clarification: Moreover, for your bean post processor to check for path existence, it must be able to access the path property. This can be done by adding the getPath() method to this interface.

8. It’s possible to replace the original bean instance with a brand-new instance in your bean post processor
a) True
b) False
Answer: a
Clarification: Both the postProcessBeforeInitialization() and postProcessAfterInitialization() methods must return an instance for the bean being processed.

9. PathCheckingBeanPostProcessor will not work properly in case of:-
a) XML Configuration
b) Java based Configuration
c) JSR Annotation
d) None of the mentioned
Answer: c
Clarification: This is because your bean post processor has a lower priority than CommonAnnotationBeanPostProcessor by default. As a result, the initialization method will be called before your path checking.

10. Which bean factory post processor externalizes part of the bean configurations into a properties file
a) PropertyPlaceholderConfigurer
b) PropertyPlaceholderRegister
c) PropertyGetPath
d) None of the mentioned
Answer: a
Clarification: Spring comes with a bean factory post processor called PropertyPlaceholderConfigurer for you to externalize part of the bean configurations into a properties file.

11. Which interface defines methods for resolving text messages
a) MessageSource
b) ApplicationListener
c) ApplicationContextListener
d) TextEvent
Answer: a
Clarification: MessageSource is an interface that defines several methods for resolving messages.

12. Which interface is used to listen to certain events
a) ApplicationListener
b) ContextListener
c) EventListener
d) None of the mentioned
Answer: a
Clarification: For a bean to listen to certain events, it must implement the ApplicationListener interface and handle the events in the onApplicationEvent() method.

13. Which method is used to publish your own custom event
a) contextPublish
b) publishEvent
c) applicationEventPublish
d) addEvent
Answer: b
Clarification: Any bean can publish an event by calling an application event publisher’s publishEvent() method.

14. Which of the following is a well known recognized event
a) ContextCloasedEvemt
b) ContextRefreshedEvent
c) RequestHandledEvent
d) All of the mentioned
Answer: d
Clarification: The application context itself will also publish container events such as ContextClosedEvent, ContextRefreshedEvent, and RequestHandledEvent.

15. Which event is provoked when web request comes into action
a) ContextClosedEvent
b) ContextStoppedEvent
c) SessionEvent
d) RequestHandledEvent
Answer: d
Clarification: Web request events are handled by RequestHandledEvent.