| Snaprecruit.com

| Snaprecruit.com

Interview question based on skill :

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. The template handles the boilerplate tasks for you and also converts the JMS API JMSException hierarchy into Spring runtime exception:-

Correct Answer is : org.springframework.jms.JmsException

2. To address different JMS APIs, Spring provides :-

Correct Answer is : All of the mentioned

3. Before you can send and receive JMS messages, you need to install a JMS message broker:-

Correct Answer is : Apache ActiveMQ

4. In the preceding sendMail() method, you first create JMS-specific ConnectionFactory. 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) { } } } } }

Correct Answer is : TRUE

5. In JMS, there are two types of destinations:- 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) { } } } } }

Correct Answer is : all of the mentioned

6. There are several types of messages defined in the JMS API, including:-

Correct Answer is : All of the mentioned

7. To send a JMS message with this template, you simply call:-

Correct Answer is : send

8. The MessageCreator interface declares method:-

Correct Answer is : createMessage()

9. A JMS template helps you to obtain and release the JMS connection and session.

Correct Answer is : TRUE

10. JMS sender and receiver classes can also extend to retrieve a JMS template:-

Correct Answer is : JmsGatewaySupport

11. When you need access to the JMS template.

Correct Answer is : getJmsTemplate

12. Spring provides an implementation of SimpleMessageConvertor to handle the translation of a JMS message received.

Correct Answer is : TRUE

13. By default, the JMS template uses SimpleMessageConverter for converting TextMessage to or from a string.

Correct Answer is : TRUE

14. For your front desk and back office classes, you can send and receive a map using the:-

Correct Answer is : all of the mentioned

15. There are two main options for scheduling tasks on the Java platform:-

Correct Answer is : All of the mentioned

16. Spring supports JMX by allowing you to export any beans in its IoC container as model MBeans.

Correct Answer is : TRUE

17. Connectors to expose your MBeans for remote access over a specific protocol by using a factory bean.

Correct Answer is : All of the mentioned

18. Spring can also detect and export your MBeans automatically from beans declared in the IoC container and annotated with JMX-specific annotations defined by Spring.

Correct Answer is : TRUE

19. Method, all files in the source directory will be replicated to the destination directory.

Correct Answer is : replicate

20. o register an MBean, you need an instance of the interface :- import java.lang.management.ManagementFactory; import javax.management.Descriptor; import javax.management.JMException; import javax.management.MBeanServer; import javax.management.ObjectName; import javax.management.modelmbean.DescriptorSupport; import javax.management.modelmbean.InvalidTargetObjectTypeException; import javax.management.modelmbean.ModelMBeanAttributeInfo; import javax.management.modelmbean.ModelMBeanInfo; import javax.management.modelmbean.ModelMBeanInfoSupport; import javax.management.modelmbean.ModelMBeanOperationInfo; import javax.management.modelmbean.RequiredModelMBean; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext("beans-jmx.xml"); FileReplicator documentReplicator = (FileReplicator) context.getBean("documentReplicator"); try { MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = new ObjectName("bean:name=documentReplicator"); RequiredModelMBean mbean = new RequiredModelMBean(); mbean.setManagedResource(documentReplicator, "objectReference"); Descriptor srcDirDescriptor = new DescriptorSupport(new String[] { "name=SrcDir", "descriptorType=attribute", "getMethod=getSrcDir", "setMethod=setSrcDir" }); ModelMBeanAttributeInfo srcDirInfo = new ModelMBeanAttributeInfo( "SrcDir", "java.lang.String", "Source directory", true, true, false, srcDirDescriptor); Descriptor destDirDescriptor = new DescriptorSupport(new String[] { "name=DestDir", "descriptorType=attribute", "getMethod=getDestDir", "setMethod=setDestDir" }); public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext("beans-jmx.xml"); FileReplicator documentReplicator = (FileReplicator) context.getBean("documentReplicator"); ModelMBeanAttributeInfo destDirInfo = new ModelMBeanAttributeInfo( "DestDir", "java.lang.String", "Destination directory", true, true, false, destDirDescriptor); ModelMBeanOperationInfo getSrcDirInfo = new ModelMBeanOperationInfo( "Get source directory", FileReplicator.class.getMethod("getSrcDir")); ModelMBeanOperationInfo setSrcDirInfo = new ModelMBeanOperationInfo( "Set source directory", FileReplicator.class.getMethod("setSrcDir", String.class)); ModelMBeanOperationInfo getDestDirInfo = new ModelMBeanOperationInfo( "Get destination directory", FileReplicator.class.getMethod("getDestDir")); ModelMBeanOperationInfo setDestDirInfo = new ModelMBeanOperationInfo( "Set destination directory", FileReplicator.class.getMethod("setDestDir", String.class)); ModelMBeanOperationInfo replicateInfo = new ModelMBeanOperationInfo( "Replicate files", FileReplicator.class.getMethod("replicate")); ModelMBeanInfo mbeanInfo = new ModelMBeanInfoSupport( "FileReplicator", "File replicator", new ModelMBeanAttributeInfo[] { srcDirInfo, destDirInfo }, null, new ModelMBeanOperationInfo[] { getSrcDirInfo, setSrcDirInfo, getDestDirInfo, setDestDirInfo, replicateInfo }, null); mbean.setModelMBeanInfo(mbeanInfo); mbeanServer.registerMBean(mbean, objectName); } catch (JMException e) { ... } catch (InvalidTargetObjectTypeException e) { ... } catch (NoSuchMethodException e) { ... } System.in.read(); } }

Correct Answer is : javax.management.MBeanServer