Java MCQ Set 1
1. Payload format for REST services.
a) RSS
b) Atom
c) JSON
d) All of the mentioned
Answer
Answer: d [Reason:] JSON, in addition to RSS and Atom, has blossomed into a favorite payload format for REST services.
2. All REST service payloads rely on XML markup.
a) True
b) False
Answer
Answer: b [Reason:] JSON is different in the sense that its content is a special notation based on the JavaScript language.
3. Class that forms part of Spring to apply JSON content.
a) MappingJacksonJsonView
b) MappingJsonView
c) MappingJacksonJson
d) JsonView
Answer
Answer: a [Reason:] In addition to relying on Spring’s REST support, we will also use the MappingJacksonJsonView class that forms part of Spring to facilitate the publication of JSON content.
4. The MappingJacksonJsonView class depends on Jackson JSON processor library.
a) org.codehaus.jackson
b) jackson-mapper-asl
c) all of the mentioned
d) none of the mentioned
Answer
Answer: a [Reason:] The MappingJacksonJsonView class depends on the presence of the Jackson JSON processor library which can be downloaded at http://wiki.fasterxml.com/JacksonDownload.
5. Information you wish to publishas a JSON Object can be located in a RDBMS or text file, accessed through JDBC or ORM.
a) True
b) False
Answer
Answer: a [Reason:] This information can be located in a RDBMS or text file, accessed through JDBC or ORM, inclusively be part of a Spring bean or some other type of construct.
6. JSON payload consists of text and separators like.
a) { , }
b) ( , )
c) :
d) All of the mentioned
Answer
Answer: d [Reason:] a JSON payload consists of text and separators like { , }, ( , ), : and “.
7. To access JSON in a Spring application, library used is:-
a) JSON-LIB
b) SpringJSON-lib
c) JSON-lib
d) None of the mentioned
Answer
Answer: a [Reason:] Though it’s technically possible to access JSON in a Spring application (i.e., on the server side), using a third-party Java library like JSON-LIB (http://json-lib.sourceforge.net/ ).
8. You are often better served accessing and manipulating REST services with XML payloads in Spring applications.
a) True
b) False
Answer
Answer: a [Reason:] The Java platform’s native support for XML, in addition to the fact that XML is more intuitive and does not have the same processing limitations as browsers.
9. Class which is capable of performing a multitude of operations on REST services.
a) RestTemplate
b) XPathTemplate
c) XMLTemplate
d) JavaTemplate
Answer
Answer: a [Reason:] Spring RestTemplate class is capable of performing a multitude of operations on REST services in order for their payloads to be used inside Spring applications, processing elaborate XML responses requires using a set of approaches beyond those of this last class.
10. XML query language for selecting nodes from an XML document.
a) XPathTemplate
b) XPath
c) All of the mentioned
d) None of the mentioned
Answer
Answer: b [Reason:] XPath—an XML query language for selecting nodes from an XML document— knowledge about Spring’s HttpConverterMessage, as well as supporting facilities like Spring’s XPathTemplate.
11. The Handler method assigns the returning XML payload to a String.
a) True
b) False
Answer
Answer: a [Reason:] The handler method makes use of the getForObject method of the RestTemplate class and assigns the returning XML payload to a String, which is then added to the handler method’s Model object.
12. To extract and manipulate payloads in Spring REST in a format other than String.
a) HttpConverter
b) HttpMessage
c) HttpConverterMessage
d) None of the mentioned
Answer
Answer: c [Reason:] All objects that are returned and inclusively passed to the methods belonging to the RestTemplate class are converted to and from HTTP messages using a class which implements the HttpConverterMessage interface.
13. To write your own converters relying on the MarshallingHttpMessageConverter interface that would allow the use of custom marshallers.
a) messageConverters
b) messageConvert
c) converters
d) convertersMessage
Answer
Answer: a [Reason:] Using custom converters requires registering them with the messageConverters bean property in a Spring application.
14. To override the default implementations registered with the RestTemplate class.
a) messageConverters
b) messageConvert
c) converters
d) convertersMessage
Answer
Answer: a [Reason:] It’s also possible to override the default implementations registered with the RestTemplate class using the same messageConverters bean property.
15. To extract and manipulate the contents of a REST service’s payload.
a) messageConverters
b) StreamSource class
c) converters
d) convertersMessage
Answer
Answer: b [Reason:] It becomes easier to extract and manipulate the contents of a REST service’s payload, since it can be done through the more flexible StreamSource class.
Java MCQ Set 2
1. Design pattern implemented by Dispatcher Servlet.
a) jsp
b) tiles
c) front controller
d) none of the mentioned
Answer
Answer: c [Reason:] 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
Answer: a [Reason:] 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
Answer: b [Reason:] 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’s annotation.
a) @Before
b) @Controller
c) @After
d) @RequestMapping
Answer
Answer: d [Reason:] 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
Answer: d [Reason:] 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
Answer: d [Reason:] 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
Answer: c [Reason:] 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
Answer: c [Reason:] 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
Answer: c [Reason:] 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
Answer: a [Reason:] Once the controller class has resolved a view name into a view implementation, per the view implementation’s 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
Answer: a [Reason:] 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
Answer: b [Reason:] The @RequestMapping annotation can be applied to the class level or the method level.
13. Bean classes preregistered in the web application context by default.
a) DefaultAnnotationHandlerMapping
b) AnnotationMethodHandlerAdapter
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] Next, the DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter bean classes are preregistered in the web application context by default.
14. By default, @RequestMapping gets all the POST Requests.
a) True
b) False
Answer
Answer: b [Reason:] 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
Answer: d [Reason:] Each handler interceptor must implement the HandlerInterceptor interface, which contains three callback methods for you to implement: preHandle(), postHandle(), and afterCompletion().
Java MCQ Set 3
1. The core interface of Spring’s e-mail support is:-
a) MailSender
b) EMail
c) All of the mentioned
d) None of the mentioned
Answer
Answer: a [Reason:] Spring’s e-mail support makes it easier to send e-mail by providing an abstract and implementation-independent API for sending e-mail. The core interface of Spring’s e-mail support is MailSender.
2. The JavaMailSender interface is a subinterface of MailSender that includes specialized JavaMail features:-
a) Multipurpose Internet Mail Extensions
b) Multipurpose Internet Mail
c) Multipurpose Internet Extensions
d) None of the mentioned
Answer
Answer: a [Reason:] The JavaMailSender interface is a subinterface of MailSender that includes specialized JavaMail features such as Multipurpose Internet Mail Extensions (MIME) message support. To send an e-mail message with HTML content, inline images, or attachments, you have to send it as a MIME message.
3. Before you implement the ErroNotifier interface in this way, you may need a local e-mail server that supports the Simple Mail Transfer Protocol (SMTP) for testing purposes.
a) True
b) False
Answer
Answer: a [Reason:] Before you implement the interface in this way, you may need a local e-mail server that supports the Simple Mail Transfer Protocol (SMTP) for testing purposes. We recommend installing Apache James Server (http://james.apache.org/server/index.html), which is very easy to install and configure.
4. You can implement the interface to send e-mail notifications in case of errors.
a) Notify
b) Error
c) ErrorNotifier
d) None of the mentioned
Answer
Answer: c [Reason:] You can implement the ErrorNotifier interface to send e-mail notifications in case of errors.
5. You send the e-mail by making a call to:-
a) Transport.send()
b) Transport.sendTo()
c) All of the mentioned
d) None of the mentioned
Answer
Answer: a [Reason:] You send the e-mail by making a call to Transport.send().
6. The default port used by JavaMailSenderImpl is the:-
a) SMTP port 24
b) SMTP port 22
c) SSH port 22
d) SMTP port 25
Answer
Answer: d [Reason:] The default port used by JavaMailSenderImpl is the standard SMTP port 25, so if your e-mail server listens on this port for SMTP, you can simply omit this property.
7. If you have a JavaMail session configured in your Java EE application server, you can first look it up with the help of:-
a) JndiObjectFactory
b) JndiObjectFactoryBean
c) JndiObject
d) None of the mentioned
Answer
Answer: b [Reason:] If you have a JavaMail session configured in your Java EE application server, you can first look it up with the help of JndiObjectFactoryBean.
8. MIME is supported by JavaMail through the:-
a) javax.mail.internet.Mime
b) javax.mail.internet.Message
c) javax.mail.internet.MimeMessage
d) javax.mail.internet.Mail
Answer
Answer: c [Reason:] To send e-mail that contains HTML content, inline images, or attachments, you have to construct and send a MIME message instead. MIME is supported by JavaMail through the javax.mail.internet.MimeMessage class.
9. The JavaMailSenderImpl instance you injected does implement this interface.
a) True
b) False
Answer
Answer: a [Reason:] The JavaMailSenderImpl instance you injected does implement this interface, so you needn’t modify your bean configurations.
10. Quartz supports several types of triggers:-
a) SimpleTrigger
b) CronTrigger
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] Quartz supports two types of triggers: SimpleTrigger and CronTrigger.
11. SimpleTrigger allows you to set trigger properties:-
a) start time
b) end time
c) repeat interval
d) all of the mentioned
Answer
Answer: d [Reason:] SimpleTrigger allows you to set trigger properties such as start time, end time, repeat interval, and repeat count.
12. CronTrigger accepts a Unix cron expression for you to specify the times to run your job.
a) True
b) False
Answer
Answer: a [Reason:] For example, you can replace the preceding SimpleTrigger with the following CronTrigger to run your job at 17:30 every day:
CronTrigger trigger = new CronTrigger(); trigger.setName("documentReplicationJob"); trigger.setCronExpression("0 30 17 * * ?");
13. Spring also offers MethodInvokingJobDetailFactoryBean for you to define a job that executes a single method of a particular object.
a) True
b) False
Answer
Answer: a [Reason:] This saves you the trouble of creating a job class.
14. You can configure a Quartz SimpleTrigger object in Spring’s bean configuration file through:-
a) SimpleTrigger
b) SimpleTriggerBean
c) All of the mentioned
d) None of the mentioned
Answer
Answer: b [Reason:] You can configure a Quartz SimpleTrigger object in Spring’s bean configuration file through SimpleTriggerBean, which requires a reference to a JobDetail object. This bean provides common default values for certain trigger properties, such as using the bean name as the job name and setting indefinite repeat count.
15. Spring 3.0 debuts new support for configuring:-
a) TaskExecutors
b) TaskSchedulers
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] Spring 3.0 debuts new support for configuring TaskExecutors and TaskSchedulers. This capability, coupled with the ability to schedule method execution using the @Scheduled annotation, makes Spring 3.0 very capable of meeting this challenge.
Java MCQ Set 4
1. Spring-WS supports using XML marshalling technology to marshal and unmarshall objects to and from XML documents.
a) True
b) False
Answer
Answer: a [Reason:] This technology is also known as object/XML mapping (OXM), because you are actually mapping objects to and from XML documents.
2. To implement endpoints with an XML marshalling technology, you have to extend the:-
a) AbstractMarshallingPayload
b) AbstractMarshalling
c) AbstractMarshallingPayloadEndpoint
d) None of the mentioned
Answer
Answer: c [Reason:] To implement endpoints with an XML marshalling technology, you have to extend the AbstractMarshallingPayloadEndpoint class and configure an XML marshaller for it.
3. Marshaller for JAXB 1.0:-
a) org.springframework.oxm.jaxb.Jaxb1Marshaller
b) org.springframework.oxm.jaxb.Jaxb2Marshaller
c) org.springframework.oxm.castor.CastorMarshall
d) org.springframework.oxm.xmlbeans.XmlBeansMarshaller
Answer
Answer: a [Reason:] JAXB 1.0 org.springframework.oxm.jaxb.Jaxb1Marshaller.
4. Marshaller for JAXB 2.0:-
a) org.springframework.oxm.jaxb.Jaxb1Marshaller
b) org.springframework.oxm.jaxb.Jaxb2Marshaller
c) org.springframework.oxm.castor.CastorMarshall
d) org.springframework.oxm.xmlbeans.XmlBeansMarshaller
Answer
Answer: b [Reason:] JAXB 2.0 org.springframework.oxm.jaxb.Jaxb2Marshaller.
5. Marshaller for Castor:-
a) org.springframework.oxm.jaxb.Jaxb1Marshaller
b) org.springframework.oxm.jaxb.Jaxb2Marshaller
c) org.springframework.oxm.castor.CastorMarshall
d) org.springframework.oxm.xmlbeans.XmlBeansMarshaller
Answer
Answer: c [Reason:] Castor org.springframework.oxm.castor.CastorMarshaller.
6. Marshaller for XMLBeans:-
a) org.springframework.oxm.jaxb.Jaxb1Marshaller
b) org.springframework.oxm.jaxb.Jaxb2Marshaller
c) org.springframework.oxm.castor.CastorMarshall
d) org.springframework.oxm.xmlbeans.XmlBeansMarshaller
Answer
Answer: d [Reason:] XMLBeans org.springframework.oxm.xmlbeans.XmlBeansMarshaller.
7. Marshaller for JiBX:-
a) org.springframework.oxm.jaxb.Jaxb1Marshaller
b) org.springframework.oxm.jaxb.Jaxb2Marshaller
c) org.springframework.oxm.castor.CastorMarshall
d) org.springframework.oxm.jibx.JibxMarshaller
Answer
Answer: d [Reason:] JiBX org.springframework.oxm.jibx.JibxMarshaller.
8. Marshaller for XStream:-
a) org.springframework.oxm.jaxb.Jaxb1Marshaller
b) org.springframework.oxm.jaxb.Jaxb2Marshaller
c) org.springframework.oxm.xstream.XStreamMarshaller
d) org.springframework.oxm.jibx.JibxMarshaller
Answer
Answer: c [Reason:] XStream org.springframework.oxm.xstream.XStreamMarshaller.
9. Spring-WS supports various XML marshalling APIs.
a) Castor
b) JAXB 1.0
c) XMLBeans
d) All of the mentioned
Answer
Answer: d [Reason:] Spring-WS supports various XML marshalling APIs, including JAXB 1.0, JAXB 2.0, Castor, XMLBeans, JiBX, and XStream.
10. For some marshalling APIs, the object model must be generated by them so that they can insert marshalling-specific information.
a) True
b) False
Answer
Answer: a [Reason:] Because Castor supports marshalling between XML messages and arbitrary Java objects, you can start creating the following classes by yourself.
11. A marshalling endpoint requires:-
a) marshaller
b) unmarshaller
c) all of the mentioned
d) none of the mentioned
Answer
Answer: c [Reason:] A marshalling endpoint requires both the marshaller and unmarshaller properties to be set. Usually, you can specify a single marshaller for both properties. For Castor, you declare a CastorMarshaller bean as the marshaller.
12. Castor requires a mapping configuration file to know how to map objects to and from XML documents.
a) True
b) False
Answer
Answer: a [Reason:] You can create this file in the classpath root and specify it in the mappingLocation property (e.g., mapping.xml).
13. Spring-WS supports annotating an arbitrary class as a service endpoint by :-
a) @Endpoint
b) @End
c) @Point
d) None of the mentioned
Answer
Answer: a [Reason:] Spring-WS supports annotating an arbitrary class as a service endpoint by the @Endpoint annotation, without extending a framework-specific class.
14. When you are using XML marshalling, WebServiceTemplate requires both the marshaller and unmarshaller properties to be set.
a) True
b) False
Answer
Answer: a [Reason:] You can also set them to WebServiceGatewaySupport if you extend this class to have WebServiceTemplate auto-created.
15. A Spring-WS client can also marshall and unmarshall the request and response objects to and from XML messages.
a) True
b) False
Answer
Answer: a [Reason:] As an example, we will create a client using Castor as the marshaller so that you can reuse the object models.
Java MCQ Set 5
1. When you call the receive() method on a JMS message consumer to receive a message.
a) send
b) receive
c) All of the mentioned
d) None of the mentioned
Answer
Answer: b [Reason:] When you call the receive() method on a JMS message consumer to receive a message, the calling thread is blocked until a message is available.
2. EJB component which was introduced for asynchronous reception of JMS messages.
a) message-driven bean
b) message-driven
c) message bean
d) none of the mentioned
Answer
Answer: a [Reason:] Starting with EJB 2.0, a new kind of EJB component called a message-driven bean (MDB) was introduced for asynchronous reception of JMS messages.
3. MDB must implements interfaces:-
a) javax.ejb.MessageDrivenBean
b) javax.jms.MessageListener
c) all of the mentioned
d) none of the mentioned
Answer
Answer: c [Reason:] An MDB must implement both the javax.ejb.MessageDrivenBean and javax.jms.MessageListener interfaces and override all EJB life cycle methods (ejbCreate and ejbRemove).
4. In EJB 3.0, an MDB can be a POJO that implements the MessageListener interface and is annotated with the:-
a) @MessageDrive
b) @Message
c) all of the mentioned
d) @MessageDriven
Answer
Answer: d [Reason:] In EJB 3.0, an MDB can be a POJO that implements the MessageListener interface and is annotated with the @MessageDriven annotation.
5. You create a message listener to listen for JMS messages. This negates the need for the approach taken in BackOfficeImpl in previous recipes.
a) True
b) False
Answer
Answer: a [Reason:] For example, the following MailListener listens for JMS messages that contain mail information:-
import javax.jms.JMSException; import javax.jms.MapMessage; import javax.jms.Message; import javax.jms.MessageListener; import org.springframework.jms.support.JmsUtils; public class MailListener implements MessageListener { public void onMessage(Message message) { MapMessage mapMessage = (MapMessage) message; try { Mail mail = new Mail(); mail.setMailId(mapMessage.getString("mailId")); mail.setCountry(mapMessage.getString("country")); mail.setWeight(mapMessage.getDouble("weight")); displayMail(mail); } catch (JMSException e) { throw JmsUtils.convertJmsAccessException(e); } } private void displayMail(Mail mail) { System.out.println("Mail #" + mail.getMailId() + " received"); } }
6. A message listener must implement the:-
a) javax.jms.MessageListener
b) javax.jms.Message
c) javax.jms
d) none of the mentioned
Answer
Answer: a [Reason:] A message listener must implement the javax.jms.MessageListener interface.
7. When a JMS message arrives, the onMessage() method will be called with the message as the method argument.
a) True
b) False
Answer
Answer: a [Reason:] In this sample, you simply display the mail information to the console.
import javax.jms.JMSException; import javax.jms.MapMessage; import javax.jms.Message; import javax.jms.MessageListener; import org.springframework.jms.support.JmsUtils; public class MailListener implements MessageListener { public void onMessage(Message message) { MapMessage mapMessage = (MapMessage) message; try { Mail mail = new Mail(); mail.setMailId(mapMessage.getString("mailId")); mail.setCountry(mapMessage.getString("country")); mail.setWeight(mapMessage.getDouble("weight")); displayMail(mail); } catch (JMSException e) { throw JmsUtils.convertJmsAccessException(e); } } private void displayMail(Mail mail) { System.out.println("Mail #" + mail.getMailId() + " received"); } }
8. Method to convert MapMessage Object into Spring’s runtime exception JmsException.
a) JmsUtils.convertJmsAccessException()
b) JmsUtils.convertJmsAccess()
c) JmsUtils.convertJms()
d) none of the mentioned
Answer
Answer: a [Reason:] When extracting message information from a MapMessage object, you need to handle the JMS API’s JMSException. You can make a call to JmsUtils.convertJmsAccessException() to convert it into Spring’s runtime exception JmsException.
9. Spring provides several types of message listener containers:-
a) SimpleMessageListenerContainer
b) DefaultMessageListenerContainer
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] Spring provides several types of message listener containers for you to choose from in the org.springframework.jms.listener package, of which SimpleMessageListenerContainer and DefaultMessageListenerContainer are the most commonly used.
10. If you have a transaction requirement in receiving messages, you have to use:-
a) SimpleMessageListenerContainer
b) DefaultMessageListenerContainer
c) All of the mentioned
d) None of the mentioned
Answer
Answer: b [Reason:] If you have a transaction requirement in receiving messages, you have to use DefaultMessageListenerContainer.
11. You have to set the delegate property of MessageListenerAdapter to your target bean.
a) True
b) False
Answer
Answer: a [Reason:] By default, this adapter will call the method whose name is handleMessage on that bean.
12. Using Spring’s JMS support with a very simple instance of:-
a) org.apache.activemq.ActiveMQConnectionFactory
b) org.apache.activemq.ActiveMQConnection
c) org.apache.activemq.ActiveMQ
d) none of the mentioned
Answer
Answer: a [Reason:] We’ve explored using Spring’s JMS support with a very simple instance of org.apache.activemq.ActiveMQConnectionFactory as our connection factory.
13. ActiveMQ, provides only one pooled connection factory class alternative.
a) True
b) False
Answer
Answer: b [Reason:] ActiveMQ provides two, actually: one for use consuming messages with a JCA connector and another one for use outside of a JCA container.
14. It caches consumers correctly, or use Spring’s ConnectionFactory implementations.
a) MessageListenerContainer
b) MessageListener
c) MessageContainer
d) None of the mentioned
Answer
Answer: a [Reason:] MessageListenerContainer implementations mechanism (MDPs), because it caches consumers correctly, or use Spring’s ConnectionFactory implementations.
15. Implementation which returns the same underlying JMS connection each time (which is thread-safe according to the JMS API) and ignores calls to the close() method.
a) org.springframework.jms.connection.SingleConnectionFactory
b) org.springframework.jms.connection.Single
c) org.springframework.jms.connection.SingleConnection
d) none of the mentioned
Answer
Answer: a [Reason:] org.springframework.jms.connection.SingleConnectionFactory, returns the same underlying JMS connection each time (which is thread-safe according to the JMS API) and ignores calls to the close() method.