Java MCQ Number 01085

Java MCQ Set 1

1. Spring’s HibernateTemplate can simplify your DAO implementation by managing sessions and transactions for you.
a) True
b) False

Answer

Answer: a [Reason:] However, using HibernateTemplate means your DAO has to depend on Spring’s API.

2. An alternative to Spring’s HibernateTemplate is:-
a) HibernateContext
b) Hibernate’s contextual sessions
c) All of the mentioned
d) None of the mentioned

Answer

Answer: b [Reason:] An alternative to Spring’s HibernateTemplate is to use Hibernate’s contextual sessions.

3. Session factory can manage contextual sessions for you and allows you to retrieve them by the:-
a) getSession() method
b) getCurrent() method
c) getCurrentSession() method
d) none of the mentioned

Answer

Answer: c [Reason:] In Hibernate 3, a session factory can manage contextual sessions for you and allows you to retrieve them by the getCurrentSession() method on org.hibernate.SessionFactory.

4. DAO methods require access to the session factory, which can be injected:-
a) a setter method
b) constructor argument
c) none of the mentioned
d) all of the mentioned

Answer

Answer: d [Reason:] To use the contextual session approach, your DAO methods require access to the session factory, which can be injected via a setter method or a constructor argument.

5. DAO methods must be made transactional.
a) True
b) False

Answer

Answer: a [Reason:] This is required because Spring wraps the SessionFactory with a proxy that expects that Spring’s transaction management is in play when methods on a session are made.

6. Annotation to find a transaction and then fail, complaining that no Hibernate session’s been bound to the thread.
a) @Transaction
b) @Transactional
c) @Transactions
d) None of the mentioned

Answer

Answer: b [Reason:] This ensures that the persistence operations within a DAO method will be executed in the same transaction and hence by the same session.

7. In the bean configuration file for Hibernate (i.e., beans-hibernate.xml), you have to declare a HibernateTransactionManager instance for this application and enable declarative transaction via:-
a) tx:annotation
b) tx:annotationdriven
c) tx:annotation-driven
d) none of the mentioned

Answer

Answer: c [Reason:] In the bean configuration file for Hibernate (i.e., beans-hibernate.xml), you have to declare a HibernateTransactionManager instance for this application and enable declarative transaction management via tx:annotation-driven.

8. HibernateTemplate will translate the native Hibernate exceptions into exceptions in Spring’s DataAccessException hierarchy.
a) True
b) False

Answer

Answer: a [Reason:] This allows consistent exception handling for different data access strategies in Spring.

9. Annotation for Hibernate exceptions to be translated into Spring’s DataAccessException for consistent exception handling:-
a) @Translation
b) @Repo
c) @Repository
d) None of the mentioned

Answer

Answer: c [Reason:] If you want the Hibernate exceptions to be translated into Spring’s DataAccessException for consistent exception handling, you have to apply the @Repository annotation to your DAO class that requires exception translation.

10. Instance to translate the native Hibernate exceptions into data access exceptions in Spring’s DataAccessException hierarchy.
a) PersistenceExceptionPostProcessor
b) PersistenceExceptionTranslation
c) PersistenceException
d) PersistenceExceptionTranslationPostProcessor

Answer

Answer: d [Reason:] This bean post processor will only translate exceptions for beans annotated with @Repository.

11. You can assign a component name in this annotation and have the session factory auto-wired by the Spring IoC container with @Autowired.
a) True
b) False

Answer

Answer: a [Reason:] In Spring, @Repository is a stereotype annotation. By annotating it, a component class can be auto-detected through component scanning.

12. Spring provides to simplify your DAO implementation by managing entity managers and transactions for you:-
a) HibernateTemplate
b) JpaTemplate
c) SpringTemplate
d) None of the mentioned

Answer

Answer: b [Reason:] Using Spring’s JpaTemplate means your DAO is dependent on Spring’s API.

13. Annotation used for entity manager injection in EJB components.
a) @PersistenceContext
b) @Persistence
c) @PersistenceCon
d) None of the mentioned

Answer

Answer: a [Reason:] Spring can also interpret this annotation by means of a bean post processor.

14. To use the context injection approach, you can declare an entity manager field in your DAO and annotate it with the @PersistenceContext annotation.
a) True
b) False

Answer

Answer: a [Reason:] Spring will inject an entity manager into this field for you to persist your objects.

15. JpaTemplate will translate the native JPA exceptions into exceptions in Spring’s DataAccessException hierarchy.
a) True
b) False

Answer

Answer: a [Reason:] If you want JPA exceptions to be translated into Spring’s DataAccessException, you have to apply the @Repository annotation to your DAO class.

Java MCQ Set 2

1. The concept of an endpoint in web services is much like that of a controller in web applications.
a) True
b) False

Answer

Answer: a [Reason:] The difference is that a web controller deals with HTTP requests and HTTP responses, while a service endpoint deals with XML request messages and XML response messages.

2. Spring-WS provides various abstract endpoint classes for you to process the request.
a) org.springframework.ws.server.endpoint
b) org.springframework.ws.server
c) org.springframework.*
d) none of the mentioned

Answer

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

3. Endpoint Classes for DOM:-
a) AbstractDomPayloadEndpoint
b) AbstractJDomPayloadEndpoint
c) AbstractDom4jPayloadEndpoint
d) AbstractXomPayloadEndpoint

Answer

Answer: a [Reason:] Endpoint Classes for Different XML Processing Technologies/APIs
Technology/API Endpoint Class
DOM AbstractDomPayloadEndpoint

4. Endpoint Classes for JDOM:-
a) AbstractDomPayloadEndpoint
b) AbstractJDomPayloadEndpoint
c) AbstractDom4jPayloadEndpoint
d) AbstractXomPayloadEndpoint

Answer

Answer: b [Reason:] Endpoint Classes for Different XML Processing Technologies/APIs
Technology/API Endpoint Class
JDOM AbstractJDomPayloadEndpoint

5. Endpoint Classes for dom4j:-
a) AbstractDomPayloadEndpoint
b) AbstractJDomPayloadEndpoint
c) AbstractDom4jPayloadEndpoint
d) AbstractXomPayloadEndpoint

Answer

Answer: c [Reason:] Endpoint Classes for Different XML Processing Technologies/APIs
Technology/API Endpoint Class
dom4j AbstractDom4jPayloadEndpoint

6. Endpoint Classes for XOM:-
a) AbstractDomPayloadEndpoint
b) AbstractJDomPayloadEndpoint
c) AbstractDom4jPayloadEndpoint
d) AbstractXomPayloadEndpoint

Answer

Answer: d [Reason:] Endpoint Classes for Different XML Processing Technologies/APIs
Technology/API Endpoint Class
XOM AbstractXomPayloadEndpoint

7. Endpoint Classes for SAX:-
a) AbstractDomPayloadEndpoint
b) AbstractSaxPayloadEndpoint
c) AbstractDom4jPayloadEndpoint
d) AbstractXomPayloadEndpoint

Answer

Answer: b [Reason:] Endpoint Classes for Different XML Processing Technologies/APIs
Technology/API Endpoint Class
SAX AbstractSaxPayloadEndpoint

8. Endpoint Classes for Event-based StAX:-
a) AbstractDomPayloadEndpoint
b) AbstractSaxPayloadEndpoint
c) AbstractDom4jPayloadEndpoint
d) AbstractStaxEventPayloadEndpoint

Answer

Answer: d [Reason:] Endpoint Classes for Different XML Processing Technologies/APIs
Technology/API Endpoint Class
Event-based Stax AbstractStaxEventPayloadEndpoint

9. Endpoint Classes for Streaming StAX :-
a) AbstractDomPayloadEndpoint
b) AbstractSaxPayloadEndpoint
c) AbstractStaxStreamPayloadEndpoint
d) AbstractStaxEventPayloadEndpoint

Answer

Answer: c [Reason:] Endpoint Classes for Different XML Processing Technologies/APIs
Technology/API Endpoint Class
Streaming Stax AbstractStaxStreamPayloadEndpoint

10. Endpoint Classes for XML marshalling :-
a) AbstractDomPayloadEndpoint
b) AbstractSaxPayloadEndpoint
c) AbstractStaxStreamPayloadEndpoint
d) AbstractMarshallingPayloadEndpoint

Answer

Answer: d [Reason:] Endpoint Classes for Different XML Processing Technologies/APIs
Technology/API Endpoint Class
XML marshalling AbstractMarshallingPayloadEndpoint

11. If you need to get access to the entire SOAP message, you should write an endpoint class by implementing:-
a) org.springframework.ws.server.endpoint.MessageEndpoint
b) org.springframework.ws
c) org.springframework.ws.server.endpoint
d) all of the mentioned

Answer

Answer: a [Reason:] If you need to get access to the entire SOAP message, you should write an endpoint class by implementing the org.springframework.ws.server.endpoint.MessageEndpoint org.springframework.ws.server.endpoint.MessageEndpoint interface.

12. You can create a dom4j endpoint by extending the:-
a) AbstractDom4jPayloadEndpoint
b) AbstractDom4jPayload
c) AbstractDom4jEndpoint
d) None of the mentioned

Answer

Answer: a [Reason:] You can create a dom4j endpoint by extending the AbstractDom4jPayloadEndpoint class.

13. In this method, you can access the request XML element, whose type is org.dom4j.Element, and the response document, whose type is org.dom4j.Document, as method arguments.
a) invoke
b) invokeInterval
c) invokeInternal
d) none of the mentioned

Answer

Answer: c [Reason:] The core method defined in this class that you must override is invokeInternal().

14. Web services can be invoked through the core template class:-
a) org.springframework.ws.client.core.WebServiceTemplate
b) JDBC Template
c) All of the mentioned
d) None of the mentioned

Answer

Answer: a [Reason:] When using Spring-WS on the client side, web services can be invoked through the core template class org.springframework.ws.client.core.WebServiceTemplate.

15. WebServiceTemplate provides a sendSourceAndReceiveToResult() method that accepts arguments:-
a) java.xml.transform.Source
b) java.xml.transform.Result
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] In the getTemperatures() method, you first build the request message using the dom4j API. WebServiceTemplate provides a sendSourceAndReceiveToResult() method that accepts a java.xml.transform.Source and a java.xml.transform.Result object as arguments.

Java MCQ Set 3

1. A workflow system extricates that process state from the domain and into a separate layer, called a business process.
a) True
b) False

Answer

Answer: a [Reason:] A workflow system also typically models which agents in the system do what work, providing work lists for different agents in the system.

2. A workflow engine lets you model the process in a higher-level form:-
a) XML
b) Use Case
c) UML
d) All of the mentioned

Answer

Answer: c [Reason:] A workflow engine lets you model the process in a higher-level form, roughly corresponding in code to what a UML activity diagram can describe.

3. A language that, when deployed to a BPEL container, describes the execution of a process.
a) WS-BPEL (BPEL 2.0)
b) WS-BPEL (BPEL)
c) WS-BPEL for People (BPEL4People)
d) Business Process Modeling Notation (BPMN)

Answer

Answer: b [Reason:] It interfaces with the outside world via the invocation of external web services. This language describes the runtime behavior of a process.

4. The main feature common to traditional workflow systems is the ability to support work lists for actors in a process.
a) WS-BPEL (BPEL 2.0)
b) WS-BPEL (BPEL)
c) WS-BPEL for People (BPEL4People)
d) Business Process Modeling Notation (BPMN)

Answer

Answer: a [Reason:] BPEL had no such support, as it didn’t support human tasks (that is, wait states for people). This specification addresses that exact shortcoming.

5. This provides a set of diagramming notations that describe a business process. This notation is akin to UML’s activity diagram.
a) WS-BPEL (BPEL 2.0)
b) WS-BPEL (BPEL)
c) WS-BPEL for People (BPEL4People)
d) Business Process Modeling Notation (BPMN)

Answer

Answer: d [Reason:] The notation is sometimes ambiguous, however, and one of the formidable challenges facing BPM vendors is creating a drawing tool that can take a round-trip to BPEL and back, providing seamless authoring.

6. A way of letting your process rest in a known condition indefinitely.
a) State
b) Activity
c) Sequence
d) Subprocess

Answer

Answer: a [Reason:] “State” can mean many things, but simply, it’s a pause or window in the action.

7. A pause in the action that can only move forward when a known actor or agent in the system moves it forward.
a) State
b) Activity
c) Sequence
d) Subprocess

Answer

Answer: b [Reason:] An activity is a pause in the action that can only move forward when a known actor or agent in the system moves it forward.

8. An aggregation of states, activities, and other types of constructs that serializes them.
a) State
b) Activity
c) Sequence
d) Subprocess

Answer

Answer: c [Reason:] A sequence is simply an aggregation of states, activities, and other types of constructs that serializes them.

9. A concurrent execution of multiple threads of execution at the same time, originating from a common thread.
a) State
b) Activity
c) Sequence
d) Fork or concurrence or split

Answer

Answer: d [Reason:] Some parts of a business process are inherently sequential, and some are readily concurrent.

10. Each department may have its own task list to complete in order to achieve the goals of the overarching process.
a) State
b) Activity
c) Subprocess
d) Fork or concurrence or split

Answer

Answer: c [Reason:] These subtasks (basically a separate process unto their own) may be modeled as a subprocess.

11. A decision describes a node that is conditional, based on some logic that you inject.
a) True
b) False

Answer

Answer: a [Reason:] You might use this to vary the execution based on some fact that you provide the process as a parameter.

12. To use PostgreSQL, you need to add a the driver library to the classpath.
a) True
b) False

Answer

Answer: a [Reason:] You might use this to vary the execution based on some fact that you provide the process as a parameter.

13. To use PostgreSQL, you need to add a the driver library to the classpath.
a) True
b) False

Answer

Answer: a [Reason:] If you are using Maven, add the following dependency to your project.

<dependency>
   <groupId>postgresql</groupId>
   <artifactId>postgresql</artifactId>
   <version>8.3-603.jdbc3</version>
</dependency>

14.

<dependency>
        <groupId>org.jbpm.jbpm4</groupId>
        <artifactId>jbpm-jpdl</artifactId>
        <version>4.3</version>
</dependency>

Dependency for JBPM 4.
a) True
b) False

Answer

Answer: a [Reason:] If you’re looking to find out more, read the documentation, and get the downloadable binaries for exploration, check out http://jboss.org/jbossjbpm/.

15. JBPM supports databases such as:-
a) Oracle
b) SQL Server
c) MySql
d) All of the mentioned

Answer

Answer: d [Reason:] It’s hard to find an exhaustive or conclusive list of supported databases for jBPM, but because it’s built on Hibernate, you can expect it’s going to work on the big-name databases: Oracle, SQL Server, MySQL, PostgreSQL, and so forth.

Java MCQ Set 4

1. You want to share object state across multiple virtual machines.
a) Terracotta
b) Hibernate Transaction
c) All of the mentioned
d) None of the mentioned

Answer

Answer: a [Reason:] You can use Terracotta to build such a solution. Terracotta (http://www.terracotta.org) is a free open source clustering solution.

2. The company, Terracotta, has also recently become the corporate sponsor of:-
a) Ehcache
b) Quartz
c) All of the mentioned
d) None of the mentioned

Answer

Answer: c [Reason:] The company, Terracotta, has also recently become the corporate sponsor of the Ehcache and Quartz projects.

3. Terracotta works like many other clustered caches, except that, in addition to being a good Hibernate clustered cache.
a) True
b) False

Answer

Answer: a [Reason:] It also works as a mostly unnoticeable engine to enable API-free shared state across a cluster.

4. Terracotta doesn’t use serialization of objects.
a) True
b) False

Answer

Answer: a [Reason:] Terracotta doesn’t use serialization of objects (not even highly compact serialization like Swift, Google’s Protocol Buffers, Coherence Pofs, or Hazelcast DataSerializables), and instead ferries around deltas of VM memory across the cluster.

5. Terracotta works as a JVM agent that monitors the object graph of a given JVM instance.
a) True
b) False

Answer

Answer: a [Reason:] It ensures replication of object state across a cluster.

6. Terracotta is different than most clustered caches today because it has no visible API
a) True
b) False

Answer

Answer: a [Reason:] Terracotta is different than most clustered caches today because it has no visible API, and because it’s far more efficient in conveying the changed state to nodes across the cluster.

7. Terracotta has a client/server architecture.
a) True
b) False

Answer

Answer: a [Reason:] The server, in this case, is the one that contains the original working memory.

8. To deploy a Terracotta application, you first download the distribution. The distribution provides :-
a) utility scripts
b) JAR files
c) All of the mentioned
d) None of the mentioned

Answer

Answer: c [Reason:] The distribution provides utility scripts, as well as JARs. You may download Terracotta from http://www.terracotta.org.

9. On Unix-like operating systems, you start Terracotta as :-
a) $TERRACOTTA HOME/bin/start-tc-server.sh –f $PATH TO TERRACOTTA CONFIGURATION
b) $TERRACOTTA HOME/bin/start-tc-server.sh –f $PATH TO TERRACOTTA
c) $TERRACOTTA HOME/bin/start-tc-server.sh –f $PATH TO TERRACOTTA bin
d) None of the mentioned

Answer

Answer: a [Reason:] On Unix-like operating systems, you start Terracotta as follows:
$TERRACOTTA HOME/bin/start-tc-server.sh –f $PATH TO TERRACOTTA CONFIGURATION

10. For each virtual machine client that you want to “see” and share that state, start it with a customized bootclasspath parameter when starting Java.
a) True
b) False

Answer

Answer: a [Reason:] The arguments for this vary per operating system, so Terracotta provides a handy script for determining the correct arguments, dso-env.sh.

11. To use the script on Unix-like operating systems:
a) $TERRACOTTA HOME/bin/dso-env.sh $HOST:3312
b) $TERRACOTTA HOME/bin/dso-env.sh $HOST:$PORT
c) All of the mentioned
d) None of the mentioned

Answer

Answer: b [Reason:] To use the script on Unix-like operating systems:
$TERRACOTTA HOME/bin/dso-env.sh $HOST:$PORT

12. To distribute processing over many nodes, perhaps to increase result speed through the use of concurrences, perhaps merely to provide load balance and fault tolerance.
a) Grid
b) GridGain
c) All of the mentioned
d) None of the mentioned

Answer

Answer: b [Reason:] You can use something like GridGain, which was designed to transparently offload processing to a grid.

13. GridGain is an implementation of a processing grid.
a) True
b) False

Answer

Answer: a [Reason:] GridGain differs from data grids like Terracotta or Coherence, although data grids and processing grids are often used together.

14. There are many data grids, such as :-
a) Coherence
b) Terracotta
c) Hadoop’s HFS
d) All of the mentioned

Answer

Answer: d [Reason:] These are designed to be fault-tolerant, memory-based RAM disks, essentially.

15. Map/reduce is a pattern that was popularized by Google, and it comes from functional programming languages, which often have:-
a) map
b) reduce
c) none of the mentioned
d) all of the mentioned

Answer

Answer: d [Reason:] The idea is that you somehow partition a job and send those pieces to be processed. Finally, you take the results and join them, and those results are then sent back. Often, you won’t have results per se; instead, you’ll have sought only to distribute the processing asynchronously.

Java MCQ Set 5

1. Transaction capabilities are built on top of the first class support already provided by the core Spring framework.
a) True
b) False

Answer

Answer: a [Reason:] Where relevant, Spring Batch surfaces the configuration so that you can control it.

2. Spring’s core framework provides first-class support for transactions.
a) Transaction
b) TransactionManager
c) All of the mentioned
d) None of the mentioned

Answer

Answer: b [Reason:] You simply wire up a TransactionManager and give Spring Batch a reference, just as you would in any regular JdbcTemplate or HibernateTemplate solution.

3. The batch.xml file establishes a:-
a) BasicDataSource
b) DataSourceTransactionManager
c) All of the mentioned
d) None of the mentioned

Answer

Answer: c [Reason:] The TransactionManager and BasicDataSource were then wired to the JobRepository, which was in turn wired to the JobLauncher, which you used to launch all jobs thus far.

4. Spring Batch will, by default, try to pluck the:-
a) PlatformTransactionManager
b) transactionManager
c) All of the mentioned
d) None of the mentioned

Answer

Answer: c [Reason:] The transaction manager reference can be specified, but in your solutions, it wasn’t required because Spring Batch will, by default, try to pluck the PlatformTransactionManager named transactionManager from the context and use it.

5. Spring Batch excels in the robustness it surfaces as simple configuration options for the edge and failure cases.
a) True
b) False

Answer

Answer: a [Reason:] If a write fails on an ItemWriter, or some other exception occurs in processing, Spring Batch will rollback the transaction.

6. Element to configure this for the step:-
a) no-rollback-exception-classes
b) no-rollback-exception
c) no-rollback
d) none of the mentioned

Answer

Answer: a [Reason:] You can use the no-rollback-exception-classes element to configure this for the step. The value is a list of Exception classes that should not cause the transaction to roll back.

7.

<step id = "step2">
   <tasklet>
           <chunk reader="reader" writer="writer" commit-interval="10" />
           <no-rollback-exception-classes>
           <include class="com.yourdomain.exceptions.YourBusinessException"/>
           </no-rollback-exception-classes>
   </tasklet>
</step>

no-rollback-exception-classes element Exception classes that should not cause the transaction to roll back.
a) True
b) False

Answer

Answer: a [Reason:] You can use the no-rollback-exception-classes element to configure this for the step. The value is a list of Exception classes that should not cause the transaction to roll back.

8. You want to work with a resource that may fail when you try to read from or write to it.
a) TransactionManager
b) Transaction
c) Spring batch’s retry
d) All of the mentioned

Answer

Answer: c [Reason:] Use Spring Batch’s retry capabilities to systematically retry the read or write.

9. Some invocations will fail but may be retried with some likelihood of success in a transactional scenario.
a) True
b) False

Answer

Answer: b [Reason:] For example, an update to the database resulting in org.springframework.dao.DeadlockLoserDataAccessException might be usefully retried.

10.

<step id = "step23">
       <tasklet transaction-manager="transactionManager">
            <chunk reader="csvFileReader" writer="jdbcItemWriter" commit-interval="10" retry-limit="3" cache-capacity="10">
           <retryable-exception-classes>
           <include class="org.springframework.dao.DeadlockLoserDataAccessException"/>
           </retryable-exception-classes> 
           </chunk>
       </tasklet>
</step>

You can specify exception classes on which to retry the operation.
a) True
b) False

Answer

Answer: a [Reason:] As with the rollback exceptions, you can delimit this list of exceptions with newlines or commas.

11. You can leverage Spring Batch’s support for retries and recovery in your own code.
a) True
b) False

Answer

Answer: a [Reason:] For example, you can have a custom ItemWriter in which retry functionality is desired or even an entire service interface for which retry support is desired.

12. Template that (much like its various other Template cousins) isolates your logic from the nuances of retries and instead enables you to write the code as though you were only going to attempt it once.
a) Retry
b) RetryTemplate
c) All of the mentioned
d) None of the mentioned

Answer

Answer: b [Reason:] Spring Batch supports these scenarios through the RetryTemplate that (much like its various other Template cousins) isolates your logic from the nuances of retries and instead enables you to write the code as though you were only going to attempt it once.

13. The RetryTemplate supports many use cases, with convenient APIs to wrap.
a) True
b) false

Answer

Answer: a [Reason:] Otherwise tedious retry/fail/recover cycles in concise, single-method invocations.

14. The RetryTemplate itself is configured in the Spring context, although it’s trivial to create in code.
a) True
b) False

Answer

Answer: a [Reason:] I declare it in the Spring context only because there is some surface area for configuration when creating the object, and I try to let Spring handle the configuration.

15. One of the more useful settings for the RetryTemplate is the :-
a) BackOff
b) Back
c) BackOffPolicy
d) All of the mentioned

Answer

Answer: c [Reason:] BackOffPolicy dictates how long the RetryTemplate should back off between retries.

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.