Sun Java Solaris Communities My SDN Account Join SDN
 
Enterprise JavaBeans (EJB) Technology Quizzes

Enterprise JavaBeans 3.0 Simplified API Quiz

Quizzes Index


May 2006

This short quiz is based on the Simplified API introduced in the EJB 3.0 Specification. Test your knowledge of business interfaces, annotations, and default behavior of Session beans and Message Driven Beans.

Choose one answer for each question, then click Submit to see how you scored.

1. How many Local business interfaces can one EJB 3.0 Session bean have?

 A. 0
 B. 1
 C. 2
 D. As many as it wants.
 

2. Given a Session bean class with the following annotations:

private @EJB(name="fooejbref") Foo foo;
private @Resource SessionContext sessionCtx;

Which of the following could be used to retrieve the ejb dependency declared above?

 A. (Foo) sessionCtx.lookup("foo");
 B. (Foo) sessionCtx.lookup("fooejbref");
 C. InitialContext ic = new InitialContext();
(Foo) ic.lookup("java:comp/env/foo");
 D. InitialContext ic = new InitialContext();
(Foo) ic.lookup("java:comp/env/fooejbref");
 E A and C
 F B and D
 

3. Which are valid declarations for a Local business interface?

public interface Foo1 {
  public void foo();
}

import javax.ejb.Local;
@Local
public interface Foo2 {
  public void foo();
}

import javax.ejb.*;
@Local
public interface Foo3 extends EJBLocalObject {
  public void foo();
}

import javax.ejb.*;
@Local
@Remote
public interface Foo4 {
  public void foo();
}
 A. Foo1, Foo2, Foo3
 B. All of the above
 C. Foo2
 D. Foo1, Foo2
 

4. An interceptor class may contain:

 A. AroundInvoke methods.
 B. Lifecycle Callback methods.
 C. A and B
 D. None of the above.
 

5. Given the following @EJB declarations:

@EJB(beanName="foo") Foo ref1;
@EJB(beanName="foo") Foo ref2;

@EJB(beanName="bar") Bar ref3;
@EJB(beanName="bar") Bar ref4;

Where ejb "foo" is a Stateful Session bean with Local business interface Foo and ejb "bar" is a Stateless Session bean with Local business interface Bar

After injection has completed, what would be the output of the following code?

System.out.println(ref1.equals(ref2));
System.out.println(ref3.equals(ref4));
 A. false
false
 B. false
true
 C. true
false
 D. true
true
 

6. Which is a valid declaration of a PostConstruct method in a Session bean class?

public  @PostConstruct void postConstruct1() {}
private @PostConstruct void postConstruct2() {}
 A. postConstruct1
 B. postConstruct2
 C. A and B
 D. None of the above.
 

7. Given the following Message Driven Bean declaration:

@MessageDriven
public class FooMsgBean implements javax.jms.MessageListener {
  public void onMessage(Message m) { ... }
}

Assuming it is deployed without an ejb-jar.xml, which best describes the transactional nature of the onMessage method ?

 A. The bean has bean-managed transactions. It is the bean developer's responsibility to demarcate transactions within onMessage().
 B. The bean has container-managed transactions and the onMessage method has tx attribute NOT_SUPPORTED.
 C. The bean has container-managed transactions and the onMessage method has tx attribute REQUIRED.
 D. The bean has container-managed transactions and the onMessage method has tx attribute REQUIRES_NEW.
 

8. Given the following Remote business interface:

@Remote 
public interface Hello {
  public String hello();
}

Which exceptions can be received by the caller as a result of invoking the hello() method?

 A. javax.ejb.EJBException
 B. java.rmi.RemoteException
 C. A and B
 D. None of the above.
 

9. In a Stateful Session bean, dependency injection takes place:

 A. After the @PostConstruct lifecycle callback is invoked on the bean instance.
 B. Before any business methods or lifecycle callback methods are invoked on the bean instance.
 C. After the ejbCreate method is called on the bean instance.
 D. Stateful Session beans do not support dependency injection.
 

10. Which of the following results in the removal of an EJB 3.0 Stateful Session bean?

 A. Calling a business method that has been annotated with @Remove.
 B. Calling remove() on an EJBObject created from the bean's Adapted Home interface.
 C. Throwing a runtime exception from one of the bean's business methods.
 D. All of the above.
 

Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.