EJB MT solutions of Niit Ques. 101 to 125

EJB MT solutions of Niit Ques. 101 to 125












SNo: 101
Ques: Billy is using following code for his message driven bean:
@MessageDriven(mappedName = "jms/NewMessage", activationConfig =  {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
@TransactionManagement(TransactionManagementType.CONTAINER)
public class MessageDrivenBean implements MessageListener {
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void onMessage(Message msg){ }
}
You have specified REQUIRED as transaction attribute type but unexpectedly even though if there is an active transaction, when the onMessage method is called, it is always executed in a new transaction. Identify the reason for this unexpected result.
Options:
  1,Message driven beans are always called in a new transaction if the transaction attribute type is REQUIRED.
  2,Message driven beans are always called in a new transaction when CMT is used no matter what type of the transaction attribute type is specified.
  3,Message driven beans are always called in a new transaction no matter if CMT or BMT is used.
  4,REQUIRED transaction attribute indicates that the bean should always be called in a new transaction, so if instead of message driven bean any other bean was used the method would have been called in a new transaction.
Answer: 1
Marks: 4

=============================================================

SNo: 102
Ques: Billy is using following code for his message driven bean:

@MessageDriven(mappedName="jms/MessageQueue")
public class MessageDrivenBean implements MessageListener {
  public void onMessage(Message msg) {//code for message processing}
  public void finalize(){//some processing}
}

Please verify the preceding code to rectify if it contains any issues
Options:
  1,The above code does not have any issues and will successfully create a message driven bean namely MessageDrivenBean.
  2,@MessageDriven annotation only defines mappedName property, messageListenerInterface attribute should also be specified.
  3,finalize() method is a protected message in Object class so it cannot be public in the MessageDrivenBean class.
  4,It is not recommended that message driven bean should implement the finalize method. So the finalize method should be removed.
Answer: 4
Marks: 4

=============================================================

SNo: 103
Ques: Billy is using following code for his message driven bean:
@MessageDriven(mappedName="jms/MessageQueue",
                         messageListenerInterface=javax.jms.MessageListener.class)
public class MessageDrivenBean {
  public void onMessage(TextMessage msg) {//code for message processing}
}
But at times he is facing a runtime exception. Please verify the preceding code to rectify if it contains any issues
Options:
  1,MessageDrivenBean is not implementing the MessageListener interface and so when container tries to notify the bean with the message a run time exception is thrown.
  2,MessageDrivenBean is not implementing the onMessage(Message) method and so when container tries to notify the bean with any other type of message(ObjectMessage,MapMessage etc.) a run time exception is thrown.
  3,MessageDrivenBean is not explicitly implementing the default constructor and so when container tries to notify the bean with the message a run time exception is thrown.
  4,There is no issue with the code, the runtime exception is occurring because of some configuration issue with the server.
Answer: 2
Marks: 4

=============================================================

SNo: 104
Ques: Billy is using the following code to create a asynchronous message driven bean:

@MessageDriven(mappedName = "jms/MessageDrivenBean", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
@ActivationConfigProperty(propertyName = "clientId", propertyValue = "MessageDrivenBean"),
@ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "MessageDrivenBean")
})
@TransactionManagement(TransactionManagementType.CONTAINER)
public class MessageDrivenBean implements MessageListener {
public void onMessage(Message msg){ }
}

While executing the onMessage method, if an exception is thrown, you have specified to rollback the transaction. But this is resulting in an endless loop. What could be the possible reason for the same


Options:
  1,When the onMessage method of message driven bean fails the container tries to rectify the issue by calling the onMessage method again. But, the onMessage method fails again and again as the message has an error eventually causing an end-less loop.
  2,When Auto-acknowledge, is used the container tries to notify the message driven bean of the error by calling the onMessage method. But, the onMessage method fails again and again as the message has an error and container will again try to notify the bean using onMessage method eventually causing an end-less loop.
  3,When javax.jms.Topic is used as a destination type, the container tries to resend all the unprocessed messages by calling the onMessage method. But, the onMessage method fails again, as the message has an error and the messages remain unprocessed. The container will continue to call the onMessage method eventually causing an end-less loop.
  4,When a transaction is rollbacked the message is again delivered to the message driven bean. However, the onMessage method will fail again as the message has an error which will again rollback the transaction, eventually causing an endless loop.
Answer: 4
Marks: 4

=============================================================

SNo: 105
Ques: You are implementing a banking site for which you have created the SavingAccount entity bean for manipulating the saving bank accounts. You have created three methods in the bean, the createAccount for creating account, the closeAccount for closing account and the updateAccount for updating account. The bean methods can be called from any roles SysAdmin, Manager or Guest i.e. the container should not check the security of the bean methods. You are using the following code snippet in your deployment descriptor file to achieve this:
<method-permission>
<role-name>*</role-name>
<method>
<ejb-name>SavingAccountBean</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
Even though you are calling the bean from SysAdmin role the container is not executing the bean methods. Identify the error in the preceding code.
Options:
  1,This is not a valid way to indicate that the bean can be executed from any role, instead unchecked element should be used in the method-permission element.
  2,The method-permission element in the deployment descriptor specifies the roles which are not allowed, so the above code tells container not to allow any role.
  3,The deployment descriptor does not indicate which type of bean for which the  security is enforced, so container disallows all the roles.
  4,The * is used as method name so as per the method-permission tag it'll allow the method whose name is * and as none of the methods are named * the container blocks all the calls.
Answer: 1
Marks: 4

=============================================================

SNo: 106
Ques: Which of the following options in a Java EE Application Environment does not contain the exception handling code
Options:
  1, Enterprise bean method
  2, Container
  3, Enterprise bean client
  4, Naming Service
Answer: 4
Marks: 1

=============================================================

SNo: 107
Ques: How can you rollback a transaction when an exception is thrown
Options:
  1, Setting the rollback value of the ApplicationException annotation to true.
  2, Setting the rollback value of the CreateException to true.
  3, Setting the rollback value of the RemoteException to true.
  4, Setting the rollback value of the ObjectNotFoundException to true.
Answer: 1
Marks: 1

=============================================================

SNo: 108
Ques: Which of the following interfaces' method is used to check the rollback status of the transaction
Options:
  1, javax.transaction.UserTransaction interface.
  2, javax.ejb.TimedObject interface
  3, javax.resource.ResourceException interface
  4, javax.resources.cci interface
Answer: 1
Marks: 1

=============================================================

SNo: 109
Ques: Which of the following methods is used to create a query object
Options:
  1, createNamedQuery
  2, createQuery
  3, createNativeQuery
  4, createdQuery
Answer: 2
Marks: 1

=============================================================

SNo: 110
Ques: Which of the following options will you use in a bean client code to determine the state of the client transaction
Options:
  1, UserTransaction.getStatus method
  2, setParameter method
  3, getBeanStatus method
  4, setRollbackOnly method
Answer: 1
Marks: 1

=============================================================

SNo: 111
Ques: Which of the following exceptions is defined in the throws clause of the enterprise bean business interfaces or in a message listener interface
Options:
  1, RemoteException
  2, Application exception
  3, EJBException
  4, RuntimeException
Answer: 2
Marks: 2

=============================================================

SNo: 112
Ques: In which of the following tiers the exceptions can be caused by an error in the underlying data resource, such as the inability to establish a database connection
Options:
  1, Client tier
  2, Client-to-application server tier
  3, EIS tier
  4, Application server tier
Answer: 3
Marks: 2

=============================================================

SNo: 113
Ques: Which of the following areas defines an exception caused by errors in the services supplied to the enterprise bean by the Java EE technology container
Options:
  1, The EIS tier
  2, The client-to-application server tier infrastructure
  3, The client tier
  4, The application server tier
Answer: 4
Marks: 2

=============================================================

SNo: 114
Ques: Which of the following options will you use to deal with the situation that may effect the data integrity and, in addition, a transaction rollback occurs
Options:
  1, Call the setRollbackOnly method and throw an application exception
  2, Call the setRollbackOnly method and throw a RuntimeException
  3, Call the setRollbackOnly method and throw an EJBException
  4, Call the setRollbackOnly method and throw a RemoteException
Answer: 1
Marks: 2

=============================================================

SNo: 115
Ques: Which of the following transactions indicates that a method requiring a transaction context has been invoked without the required transaction context
Options:
  1, Transaction-rollback exception
  2, Transaction-required exception
  3, EJBException
  4, RemoteException
Answer: 2
Marks: 2

=============================================================

SNo: 116
Ques: Which of the following beans must directly or indirectly implement the javax.jms.MessageListener interface
Options:
  1, JMS messagedriven bean
  2, Stateful Session beans
  3, Non JMS message-driven bean
  4, Entity beans
Answer: 1
Marks: 2

=============================================================

SNo: 117
Ques: Which of the following options is correct in reference to the Message-driven beans
Options:
  1, Message-driven beans have remote component and local component interfaces.
  2, Message-driven beans provide Java EE components with a direct interface.
  3, Message-driven beans have no client-visible identity.
  4, Message-driven beans are not anonymous to clients.
Answer: 3
Marks: 2

=============================================================

SNo: 118
Ques: Which of the following options is correct in reference to the callback method in a message driven bean (MDB)
Options:
  1, It can have any type of access modifier (public, default, protected or private).
  2, It must throw an application exception.
  3, It cannot throw a runtime exception.
  4, It must use dependency injections.
Answer: 1
Marks: 2

=============================================================

SNo: 119
Ques: While creating a non-JMS message-driven bean class, which of the following annotations will you use to annotate the message-driven bean class
Options:
  1, MessageDriven metadata annotation
  2, PostCosntruct metadata annotation.
  3, PreDestroy metadata annotation.
  4, Resource metadata annotation
Answer: 1
Marks: 2

=============================================================

SNo: 120
Ques: Which of the following statements is true regarding the Non-JMS Message-driven bean class
Options:
  1, The class must be declared public.
  2, The class must be declared final.
  3, The class must be declared abstract.
  4, Define a finalize method.
Answer: 1
Marks: 2

=============================================================

SNo: 121
Ques: Which of the following functions can be performed by an enterprise bean by using the timer functionality tasks
Options:
  1, Interrogate a timer callback notification object.
  2, Annotate the method with the Timeout annotation.
  3, Identify the user
  4, Makes the application portable.
Answer: 1
Marks: 2

=============================================================

SNo: 122
Ques: Which of the following methods of the Timer class returns a serializable handle to the timer object and  it enables you to obtain a reference to the timer object at a future date
Options:
  1, getTimeRemaining
  2, getHandle
  3, getNextTimeout
  4, getInfo
Answer: 2
Marks: 2

=============================================================

SNo: 123
Ques: Which of the following TimerService methods will you use to create an interval timer with an initial relative time-based notification
Options:
  1, createTimer(long initialDuration, long intervalDuration, Serializable info)
  2, createTimer(Date initialExpiration, long intervalDuration, Serializable info)
  3, createTimer(long duration, Serializable info)
  4, createTimer(Date expiration, Serializable info)
Answer: 1
Marks: 2

=============================================================

SNo: 124
Ques: Which of the following method signatures is used to define a callback method in the callback listener class
Options:
  1, public void methodName(EntityClassType b)
  2, public void methodName()
  3, public void anyMethodName(InvocationContext ic)
  4, public Object anyMethodName(InvocationContext ic) throws Exception
Answer: 1
Marks: 2

=============================================================

SNo: 125
Ques: Which of the following is the correct signature to define a life-cycle callback interceptor method in the interceptor class
Options:
  1, public void methodName()
  2, protected void MethodName(InvocationContext ic)
  3, public Object MethodName(InvocationContext ic) throws Exception
  4, public void methodName(EntityClassType b)
Answer: 2
Marks: 2

0 Comments