Java MCQ Number 01103

Java MCQ Set 1

1. The main mission of Spring Roo is fundamentally and sustainably improve Java developer productivity without compromising engineering integrity or flexibility.
a) True
b) False

Answer

Answer: a [Reason:] This has a lot of implications. Applications built in Roo are Java applications that benefit from the mature Java language and platform.

2. Library which helps Spring Roo in using of the command line shell.
a) JTag
b) JLine
c) JHib
d) None of the mentioned

Answer

Answer: b [Reason:] The shell is quite smart, featuring tab completion, line history, and much more. These features are surfaced pretty consistently on all platforms, thanks to the excellent JLine library (http://jline.sourceforge.net). JLine handles some features inconsistently, however, on Windows—nothing fundamentally irresolvable, mind you, just nuisances like shell color differences and line history glitches. Proceed full speed ahead, but if you’re not using a Unix-like operating system, be aware of the (ever diminishing) possibility of issues.

3. To check version of Maven.
a) mvn –v
b) mvn -v
c) mvn –version
d) all of the mentioned

Answer

Answer: c [Reason:] Start a new shell session and confirm that you can issue the following command without error, in any directory on your system: mvn –version.

4. To confirm Roo version.
a) roo.sh
b) roo
c) roo quit
d) roo.sh quit

Answer

Answer: d [Reason:] Confirm that you saw output. On my system, the output looked like this:
$ roo.sh quit
____ ____ ____
/ __ / __ / __
/ /_/ / / / / / / /
/ _, _/ /_/ / /_/ /
/_/ |_|____/____/
1.0.2.RELEASE [rev 638]
Welcome to Spring Roo. For assistance press TAB or type “hint” then hit ENTER.

5. The Spring Roo shell is a blank slate. It represents the ultimate user interface for Spring Roo to facilitate development.
a) True
b) False

Answer

Answer: a [Reason:] A custom command line shell to facilitate the developer. This shell can be intimidating to the uninitiated.

6. Spring Roo supports tab completion.
a) True
b) False

Answer

Answer: a [Reason:] It supports tab completion, which will enable you to tab your way to a completely specified command.

7. You can ask Roo questions using:-
a) tab
b) hint
c) all of the mentioned
d) none of the mentioned

Answer

Answer: b [Reason:] You can ask it questions using the hint command, and it does its best to direct you in response.

8. Spring Roo file extension is:-
a) .xml
b) .xhtml
c) .roo
d) .groovy

Answer

Answer: c [Reason:] The Spring Roo shell is pretty darned handy, and even fun, but on the surface, it would appear to lack the reusability we developers have come to expect from our tools.

9. To run the script:-
a) roo.sh script –file ~/Desktop/myapp.roo
b) roo.sh –file ~/Desktop/myapp.roo
c) all of the mentioned
d) none of the mentioned

Answer

Answer: a [Reason:] To run the script, simply invoke the Roo shell as follows (changing the path of the file as appropriate):
roo.sh script –file ~/Desktop/myapp.roo.

10. Maven Directory to hold the non–unit-test Java files for your application.
a) src/main/java
b) src/main/resources
c) src/main/webapp
d) src/test/java

Answer

Answer: a [Reason:] A directory to hold the non–unit-test Java files for your application.

11. Maven Directory which holds classpath resources that aren’t Java class files.
a) src/main/java
b) src/main/resources
c) src/main/webapp
d) src/test/java

Answer

Answer: b [Reason:] Note, this is for classpath resources and is not appropriate, for example, for web application resources. For that you need src/main/webapp.

12. Maven Directory whic is used to hold the rest of a web application’s structure.
a) src/main/java
b) src/main/resources
c) src/main/webapp
d) src/test/java

Answer

Answer: c [Reason:] If you were going to develop a web application, put everything except what you would put in WEB-INF/classes in this folder.

13. This directory holds artifacts intended to test the Java classes under the src/main/java folder.
a) src/test/java
b) src/main/resources
c) src/main/webapp
d) src/test/java

Answer

Answer: a [Reason:] Typically, the package structures mirrors the package structure in src/main/java, allowing your tests to have package-friendly visibility to the classes under test.

14. This directory holds resources needed by your test classes at test time.
a) src/test/java
b) src/test/resources
c) src/main/webapp
d) src/test/java

Answer

Answer: b [Reason:] This directory holds resources needed by your test classes at test time, in the same way that src/main/resources works.

15. To package the project using the Roo shell.
a) perform package
b) roo.sh
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] pring Roo also lets you perform certain operations using Maven from within the Roo shell. To package the project using the Roo shell, launch it again (using roo.sh), and invoke the following command:
$ roo perform package

Java MCQ Set 2

1. The plug-in, which provides Maven support to Eclipse
a) m2eclipse
b) m2plugin
c) plugin
d) none of the mentioned

Answer

Answer: a [Reason:] The m2eclipse plug-in, which provides Maven support to Eclipse (and thus to SpringSource Tool Suite), can do all the heavy lifting of importing your project, since it is just a stock-standard Maven project.

2. Spring Roo provides very powerful support to bootstrap most solutions.
a) True
b) False

Answer

Answer: a [Reason:] It’s entirely possible there’s a plug-in that will do the job for you.

3. A database and some sort of persistence mechanism using command:-
a) persistence setup –database HYPERSONIC_IN_MEMORY –provider HIBERNATE
b) persistence setup –database HYPERSONIC_IN_MEMORY –provider
c) persistence setup –database HYPERSONIC_IN_MEMORY
d) persistence –database HYPERSONIC_IN_MEMORY –provider HIBERNATE

Answer

Answer: a [Reason:] Enter persistence setup as it suggests. On my console, I ended up entering the following command:
roo> persistence setup –database HYPERSONIC_IN_MEMORY –provider HIBERNATE

4. persistence setup –database HYPERSONIC_IN_MEMORY –provider HIBERNATE command creates files:-
a) src/main/resources/META-INF/persistence.xml
b) src/main/resources/META-INF/spring/database.properties
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] In my project, the command created two new files (src/main/resources/META-INF/persistence.xml and src/main/resources/META-INF/spring/database.properties), and it updated two files (src/main/resources/META-INF/spring/applicationContext.xml and pom.xml).

5. The file which contains useful configuration for Hypersonic in-memory database.
a) src/main/resources/META-INF/spring/database.properties
b) src/main/resources/META-INF/persistence.xml
c) src/main/resources/META-INF/pom.xml
d) none of the mentioned

Answer

Answer: a [Reason:] The file src/main/resources/META-INF/spring/database.properties contains useful configuration to facilitate connection to the Hypersonic in-memory database.

6. The file which is the standard JPA configuration file to enable the Hibernate-based JPA implementation.
a) src/main/resources/META-INF/spring/database.properties
b) src/main/resources/META-INF/persistence.xml
c) src/main/resources/META-INF/pom.xml
d) none of the mentioned

Answer

Answer: b [Reason:] The file src/main/resources/META-INF/persistence.xml is the standard JPA configuration file to enable the Hibernate-based JPA implementation to do its work.

7. Spring application context, src/main/resources/META-INF/spring/applicationContext.xml consists of:-
a) Data Source
b) JPA Transaction Manager
c) JPA entity manager factory
d) All of the mentioned

Answer

Answer: d [Reason:] Finally, the Spring application context, src/main/resources/META-INF/spring/applicationContext.xml, has been updated to have a data source, a JPA transaction manager, and a JPA entity manager factory.

8. Command to create a Spring MVC controller that provides a UI:-
a) controller scaff –class ~.web.CustomerController –entity ~.domain.Customer
b) controller scaff –class ~.web.CustomerController –entity
c) none of the mentioned
d) all of the mentioned

Answer

Answer: a [Reason:] Type the following command to create a Spring MVC controller that provides a UI to manipulate Customer entities (and stand back!):
controller scaff –class ~.web.CustomerController –entity ~.domain.Customer

9. To deploy the application to a web container:-
a) mvn tomcat:run
b) mvn jetty:run
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] In the project directory, in the standard shell, run mvn tomcat:run or mvn jetty:run, and open http://localhost:8080 in your browser.

10. Spring Roo’s root folder (or any of the source packages) is:-
a) src/main/java, src/main/resources
b) src/test/java
c) src/test/resources
d) all of the mentioned

Answer

Answer: d [Reason:] The root folder (or any of the source packages, e.g., src/main/java, src/main/resources, src/test/java, or src/test/resources).

Java MCQ Set 3

1. Transactions can be described with key properties:-
a) Atomicity
b) Consistency
c) Isolation
d) All of the mentioned

Answer

Answer: d [Reason:] The concept of transactions can be described with four key properties: atomicity, consistency, isolation, and durability (ACID).
• Atomicity: A transaction is an atomic operation that consists of a series of actions.
The atomicity of a transaction ensures that the actions either complete entirely or
take no effect at all.
• Consistency: Once all actions of a transaction have completed, the transaction is
committed. Then your data and resources will be in a consistent state that
conforms to business rules.
• Isolation: Because there may be many transactions processing with the same data
set at the same time, each transaction should be isolated from others to prevent
data corruption.
• Durability: Once a transaction has completed, its result should be durable to
survive any system failure (imagine if the power to your machine was cut right in
the middle of a transaction’s commit). Usually, the result of a transaction is
written to persistent storage.

2. To access a database running on the Derby server, you have to add:-
a) Derby client library
b) Tomcat client library
c) All of the mentioned
d) None of the mentioned

Answer

Answer: a [Reason:] To access a database running on the Derby server, you have to the Derby client library to your CLASSPATH.

3. Spring’s transaction support offers a set of technology-independent facilities, including transaction managers.
a) org.springframework.transaction.PlatformTransactionManager
b) org.springframework.transaction.support.TransactionTemplate
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] Spring’s transaction support offers a set of technology-independent facilities, a transaction template (e.g., org.springframework.transaction.support.TransactionTemplate), and transaction declaration support to simplify your transaction management tasks.

4. Spring’s core transaction management abstraction is based on the interface:-
a) PlatformTransaction
b) PlatformTransactionManager
c) TransactionManager
d) PlatformManager

Answer

Answer: b [Reason:] It encapsulates a set of technology-independent methods for transaction management.

5. The PlatformTransactionManager interface provides methods for working with transactions:
a) getTransaction(TransactionDefinition definition)
b) commit(TransactionStatus status)
c) rollback(TransactionStatus status)
d) all of the mentioned

Answer

Answer: d [Reason:]
• TransactionStatus getTransaction(TransactionDefinition definition) throws
TransactionException
• void commit(TransactionStatus status) throws TransactionException;
• void rollback(TransactionStatus status) throws TransactionException;

6. Spring has several built-in implementations of PlatformTransactionManager interface for use with different transaction management APIs.
a) True
b) False

Answer

Answer: a [Reason:]
• If you have to deal with only a single data source in your application and access it
with JDBC, DataSourceTransactionManager should meet your needs.
• If you are using JTA for transaction management on a Java EE application server,
you should use JtaTransactionManager to look up a transaction from the
application server. Additionally, JtaTransactionManager is appropriate for
distributed transactions (transactions that span multiple resources). Note that
while it’s common to use a JTA transaction manager to integrate the application
servers’ transaction manager, there’s nothing stopping you from using a stand-
alone JTA transaction manager such as Atomikos.
• If you are using an object/relational mapping framework to access a database, you
should choose a corresponding transaction manager for this framework, such as
HibernateTransactionManager and JpaTransactionManager.

7. A transaction manager is declared in the Spring IoC container as a normal bean.
a) True
b) False

Answer

Answer: a [Reason:] For example, the following bean configuration declares a DataSourceTransactionManager instance. It requires the dataSource property to be set so that it can manage transactions for connections made by this data source.

8. Method that allows you to start a new transaction (or obtain the currently active transaction).
a) getTransaction()
b) commit()
c) rollback()
d) all of the mentioned

Answer

Answer: a [Reason:] Spring’s transaction manager provides a technology-independent API that allows you to start a new transaction (or obtain the currently active transaction) by calling the getTransaction() method.

9. PlatformTransactionManager is an abstract unit for transaction management.
a) True
b) False

Answer

Answer: a [Reason:] Because PlatformTransactionManager is an abstract unit for transaction management, the methods you called for transaction management are guaranteed to be technology independent.

10. Method to start a new transaction with that definition:-
a) getTransaction()
b) commit()
c) rollback()
d) none of the mentioned

Answer

Answer: a [Reason:] Once you have a transaction definition, you can ask the transaction manager to start a new transaction with that definition by calling the getTransaction() method.

11. To help you control the overall transaction management process and transaction exception handling.
a) SpringTransactionTemplate
b) TransactionTemplate
c) Transaction
d) None of the mentioned

Answer

Answer: b [Reason:] Spring also provides a TransactionTemplate to help you control the overall transaction management process and transaction exception handling.

12. You just have to encapsulate your code block in a callback class that implements the TransactionCallback interface and pass it to the TransactionTemplate’s execute method for execution. In this way, you don’t need to repeat the boilerplate transaction management code for this block.
a) True
b) False

Answer

Answer: a [Reason:] In this way, you don’t need to repeat the boilerplate transaction management code for this block.

13. A TransactionTemplate can accept a transaction callback object that implements:-
a) TransactionCallback
b) TransactionCallbackWithoutResult class
c) All of the mentioned
d) None of the mentioned

Answer

Answer: c [Reason:] A TransactionTemplate can accept a transaction callback object that implements either the TransactionCallback or an instance of the one implementor of that interface provided by the framework, the TransactionCallbackWithoutResult class.

14. Spring (since version 2.0) offers a transaction advice that can be easily configured via the:-
a) rx:advice
b) bx:advice
c) tx:advice
d) none of the mentioned

Answer

Answer: c [Reason:] This advice can be enabled with the AOP configuration facilities defined in the aop saop schema.

15. You can omit the transaction-manager attribute in the element if your transaction manager has the name transactionManager.
a) True
b) False

Answer

Answer: a [Reason:] This element will automatically detect a transaction manager with this name. You have to specify a transaction manager only when it has a different name.

Java MCQ Set 4

1. To send a message into the bus and transform it before working with it further.
a) adding extra headers or augmenting the payload
b) transformer
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] You might also want to transform a message by enriching it—adding extra headers or augmenting the payload so that components downstream in the processing pipeline can benefit from it. Use a transformer component to take a Message of a payload and send the Message out with a payload of a different type.

2. Spring Integration provides a transformer message endpoint to permit the augmentation of the message headers.
a) True
b) False

Answer

Answer: a [Reason:] Spring Integration provides a transformer message endpoint to permit the augmentation of the message headers or the transformation of the message itself. In Spring Integration, components are chained together, and output from one component is returned by way of the method invoked for that component.

3.

import org.springframework.integration.annotation.Transformer;
import org.springframework.integration.core.Message;
import org.springframework.integration.message.MessageBuilder;
import java.util.Map;
public class InboundJMSMessageToCustomerWithExtraMetadataTransformer {
	@Transformer
public Message<Customer> transformJMSMapToCustomer(
	Message<Map<String, Object>> inboundSpringIntegrationMessage) {
	Map<String, Object> jmsMessagePayload =
	inboundSpringIntegrationMessage.getPayload();
	Customer customer = new Customer();
	customer.setFirstName((String) jmsMessagePayload.get("firstName"));
	customer.setLastName((String) jmsMessagePayload.get("lastName"));
	customer.setId((Long) jmsMessagePayload.get("id"));
return MessageBuilder.withPayload(customer)
	.copyHeadersIfAbsent( inboundSpringIntegrationMessage.getHeaders())
	.setHeaderIfAbsent("randomlySelectedForSurvey", Math.random() > .5)
	.build();
}
}

The output is constructed dynamically using MessageBuilder to create a message that has the same payload as the input message as well as copy the existing headers and adds an extra header:
a) randomlySelected
b) randomlySelectedForSurvey
c) randomly
d) none of the mentioned

Answer

Answer: b [Reason:] As before, this code is simply a method with an input and an output. The output is constructed dynamically using MessageBuilder to create a message that has the same payload as the input message as well as copy the existing headers and adds an extra header: randomlySelectedForSurvey.

4. Spring Integration provides the ability to catch exceptions and send them to an error channel of your choosing. By default, it’s a global channel called :-
a) error
b) exceptionChannel
c) exception
d) errorChannel

Answer

Answer: d [Reason:] You can have components subscribe to messages from this channel to override the exception handling behavior.

5. The errorChannel doesn’t need to be a service-activator.
a) True
b) False

Answer

Answer: a [Reason:] We just use it for convenience here. The code for the following service-activator depicts some of the machinations you might go through to build a handler for the errorChannel.

6. All errors thrown from Spring Integration components will be a subclass of:-
a) Messaging
b) MessagingException
c) Exception
d) None of the mentioned

Answer

Answer: b [Reason:] MessagingException carries a pointer to the original Message that caused an error, which you can dissect for more context information.

7. One way to discriminate by Exception type is to use:-
a) org.springframework.integration.router.ErrorMessageExceptionType
b) org.springframework.integration.router.ErrorMessageException
c) org.springframework.integration.router.ErrorMessageExceptionTypeRouter
d) none of the mentioned

Answer

Answer: c [Reason:] Sometimes, more specific error handling is required. One way to discriminate by Exception type is to use the org.springframework.integration.router.ErrorMessageExceptionTypeRouter class.

8. Sending all the errors to the same channel can eventually lead to a large switch-laden class that’s too complex to maintain.
a) True
b) False

Answer

Answer: a [Reason:] Instead, it’s better to selectively route error messages to the error channel most appropriate to each integration.

9. You can explicitly specify on what channel errors for a given integration should go.
a) True
b) False

Answer

Answer: a [Reason:] A component (service-activator) that upon receiving a message, adds a header indicating the name of the error channel.

10. Spring Integration will use that header and forward errors encountered in the processing of this message to that channel.
a) True
b) False

Answer

Answer: a [Reason:] The following example shows a component (service-activator) that upon receiving a message, adds a header indicating the name of the error channel. Spring Integration will use that header and forward errors encountered in the processing of this message to that channel.

import org.apache.log4j.Logger;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageHeaders;
import org.springframework.integration.message.MessageBuilder;
public class ServiceActivatorThatSpecifiesErrorChannel {
private static final Logger logger = Logger.getLogger(
	ServiceActivatorThatSpecifiesErrorChannel.class);
	@ServiceActivator
public Message<?> startIntegrationFlow(Message<?> firstMessage)
throws Throwable {
return MessageBuilder.fromMessage(firstMessage).
setHeaderIfAbsent( MessageHeaders.ERROR_CHANNEL,
"errorChannelForMySolution").build();
}
}

11.

import org.apache.log4j.Logger;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageHeaders;
import org.springframework.integration.message.MessageBuilder;
public class ServiceActivatorThatSpecifiesErrorChannel {
private static final Logger logger = Logger.getLogger(
	ServiceActivatorThatSpecifiesErrorChannel.class);
	@ServiceActivator
public Message<?> startIntegrationFlow(Message<?> firstMessage)
throws Throwable {
return MessageBuilder.fromMessage(firstMessage).
setHeaderIfAbsent( MessageHeaders.ERROR_CHANNEL,
"errorChannelForMySolution").build();
}
}

All errors that come from the integration in which this component is used will be directed to:-
a) customErrorChannel
b) customError
c) errorChannel
d) none of the mentioned

Answer

Answer: a [Reason:] Thus, all errors that come from the integration in which this component is used will be directed to customErrorChannel, to which you can subscribe any component you like.

Java MCQ Set 5

1. This encapsulates the context of a test’s execution:-
a) Test context
b) Test context manager
c) Test context listener
d) Test execution listener

Answer

Answer: a [Reason:] This encapsulates the context of a test’s execution, including the application context, test class, current test instance, current test method, and current test exception.

2. This manages a test context for a test and triggers test execution listeners:-
a) Test context
b) Test context manager
c) Test context listener
d) Test execution listener

Answer

Answer: b [Reason:] This manages a test context for a test and triggers test execution listeners at predefined test execution points, including when preparing a test instance, before executing a test method (before any framework-specific initialization methods), and after executing a test method (after any framework-specific cleanup methods).

3. This defines a listener interface; by implementing this, you can listen to test execution events.
a) Test context
b) Test context manager
c) Test context listener
d) Test execution listener

Answer

Answer: d [Reason:] The TestContext framework provides several test execution listeners for common testing features, but you are free to create your own.

4. Spring provides convenient TestContext support classes for:-
a) JUnit3
b) JUnit4
c) TestNG5
d) All of the mentioned

Answer

Answer: d [Reason:] Spring provides convenient TestContext support classes for JUnit 3, JUnit 4, and TestNG 5, with particular test execution listeners preregistered.

5. JUnit 4 allows you to annotate your test methods with:-
a) @Test
b) @Autowire
c) @JTest
d) None of the mentioned

Answer

Answer: a [Reason:] JUnit 4 allows you to annotate your test methods with JUnit’s @Test annotation, so an arbitrary public method can be run as a test case.

6. Usually, a test and its target class are located in the same package, but the source files of tests are stored in a separate directory.
a) True
b) False

Answer

Answer: a [Reason:] (e.g., test) from the source files of other classes (e.g., src).

7. Method to perform cleanup tasks:-
a) finalize
b) tearDown
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] You can override the tearDown() method to perform cleanup tasks, such as releasing permanent resources.

8. The static assert methods is declared in the:-
a) org.junit.Assert
b) org.junit.*
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] You can override the tearDown() method to perform cleanup tasks, such as releasing permanent resources.

9. Attribute which specifies the exception type:-
a) after
b) expected
c) before
d) test

Answer

Answer: b [Reason:] JUnit 4 offers a powerful feature that allows you to expect an exception to be thrown in a test case. You can simply specify the exception type in the expected attribute of the @Test annotation.

10. Test data sets are provided by data providers, which are methods with the:-
a) @DataProvider
b) @Autowire
c) @JTest
d) None of the mentioned

Answer

Answer: a [Reason:] In TestNG, test data sets are provided by data providers, which are methods with the @DataProvider annotation.

11. An object that simulates a dependent object:-
a) stub
b) mock
c) test
d) none of the mentioned

Answer

Answer: a [Reason:] A stub is an object that simulates a dependent object with the minimum number of methods required for a test.

12. An Object which usually knows how its methods are expected to be called:-
a) stub
b) mock
c) test
d) none of the mentioned

Answer

Answer: b [Reason:] In contrast to a stub, a mock object usually knows how its methods are expected to be called in a test.

13. Libraries that can help create mock objects:-
a) EasyMock
b) jMock
c) All of the mentioned
d) None of the mentioned

Answer

Answer: c [Reason:] In Java, there are several libraries that can help create mock objects, including EasyMock and jMock.

14. Test used to test several units in combination as a whole.
a) Integration tests
b) JUnit4
c) TestNG5
d) All of the mentioned

Answer

Answer: a [Reason:] Integration tests, in contrast, are used to test several units in combination as a whole.

15. Spring supports web controller testing by providing Servlet API:-
a) MockHttpServletRequest
b) MockHttpServletResponse
c) MockHttpSession
d) All of the mentioned

Answer

Answer: d [Reason:] Spring supports web controller testing by providing a set of mock objects for the Servlet API (including MockHttpServletRequest, MockHttpServletResponse, and MockHttpSession).

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.