O'Reilly logo

Head First EJB by Bert Bates, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Coffee Cram: Mock Exam

  1. Which statements about session beans are true? (Choose all that apply.)

    A.

    A stateful session bean is typically used to represent a row in a database

    B.

    The client must call the ejbActivate method before calling any business methods.

    C.

    A stateful session bean’s fields can contain client conversational state.

    D.

    They are typically used as asynchronous message consumers.

  2. Which list(s) correctly sequence some of the steps in a session bean’s lifecycle? (Choose all that apply.)

    A.

    ejbCreate(), newInstance(), setSessionContext()

    B.

    newInstance(), setSessionContext(), ejbCreate()

    C.

    ejbCreate(), setSessionContext(), newInstance()

    D.

    newInstance(), ejbCreate(), setSessionContext().

    E.

    setSessionContext(), newInstance(), ejbCreate()

  3. Which types of session bean instance fields can be successfully passivated and reactivated? (Choose all that apply.)

    A.

    A reference to the remote home interface.

    B.

    A reference to the UserTransaction interface

    C.

    A reference to a database cursor.

    D.

    A reference to the SessionContext object.

    E.

    A reference to a socket.

  4. Which are valid remote component interfaces for a session bean? (Choose all that apply.)

    A.

    public interface MyBean extends javax.ejb.EJBObject {
       void myMethod();
    }

    B.

    public interface MyBean extends javax.ejb.EJBObject
    throws RemoteException {
       void myMethod();
    }

    C.

    public interface MyBean extends
    javax.ejb.EJBHomeObject {
       void myMethod() throws RemoteException;
    }

    D.

    public interface MyBean extends javax.ejb.EJBObject {
        void myMethod() throws RemoteException;
    }

  5. If a client makes a call to a session object that has been removed by the container, which exceptions can be thrown? (Choose all that apply.)

    A.

    java.rmi.RemoteException

    B.

    javax.ejb.RemoveException

    C.

    java.rmi.NoSuchObjectException

    D.

    javax.ejb.NoSuchEntityException

    E.

    javax.ejb.ObjectNotFoundException

  6. Given:

    15. MyBean create(String name) throws CreateException, RemoteException;

    Which session bean interface can contain this method?

    A.

    Only stateful session beans

    B.

    Only stateless session beans

    C.

    Both stateful and stateless session beans

    D.

    Neither stateful nor stateless session beans

  7. What is true about a session bean’s lifecycle? (Choose all that apply.)

    A.

    If a business method throws a system exception the bean will be passivated.

    B.

    A passivated bean must be activated before it can be removed.

    C.

    A stateless session bean’s removal must be initiated by the client not the container.

    D.

    Stateless session beans cannot implement the SessionSynchronization interface.

  8. Which are required of the bean provider to ensure that a session bean is successfully passivated? (Choose all that apply.)

    A.

    The provider must call ejbPassivate().

    B.

    The provider must always add business logic to the ejbPassivate() method, if the bean is stateful.

    C.

    The provider must close any database connections before ejbPassivate() completes.

    D.

    The provider must assume that any state stored in instance fields marked transient will be lost.

    E.

    The provider must assume that any reference to the SessionContext object will be not survive passivation if the SessionContext object is not serializable.

  9. Given a stateless session bean with container-managed transaction demarcation, from which method(s) can you access another bean? (Choose all that apply.)

    A.

    ejbCreate()

    B.

    ejbRemove()

    C.

    a business method

    D.

    setSessionContext()

  10. (Note: The real exam has several types of ‘drag and drop’ questions, that we’re going to do a lame job of simulating with this question...)

    Match the methods on the left with the interfaces in which those methods can be found, on the right. A match is correct if the method is either declared in, or inherited by, the interface. Note: There may be some many-to-one and one-to-many relationships in your answer.

    1. afterCompletion

    2. getUserTransaction

    3. afterBegin

    4. isCallerInRole

    5. getRollBackOnly

    6. setSessionContext

    7. setRollbackOnly

    1. SessionSynchronization

    2. SessionContext

    3. SessionBean

    4. UserTransaction

  11. What is true about a session bean’s lifecycle? (Choose all that apply.)

    A.

    The container will always create a new session bean instance when the client invokes the create() method on the home interface of a stateless bean.

    B.

    The container will always call ejbRemove() when the client invokes the remove() method on a stateless bean’s home interface.

    C.

    A session bean cannot be passivated while it is in a transaction.

    D.

    The setSessionContext() method is not invoked during a stateless bean’s lifecycle

  12. Which of the following methods are container callback methods? (Choose all that apply.)

    A.

    ejbPassivate()

    B.

    setRollbackOnly()

    C.

    setSessionContext()

    D.

    getRollbackOnly()

    E.

    getUserTransaction()

  13. In what case(s) will the container fail to call ejbRemove() on a session bean? (Choose all that apply.)

    A.

    If the container crashes.

    B.

    If an application exception is thrown from a business method.

    C.

    If a timeout occurs while the bean is in the method ready state.

    D.

    If an application exception is thrown from within a transaction.

  14. Which method(s) allow both stateful and stateless session beans with bean-managed transaction demarcation to access UserTransaction methods? (Choose all that apply.)

    A.

    ejbCreate()

    B.

    ejbRemove()

    C.

    a business method

    D.

    setSessionContext()

  15. For which type of bean can the container passivate an instance that is in a transaction?

    A.

    only stateful session beans

    B.

    only stateless session beans

    C.

    both stateful and stateless session beans

    D.

    neither stateful nor stateless session beans

  16. For session beans, which are the responsibility of the Container? (Choose all that apply.)

    A.

    Invoking the local interface create() method.

    B.

    Invoking the getSessionContext() method.

    C.

    Invoking the ejbCreate() method.

    D.

    Ensuring that the ejbRemove() method is always invoked.

  17. For this drag and drop type question, you can use each element only once. Which interface should be matched with which fact, so that all four matches are correct?

    1. remote component

    2. remote home

    3. local component

    4. local home

    1. Has a getHomeHandle() method

    2. extends 'javax.ejb.EJBObject'

    3. methods must NOT throw 'java.rmi.RemoteException'

    4. can be used to retrieve an EJBLocalObject

  18. Which can be called by the container during the lifecycle of a session bean? (Choose all that apply.)

    A.

    create()

    B.

    bean constructor

    C.

    setRollbackOnly()

    D.

    getUserTransaction()

    E.

    ejbRemove()

  19. Which statements about a session bean class are true? (Choose all that apply.)

    A.

    They can be marked ‘final’

    B.

    They do not need a no-argument constructor.

    C.

    Their component interface methods can be ‘private’.

    D.

    Their business method names must start with “ejb”.

    E.

    Their ‘ejbCreate’ methods must not be declared as ‘final’.

  20. For which type of bean can the SessionSynchronization interface be implemented?

    A.

    only stateful session beans

    B.

    only stateless session beans

    C.

    both stateful and stateless session beans

    D.

    neither stateful nor stateless session beans

  21. Which statements are true for stateless session bean instances? (Choose all that apply.)

    A.

    Any instance can be used for any client.

    B.

    Conversational state must be retained across methods

    C.

    Conversational state must be retained across transactions.

    D.

    They can be passivated.

    E.

    They do not support transactions.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required