Java MCQ Number 01098

Java MCQ Set 1

1. Integration of Spring which have each application produce files of shared data for others to consume.
a) File transfer
b) Shared Database
c) Remote Procedure Invocation
d) Messaging

Answer

Answer: a [Reason:] File transfer: Have each application produce files of shared data for others to consume and consume files that others have produced.

2. Integration of Spring which have the applications store the data they want to share in a common database.
a) File transfer
b) Shared Database
c) Remote Procedure Invocation
d) Messaging

Answer

Answer: b [Reason:] This usually takes the form of a database to which different applications have access.

3. Integration of Spring which have each application expose some of its procedures so that they can be invoked remotely and have applications invoke them to initiate behavior and exchange data.
a) File transfer
b) Shared Database
c) Remote Procedure Invocation
d) Messaging

Answer

Answer: c [Reason:] There is specific support for optimizing RPC (remote procedure calls such as SOAP, RMI, and HTTP Invoker) exchanges using Spring Integration.

4. Integration of Spring which have each application connect to a common messaging system and exchange data and invoke behavior using messages.
a) File transfer
b) Shared Database
c) Remote Procedure Invocation
d) Messaging

Answer

Answer: d [Reason:] This style, most enabled by JMS in the JEE world, also describes other asynchronous or multicast publish/subscribe architectures.

5. Using an ESB lets you hide the origin of the message from the code that’s handling it.
a) True
b) False

Answer

Answer: a [Reason:] You’ll use this solution as an easy way to see how a Spring Integration solution can be built.

6. As with a standard MDP, configuration for the ConnectionFactory exists.
a) True
b) False

Answer

Answer: a [Reason:] There’s also a lot of other schema required for using the configuration elements available in Spring Integration.

7. The configuration starts with the inboundHelloJMSMessageChannel channel, which tells Spring Integration what to name the point-to-point connection from the message queue to the:-
a) service-activator
b) service
c) all of the mentioned
d) none of the mentioned

Answer

Answer: a [Reason:] You typically define a new channel for every point-to-point connection.

8. An adapter is a component that knows how to speak to a specific type of subsystem and translate messages on that subsystem into something that can be used in the Spring Integration bus only.
a) True
b) False

Answer

Answer: a [Reason:] Adapters also do the same in reverse, taking messages on the Spring Integration bus and translating them into something a specific subsystem will understand.

9. A service-activator, however, only helps you invoke your application’s business logic on receipt of a message.
a) True
b) False

Answer

Answer: a [Reason:] What you do in the business logic, connecting to another system or not, is up to you.

10. The next component, a service-activator, listens for messages coming into that channel and invokes the bean referenced by the :-
a) ref
b) after
c) before
d) all of the mentioned

Answer

Answer: a [Reason:] The next component, a service-activator, listens for messages coming into that channel and invokes the bean referenced by the ref attribute, which in this case is the bean defined previously: inboundHelloWorldJMSPingServiceActivator.

11. Headers Found in Spring Integration Messages:-
a) ID
b) TIMESTAMP
c) CORRELATION_ID
d) All of the mentioned

Answer

Answer: d [Reason:] Constant ID This is a unique value assigned to the message by the Spring Integration engine.
TIMESTAMP Timestamp assigned to the message.
CORRELATION_ID This is optional. It is used by some components (such as aggregators) to group
messages together in some sort of processing pipeline.
REPLY_CHANNEL The String name of the channel to which the output of the current component
should be sent. This can be overridden.
ERROR_CHANNEL The String name of the channel to which the output of the current component
should be sent if an exception bubbles up into the runtime. This can be overridden.
EXPIRATION_DATE Used by some components as a threshold for processing after which a component
can wait no longer in processing.
SEQUENCE_NUMBER The order in which the message is to be sequenced; typically used with a sequencer.
SEQUENCE_SIZE
838
Description
The size of the sequence so that an aggregator can know when to stop waiting for
more messages and move forward. This is useful in implementing “join”
functionality.

12. Some header values are specific to the type of the source message’s payload.
a) True
b) False

Answer

Answer: a [Reason:] Some header values are specific to the type of the source message’s payload; for example, payloads sourced from a file on the file system are different from those coming in from a JMS queue, which are different from messages coming from an e-mail system.

13. Component-specific headers are the constants defined for files on:-
a) org.springframework.integration.file.FileHeaders: FILENAME
b) org.springframework.integration.file.FileHeaders: PREFIX
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] An example of component-specific headers are the constants defined for files on org.springframework.integration.file.FileHeaders: FILENAME and PREFIX.

14. Annotation to get access to header metadata:-
a) @Ref
b) @service
c) @Header
d) None of the mentioned

Answer

Answer: c [Reason:] Another way to get access to header metadata is to simply have it passed as parameters to your component’s method. You simply annotate the parameter with the @Header annotation, and Spring Integration will take care of the rest.

15. The code for the service-activator has changed to reflect the fact that you’re expecting a message containing a message of type:-
a) Message<java.io.File>
b) Message<java.io>
c) All of the mentioned
d) None of the mentioned

Answer

Answer: a [Reason:] The code for the service-activator has changed to reflect the fact that you’re expecting a message containing a message of type Message<java.io.File>.

Java MCQ Set 2

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

Answer

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

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

Answer

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

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

Answer

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

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

Answer

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

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

Answer

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

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

Answer

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

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

Answer

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

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

Answer

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

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

Answer

Answer: b [Reason:] AbstractTestNGSpringContextTests class also implements the ApplicationContextAware interface.

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

Answer

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

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

Answer

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

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

Answer

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

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

Answer

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

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

Answer

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

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

Answer

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

Java MCQ Set 3

1. Which special type of advice is used to implement an interface?
a) Introduction
b) Before
c) After
d) AfterSpecial

Answer

Answer: a [Reason:] It allows your objects to implement an interface dynamically by providing an implementation class for that interface.

2. Introduction advice helps in implementing multiple inheritance
a) True
b) False

Answer

Answer: a [Reason:] You are able to introduce multiple interfaces with multiple implementation classes to your objects at the same time.

3. In introduction advice you have to modify class to introduce new methods
a) True
b) False

Answer

Answer: b [Reason:] You can introduce methods to your existing classes even without source code available.

4. How does an Introduction advice do this in Spring?
a) dynamic proxy
b) web proxy
c) implements org.springframework.net.bundle interface
d) none of the mentioned

Answer

Answer: a [Reason:] Introduction works by adding an interface to the dynamic proxy.

5. Annotation used to declare an introduction
a) Before
b) After
c) @DeclareParents
d) None of the mentioned

Answer

Answer: c [Reason:] In this aspect, you can declare an introduction by annotating an arbitrary field with the @DeclareParents annotation.

6. Target Classes can be denoted by Introduction Annotation
a) True
b) False

Answer

Answer: a [Reason:] The value attribute of the @DeclareParents annotation type indicates which classes are the targets for this introduction.

7. Attribute used to specify implementation class
a) no such attribute
b) defaultImpl
c) defaultInterface
d) defaultImplement

Answer

Answer: b [Reason:] The interface to introduce is determined by the type of the annotated field. Finally, the implementation class used for this new interface is specified in the defaultImpl attribute.

8. How to keep track of the usage of your beans
a) Calling Count
b) Last modified date
c) New Interface to your object
d) All of the mentioned

Answer

Answer: d [Reason:] You can introduce a new interface to your objects with an implementation class that holds the state field.

9. How to introduce counter field to original bean class?
a) Using Spring AOP
b) Implementing interface
c) AspectJ Pointcut
d) None of the mentioned

Answer

Answer: a [Reason:] Since there is no field for storing the counter value in the original classes, you need to introduce one with Spring AOP.

10. Tag used to declare aspects
a) aop:config
b) aop:auto-proxy
c) aop:autowire
d) None of the mentioned

Answer

Answer: a [Reason:] In the bean configuration file, all the Spring AOP configurations must be defined inside the aop:config element.

Java MCQ Set 4

1. Class which declares a number of overloaded update() template methods to control the overall update process.
a) org.springframework.jdbc.core.JdbcTemplate
b) org.springframework.jdbc.core.*
c) org.springframework.jdbc.*
d) none of the mentioned

Answer

Answer: a [Reason:] The org.springframework.jdbc.core.JdbcTemplate class declares a number of overloaded update() template methods to control the overall update process.

2. You implement this interface to override the statement creation task.
a) PreparedStatement
b) PreparedStatementCreator
c) PreparedCreator
d) None of the mentioned

Answer

Answer: b [Reason:] The first callback interface to introduce is PreparedStatementCreator. You implement this interface to override the statement creation task and the parameter binding task of the overall update process.

3. When implementing the PreparedStatementCreator interface, you will get the database connection as the createPreparedStatement() method’s argument.
a) True
b) False

Answer

Answer: a [Reason:] All you have to do in this method is to create a PreparedStatement object on this connection and bind your parameters to this object.

4. It is better to implement the PreparedStatementCreator interface and other callback interfaces as inner classes if they are used within one method only.
a) True
b) False

Answer

Answer: a [Reason:] This is because you can get access to the local variables and method arguments directly from the inner class, instead of passing them as constructor arguments.

5. PreparedStatementSetter, as its name indicates, create a PreparedStatement object on this connectionthe parameter as well as binding task of the overall update process.
a) True
b) False

Answer

Answer: b [Reason:] The second callback interface, PreparedStatementSetter, as its name indicates, performs only the parameter binding task of the overall update process.

6. The JdbcTemplate class offers template method for batch update operations.
a) batchUpdate()
b) update()
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] It requires a SQL statement and a BatchPreparedStatementSetter object as arguments. In this method, the statement is compiled (prepared) only once and executed multiple times.

7. The JdbcTemplate class declares a number of overloaded query() template methods to control the overall query process.
a) True
b) False

Answer

Answer: c [Reason:] You can override the statement creation (task 2) and the parameter binding by implementing the PreparedStatementCreator and PreparedStatementSetter interfaces, just as you did for the update operations.

8. The primary interface that allows you to process the current row of the result set.
a) PreparedStatementSetter
b) PreparedStatementCreator
c) RowCallbackHandler
d) All of the mentioned

Answer

Answer: c [Reason:] RowCallbackHandler is the is the primary interface that allows you to process the current row of the result set.

9. RowCallbackHandler’s purpose is to map a single row of the result set to a customized object.
a) True
b) False

Answer

Answer: b [Reason:] RowCallbackHandler is the is the primary interface that allows you to process the current row of the result set.

10. Method of RowMapper interface in which, you have to construct the object that represents a row and return it as the method’s return value.
a) mapRow()
b) query()
c) update()
d) none of the mentioned

Answer

Answer: a [Reason:] From the viewpoint of reuse, it’s better to implement the RowMapper interface as a normal class than as an inner class. In the mapRow() method of this interface, you have to construct the object that represents a row and return it as the method’s return value.

11. RowMapper implementation which can automatically map a row to a new instance of the specified class.
a) BeanPropertyRowMapper
b) BeanPropertyRow
c) All of the mentioned
d) None of the mentioned

Answer

Answer: a [Reason:] Note that the specified class must be a top-level class and must have a default or no-argument constructor. It first instantiates this class and then maps each column value to a property by matching their names.

12. Method which provides list of maps.
a) queryForList()
b) update
c) query()
d) all of the mentioned

Answer

Answer: a [Reason:] Without the help of RowMapper, you can still call the queryForList() method and pass in a SQL statement. The returned result will be a list of maps. Each map stores a row of the result set with the column names as the keys.

13. Spring JDBC framework offers a convenient class, to simplify your DAO implementation.
a) org.springframework.jdbc.core.support
b) org.springframework.jdbc.core.support.JdbcDaoSupport
c) all of the mentioned
d) none of the mentioned

Answer

Answer: b [Reason:] Spring JDBC framework offers a convenient class, org.springframework.jdbc.core.support.JdbcDaoSupport, to simplify your DAO implementation. This class declares a jdbcTemplate property, which can be injected from the IoC container or created automatically from a data source.

14. The org.springframework.jdbc.core.support.JdbcDaoSupport class has a setDataSource() method and a setJdbcTemplate() method.
a) True
b) False

Answer

Answer: a [Reason:] Your DAO class can extend this class to have these methods inherited.

15. Method to retrieve the JDBC template.
a) setJdbcTemplate()
b) getTemplate()
c) getJdbc()
d) getJdbcTemplate()

Answer

Answer: d [Reason:] In your DAO methods, you can simply call the getJdbcTemplate() method to retrieve the JDBC template. You also have to delete the dataSource and jdbcTemplate properties, as well as their setter methods, from your DAO class, because they have already been inherited. Again, for simplicity’s sake, only the change to the insert() method is shown.

Java MCQ Set 5

1. Template which can send and receive JMS messages with much less code
a) JmsTemplate
b) EMail
c) All of the mentioned
d) None of the mentioned

Answer

Answer: a [Reason:] With a JMS template (Spring framework class JmsTemplate), you can send and receive JMS messages with much less code.

2. The template handles the boilerplate tasks for you and also converts the JMS API’s JMSException hierarchyinto Spring’s runtime exception:-
a) org.springframework.jms.Jms
b) org.springframework.jms.JmsException
c) org.springframework.jms.JmsTemplate
d) none of the mentioned

Answer

Answer: b [Reason:] The translation converts exceptions to a mirrored hierarchy of unchecked exceptions.

3. To address different JMS APIs, Spring provides :-
a) JmsTemplate
b) JmsTemplate102
c) All of the mentioned
d) None of the mentioned

Answer

Answer: c [Reason:] To address different JMS APIs, Spring provides two JMS template classes, JmsTemplate and JmsTemplate102, for these two versions of JMS.

4. Before you can send and receive JMS messages, you need to install a JMS message broker:-
a) Apache ActiveM
b) Apache Active
c) Apache MQ
d) Apache ActiveMQ

Answer

Answer: d [Reason:] Before you can send and receive JMS messages, you need to install a JMS message broker. For simplicity’s sake, we have chosen Apache ActiveMQ (http://activemq.apache.org/) as our message broker, which is very easy to install and configure.

5.

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

In the preceding sendMail() method, you first create JMS-specific ConnectionFactory.
a) True
b) False

Answer

Answer: a [Reason:] In the preceding sendMail() method, you first create JMS-specific ConnectionFactory and Destination objects with the classes provided by ActiveMQ.

6.

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

In JMS, there are two types of destinations:-
a) topic
b) queue
c) all of the mentioned
d) none of the mentioned

Answer

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

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

Answer

Answer: d [Reason:] There are several types of messages defined in the JMS API, including TextMessage, MapMessage, BytesMessage, ObjectMessage, and StreamMessage.

8. To send a JMS message with this template, you simply call:-
a) send
b) sendTo
c) all of the mentioned
d) none of the mentioned

Answer

Answer: a [Reason:] To send a JMS message with this template, you simply call the send() method and provide a message destination, as well as a MessageCreator object, which creates the JMS message you are going to send.

9. The MessageCreator interface declares method:-
a) createMessage()
b) create()
c) createMsg()
d) none of the mentioned

Answer

Answer: a [Reason:] The MessageCreator interface declares only a createMessage() method for you to implement.

10. A JMS template helps you to obtain and release the JMS connection and session.
a) True
b) False

Answer

Answer: a [Reason:] A JMS template helps you to obtain and release the JMS connection and session, and it sends the JMS message created by your MessageCreator object.

11. JMS sender and receiver classes can also extend to retrieve a JMS template:-
a) JmsGatewaySupport
b) JmsGateway
c) All of the mentioned
d) None of the mentioned

Answer

Answer: a [Reason:] Just like your DAO class can extend JdbcDaoSupport to retrieve a JDBC template, your JMS sender and receiver classes can also extend JmsGatewaySupport to retrieve a JMS template.

12. When you need access to the JMS template.
a) setJmsTemplate
b) getJmsTemplate
c) getJms
d) none of the mentioned

Answer

Answer: b [Reason:] When you need access to the JMS template, you just make a call to getJmsTemplate().

13. Spring provides an implementation of SimpleMessageConvertor to handle the translation of a JMS message received.
a) True
b) False

Answer

Answer: a [Reason:] Spring provides an implementation of SimpleMessageConvertor to handle the translation of a JMS message received to a business object and the translation of a business object to a JMS message.

14. By default, the JMS template uses SimpleMessageConverter for converting TextMessage to or from a string.
a) True
b) False

Answer

Answer: a [Reason:] By default, the JMS template uses SimpleMessageConverter for converting TextMessage to or from a string, BytesMessage to or from a byte array, MapMessage to or from a map, and ObjectMessage to or from a serializable object.

15. For your front desk and back office classes, you can send and receive a map using the:-
a) convertAndSend()
b) receiveAndConvert()
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] For your front desk and back office classes, you can send and receive a map using the convertAndSend() and receiveAndConvert() methods, and the map will be converted to/from MapMessage.

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.