Java MCQ Number 01102

Java MCQ Set 1

1. A transaction’s propagation behavior can be specified by the:-
a) propagation
b) consistency
c) isolation
d) All of the mentioned

Answer

Answer: a [Reason:] A transaction’s propagation behavior can be specified by the propagation transaction attribute.

2. Transaction’s propagation behavior are defined in the:-
a) org.springframework.transaction.Transaction
b) org.springframework.transaction.TransactionDefinition
c) all of the mentioned
d) none of the mentioned

Answer

Answer: b [Reason:] These behaviors are defined in the org.springframework.transaction.TransactionDefinition interface.

3. If there’s an existing transaction in progress, the current method should run within this transaction.
a) Required
b) REQUIRES NEW
c) SUPPORTS
d) NOT SUPPORTED

Answer

Answer: a [Reason:] If there’s an existing transaction in progress, the current method should run within this transaction. Otherwise, it should start a new transaction and run within its own transaction.

4. The current method must start a new transaction and run within its own transaction.
a) Required
b) REQUIRES NEW
c) SUPPORTS
d) NOT SUPPORTED

Answer

Answer: b [Reason:] The current method must start a new transaction and run within its own transaction. If there’s an existing transaction in progress, it should be suspended.

5. If there’s an existing transaction in progress, the current method can run within this transaction.
a) Required
b) REQUIRES NEW
c) SUPPORTS
d) NOT SUPPORTED

Answer

Answer: c [Reason:] Otherwise, it is not necessary to run within a transaction.

6. The current method should not run within a transaction.
a) Required
b) REQUIRES NEW
c) SUPPORTS
d) NOT SUPPORTED

Answer

Answer: d [Reason:] The current method should not run within a transaction. If there’s an existing transaction in progress, it should be suspended.

7. The current method must run within a transaction.
a) Required
b) MANDATORY
c) SUPPORTS
d) NOT SUPPORTED

Answer

Answer: b [Reason:] The current method must run within a transaction. If there’s no existing transaction in progress, an exception will be thrown.

8. The current method should not run within a transaction. If there’s an existing transaction in progress, an exception will be thrown.
a) Required
b) MANDATORY
c) SUPPORTS
d) NEVER

Answer

Answer: d [Reason:] The current method should not run within a transaction. If there’s an existing transaction in progress, an exception will be thrown.

9. If there’s an existing transaction in progress, the current method should run within the nested transaction.
a) Required
b) MANDATORY
c) NESTED
d) NEVER

Answer

Answer: c [Reason:] If there’s an existing transaction in progress, the current method should run within the nested transaction (supported by the JDBC 3.0 save point feature) of this transaction. Otherwise, it should start a new transaction and run within its own transaction.

10. For two transactions T1 and T2, T1 reads a field that has been updated by T2 but not yet committed.
a) Dirty Read
b) Nonrepeatable read
c) Phantom read
d) Lost Updates

Answer

Answer: a [Reason:] Later, if T2 rolls back, the field read by T1 will be temporary and invalid.

11. For two transactions T1 and T2, T1 reads a field and then T2 updates the field.
a) Dirty Read
b) Nonrepeatable read
c) Phantom read
d) Lost Updates

Answer

Answer: b [Reason:] Later, if T1 reads the same field again, the value will be different.

12. For two transactions T1 and T2, T1 reads some rows from a table and then T2 inserts new rows into the table.
a) Dirty Read
b) Nonrepeatable read
c) Phantom read
d) Lost Updates

Answer

Answer: c [Reason:] Later, if T1 reads the same table again, there will be additional rows.

13. For two transactions T1 and T2, they both select a row for update, and based on the state of that row, make an update to it.
a) Dirty Read
b) Nonrepeatable read
c) Phantom read
d) Lost Updates

Answer

Answer: d [Reason:] Thus, one overwrites the other when the second transaction to commit should have waited until the first one committed before performing its selection.

14. Isolation Levels Supported by Spring:-
a) DEFAULT
b) READ COMMITTED
c) READ UNCOMMITTED
d) All of the mentioned

Answer

Answer: d [Reason:] Isolation Description
DEFAULT Uses the default isolation level of the underlying database. For most databases,
the default isolation level is READ COMMITTED.
READ UNCOMMITTED Allows a transaction to read uncommitted changes by other transactions. The
dirty read, nonrepeatable read, and phantom read problems may occur.
READ COMMITTED Allows a transaction to read only those changes that have been committed by
other transactions. The dirty read problem can be avoided, but the nonrepeatable
read and phantom read problems may still occur.
REPEATABLE READ Ensures that a transaction can read identical values from a field multiple times.
For the duration of this transaction, updates made by other transactions to this
field are prohibited. The dirty read and nonrepeatable read problems can be
avoided, but the phantom read problem may still occur.
SERIALIZABLE Ensures that a transaction can read identical rows from a table multiple times. For
the duration of this transaction, inserts, updates, and deletes made by other
transactions to this table are prohibited. All the concurrency problems can be
avoided, but the performance will be low.

15. The exceptions that cause a transaction to roll back or not can be specified by attribute:-
a) rollback
b) commit
c) serialize
d) none of the mentioned

Answer

Answer: a [Reason:] Any exceptions not explicitly specified in this attribute will be handled by the default rollback rule (i.e., rolling back for unchecked exceptions and not rolling back for checked exceptions).

Java MCQ Set 2

1. A web service contract is described using :-
a) Web Services Description Language
b) Web Services Description
c) All of the mentioned
d) None of the mentioned

Answer

Answer: a [Reason:] In contract-last, you expose an existing service interface as a web service whose service contract is generated automatically.

2. There are two approaches to developing a web service, depending on whether you define the contract first or last.
a) True
b) False

Answer

Answer: a [Reason:] A web service contract is described using Web Services Description Language (WSDL). In contract-last, you expose an existing service interface as a web service whose service contract is generated automatically. In contract-first, you design the service contract in terms of XML and then write code to fulfill it.

3. In contrast, the contract-first approach encourages you to think of the service contract first in terms of :-
a) XML
b) XML Schema(.xsd)
c) WSDL
d) All of the mentioned

Answer

Answer: d [Reason:] In contrast, the contract-first approach encourages you to think of the service contract first, in terms of XML, using XML schema (.xsd) and WSDL.

4. In some cases, it’s also hard to map an object to XML (e.g., an object graph with cyclic references) because there’s actually an impedance mismatch between an object model and an XML model.
a) True
b) False

Answer

Answer: a [Reason:] Just like that between an object model and a relational model.

5. Service exporters that can export a bean as a remote service based on the :-
a) RMI
b) Hessian
c) Burlap
d) All of the mentioned

Answer

Answer: d [Reason:] Spring comes with several service exporters that can export a bean as a remote service based on the RMI, Hessian, Burlap, or HTTP Invoker remoting technologies.

6. Spring comes with a service exporter that can export a bean as a SOAP web service.
a) True
b) False

Answer

Answer: b [Reason:] Spring doesn’t come with a service exporter that can export a bean as a SOAP web service. We will use Apache CXF, which is the de facto successor to XFire.

7. The standard for deploying web services on the Java EE platform as of Java EE 1.4:-
a) JAX-RPC
b) JAX
c) RPC
d) None of the mentioned

Answer

Answer: a [Reason:] The standard for deploying web services on the Java EE platform as of Java EE 1.4 was called JAX-RPC. It supported SOAP 1.0 and 1.1, but didn’t support message-oriented web services.

8. To send objects across the wire, beans need to be encoded using the Java Architecture for XML Binding (JAXB).
a) True
b) False

Answer

Answer: a [Reason:] JAXB supports many class types out of the box with no special support.

9. If you are deploying into a Java EE 5 (or better) container, you may simply create a bean that is annotated with:-
a) javax.jws.WebService
b) javax.jws.WebServiceProvider
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] If you are deploying into a Java EE 5 (or better) container, you may simply create a bean that is annotated with javax.jws.WebService or javax.jws.WebServiceProvider and deploy that into a container in your web application.

10. If you are using the JAX-RS Reference Implementation, this intermediary step will involve a tool called wsgen.
a) True
b) False

Answer

Answer: a [Reason:] It will generate the configuration (a file called sun-jaxws.xml) and wrapper beans required to expose your service.

11. Spring provides a factory that can export beans annotated with:-
a) javax.jws.WebService
b) javax.jws.WebServiceProvider
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] Spring provides a factory that can export beans annotated with javax.jws.WebService or javax.jws.WebServiceProvider inside the Spring context and then publishes the services using the JAX-WS runtime.

12. Exposing a stand-alone SOAP endpoint using the:-
a) SimpleJaxWsServiceExporter
b) JAX-WS
c) All of the mentioned
d) None of the mentioned

Answer

Answer: c [Reason:] Exposing a stand-alone SOAP endpoint using the SimpleJaxWsServiceExporter or the support for JAX-WS in a Java EE container in conjunction with Spring is simple, but these solutions ignore the largest cross-section of developers—people developing on Tomcat.

13. Tomcat doesn’t support JAX-WS by itself.
a) True
b) False

Answer

Answer: a [Reason:] Tomcat doesn’t support JAX-WS by itself, so we need to help it by embedding a JAX-WS runtime. There are many choices, and you’re free to take your pick. Two popular choices are Axis2 and CXF, both of which are Apache projects.

14. CXF represents the consolidation of the Celtix and XFire projects, which each had useful SOAP support.
a) True
b) False

Answer

Answer: a [Reason:] For our example, we’ll embed CXF since it’s robust, fairly well tested, and provides support for other important standards like JAX-RS, the API for REST-ful endpoints.

15. Factory to use our Spring bean as the implementation:-
a) jaxws:end
b) jaxws:endpoint
c) all of the mentioned
d) none of the mentioned

Answer

Answer: b [Reason:] We tell the jaxws:endpoint factory to use our Spring bean as the implementation. We tell it at what address to publish the service using the address element.

Java MCQ Set 3

1. To fork the process flow from one component to many, either all at once or to a single one based on a predicate condition.
a) splitter
b) fork
c) all of the mentioned
d) none of the mentioned

Answer

Answer: a [Reason:] You can use a splitter component (and maybe its cohort, the aggregator component) to fork and join (respectively) control of processing.

2. A splitter takes an input message and asks you, the user of the component, on what basis it should split the Message.
a) True
b) False

Answer

Answer: a [Reason:] You’re responsible for providing the split functionality.

3. Spring Integration ships with useful splitters that require no customization.
a) Splitter
b) XPathMessageSplitter
c) All of the mentioned
d) None of the mentioned

Answer

Answer: b [Reason:] In a few cases, Spring Integration ships with useful splitters that require no customization. One example is the splitter provided to partition an XML payload along an XPath query, XPathMessageSplitter.

4. Return type of the method annotated by the @Splitter annotation is of type:-
a) java.util.Collection
b) java.util.Date
c) all of the mentioned
d) none of the mentioned

Answer

Answer: a [Reason:] The configuration for this is not terribly different from the previous solutions. The Java code is just about the same as well, except that the return type of the method annotated by the @Splitter annotation is of type java.util.Collection.

5. Annotation which collects a series of messages (based on some correlation that you help Spring Integration make between the messages).
a) @After
b) @Splitter
c) @Aggregator
d) None of the mentioned

Answer

Answer: c [Reason:] An @Aggregator collects a series of messages (based on some correlation that you help Spring Integration make between the messages) and publishes a single message to the components downstream.

6. To determine how many messages to read until it can stop:-
a) SequenceSizeCompletionStrategy
b) SequenceSizeCompletion
c) SequenceSize
d) None of the mentioned

Answer

Answer: a [Reason:] There are many ways for Spring Integration to correlate incoming messages. To determine how many messages to read until it can stop, it uses the class SequenceSizeCompletionStrategy, which reads a well known header value (aggregators are often used after a splitter.

7. For correlation when you might not have a size but know that you’re expecting messages that share a common header value within a known time, Spring Integration provides the HeaderAttributeCorrelationStrategy.
a) True
b) False

Answer

Answer: a [Reason:] In this way, it knows that all messages with that value are from the same group, in the same way that your last name identifies you as being part of a larger group.

8. The only custom logic is a POJO with an @Aggregator annotation on a method expecting a collection of Message objects.
a) True
b) False

Answer

Answer: a [Reason:] It could, of course, be a collection of Customer objects, because they are what you’re expecting as output from the previous splitter.

9. You want to conditionally move a message through different processes based on some criteria.
a) router component
b) EAI
c) all of the mentioned
d) none of the mentioned

Answer

Answer: a [Reason:] You can use a router component to alter the processing flow based on some predicate. You can also use a router to multicast a message to many subscribers (as you did with the splitter).

10. There are some convenient default routers available to fill common needs:-
a) PayloadTypeRouter
b) PayloadType
c) Payload
d) None of the mentioned

Answer

Answer: a [Reason:] There are some convenient default routers available to fill common needs, such as payload-type–based routing (PayloadTypeRouter) and routing to a group or list of channels (RecipientListRouter).

11. To receive messages from an external system and process them using Spring Integration.
a) channel
b) channel adapter
c) EJP
d) none of the mentioned

Answer

Answer: b [Reason:] Spring Integration makes it trivially easy to build one.

12. Adapters are opaque in nature.
a) True
b) False

Answer

Answer: a [Reason:] Your external system interfaces with the adapter.

13. Sometimes, functionality is made available from within the application via:-
a) Stable API
b) Cohesive API
c) All of the mentioned
d) None of the mentioned

Answer

Answer: c [Reason:] Sometimes, functionality is made available from within the application via a cohesive, stable API but in a component model or form that isn’t directly accessible to the bus.

14. You use Spring Integration’s inbound-channel-adapter element to wire the TwitterMessageSource and a poller element.
a) True
b) False

Answer

Answer: a [Reason:] The poller element is configured to run every 10 seconds and to consume as many as 100 messages each time it runs.

15. The API surfaces a Paging object, which works something like Criteria in Hibernate.
a) True
b) False

Answer

Answer: a [Reason:] You can configure how many results to return using the count property. The most interesting option is called the sinceId, which lets you search for all records occurring after the Status having the ID equal to the value given as the sinceId.

Java MCQ Set 4

1. 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

Answer

Answer: b [Reason:] 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.

2. Spring Integration does support reading files into the bus.
a) True
b) False

Answer

Answer: a [Reason:] Spring Batch does support providing custom, unique endpoints for data.

3. No processing system (such as an ESB) can deal with a million records at once efficiently.
a) True
b) False

Answer

Answer: a [Reason:] Strive to decompose bigger events and messages into smaller ones.

4. Spring Batch reads the file, transforms the records into:-
a) objects
b) outputs
c) all of the mentioned
d) none of the mentioned

Answer

Answer: a [Reason:] Spring Batch reads the file, transforms the records into objects, and writes the output to a JMS topic with a key correlating the original batch to the JMS message.

5. The BPM engine would thread together the different actors and work lists,
a) True
b) False

Answer

Answer: a [Reason:] The BPM engine would thread together the different actors and work lists, allow work to continue over the course of days instead of the small millisecond timeframes Spring Integration is more geared to.

6. You want to expose an interface to clients of your service, without betraying the fact that your service is implemented in terms of messaging middleware.
a) Enterprise Integration Patterns
b) Gateway
c) All of the mentioned
d) None of the mentioned

Answer

Answer: c [Reason:] Use a gateway—a pattern from the classic book Enterprise Integration Patterns by Gregor Hohpe and Bobby Woolf (Addison-Wesley, 2004) that enjoys rich support in Spring Integration.

7. Serving to abstract away the functionality of other components in an abbreviated interface to provide courser functionality.
a) facade
b) façade
c) gateway
d) none of the mentioned

Answer

Answer: b [Reason:] You might use a façade to build an interface oriented around vacation planning that in turn abstracts away the minutiae of using a car rental, hotel reservation, and airline reservation system.

8. The capability to hide messaging behind a POJO interface.
a) Lingo
b) JCA
c) JMS
d) All of the mentioned

Answer

Answer: d [Reason:] Lingo, a project from Codehaus.org that is no longer under active development, had such a feature that was specific to JMS and the Java EE Connector Architecture (JCA –it was originally used to talk about the Java Cryptography Architecture, but is more commonly used for The Java EE Connector Architecture now).

9. The most fundamental support for gateways comes from the Spring Integration class:-
a) SimpleMessagingGateway
b) SimpleMessaging
c) SimpleGateway
d) None of the mentioned

Answer

Answer: a [Reason:] The class provides the ability to specify a channel on which requests should be sent and a channel on which responses are expected.

10. The SimpleMessagingGateway needs a request and a response channel, and it coordinates the rest.
a) True
b) False

Answer

Answer: a [Reason:] You’re doing nothing but forwarding the request to a service-activator, which in turn adds the operands and sends them out on the reply channel.

11. The first thing that the client configuration does is import a shared application context (to save typing if nothing else) that declares a JMS connection factor.
a) True
b) False

Answer

Answer: a [Reason:] The first thing that the client configuration does is import a shared application context (to save typing if nothing else) that declares a JMS connection factory that you reference in the client and service application contexts.

12. Messages sent on the requests channel are forwarded to the:-
a) jms:outbound-gateway
b) jms:outbound
c) jms-gateway
d) all of the mentioned

Answer

Answer: a [Reason:] The jms:outbound-gateway is the component that does most of the work. It takes the message you created and sends it to the request JMS destination, setting up the reply headers and so on.

13. The gateway element simply exists to identify the component and the interface.
a) True
b) False

Answer

Answer: a [Reason:] The gateway element simply exists to identify the component and the interface, to which the proxy is cast and made available to clients.

14. There is no coupling between the client facing interface exposed via the gateway component and the interface of the service that ultimately handles the messages.
a) True
b) False

Answer

Answer: a [Reason:] We use the interface for the service and the client to simplify the names needed to understand everything that’s going on.

15. The service-activator is what handles actual processing and there’s no mention of a response channel, for either the service-activator, or for the inbound JMS gateway.
a) True
b) False

Answer

Answer: a [Reason:] The service-activator looks, and fails to find, a reply channel and so uses the reply channel created by the inbound JMS gateway component, which in turn has created the reply channel based on the header metadata in the inbound JMS message.

Java MCQ Set 5

1. DispatcherServtlet dispatches portlet requests to appropriate handlers that handle the requests.
a) True
b) False

Answer

Answer: b [Reason:] DispatcherPortlet. It dispatches portlet requests to appropriate handlers that handle the requests. It acts as the front controller of Spring Portlet MVC, and every portlet request must go through it so that it can manage the entire request-handling process.

2. Maps each request to a handler through one or more handler mapping beans.
a) DispatcherServlet
b) DispatcherPortlet
c) All of the mentioned
d) None of the mentioned

Answer

Answer: b [Reason:] Once it has picked an appropriate handler, it will invoke this handler to handle the request.

3. In portlets, there are URLs:-
a) render
b) action
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] In portlets, there are two types of URLs: render URLs and action URLs.

4. When a user triggers a render URL, the portlet container will ask all the portlets in the same page to handle a render request to render its view.
a) True
b) False

Answer

Answer: a [Reason:] When a user triggers a render URL, the portlet container will ask all the portlets in the same page to handle a render request to render its view, unless the view’s content has been cached.

5. When a user triggers an action URL in a portlet, the portlet container will first ask the target portlet to handle an action request.
a) True
b) False

Answer

Answer: a [Reason:] A controller should return an object in response to a render request. However, when a user triggers an action URL in a portlet, the portlet container will first ask the target portlet to handle an action request. A controller needn’t return anything for an action request.

6. After Controller has finished handling a render request, it returns:-
a) model name
b) view name
c) view obect
d) all of the mentioned

Answer

Answer: d [Reason:] After a controller has finished handling a render request, it returns a model and a view name, or sometimes a view object, to DispatcherPortlet.

7. DispatcherPortlet resolves a view name from one or more view resolver beans.
a) True
b) False

Answer

Answer: a [Reason:] DispatcherPortlet renders the view and passes in the model returned by the controller. Note that an action request doesn’t need to render a view.

8. portlet deployment descriptor file is:-
a) portlet.xml
b) portlet.config
c) portlet.xhtml
d) none of the mentioned

Answer

Answer: a [Reason:] The Java Portlet specification defines the valid structure of a portlet application, which is very similar to that of a web application, but with the addition of a portlet deployment descriptor (i.e., portlet.xml).

9. Servlet Listener to load the root application context at startup.
a) ContextLoader
b) ContextLoaderListener
c) All of the mentioned
d) None of the mentioned

Answer

Answer: b [Reason:] In the web deployment descriptor (i.e., web.xml), you have to register the servlet listener ContextLoaderListener to load the root application context at startup.

10. Unlike in a web application, you can’t control URLs directly in a portlet.
a) True
b) False

Answer

Answer: a [Reason:] In the web deployment descriptor (i.e., web.xml), you have to register the servlet listener ContextLoaderListener to load the root application context at startup.

11. You can chain multiple handler mapping annotations as required to portlet.
a) True
b) False

Answer

Answer: a [Reason:] Spring Portlet MVC comes with several strategies for you to map portlet requests.

12. The preceding controller handles portlet requests:-
a) render requests
b) action requests
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] The preceding controller handles two types of portlet requests: render requests and action requests.

13. When handling a render request, it gets the time zone attribute from the portlet preference.
a) True
b) False

Answer

Answer: a [Reason:] When handling a render request, it gets the time zone attribute from the portlet preferences and passes it to the view for editing.

14. When handling an action request, it gets the time zone parameter from the portlet request.
a) True
b) False

Answer

Answer: a [Reason:] When handling an action request, it gets the time zone parameter from the portlet request and stores it in the portlet preferences as an attribute, which will override the existing one.

15. The submission URL of this form should be a portlet action URL that will trigger an action request to the current portlet.
a) True
b) False

Answer

Answer: a [Reason:] In portlets, you have to construct an action URL with the portlet:actionURL tag defined in the portlet tag library.

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.