To get all 300 SCBCD 5.0 Questions, click here.
1) Consider the following Stateless Session Bean,
@Stateless
public class MyTestBean implements MyTestLocal
{
public void cleanResources( )
{
}
}
You want to annotate the method cleanResources() with @PreDestroy Annotation using XML Deployment Descriptor. Which of the following will correctly do that? 1.
2.
3.
4. None of the above.
2) A Stateful Session Bean by name 'ResourceAllocatorBean' has a business method by name 'allocate' along with a number of methods. You have developed an interceptor class 'net.javabeat.ejb3.LoggingInterceptor' which you want to apply to the method 'allocate' of the 'ResourceAllocatorBean'. Which of the following is the correct way to achieve that?
1.
2.
3.
4. None of the above.
3) Given the following session bean,
@Stateful
public class CounterBean implements CounterRemote
{
// Line 'A'
public int count()
{
// Line 'B'.
userTransaction.begin();
// Do something here
userTransaction.commit();
}
}
Which of the following code snippets can be inserted into the lines marked by identifiers A and B so that the above bean code will compile without any compilation errors? 1.
@Resource
private SessionContext sessionContext; // Line 'A'
Transaction userTransaction = sessionContext.getTransaction(); // Line 'B'
2.
@Resource
private SessionContext sessionContext; // Line 'A'
UserTransaction userTransaction = sessionContext.getUserTransaction(); // Line 'B'
3.
@Resource
private ApplicationTransaction transaction; // Line 'A'
UserTransaction userTransaction = transaction.getUserTransaction(); // Line 'B'
4. None of the above.
4) Which of the following is not a life-cycle method for a Stateful Session Bean?
1. Post Construction
2. Pre Destruction
3. Post Activation
4. Pre Construction
5. Pre Passivation
6. All the Above
5) Imagine that you have a business interface by name 'Template'. Which of the following ways can be used by the Client Application to acquire a reference to the business interface (assuming that this interface is bound in the JNDI Context)?
1.
@Resource
SessionContext context;
รข€¦
Template template = (Template)context.lookup("template");
2.
@EJB
Template template;
3.
Template template = null;
InitialContext context = new InitialContext();
template = (Template)Context.lookup("java:comp/ejb/template");
4. All the above.
6) Which of the following code snippets correctly declares a Message-Driven Bean by name 'TestMessageDrivenBean'?
1.
public class TestMessageDrivenBean implements javax.jms.MessageListener
{
public void onMessage(Message message)
{
// Business logic here.
}
}
2.
public class TestMessageDrivenBean implements javax.ejb.MessageListener
{
public void onMessage(Message message)
{
// Business logic here.
}
}
3.
public class TestMessageDrivenBean implements javax.ejb.MessageListener
{
public void ejbRemove()
{
}
public void setMessageDrivenContext(MessageDrivenContext context)
{
}
}
4. All the above.
7) Imagine that the Application you develop periodically sends some events to some other parts of the Application at some defined intervals. Which of the following enterprise bean(s) can be used in this scenario?
1. Entity Bean
2. Stateful Session Bean
3. Stateless Session Bean
4. Message Driven Bean
5. Timer Bean
6. None of the above.
8) Assume that your Application has created as instance of EntityManager with the following piece of code,
EntityManagerFactory factory = Persistence.createEntityManagerFactory("...");
EntityManager manager = factory.createEntityManager();
Which of the following methods can be used to check whether the handle of the EntityManager instance is valid?
1. EntityManager.isValid()
2. EntityManager.isHandleValid()
3. EntityManager.isOpen()
4. None of the above.
9) Which of the following way is used for creating an extended persistence context?
1.
EntityManager entityManager = ...;
PersistenceContext context = entityManager.createExtendedPersistenceContext();
2.
EntityManagerFactory factoy = Persistence.createEntityManagerFactory();
EntityManager entityManager = factory.createEntityManager();
PersistenceContext context =
entityManager.createPersistenceContext(PersistenceContextType.EXTENDED);
3.
@PersistenceContext(unitName = "...", type=PersistenceContextType.EXTENDED)
private EntityManager entityManager;
4. None of the above.
10) Which of the following criteria is needed to make a plain java class by name 'Employer' as an entity and that can also be transferred and accessible by a remote application?
1.
@Entity
public class Employer
{
}
2.
public class Employer extends javax.persistence.Entity
{
}
3.
@Entity
public class Employer implements Serializable
{
}
4. All the above.
Answers
1) b.
Option b is correct. The element 'lifecycle-callback-method' must be used specifying the name of the method and this element should be included within the element 'pre-destroy'.
2)4) a.
Option a is correct. This option correctly defines the elements for associating an enterprise bean and the interceptor class along with the method that should be intercepted.
3) b.
Option b is correct. The business method 'count' is trying to explicitly start a transaction, then do some business logic and finally commit the transaction. Here, since the transaction is controlled at the Application level, this transaction should be of type 'UserTransaction'. A UserTransaction object can be obtained a reference by calling the method getUserTransaction() on the Session Context object which is already initialized by the Container by applying the Annotation '@Resource'.
4) d.
Option d is correct. The life-cycle method Pre Construction is not valid for a Stateful Session Bean (as well as for any Enterprise Bean).
5) d.
All the options are correct. Options a and b using the dependency injection mechanism for initializing the business interface (from EJB 3.0). Option c uses the older style (EJB 2.1) for acquiring the reference to the business interface.
6) a.
Option a is correct. It is mandatory for a Message-Driven Bean to implement the MessageListener interface thereby overriding the onMessage() method.
7) c and d.
Options c and d are correct. It should be noted that only Stateless Session Beans and Message Driven Beans can make use of the Timer Service provided by the Container.
8) c.
Option c is correct. The method isOpen() will return true if the handle of the EntityManager is valid and it is not closed.
9) c.
Option c is correct. There is no such interface called PersistenceContext defined by the JPA Specification. A Persistence context is a virtual object that comes into existence whenever an EntityManager instance is created.
10) c.
Option c is correct. The class must be annotated with @Entity and must implement the Serializable interface (or the Externalizable interface).
To get all 300 SCBCD 5.0 Questions, click here.