EJB FAQ's 100!!!

QUESTION NO : 1
QUESTION STATEMENT : You have written a web application using EJBs on an application server. Now the requirement to migrate the EJBs to another application server vendor arises. Which of the following types of Enterprise Java Bean will be most likely to be difficult to port from one App Server to another?

CHOICES :

a) Stateful Session Bean
b) Stateless Session Bean
c) BMP (Bean Managed Persistence) Entity Bean
d) CMP (Container Managed Persistence) Entity Bean


CORRECT ANSWER : d

EXPLANATION :
Choice D is Correct. EJBs are portable if you write them to be. Session beans and BMP (bean managed
persistence) entity beans usually port quite easily. In contrast, CMP (container managed persistence) entity beans need a
good bit of work.

Quite often, applications that rely on a clustering implementation take longer to port, as clustering is
a big differentiator between vendors and is also not addressed adequately in the EJB specification. The work might not be in
rewriting code, but in reconfiguring deployment descriptors and container/server configurations. In addition, administration
and configuration tools and mechanisms are vendor-specific, as are things like startup and shutdown scripts and sometimes
build scripts.


--------------------------------------------------------------------

QUESTION NO : 2
QUESTION STATEMENT : Which interface should be implemented by a stateful session bean if it needs to synchronize its conversational state with the transactional context ?

CHOICES :

a) javax.transaction.UserTransaction
b) javax.ejb.SessionSynchronization
c) javax.ejb.EJBContext
d) javax.transaction.TransactionContext
e) javax.ejb.SessionTransaction

CORRECT ANSWER : b

EXPLANATION :
Choice B is Correct. If a bean needs to synchronize its conversational state with the transactional context,
the bean class must implement the javax.ejb.SessionSynchronization interface. This interface contains methods to notify the
session bean when a transaction begins, when it is about to complete, and when it has completed.The enterprise bean developer
can use these methods to synchronize the state of the session enterprise bean instance with ongoing transactions.

UserTransaction provides an interface to the transaction manager that allows the application developer to manage the scope of
a transaction explicitly. So A is not the correct answer. EJBContext interface is the bean class’s interface to the container
system. It provides information about the security identity and transaction status. So C is also not the right answer. D and
E are interfaces which do not exist.


--------------------------------------------------------------------

QUESTION NO : 3
QUESTION STATEMENT : For every EJB, you write a Home Interface, Remote Interface and the Bean class. EJB doesn't require that the bean class implement these interfaces. Its encouraged that the bean class implement these interfaces. True/False?

CHOICES :

a) True
b) False


CORRECT ANSWER : b

EXPLANATION :
False, its not advisable for Bean class to implement the Remote and Home interface. The Home interface extends
EJBHome and the Remote interface extends EJBObject. These base interfaces (EJBObject and EJBHome) define a lot of other
methods that are maintained by container automatically. In case the Bean class is implementing the Remote and Home
interfaces, it becomes necessary for it to implement all those methods which are being taken care by the Container. Thus its
not advisable and discouraged for Bean class to implement Remote and Home interface.


--------------------------------------------------------------------

QUESTION NO : 4
QUESTION STATEMENT : You have an enterprise application that needs to display a large list of categories in order to let a user select from that list. The average size of the list is 100. If you decide to use Enterprise Java Beans to retrieve the data, which of the following EJB types would be the best choice in terms of performance and utilization of resources ?

CHOICES :

a) Stateless Session Bean
b) Stateful Session Bean
c) BMP Entity Bean
d) CMP Entity Bean


CORRECT ANSWER : b

EXPLANATION :
Choice B is Correct. When you are retrieving data to display in a list, you usually need only a small subset
of data. If you use a custom finder method to retrieve a large set of entity beans and utilize only a small set of data
elements, it would be a huge wastage of resources.So instead of retrieving and iterating over a collection of entity beans,
create a Stateful Session Bean that can retrieve only those pieces of data that are necessary through a simple SQL query.
Also, all entity beans are automatically distributed, transactional and persistent. There is a considerable amount of
overhead associated with each of these services. So in a situation like the above where a huge amount of data just needs to
be read and not modified, if we use entity beans, it would cause unnecessary overhead. Since the selection made by each user
needs to be stored for further operations, stateful session beans are preferred over stateless beans.


--------------------------------------------------------------------

QUESTION NO : 5
QUESTION STATEMENT : Which of the following are the differences between a Stateless Session bean and a Stateful Session Bean?

CHOICES :

a) Stateless beans define instance pooling in their lifecycle and stateful beans do not.
b) Stateful beans can have instance variables while stateless beans cannot.
c) A stateless session bean only has one ejbCreate() method which takes no arguments while a stateful bean can have any
number of overloaded ejbCreate() methods.
d) Calling the create method of EJBHome does not result in a call to the bean's ejbCreate() method in the case of a
stateless bean while it does in the case of a stateful bean.
e) The EJBObject of a stateless bean can be shared by multiple clients concurrently, but in the case of a stateful bean each
client has a dedicated EJBObject.


CORRECT ANSWER : acd

EXPLANATION :
Choice A, C and D are Correct. B and E are false. Stateless session beans can have instance variables similar
to stateful beans ,but the state of these variables are not preserved between method invocations as it is in the case of
stateful beans.With session beans of both types, the EJB object is dedicated to one client. A stateless session bean may be
used by multiple clients one after the other, but the same EJB object is not accessed concurrently by more than 1 client.

Stateless beans have only 2 states in their lifecycle, the Does Not Exist State and Method Ready Pool State. Stateful beans
are not pooled since each one is dedicated for a particular client only and hence cannot be reused. In stateless session
beans, calling EJBHome's create() method results in the creation of an EJBObject for the bean, but ejbCreate() of the bean is
not invoked. Since the state is not maintained having arguments for the create() method is illegal. The no-argument version
of ejbCreate() is invoked by the container after the bean is instantiated.


--------------------------------------------------------------------

QUESTION NO : 6
QUESTION STATEMENT : Which of the following exceptions is thrown by the ejbLoad() method of an entity bean when the database row to be loaded is not found ?

CHOICES :

a) NoSuchEntityException
b) EJBException
c) RemoteException
d) ObjectNotFoundException
e) FinderException


CORRECT ANSWER : a

EXPLANATION :
Choice A is Correct. NoSuchEntityException is a system exception thrown by the ejbLoad() method of an entity
bean when the database row to be loaded is not found and also by the ejbStore() method when the database row to be updated
cannot be found. This is a system exception which causes the container to rollback the transaction automatically.

EJBException is also a SystemException, but is called by the EJB methods only if any other system problem has occurred.
RemoteException is never thrown directly by the bean, the container throws this exception if the bean throws an EJBException.
ObjectNotfoundException is thrown by a finder method if a requested database row could not be found. FinderException is the
super class of ObjectNotFoundException.


--------------------------------------------------------------------

QUESTION NO : 7
QUESTION STATEMENT : In which of the following cases do we need to use the narrow method of PortableRemoteObject to get the correct object type from the object reference returned by the method ?

CHOICES :

a) When an EJB home reference is obtained using the javax.naming.Context.lookup() method
b) When an EJB object reference is obtained using the javax.ejb.Handle.getEJBObject() method
c) When the EJB object reference is obtained using the create() method of the home object
d) When the EJB object reference is obtained using the findByPrimaryKey() method of the home object.


CORRECT ANSWER : ab

EXPLANATION :
Choice A and B are Correct. The PortableRemoteObject.narrow() method is used to explicitly narrow the remote
reference returned by a method to a more specific type as is needed in a typical object oriented environment. The
PortableRemoteObject abstracts the narrowing process so that any underlying protocol (eg: IIOP) can be used for
narrowing.

The narrow method takes 2 arguments : the remote reference that is to be narrowed and the type it should be
narrowed to.The narrow method only needs to be used when a remote reference to an EJB object is returned without a specific
Remote interface type. In the cases A and B, the methods return a remote reference of type Object. In case A, the returned
reference needs to be narrowed to the appropriate home interface type. In case B, the returned reference needs to be narrowed
to the appropriate bean interface type. The create() and findByPrimaryKey methods defined in the home interface do not
require the use of narrow() because these methods already return the correct EJB object type. So C and D are not the right
answers.

--------------------------------------------------------------------

QUESTION NO : 8
QUESTION STATEMENT : Which of the following steps in the lifecycle of a Stateful Session bean occur for a Stateless Session Bean after the client has invoked the create() method on the EJB home?

CHOICES :

a) Container invokes Class.newInstance() method on the bean class
b) The bean instance is assigned to its EJBObject
c) Container invokes setSessionContext() method on the bean instance
d) Container invokes ejbCreate() method on the bean instance
e) Container invokes ejbRemove() method on the bean at the end of its lifecycle


CORRECT ANSWER : be

EXPLANATION :
Choice B and E are Correct. The biggest difference between a Stateful session bean and the other bean types
is that the stateful beans do not use instance pooling since they are dedicated to one client for their entire life. So when
a client invokes the create() method on an EJB home of a stateful bean, the container creates a new instance of the bean by
calling Class.newInstance(). The bean instance is now assigned to it's EJBObject. The container now invokes
setSessionContext() on the bean, handing it it's reference to the SessionContext. Finally the container invokes ejbCreate()
which matches with the create() method invoked by the client.

In the case of the Stateless session bean, the container
creates a number of stateless instances and keeps them in the method-ready pooled state.So the Class.newInstance(),
setSessionContext() and ejbCreate() are invoked by the container when the bean moves into the pooled state ready for serving
any method invocations. These methods are not re-invoked whenever a client requests a remote reference to the bean. So A, C
and D are not correct. So in stateless beans, calling the EJBHome's create() method results only in the assigning of the
EJBObject to the bean and returning the remote reference of the EJBObject to the client. So B is correct. In the case of both
types of beans, the container invokes ejbRemove() at the end of the lifecycle. So E is also correct.

--------------------------------------------------------------------


QUESTION NO : 9
QUESTION STATEMENT : Which of the following needs to be done to end the client session of a Stateful Session Bean ?

CHOICES :

a) Call the remove() method of the home object passing the primary key of the bean as the argument.
b) Call the bean's remove() method passing the Session Context of the bean as the argument.
c) Call the remove() method of the home object passing the Handle of the bean as the argument.
d) Call the remove() method of the home object passing the primary key of the bean as the argument.


CORRECT ANSWER : c

EXPLANATION :
Choice C is Correct. The EJBHome.remove() method is responsible for deleting a bean.The argument is either the
javax.ejb.Handle in the case of stateful session beans and primary key in the case of entity beans. The Handle is essentially
a serializable pointer to a specific bean. For session beans, the EJBHome.remove() on the bean ends the session's service to
the client. When EJBHome.remove() is invoked, the remote reference to the session beans becomes invalid and any
conversational state maintained by the bean is lost. If for some reason the bean can't be removed, RemoveException is
thrown


--------------------------------------------------------------------

QUESTION NO : 10
QUESTION STATEMENT : If no matching beans are found, the FindByPrimaryKey method defined in the home object of an entity bean will

CHOICES :

a) return a null reference
b) throw javax.ejb.FindException
c) throw javax.ejb.ObjectNotFoundException
d) throw RemoteException


CORRECT ANSWER : c

EXPLANATION :
Choice C is Correct. findByPrimaryKey is a standard method that all home interfaces for entity beans must
support. With Container Managed Persistence, implementations of find methods are generated automatically at deployment
time.Find methods that return a single remote reference throw a FinderException if an application error occurs and an
ObjectNotFoundException if a matching bean cannot be found.

The ObjectNotFoundException is a subtype of FinderException and
is only thrown by find methods which return single remote references. Find methods that return an Enumeration or Collection
type return an empty collection of no matching beans can be found or throw a FinderException if an application error
occurs.

--------------------------------------------------------------------

QUESTION NO : 11
QUESTION STATEMENT : Which of the following is NOT true about clients creating and finding enterprise java beans ?

CHOICES :

a) Every find method in the home interface of an entity bean should corresponding to an ejbFind() method in the bean itself.
b) Unlike entity beans, session beans do not implement find methods
c) An entity bean need not have a create() method in the home interface.
d) Find methods always return the remote-interface type for the bean
e) For CMP entity beans, implementations of the find methods are generated automatically at deployment time.


CORRECT ANSWER : d

EXPLANATION :
Choice D is Correct. Find methods of an entity bean can be of 2 types : single-entity or multi-entity
Single-entity finder methods return a remote interface type appropriate for that bean. Multi-entity finder methods return an
Enumeration or Collection type. Every find method in the home interface of an entity bean should corresponding to an
ejbFind() method in the bean itself.

Session beans do not represent an entity in the database, so they do not need find
methods. An entity bean can be designed without a create() method if it is never meant to be created by a client. Then the
entity can be only by using find() methods on the home interface. For CMP entity beans, implementations of the find methods
are generated automatically by the container at deployment time.


--------------------------------------------------------------------

QUESTION NO : 12
QUESTION STATEMENT : Which of the following interfaces provide methods to remove ejbs ?

CHOICES :

a) EJBObject
b) EJBContext
c) EJBHome
d) Context
e) SessionContext
f) EntityContext


CORRECT ANSWER : ac

EXPLANATION :
Choices A and C are correct. EJBObject and EJBHome interfaces provide the remove() method which can be used to
remove the session bean or entity bean. EJBContext interface is the bean class's interface to the container system. It
provides information about the security identity and transaction status. It also provides access to environment variables and
the bean's EJBHome. But it does not have methods to create, delete or manipulate beans in any other way. So B is not the
right choice.

SessionContext and EntityContext are specializations of the EJBContext interface. EntityContext has methods
to get an EntityBean's object reference and primary key. SessionContext provides the session bean instance with an interface
to the container. So E and F are also incorrect. D is incorrect because Context is the starting point for any JNDI lookup.
This interface represents a naming context, which consists of a set of name-to-object bindings. It contains methods for
examining and updating these bindings. So D is also a wrong choice.

QUESTION NO : 13
QUESTION STATEMENT : In which of the following scenarios would you use BMP in preference to CMP for developing an entity bean ?

CHOICES :

a) The bean's persistent data is stored in more than one data source
b) The bean's persistent data is stored in a data source that is not supported by the EJB server that you are using
c) The bean should be defined independently of the database used to store it's state.
d) The bean should be reusable and flexible across applications
e) Deployment tools are inadequate for mapping the bean instance's state to the database.


CORRECT ANSWER : abe

EXPLANATION :
Choice A, B and E are Correct. Container managed beans are the simplest to develop because they allow you to
focus on the business logic, delegating the responsibility of persistence to the EJB container.The advantage of container
managed persistence is that the bean can be defined independent of the database used to store its state. The bean state is
stored independently which makes the bean more reusable and flexible across applications.

You must use BMP if any of the
following is true about an entity bean:-The bean's persistent data is stored in more than one data source or the bean's
persistent data is stored in a data source that is not supported by the EJB server that you are using. Bean managed
persistence is also the alternative to container managed persistence when the deployment tools are inadequate for mapping
the state of the bean instance to the database.

--------------------------------------------------------------------

QUESTION NO : 14
QUESTION STATEMENT : Which of the following transaction isolation levels is the most restrictive ie; which ensures that data is NEVER accessed concurrently by transactions ?

CHOICES :

a) Read Uncommitted
b) Read Committed
c) Repeatable Read
d) Serializable


CORRECT ANSWER : d

EXPLANATION :
Choice D is Correct. Transaction isolation describe how locking is applied to data within a transaction. If
the isolation level of a method is set to Serializable, the transaction has exclusive read and update privileges to data,
other transactions can neither read nor write the same data.Dirty reads,nonrepeatable reads and phantom reads are prevented.
This is the most restricted isolation level, so it ensures that the data is always consistent.

If this isolation level is
chosen, then all transactions must wait in line to execute. This can result in a system which is very slow. So this isolation
level should be avoided wherever it is not necessary. The isolation level value of Repeatable read prohibits dirty reads and
nonrepeatable reads, but it allows phantom reads. Read committed level prohibits dirty reads, but allows nonrepeatable reads
and phantom reads. Read uncommitted level allows dirty reads, nonrepeatable reads and phantom reads.


--------------------------------------------------------------------

QUESTION NO : 15
QUESTION STATEMENT : Which of the following methods should NOT be used in the container managed transactions?

CHOICES :

a) The commit, setAutoCommit, and rollback methods of java.sql.Connection
b) The getUserTransaction method of javax.ejb.EJBContext
c) getRollbackOnly and setRollbackOnly methods of the EJBContext interface
d) Any method of javax.transaction.UserTransaction


CORRECT ANSWER : abd

EXPLANATION :
Choice A, B and D are Correct. When you use container managed transactions, we should not invoke any method
that might interfere with the transaction boundaries set by the container. The commit, setAutoCommit and rollback methods of
java.sql.Connection are used to control JDBC transactions explicitly. The getUserTransaction method of javax.ejb.EJBContext
returns a UserTransaction which is used for explicit transaction management using the Java Transaction APIs. So any method
involving the UserTransaction interface is prohibited in container managed transactions.

The EJBContext interface provides
the methods SetRollbackOnly and getRollbackOnly. The getRollbackOnly() method returns true if the current transaction has
been marked for rollback. This can be used to avoid executing work that would not be committed anyway. By invoking the
setRollbackOnly method of the EJBContext interface, the bean method instructs the container to roll back the transaction.
This power can be used if the bean detects a condition that would cause inconsistent data to be committed when the
transaction completes. These 2 methods can be used only from transactions which are container managed.


--------------------------------------------------------------------

QUESTION NO : 16
QUESTION STATEMENT : The business method of a session bean has the transaction attribute set to Required. A client attempts to invoke the bean method without a transaction context. What will be the result ?

CHOICES :

a) Container creates a new transaction context and invokes the bean method from within that context.
b) Container invokes bean methods without a transaction context.
c) TransactionRequiredException is thrown to the client.
d) TransactionNotSupportedException is thrown to the client


CORRECT ANSWER : a

EXPLANATION :
Choice A is Correct. The transaction attribute defines the transactional manner in which the container invokes
enterprise bean methods. This attribute is set for individual methods in a bean. Setting the transaction attribute to
Required, directs the container to invoke the bean method within a transaction context. If a client invokes a bean method
from within a transaction context, the container invokes the bean method within the client transaction context. If a client
invokes a bean method outside of a transaction context, the container creates a new transaction context and invokes the bean
method from within that context. The transaction context is passed to any enterprise bean objects or resources that are used
by this bean method.


--------------------------------------------------------------------

QUESTION NO : 17
QUESTION STATEMENT : A method of a stateless session bean which has a transaction attribute of TX_SUPPORTS is invoked by a client-initiated transaction.The client receives a tansactionRolledbackException. Which are the possible causes ?

CHOICES :

a) The bean method threw a RemoteException
b) The bean method threw an Application Exception
c) The bean method threw an EJBException
d) The bean method threw an Unchecked Exception


CORRECT ANSWER : d

EXPLANATION :
D is the correct choice. Regardless of the method's transaction attribute, an unchecked exception causes the
transaction to be rolled back, whether the transaction is container-initiated, client-initiated or bean-managed.Unchecked
exceptions thrown by a bean in the scope of a transaction always causes a rollback. The container catches the unchecked
exception and rethrows it to the client as a TransactionRolledbackException.

When a transaction is passed from a client to a
bean, the client defines the scope of the transaction. So application exceptions and Remote Exceptions thrown by the beans do
not automatically cause the transaction to be rolled back. So B and C are not correct. A bean does not throw RemoteException,
it is always thrown by the container itself in response to some exceptions thrown by the bean.


--------------------------------------------------------------------

QUESTION NO : 18
QUESTION STATEMENT : Which of the following method invocations on the EntityContext would cause IllegalStateException to be thrown in the case of an entity bean ?

CHOICES :

a) Invoking getEJBObject() method inside ejbCreate()
b) Invoking getEJBHome() method inside ejbFind()
c) Invoking getEJBObject() method inside ebjActivate()
d) Invoking getPrimaryKey() method inside ejbPostCreate()
e) Invoking getPrimaryKey() method inside ejbFind()


CORRECT ANSWER : ae

EXPLANATION :
A and E are the correct choices. IllegalStateException is thrown by a method of EntityContext interface if the
instance invokes this method while the instance is in a state that does not allow the instance to invoke this method.The
EntityContext is given to the bean instance at the beginning of the lifecycle, before it is made available to service any
clients. As the bean instance is swapped from one EJB object to the next, the information made available through the
entitycontext also will change. Thus though the EntityContext is always available to the bean instance, but the instance is
not always assigned to an EJBObject.

When ejbCreate() method is being executed, the bean is not associated with an
EJBObject. So calling getEJBObject() within ejbCreate() causes IllegalStateException to be thrown. So A is the right choice.
Calling getPrimaryKey() method within ejbFind method will throw IllegalStateException because when the bean is not associated with an EJBObject, its has no primary key to return. B does not cause the exception because the home object exists when any of the bean methods are invoked. C is also a valid invocation because when ejbActivate and ejbPassivate are called, the bean is already associated with an EJBObject. Though getPrimaryKey() method cannot be invoked within ejbCreate and ejbFind methods, it is valid to invoke it within ejbPostCreate() method because when this method is called, the bean already has a valid primary key.


--------------------------------------------------------------------

QUESTION NO : 19
QUESTION STATEMENT : Which of the following ACID properties specifies that a transaction should be committed only if all the tasks in it are completed successfully ?

CHOICES :

a) Atomic
b) Consistent
c) Isolated
d) Durable


CORRECT ANSWER : a

EXPLANATION :
A is the right answer. A transaction is a set of operations that transforms data from one consistent state to
another. The ACID properties that should be followed by a safe transaction are Atomicity, Consistency, Isolation and
Durability.

To be atomic, a transaction must execute completely or not at all. If at least one task in the transaction
fails, the transaction is rolled back. If all the tasks are completed successfully, the transaction is committed. Consistency
refers to the integrity of the underlying data. A transaction must transition persistent data from one consistent state to
another. If a failure occurs during processing, the data must be restored to the state it was in prior to the
transaction.

Isolation means that a transaction should be allowed to execute without interference from other transactions.
Durability means that all the data changes during the course of the transaction must be written to some type of physical
storage before the transaction is successfully completed.This ensures that the changes are not lost if the system crashes.


--------------------------------------------------------------------


QUESTION NO : 20
QUESTION STATEMENT : A web application modeling a chess game is to be developed. The application is to be built on J2EE platform using different web components like EJB's, JSP's, Servlets. Which of the following type of EJBs is most suited for representing a game of chess?

CHOICES :

a) CMP Entity Bean
b) BMP Entity Bean
c) Stateless Session Bean
d) Stateful Session Bean


CORRECT ANSWER : d

EXPLANATION :
Choice D is correct. Stateless session beans are those which do not maintain its state between client calling
its methods. Every method invocation is treated as a new interaction with the client. On the other hand, stateful session
bean maintains a state that is available to client in the subsequent calls.Entity Beans are convenient components for
business objects which represent the real life entities. For example, A Customer, A Product, An Order, A Line Item, A
Campaign Event, A Quotation etc are some entities that you might have in your CRM application.EJB 2.0 specification
introduced a new type of session bean, which is integrated with a Java Messaging Server (JMS) system.These are called Message Driven Beans (MDB). It is possible that the JMS associated with the application server, on receiving any message, would create or invoke a message driven bean.
A 'Game of Chess' would be represented by a stateful session bean because with every
call to its move() method, the state is changed and between the call to this method the state would be maintained.

--------------------------------------------------------------------

QUESTION NO : 21
QUESTION STATEMENT : You are responsible for designing and developing various web applications for your organization. You have an option to choose from various technologies and EJB is one of them. In which of the following scenarios listed below, EJB is advisable to be used ?

CHOICES :

a) Transaction Management is a concern.
b) You foresee that your application will need to scale beyond initial low usage levels. Also it will need to support
multiple and concurrent users.
c) Your application doesn't require platform independence and migration to another vendor is not a concern.
d) You want to separate web-tier from business logic.
e) Your application is a big GUI to a database.


CORRECT ANSWER : abd

EXPLANATION :
Choice A, B and D are correct. A transaction is a unit-of-work or a set of tasks that are executed together.
Transactions are atomic; in other words, all the tasks in a transaction must be completed together to consider the
transaction a success. Transactions are managed automatically, so as a bean developer you don't need to use any APIs to
explicitly manage a bean's involvement in a transaction. Simply declaring the transactional attribute at deployment time
tells the EJB server how to manage the bean at runtime. Thus choosing EJBs when transaction management is required is a wise
decision. Thus choice A is correct.
Apart from Transaction Management, the EJB container providers various other facilities
like Concurrency Service which is very useful in scenarios where a resource is simultaneosly shared by more than one user.
Thus choice B is correct.
EJBs provide standard APIs for application development. The application developed on one
Application Server can be migrated to another one with little modifications. Also being written in Java, EJB's provide
platform independence. A solution like .Net could prove successful in a situation where platform independence is not required
and being locked to single vendor is also acceptable. Thus choice C is not correct.

If your require your business logic to
be protected by a firewall, then you can deploy the web server and application server on separate machines and stick a
firewall in the middle. Thus choice D is correct.

If your application is just a big GUI to a database--heavy on data logic
but no business logic--you could achieve a deployment easily using JSPs with tag libraries connecting to a database via JDBC.
Thus EJB is not advisable in this scenario. Thus choice E is not correct.


--------------------------------------------------------------------

QUESTION NO : 22
QUESTION STATEMENT : A stateful session bean which uses bean managed transaction throws IllegalStateException when trying to commit the transaction. Which of the following is a possible reason for this ?

CHOICES :

a) The thread which calls the commit() method is no longer associated with a transaction.
b) The transaction manager encountered an unexpected error condition.
c) One of the resources involved in the transaction was unable to perform an update.
d) Heuristic decisions were made by one or more resources to roll back the transaction.
e) Heuristic decisions were made by some resources to rollback the transaction and some resources to commit.


CORRECT ANSWER : a

EXPLANATION :
A is the correct answer. Bean-managed transactions are programmatically demarcated within your bean
implementation. The transaction is completely controlled by the application. Bean managed transactions make use of
UserTransaction interface which provides methods like begin,commit and rollback for explicit transaction management. The
commit() method completes the transaction that is associated with the current thread.

This method can throw several checked
exceptions. IllegalStateException is thrown if the current thread is not associated with a transaction. So A is correct in
this case. SystemException is thrown if the transaction manager (the EJB server) encounters an unexpected error condition.
TransactionRolledbackException is thrown when the entire transaction is rolled back instead of committed; this can happen if
one of the resources was unable to perform an update or if the UserTransaction.rollBackOnly() method was called.

HeuristicRollbackException indicates that heuristic decisions were made by one or more resources to roll back the
transaction. HeuristicMixedException indicates that heuristic decisions were made by resources to both roll back and commit
the transaction; some resources decided to roll back while others decided to commit.


--------------------------------------------------------------------

QUESTION NO : 23
QUESTION STATEMENT : The following sequence of method calls occurred on a CMP entity bean instance when its business methods method1 and method2 were invoked from the same method of a client which has initiated a transaction.
entityBean.ejbLoad()
entityBean.method1()
entityBean.method2()
entityBean.ejbStore()
Which of the following MUST be true about the bean ?

CHOICES :

a) The business methods are configured with the transaction attribute of 'Never'
b) method1 and method2 are in the same transaction scope
c) method1 and method2 are in different transaction scopes
d) The business methods are NOT configured with a transaction attribute of 'Requires New'


CORRECT ANSWER : bd

EXPLANATION :
B and D are the correct answers. In container managed persistence, the ejbLoad() method is always called after
the updation of the bean's container managed fields with data from the database. ejbStore() method is called just before the
container writes the container-managed fields to the database. So typically, ejbLoad is called before a transaction and
ejbStore after a transaction.
If method1 and method2 had belonged to different transactions, ejbStore() would have been
called after the first business method invocation and ejbLoad() before the second business method call. Since that did not
happen, B is correct and C is not. The methods method1 and method2 are part of the same transaction scope.

D is true because
if the business methods had been configured with 'Requires New' option each of them would have started a new transaction of
their own. They would not have been part of the same transaction. If a bean method is configured with a transaction
attribute value of 'Never', if the calling client is part of a transaction, the bean throws a RemoteException. Since in the
above case, the bean did not throw any exception even though the client was part of a transaction, A is not true.


--------------------------------------------------------------------

QUESTION NO : 24
QUESTION STATEMENT : What value should be returned by the ejbCreate() of a CMP entity bean ?

CHOICES :

a) null
b) void
c) Primary Key object reference
d) EJBObject reference
e) Bean reference


CORRECT ANSWER : a

EXPLANATION :
Choice A is correct. The ejbCreate() method returns a null value of the primary key type for the bean.In a
CMP bean, the ejbCreate() method is called just prior to writing the bean’s container managed fields to the database. In a
CMP bean, ejbCreate() is only used to initialize the fields of the bean instance. So the return value of the ejbCreate()
method for a CMP bean is ignored.In the case of BMP beans, the ejbCreate() methods are responsible for adding the new entity
to the database. For BMP beans, it should return the primary key of the newly created entity.

--------------------------------------------------------------------

QUESTION NO : 25
QUESTION STATEMENT : An entity bean needs to invoke a method on another bean, passing itself as one of the parameters. Which of the following is the best way of achieving this ?

CHOICES :

a) Pass a this reference as the parameter for the method
b) Call the getPrimaryKey() method of the bean, get the EJBObject using the primary key and pass it as the method parameter
c) Call the getHandle() method of the bean, get the EJBObject using the handle and pass it as the method parameter
d) Call the getEJBObject() method on the EJBContext and pass it as the method parameter


CORRECT ANSWER : d

EXPLANATION :
Choice D is Correct. The getEJBObject() method in the EJBContext interface returns a remote reference to the
bean instance's EJB object.The purpose of this method is to provide the bean instance with a reference to itself when it
needs to pass itself as a method argument.The bean is provided with its entity context by the container by calling the method
setEntityContext() and EntityContext inherits EJBContext. So only one method invocation is required, which makes D the best
option.

It is illegal for a bean instance to pass a this reference to another bean, instead it passes it's remote reference
which the bean instance gets from its context.So A is not the right option. The getHandle() method returns the bean handle
which is a serializable reference to the EJB object. So it allows us to create an EJB object remote reference by calling it's
getEjbObject() method.But B is not the right option because getting the handle and then the EJBObject results in 2 method
calls.

The getPrimaryKey() returns a reference to the primary key of the bean. While the primary key can be used to get
the EJBObject using a finder method, this is also not an efficient way because it involves 2 method calls and a jndi look up
by the client. So D is the right answer.

--------------------------------------------------------------------

QUESTION NO : 26
QUESTION STATEMENT : Which of the following is the last method invoked by the container at the end of the lifecycle of an entity bean ?

CHOICES :

a) The unsetEntityContext() method
b) The ejbRemove() method
c) The ejbPassivate() method
d) The ejbStore() method


CORRECT ANSWER : a

EXPLANATION :
Choice A is Correct. When an entity bean instance leaves the instance pool to be garbage collected, the
unsetEntityContext() method is invoked by the container to alert the bean instance that it is about to be destroyed. So A is
the right answer.

B is not correct because ejbRemove() is called when the client application invokes one of the remove()
methods on the bean's ejbObject or ejbHome. With entity beans, invoking a remove method means that the entity's data is
deleted from the database. Once the ejbRemove() method has finished, the bean instance is moved back to the instance pool.
The ejbPassivate() method is called when the EJB container passivates the bean ie; the container may disassociate the bean
instance from an EJB object when it is not busy. So C is also wrong.
ejbStore() method is called just before the container
writes the container-managed fields to the database. So D is also not the right choice.


--------------------------------------------------------------------

QUESTION NO : 27
QUESTION STATEMENT : Which of the following allows an entity bean instance to obtain its own primary key and a remote reference to the EJB object ?

CHOICES :

a) EntityContext
b) InitialContext
c) Home object
d) EJBContext


CORRECT ANSWER : a

EXPLANATION :
Choice A is Correct. Entity Context is really the bean instance's interface to the container.The EntityContext
allows the bean instance to obtain its own primary key and a remote reference to the EJB object.The setEntityContext() method
is called prior to the bean instance's entry into the instance pool.

When a bean instance is associated to an EJB object,
its EntityContext changes so that the primary key and EJBObject obtainable through the entityContext match the EJBObject the
bean instance is currently associated with.After the bean instance is removed from the instance pool and before the bean
instance is garbage collected, the unsetEntityContext is invoked which indicates that the bean instance's EntityContext is no
longer implemented by the container.


--------------------------------------------------------------------

QUESTION NO : 28
QUESTION STATEMENT : Which of the following is NOT true about session beans ?

CHOICES :

a) Stateless Session beans are neither passivated nor activated.
b) A session bean does not survive server crashes.
c) Stateless session beans do not participate in instance pooling.
d) None of the above


CORRECT ANSWER : c

EXPLANATION :
Choice C is Correct. Passivation is the process of preserving the conversational state of a Stateful Session
Bean when the client is not using it. Activation is the act of restoring the saved state when the client invokes a method of
the passivated bean. Stateless session beans do not maintain the conversational state between method invocations. So they do
not need to be passivated and activated.

Instance pooling is a technique used by EJB servers to create multiple copies of
enterprise beans and then distribute them as needed. It reduces the resources needed at a time.Stateless session beans and
entity beans participate in instance pooling. Stateful session beans do not participate in pooling because they maintain the
unique state of each client and hence cannot be reused.

--------------------------------------------------------------------

QUESTION NO : 29
QUESTION STATEMENT : Which of the following are true for primary keys of entity beans ?

CHOICES :

a) Primary keys can be primitive types (int, double, long) etc.
b) All fields in the primary key class must be declared public.
c) The primary key must be serializable
d) The primary key class must implement equals() and hashcode() methods.


CORRECT ANSWER : bcd

EXPLANATION :
Choice B, C and D are Correct. Although primary keys can be primitive wrappers, primary keys cannot be
primitive types, because some of the semantics of Ejb interfaces prohibit the use of primitives.

All fields in the primary
key should be declared public so that the container can read the fields at runtime via java reflection.Since the primary key
would be used in remote invocations,it should be serializable. It should override equals and hashcode methods so that they
behave properly when invoked.


--------------------------------------------------------------------

QUESTION NO : 30
QUESTION STATEMENT : A client invokes a method on a Stateful Session bean which resulted in NoSuchObjectException. What are the possible causes ?

CHOICES :

a) The bean had already been removed by the container
b) The bean had timed out
c) The ejb server was restarted after the last method call on the bean
d) The bean is being used by another client
e) The code in the bean method caused an error
f) The method parameters passed to the method are invalid


CORRECT ANSWER : abc

EXPLANATION :
A,B and C are the correct answers. NoSuchObjectException is raised by a session bean in three situations. If
the bean does not exist because it was already removed by the container because of a remove method call or some other reason,
this exception can be thrown when a method is invoked on the bean. Timeout period for a bean is declared at deployment time.
If a bean times out, the container can remove the bean instance from the method ready state. In this case also, a method
invocation on the bean results in NoSuchObjectException.

Session beans cannot survive server crashes, so if server is
restarted after the bean creation, when the method invocation happens, this exception is thrown. Case D will never happen
because the same stateful session bean can never be accessed by more than one client. If the code in the bean method caused
an error, or if the parameters passed to the method are invalid, application exceptions or RemoteException is thrown.
So D,E
and F are not correct.

--------------------------------------------------------------------

QUESTION NO : 31
QUESTION STATEMENT : Which of the following are true about session beans implementing the SessionSynchronization interface?

CHOICES :

a) A stateless session bean should not implement the SessionSynchronization interface.
b) The session bean's instance variables can be reset to some initial values if the afterCompletion() method indicates that
the transaction was rolled back.
c) The session bean's instance variables can be reset to some initial values if the beforeCompletion() method indicates that
the transaction was rolled back.
d) The session bean should write the cached data to the database in the beforeCompletion() method
e) The beforeCompletion() method is always invoked, but the afterCompletion() method may not be invoked always.


CORRECT ANSWER : abd

EXPLANATION :
Choice A, B and D are Correct. A stateless session bean should not implement the SessionSynchronization
interface because they have no conversational state. So each method invocation of a stateless session bean must make changes
to the database explicitly. With stateful session beans we might not want to make changes to the database till the
transaction is complete ie; avoid database updates if the transaction is rolled back and postpone updates till the
transaction is committed.

The container invokes the beforeCompletion method after the business method has finished, but just
before the transaction commits. The beforeCompletion method is the last opportunity for the session bean to roll back the
transaction (by calling setRollbackOnly). If it hasn't already updated the database with the values of the instance
variables, the session bean may do so in the beforeCompletion method. The afterCompletion method indicates that the
transaction has completed. It has a single boolean parameter, whose value is true if the transaction was committed and false
if it was rolled back. If a rollback occurred, the session bean can refresh its instance variables from the database in the
afterCompletion method. So B is true and C is not.

--------------------------------------------------------------------

QUESTION NO : 32
QUESTION STATEMENT : A developer is writing a bean which has methods which read and update certain rows from a database table. The only requirement is that no other transaction should be able to make changes to the rows which have been read by the bean till the current transaction of the bean is completed. Which would be the BEST transaction isolation level for the bean ? Assume that the transaction attribute is set to Required.

CHOICES :

a) Read Only
b) Read Uncommitted
c) Read Committed
d) Repeatable Read
e) Serializable


CORRECT ANSWER : d

EXPLANATION :
Choice D is Correct. Since the requirement is that the data read by the transaction once cannot be changed by
other transactions till this transaction is completed ,we should choose Repeatable Read as the isolation level. It prevents
dirty reads and non repeatable reads. So you will be able to read each of the rows that you are modifying and then be able to
update each row knowing that none of the rows are being modified by any of the concurrent transactions. So if you choose to
reread the data at any time, the rows would have the same data.

If we use Read Committed or Read Uncommitted, another
concurrent transaction may commit data between your reads. There is no isolation level called Read Only. Serializable level
is the slowest and most restrictive. So D is a better option than E.

--------------------------------------------------------------------

QUESTION NO : 33
QUESTION STATEMENT : For Container Managed Transactions, whenever a System exception is thrown from within an EJB which of the following is handled automatically by the container ?

CHOICES :

a) Rollback the transaction
b) Throw an EJB Exception(or its subtypes) back to the client
c) Throw a RemoteException(or its subtypes) back to the client
d) Dereference and garbage collect the bean instance
e) Lets the client to recover & execute other methods of the same bean.


CORRECT ANSWER : acd

EXPLANATION :
Choice A, C and D are Correct. System exceptions are RuntimeExceptions, RemoteExceptions and their subtypes.
System exceptions always cause a transaction to roll back when thrown from a bean method. The container automatically rolls
back the transaction,logs the exception, discards the bean instance and throws a RemoteException or its subtypes when a
System Exception is thrown. The bean instance is dereferenced and garbage collected because the container assumes that the
instance maybe unstable or corrupted. If the client started the transaction, the SystemException is caught by the container
and is rethrown as TransactionRolledBackException. In other cases, the container catches the exception and rethrows its as
RemoteException. EJBException is not thrown as a result of this. The client cannot execute other methods of the same bean.

--------------------------------------------------------------------

QUESTION NO : 34
QUESTION STATEMENT : You have a CMP entity bean which includes an array of complex numbers which you want to save in the database in some appropriate format since the database does not support arrays . Which of the following callback methods would be appropriate to place the formatting code ?

CHOICES :

a) ejbCreate
b) ejbPostCreate
c) ejbPassivate
d) ejbActivate
e) ejbStore


CORRECT ANSWER : e

EXPLANATION :
E is the correct answer. The ejbStore method is called when the container decides that it is a good time to
write the entity bean's data to the database. In container-managed persistence, the bean's container-managed fields are
automatically synchronized with the database.

In most cases, we will not need the ejbLoad() and ejbStore methods because
persistence in container-managed beans is uncomplicated. We need to provide the ejbLoad and ejbStore callback methods in
container-managed beans only if more sophisticated logic is needed when synchronizing container-managed fields. Data intended
for the database can be reformatted or compressed to conserve space; data just retrieved from the database can be used to
calculate derived values for nonpersistent properties.

If we want to save an array of complex numbers in the database,
since relational databases do not support arrays, so you need to convert the array into some other format. We can use the
ejbStore() method to convert the data into the appropriate format before saving, since it will be called by the container at
that time. So E is the correct answer. To read the data back in the form of the array, we can use the ejbLoad() function
also. ejbCreate is not the right place for this, because it is called only when a new record is inserted, same applies for
ejbPostCreate. ejbPassivate is called before the bean is passivated ie; the bean instance returns to the pool. It is not
called before saving the persistent state of the bean. ejbActivate is called when the bean moves from the pooled state to the
ready state. So this is also not the place where we can put the formatting code.


--------------------------------------------------------------------

QUESTION NO : 35
QUESTION STATEMENT : Which of the following methods is used by a client to find out if a particular enterprise bean is a session bean or an entity bean ?

CHOICES :

a) isSession() method of EJBMetaData interface
b) isEntity() method of EJBMetaData interface
c) isSessionBean() method of EJBHome interface
d) isEntityBean() method of EJBHome interface


CORRECT ANSWER : a

EXPLANATION :
A is the correct answer. EJBMetaData interface describes the home interface, remote interface and primary key
classes, and also whether a bean is a session bean or an entity bean. This type of metadata is useful for Java tools like
IDEs used for building applications that use deployed enterprise Beans, and for clients using a scripting language to access
the enterprise Bean. The isSession method in the EJBMetaData interface returns true if the bean is a session bean and false
if it is an entity bean.

The EJBMetaData object is obtained by calling the function getEJBMetaData of the EJBHome class.
The EJBMetaData is not a remote interface. The class that implements this interface (this class is typically generated by
container tools) must be serializable, and must be a valid RMI/IDL value type.


--------------------------------------------------------------------

QUESTION NO : 36
QUESTION STATEMENT : One of the methods of a stateful session bean which has a transaction attribute of Supports is invoked by a non-transactional client. The stateful bean in turn invokes a method of a stateless session bean which has a transaction attribute of Mandatory. What will the possible result ?

CHOICES :

a) The container will throw TransactionNotSupported Exception
b) The container will throw TransactionRequiredException
c) The container will start a new transaction for the execution of the method of the stateless bean
d) The container will start a new transaction for the execution of the method of the stateful bean
e) The container will execute all the methods successfully without any transaction


CORRECT ANSWER : b

EXPLANATION :
B is the correct choice. The container will throw a TransactionRequiredException in this case. 'Supports'
transactional attribute means that the bean method will be included in the transaction scope if it is invoked within a
transaction, else it will be executed without a transaction scope.

When the stateful session bean which has a transaction
attribute of 'Supports' is invoked by a non-transactional client, it will also execute without a transaction. So when it
invokes a method of the stateless bean it will not be executing as part of a transaction. But for the second bean, the
transaction attribute is set to Mandatory. This attribute means that the bean method must always be part of the transaction
scope of the calling client. If the calling client is not part of a transaction, the invocation will fail, throwing a
TransactionRequiredException. So B is the choice in this case.


--------------------------------------------------------------------

QUESTION NO : 37
QUESTION STATEMENT : Which of the following EJB transaction isolation attributes ensure that dirty and non-repeatable reads do not occur?

CHOICES :

a) Serializable
b) Read Committed
c) Read Uncommitted
d) Repeatable Read


CORRECT ANSWER : ad

EXPLANATION :
A and D are the correct choices. The isolation level measures concurrent transactions' capacity to view data
that have been updated, but not yet committed, by another transaction. If other transactions were allowed to read data that
are as-yet uncommitted, those transactions could end up with inconsistent data were the transaction to roll back, or end up
waiting unnecessarily were the transaction to commit successfully.

The isolation attribute values are Read Uncommitted, Read
Committed, Repeatable Read and Serializable. Read Uncommitted: Data that have been updated but not yet committed by a
transaction may be read by other transactions. These are called dirty reads.Read Committed: Only data that have been
committed by a transaction can be read by other transactions. Repeatable Read: Only data that have been committed by a
transaction can be read by other transactions, and multiple reads will yield the same result as long as the data have not
been committed. Serializable: This, the highest possible isolation level, ensures a transaction's exclusive read-write access
to data. It includes the conditions of ReadCommitted and RepeatableRead and stipulates that all transactions run serially to
achieve maximum data integrity. This yields the slowest performance and least concurrency. Thus dirty reads and
non-repeatable reads can be avoided by using the trasaction isolation attributes of Serializable or Repeatable Read.So A and
D are correct.


--------------------------------------------------------------------

QUESTION NO : 38
QUESTION STATEMENT : You are adding a Customer EJB to a Telecom Enterprise application. The Operator role should be allowed to create a customer. Which of the following method permission settings will enable this ?

CHOICES :

a) Create a Method Permission mapping the Operator role to all the methods in the Customer EJB
b) Create a Method Permission mapping the Operator role to all the home methods of the Customer EJB
c) Create a Method Permission mapping the Operator role to the ejbCreate method in the Customer EJB
d) Create a Method Permission mapping the Operator role to the create method in the Customer EJB home


CORRECT ANSWER : bd

EXPLANATION :
B and D are the correct choices. A method permission is a mapping between one or more security roles and one
or more methods that a member of the role can invoke. To create an instance of the Customer bean, the method to be called by
the client is the create method in the home object of the Customer EJB.

Method permission can be set to all the bean
methods, a particular bean method, all the home methods or a particular home method. So in this case to give the operator
role the permission to call the create method in the EJB home, we can either set the Method Permission mapping the operator
role to all the home methods of the Customer bean or only to the create method in the home of Customer EJB.Setting permission
to all the bean methods or the ejbCreate method of the bean will not help.So A and C are wrong answers.

--------------------------------------------------------------------

QUESTION NO : 39
QUESTION STATEMENT : A JDBC data source resource for a DB2 database has been configured in the deployment descriptor of a bean with the logical name of 'mysource'. Which of the following paths would be used to access it from the bean using JNDI look up ?

CHOICES :

a) java:comp/env/mysource
b) java:comp/env/jdbc/mysource
c) java:comp/env/db2/jdbc/mysource
d) java:comp/env/jdbc/db2/mysource


CORRECT ANSWER : a

EXPLANATION :
A is the correct answer. All deployed beans,environment properties and external resources like data sources
are mapped to a set of JNDI entries which exist in a namespace called the environment naming context(ENC) or default JNDI
context. When developing a bean, the bean developer can identify the types of resources and enterprise beans that will be
referenced in the bean and bind them to the ENC.

Using java:comp/env namespace within the enterprise bean lets the bean
locate external information without prior knowledge of how the external information is named and organized in the target
operational environment. Using this naming context will not tie up a bean with the JNDI name of a resource that is known only
at the time of deployment. The default context exists in the namespace called "java:comp/env" and its subdirectories. When
the bean is deployed all the beans and resources it uses are mapped into this directory. Thus in this case the bean can look
up the data source using its logical name "mysource" by specifying java:comp/env/mysource.

Though this works, it is
advisable to keep a subcontext which describes the resource type. ( eg: ejb/ for beans, jdbc/ for JDBC DataSource factory
and so on). So if the resource is given a logical name as jdbc/mysource, to look up the resource, you say
java:comp/env/jdbc/mysource


--------------------------------------------------------------------

QUESTION NO : 40
QUESTION STATEMENT : The env-ref element in the deployment descriptor of an enterprise bean is used to define

CHOICES :

a) references to other beans
b) references to external resources
c) references to environment entries
d) references to security roles


CORRECT ANSWER : a

EXPLANATION :
A is the correct answer. The env-ref element in the deployment descriptor is used to define references to
other beans within the JNDI ENC. This makes it much easier for beans to reference other beans, they can use JNDI to look up a
reference to the home interface for any beans they are interested in. So A is right. For external resources, mapping is
performed by the resource-ref element. To define environmental entries, env-entry element is used.The security-role-ref
element is used to define the secuirity roles that are used by a bean.


--------------------------------------------------------------------

QUESTION NO : 41
QUESTION STATEMENT : Which of the following are valid for bean managed transactions ?

CHOICES :

a) A Stateful Session bean must start and end a transaction within one method, since it serves multiple clients.
b) A Stateful Session bean's transactions can span multiple methods, since it serves only one client.
c) A Stateless Session bean's transactions must start and end in the same method, since it serves multiple clients.
d) A Stateless Session bean's transactions can span multiple methods, since it serves only one client.


CORRECT ANSWER : bc

EXPLANATION :
B and C are the correct answers. Bean managed transactions are explicit transactions managed by the bean, for
which the bean makes use the UserTransaction interface. In EJB, implicit transaction management is provided on the bean
method level, so transactions execute within the scope of the method. But rarely explicit control on transactions is required
which is achieved by calling the methods of the UserTransaction interface.

With stateless session beans, transactions that
are managed using the UserTransaction must be started and completed within the same method. This is required because
stateless session bean instances are shared across multiple clients. With stateful session beans, a transaction can begin in
one method and be committed in another because a stateful bean is not used by more than one client.Thus a stateful bean
instance can associate itself with a transaction across different client-invoked methods.

--------------------------------------------------------------------

QUESTION NO : 42
QUESTION STATEMENT : Which of the following enterprise beans allow multithreaded access ?

CHOICES :

a) Stateful Session Bean
b) Reentrant Entity Bean
c) Activated Stateless Session Bean
d) Concurrent Stateless Session Bean
e) BMP Entity Bean


CORRECT ANSWER : b

EXPLANATION :
B is the right answer. Reentrance is when a thread of control attempts to reenter a bean instance.In EJB, bean
instances are non-reentrant by default, that means loopbacks are not allowed. Session beans can never be reentrant and they
throw a RemoteException if a loopback is attempted. The same is true of a non-reentrant entity bean. Entity beans can be
configured in the deployment descriptor to allow reentrance at deployment time. If you permit reentrance you also permit
multithreaded access to the bean instance.

Multithreaded access to a bean instance can result in corrupted data because
threads interfere with each other. So declaring an entity bean as reentrant is discouraged in the EJB specifications, unless
you have a very good reason of doing so.A, C and D are wrong because session beans cannot be reentrant in any case. E is
wrong because entity beans are not reentrant unless they are declared so.


--------------------------------------------------------------------

QUESTION NO : 43
QUESTION STATEMENT : Which of the following are valid differences between ejbCreate() and ejbPostCreate() methods of a CMP entity bean ?

CHOICES :

a) The bean identity is not available to the bean during the call to ejbCreate(), but is available in the ejbPostCreate()
method.
b) The caller's identity is not available to the bean during the call to ejbCreate(), but it is available in the
ejbPostCreate() method
c) ejbCreate() returns null while ejbPostCreate() returns void
d) ejbCreate() should have the same parameters as the calling create() method, but ejbPostCreate() does not take the same
parameters.
e) ejbCreate() is called before the insertion of a record into the database, while ejbPostCreate() is called after the
record insertion.


CORRECT ANSWER : ace

EXPLANATION :
A,C and E are the correct answers. In a CMP bean, the ejbCreate() method is called just prior to writing the
bean's container managed fields to the database. Values passed in to the ejbCreate() method should be used to initialize the
fields of the bean instance. Once the ejbCreate() method completes, the new record with these values are written to the
database tables. The EntityContext maintained by the bean instance does not provide it with proper identity till the
ejbCreate() method has completed. So inside the ejbCreate() method, the bean instance doesn't have access to it's primary key
or EJBObject. So A is correct.

B is not correct because EntityContext methods like getCallerPrincipal() and
isCallerInRole() can be called from ejbCreate() since user details and environment properties are available at this time. So
B is not correct. C is true because the return value of ejbCreate() is null while ejbPostCreate() does not return anything. D
is not correct because ejbCreate() and ejbPostCreate() both take the same set of parameters. E is also correct, ejbCreate()
is called prior to insertion of records while ejbPostCreate() is called after that.

--------------------------------------------------------------------

QUESTION NO : 44
QUESTION STATEMENT : Which of the following events take place first after the call of ejbCreate() method on a CMP entity bean ?

CHOICES :

a) Insertion of a record into the database
b) Calling ejbPostCreate() method
c) EJB object stub returned to the client
d) Associating the EJB Object with the bean instance


CORRECT ANSWER : a

EXPLANATION :
A is the correct choice. In a container-managed bean, the ejbCreate() method is called just prior to writing
the bean's container-managed fields to the database. Values passed in to the ejbCreate() method should be used to initialize
the fields of the bean instance. Once the ejbCreate() method completes, a new record, based on the container-managed fields,
is written to the database. Once the record has been inserted into the database, the bean instance is ready to be assigned to
an EJB object.

Once the bean is assigned to an EJBobject, the bean's identity is available. This is when the ejbPostCreate()
method is invoked. Finally, when the ejbPostCreate() processing is complete, the bean is ready to service client requests.
The EJB object stub is created and returned to client application, which will use it to invoke business methods on the
enterprise bean. So the order of execution in this case would be A,D,B and C.A is the correct answer because the record
insertion is the first event to take place after ejbCreate().

--------------------------------------------------------------------

QUESTION NO : 45
QUESTION STATEMENT : Which of the following features should be avoided in the implementation of Enterprise Java Beans ?

CHOICES :

a) Declaring static, final fields
b) Loading classes
c) Using file access
d) Loading native libraries
e) thread creation and management
f) Listen to or accepting connections on a socket


CORRECT ANSWER : cdef

EXPLANATION :
Choices C,D,E and F are the correct answers. EJB component providers/developers should be aware of and
strictly follow certain restrictions in the interest of developing reliable and portable EJB components. Nonfinal static
class fields are disallowed because enterprise bean instances will behave differently depending on whether or not they are
distributed.

It is acceptable practice to use static class fields if those fields are marked as final. Since final fields
cannot be updated, instances of the enterprise bean can be distributed by the container without concern for those fields'
values becoming unsynchronized. So A is incorrect.
Loading classes are allowed, so B is incorrect.C is correct- Enterprise
beans aren't allowed to access files primarily because files are not transactional resources. Allowing EJBs to access files
or directories in the filesystem, or to use file descriptors, would compromise component distributability, and would be a
security hazard.

D is correct because EJBs are not allowed to load native libraries since it affects portability,stability
and security. E is correct- EJBs are not encouraged to use threads because allowing enterprise bean instances to create and
manage threads would interfere with the container's ability to control its components' lifecycle.F is correct, EJBs are not
allowed to listen to or accept socket connections. If an enterprise bean is listening on a socket, it can't be passivated -
it must always be available. Enterprise beans can be network socket clients, and so they can use other network resources
(including other enterprise bean servers) to do their jobs.


--------------------------------------------------------------------

QUESTION NO : 46
QUESTION STATEMENT : A stateful session bean's conversational state has the following types of variables. Which of the them do NOT get restored after passivation and activation of the bean ?

CHOICES :

a) SessionContext
b) EJBContext
c) transient variables
d) Handle
e) EJBHome
f) EJBObject


CORRECT ANSWER : adef

EXPLANATION :
Choices A,D,E and F are correct. When a stateful bean is passivated, the conversational state of the bean is
written to the secondary storage associated with the EJBObject. When the bean is activated, the saved state is restored. A
bean's conversational state should consist of only primitive values, objects that are serializable and these special types-
SessionContext, EJBHome, EJBObject, UserTransaction and Context (only when it references the JNDI ENC). So A,E and F are
correct.

D is correct because Handle is a serializable reference to the EJBObject.Transient variables will not be preserved
when the bean is passivated.So C is not the right option. B is not correct because EJBContext does not implement
Serializable. So it will not be preserved during bean passivation.

--------------------------------------------------------------------

QUESTION NO : 47
QUESTION STATEMENT : Which method can be called on the EJBContext to obtain information about the user making the EJB method invocation ?

CHOICES :

a) getCallerPrincipal()
b) getPrincipal()
c) getRemoteUser()
d) getUserPrincipal()


CORRECT ANSWER : a

EXPLANATION :
Choice A is Correct. The servlet and EJB specifications provide different mechanisms to programmatically
obtain identity information about the user invoking a method on a secure servlet or an EJB. getCallerPrincipal() is the
method in the EJBContext interface used by a bean to track the identity of the client accessing the bean.

To get the name
of the client, we have to only invoke getName() method on the Principal object returned by getCallerPrincipal() method. B is
not correct because there is no such method called getPrincipal(). C and D are applicable only to servlets. Invoking the
getRemoteUser method on the HttpRequestObject returns the name of the user who is invoking the servlet. The getUserPrincipal
method on the HttpRequestObject returns the Principal object corresponding to the user who is invoking the servlet.

--------------------------------------------------------------------

QUESTION NO : 48
QUESTION STATEMENT : A developer is creating a Java tool which will have wizards for interacting with an enterprise bean from a client's perspective. He uses EJBMetaData interface for getting details about the bean. Which of the following information is NOT directly obtained using this interface ?

CHOICES :

a) Whether the EJB is a session or an entity bean
b) The home interface class of the EJB
c) The primary key class of the EJB
d) The remote interface class of the EJB
e) The bean class of the EJB


CORRECT ANSWER : e

EXPLANATION :
Choice E is Correct. The javax.ejb.EJBMetaData interface has methods to get the home interface, remote
interface and primary key classes of the EJB. It also has a method to get the information about the type of the bean -
whether it's a session bean or an entity bean. There is no way to get the bean class using EJBMetaData because the bean class
is not part of the client API and hence does not belong to the metadata.

The getEJBMetaData() method of the EJBHome
interface returns an instance of EJBMetaData. A tool can have wizards which use the class definitions provided by the
EJBMetaData with Java reflection to interact with a bean. A class which implements EJBMetaData should be Serializable, which
allows these tools to save the EJBMetaData object for later use.

--------------------------------------------------------------------

QUESTION NO : 49
QUESTION STATEMENT : When a BMP entity bean instance is activated from the pooled state to the ready state which of the following does NOT happen ?

CHOICES :

a) The bean leaves the instance pool to be assigned to an EJB object
b) The non-persistent fields of the bean are deserialized from secondary storage and assigned.
c) Container invokes ejbLoad() to notify the bean that its persistent fields have been synchronized
d) Non-persistent fields contain arbitrary values (dirty values) and need to be reinitialized in the ejbActivate() method.
e) Container invokes setEntityContext() method on the bean.


CORRECT ANSWER : be

EXPLANATION :
Choice B and E are correct. When an entity bean is activated, the bean instance leaves the instance pool to be
assigned to an EJB object. Once assigned to an EJBObject, the ejbActivate() method is called . For entity beans, the
non-persistent fields are not serialized to secondary storage at the time of passivation as done for Stateful Session Beans.
So at the time of activation, they are not deserialized. These fields contain arbitrary values(dirty values) and must be
reinitialized in the ejbActivate() method.


--------------------------------------------------------------------

QUESTION NO : 50
QUESTION STATEMENT : Which of the following is NOT true about defining methods in a CMP entity bean class ?

CHOICES :

a) The bean class's business methods should throw javax.ejb.RemoteException
b) For every create() method defined in the entity bean's home interface, there must be a corresponding ejbPostCreate()
method in the bean instance class.
c) For every create() method defined in the entity bean's home interface, there must be a corresponding ejbCreate() method
in the bean instance class.
d) The ejbPostCreate() method always returns void.


CORRECT ANSWER : a

EXPLANATION :
Choice A is Correct. The bean class's business methods are not required to throw RemoteException. This is
because these methods are not actually invoked remotely, they are invoked by the EJB object. If a communication failure
occurs, the container will throw the RemoteException for the bean automatically.For every create() method defined in the home
interface, there should be matching ejbCreate() and ejbPostCreate() methods defined in the bean class.The ejbPostCreate()
method must have the same parameters as the corresponding Create() method, but returns void.

--------------------------------------------------------------------

QUESTION NO : 51
QUESTION STATEMENT : Which of the following transaction attributes can be specified only for session beans and also cannot be specified for individual methods ?

CHOICES :

a) Bean Managed
b) Mandatory
c) Supports
d) Not Supported


CORRECT ANSWER : a

EXPLANATION :
Choice A is correct. The transaction attribute defines the transactional manner in which the container invokes
enterprise bean methods. If the transaction attribute is set to BeanManaged, it notifies the container that the bean class
directly handles transaction demarcation. This attribute value can be specified only for session beans and it cannot be
specified for individual bean methods.

If the transaction attribute is set to Mandatory, it directs the container to always
invoke the bean method within the transaction context associated with the client. If the transaction attribute is set to
Supports, it directs the container to invoke the bean method within a transaction context if the client invokes the bean
method within a transaction. If the transaction attribute is set to NotSupported, it directs the container to invoke bean
methods without a transaction context.

--------------------------------------------------------------------

QUESTION NO : 52
QUESTION STATEMENT : Which of the following statements about EJBs is NOT true ?

CHOICES :

a) A single entity bean instance can be shared by multiple clients.
b) Session beans cannot be reentrant and they throw a RemoteException if loopback is attempted.
c) A stateful bean instance is swapped among many EJB objects, it is not possible to predict which instance will service a
method call.
d) Session beans do not survive server crashes


CORRECT ANSWER : c

EXPLANATION :
Choice C is Correct because it is not true. Entity beans represent data in the database that is shared and
needs to be accessed concurrently. So many clients are allowed to use the same entity bean instance simultaneously.
Reentrance is when a thread of control attempts to reenter a bean instance. In EJB, bean instances are reentrant by default
which means that loopbacks are not allowed. Entity beans can be configured in the deployment descriptor to allow reentrance
at deployment time.

Session beans can never be reentrant, and they throw a RemoteException if a loopback is attempted.
Option C is true for a stateless session bean, not for a stateful bean. Since a stateless session bean does not store a
client’s state, it does not matter which bean instance serves a particular client. But in the case of Stateful Beans, it is
not possible to swap the same instance between different clients since a particular instance serves only one client. Since
session beans are not persistent, they do not survive server crashes.


--------------------------------------------------------------------

QUESTION NO : 53
QUESTION STATEMENT : Which of the following is true about comparing beans for identity ?

CHOICES :

a) The EJBObject.isIdentical method returns true if two EJB object references represent the same bean, even if the EJB
object stubs are different object instances.
b) For stateful session beans, if 2 EJB objects refer to the same type of bean, they are always considered identical.
c) Even if two entity EJB objects have the same home and same primary key, they may not be identical.


CORRECT ANSWER : a

EXPLANATION :
Choice A is Correct. An EJB object is a distributed object stub and therefore contains a lot of networking and
other state. As a result, references to 2 EJB objects maybe unequal, even if they both represent the same unique bean.

The
EJBObject.isIdentical method returns true if two EJB object references represent the same bean, even if the EJB object stubs
are different object instances.Since stateless beans do not retain the conversational state, they are considered identical if
they are of the same type. But stateful session beans are not considered to be identical just because they are of the same
type since they maintain the conversational state of the clients. For entiy beans, if they have the same home and primary
key, they are considered to be identical.


--------------------------------------------------------------------

QUESTION NO : 54
QUESTION STATEMENT : The Passivation mechanism of stateful session bean is different from that of entity bean. True/False?

CHOICES :

a) True
b) False


CORRECT ANSWER : a

EXPLANATION :
Yes, Passivation in stateful session beans is different than for entity beans. In stateful beans, passivation
means the bean's conversational-state is written to a secondary storage (often disk) and the instance is removed from memory.
The client's reference to the bean is not affected by passivation, it remains alive and usable while the bean is passivated.
When the client invokes a method on a bean that is passivated, the container will activate the bean by instantiating a new
instance and populating its conversational-state with the state written to secondary storage.

Stateful session beans, unlike
stateless beans (which do not use passivation), do use the ejbActivate() and ejbPassivate() methods.

Passivation in entity
beans means that the bean instance is disassociated with its remote reference so that the container can evict it from memory
or reuse it. Some containers will remove beans from the memory, while others will reuse instances for other more active
remote references.


--------------------------------------------------------------------

QUESTION NO : 55
QUESTION STATEMENT : You have to design a web application to implement the royalty points program of a Sports Club. Whenever a member uses the services of the club he get some points called royalty points. Each member has its royalty point structure for various sports. At the end of each quarter, the top 10 members gets some prizes and discounts. You already have a database which consists of Members Table and other Table for Royalty Points Structure (the tables are related with foreign key). In WebSphere Application Server (Advanced Edition), which of the following type of Entity Bean will be more suitable to represent Member and Royalty Point Structure?

CHOICES :

a) CMP
b) BMP
c) Both are equally suitable
d) Neither CMP nor BMP will solve the problem.


CORRECT ANSWER : b

EXPLANATION :
Choice A is correct. If we take the approach of making both the Member and Royalty Point Structure as CMP
Entity EJBs then we find that to obtain a Member and its Royalty Points we need to use two SQL SELECT statements : one to
select the Member from the Member table and another to select his/her Royalty Points from another table.

Actually there is
no need for 2 Select statements as in SQL we can retrieve the data in both the Member and the Royalty Point objects with a
single SELECT statement using a join if the two tables are linked by a foreign key relationship. Note that if you want to get
results from multiple tables from a SELECT statement, you do this by joining tables:

SELECT * from table1,table2 where
table1.id = table2.id;

The problem is that while you can do this in SQL, it isn't possible do this in the current
implementation of CMP in the WebSphere AE. VisualAge for Java does generated code for WebSphere AE to handle simple
relational joins with Entity EJBs, but only where two tables share the same primary key. It will not handle generally foreign
key relationships like the one described above.

Thus the solution to above problem is to use the BMP Bean. In fact we may
not need to represent Royalty Point at EJB, but a Java Bean that the Member EJB will create and return when asked for Royalty
Points. We can create this Royalty Points Beans in the ejbLoad() method of our Member BMP EJB.

The performance between CMP
and BMP EJB implementation will be much more visible when we need to find even more information about the Member.

--------------------------------------------------------------------

QUESTION NO : 56
QUESTION STATEMENT : Which of the following interfaces provide methods to remove ejbs ?

CHOICES :

a) EJBObject
b) EJBContext
c) EJBHome
d) Context
e) SessionContext
f) EntityContext


CORRECT ANSWER : ac

EXPLANATION :
Choices A and C are correct. EJBObject and EJBHome interfaces provide the remove() method which can be used to
remove the session bean or entity bean. EJBContext interface is the bean class's interface to the container system. It
provides information about the security identity and transaction status. It also provides access to environment variables and
the bean’s EJBHome. But it doesn’t have methods to create,delete or manipulate beans in any other way. So B is not the right
choice.

SessionContext and EntityContext are specializations of the EJBContext interface. EntityContext has methods to get
an EntityBean’s object reference and primary key. SessionContext provides the session bean instance with an interface to the
container. So E and F are also incorrect. D is incorrect because Context is the starting point for any JNDI lookup. This
interface represents a naming context, which consists of a set of name-to-object bindings. It contains methods for examining
and updating these bindings. So D is also a wrong choice.


--------------------------------------------------------------------

QUESTION NO : 57
QUESTION STATEMENT : Which of the following are true for a client performing a jndi lookup on an enterprise java bean ?

CHOICES :

a) A JNDI client always needs to explicitly set one or more properties used by the InitialContext constructor.
b) Any property values passed in directly to the InitialContext constructor are overwritten by the settings of those same
properties found elsewhere in the environment
c) The lookup() method of InitialContext throws NamingException
d) When using JNDI to access a bean, you obtain a remote reference, or stub, to the bean's EJB home


CORRECT ANSWER : cd

EXPLANATION :
Choice C and D are Correct. An initial context is the starting point for any JNDI lookup.
Javax.Naming.InitialContext class is the starting context for performing naming operations.The lookup() method of the
javax.Naming.InitialContext throws NamingException if naming resolution failed. To construct an initial context using the
supplied environment, the client can set the environment properties and pass it as an argument to the InitialContext
constructor. But since InitialContext also has a default constructor which creates an InitialContext object with default
settings.

In general, JNDI clients should assume the correct environment is already configured so there is no need to
explicitly set property values and pass them to the InitialContext constructor. However, a JNDI client may need to access a
name space other than the one identified in its environment. In this event, it is necessary to explicitly set one or more
properties used by the InitialContext constructor. So A is not true. B is also not true because any property values passed in
directly to the InitialContext constructor take precedence over settings of those same properties found elsewhere in the
environment.

--------------------------------------------------------------------

QUESTION NO : 58
QUESTION STATEMENT : Which of the following elements needs to be provided in the deployment descriptor of a session bean to make it a bean-managed transaction bean ?

CHOICES :

a) <transaction-type>Bean</transaction-type>
b) <transaction-attribute>Bean Managed</transaction-type>
c) <bean-transaction>true</bean-transaction>
d) <trans-attribute>Bean></trans-attribute>


CORRECT ANSWER : a

EXPLANATION :
Choice A is Correct. In Ejb1.1, only session beans with a <transaction-type> value of 'Bean' can be bean
managed transaction beans. Beans that manage their own transactions do not declare transaction attributes for their methods.
The transaction type element can have one of 2 values: Bean or Container. A bean that manages its own transactions will not
have container-transaction declarations in the deployment descriptor. The <container-transaction> element declares which
transactional attributes apply to which methods.


--------------------------------------------------------------------

QUESTION NO : 59
QUESTION STATEMENT : While testing a CMP entity bean, the developer discovers that the current transaction is being automatically rolled back by the container because of an exception thrown by one of the bean methods. Possible causes for the exception are?

CHOICES :

a) The entity bean's row cannot be deleted from the database
b) The database row to be updated cannot be found.
c) The database row to be loaded cannot be found
d) The database row for the requested entity bean is cannot be found.
e) An input parameter to the ejbCreate() method is invalid.


CORRECT ANSWER : bc

EXPLANATION :
Choice B and C are Correct. If a system exception occurs within a transaction, the EJB container rolls back
the transaction. However, if an application exception is thrown within a transaction, the container does not roll back the
transaction. If an entity bean's row cannot be deleted from the database the exception thrown is RemoveException which is an
application exception.If the requested database row is not found, the exception thrown is ObjectNotFoundException which is
also an application exception.

If the input parameter to the ejbCreate() method fails the exception which occurs is
CreateException which again is an application exception. So in the above cases, the container will not perform an automatic
rollback of data. The ejbLoad method throws NoSuchEntityException when the database row to be loaded is not found. The
ejbStore method throws the same exception when the database row to be updated is not found. This is a System Exception. So
the container will do an automatic rollback in these 2 cases.


--------------------------------------------------------------------

QUESTION NO : 60
QUESTION STATEMENT : Which of the following are recommended practices to be performed in the ejbPassivate() method of a stateful session bean ?

CHOICES :

a) Close any open resources, like database connections
b) All non-transient, non-serializable fields(except some special types) should be set to null.
c) All transient fields should be set to null
d) Make all database connection reference fields transient
e) All primitive type fields should be set to null


CORRECT ANSWER : abd

EXPLANATION :
A,B and D are the correct answers.When a bean is about to be passivated, its ejbPassivate() method is invoked,
alerting the bean instance that it is about to enter the Passivated state. At this time, the bean instance should close any
open resources and set all nontransient, nonserializable fields to null. This will prevent problems from occurring when the
bean is serialized.Transient fields will simply be ignored.Serializable fields will be saved.Open resources such as sockets
or JDBC connections must be closed whenever the bean is passivated. In stateful session beans, open resources will not be
maintained for the life of the bean instance. When a stateful session bean is passivated, any open resource can cause
problems with the activation mechanism.
A bean's conversational state may consist of only primitive values, objects that are
serializable, and the following special types-SessionContext, EJBHome, EJBObject, UserTransaction and Context (only when it
references the JNDI ENC) . The types in this list (and their subtypes) are handled specially by the passivation mechanism.
They don't need to be serializable; they will be maintained through passivation and restored automatically to the bean
instance when it is activated


--------------------------------------------------------------------

QUESTION NO : 61
QUESTION STATEMENT : A client performs an update on an existing record in the database using a CMP entity bean. Which of the following methods of the bean are SURELY invoked in the process ?

CHOICES :

a) ejbCreate
b) ejbRemove
c) ejbFind
d) ejbLoad
e) ejbStore


CORRECT ANSWER : cde

EXPLANATION :
C,D and E are the correct answers. When a client tries to update an existing record in the database, it has to
first locate the entity which represents this record in the database. For that it used a find method in the home interface
which return either an object implementing the bean's remote interface or a collection of such objects in the form of a
Enumeration or Collection. These find methods result in a call to the ejbFind methods in the bean class, which return either
a primary key for the appropriate bean or a collection of primary keys. So C is correct since ejbFind will be definitely
called in this case.

ejbCreate is not called because this method is invoked only when the client tries to create a new
record in the database. So here since client is only trying to update, this method is not called. ejbRemove is called only
when a client tries to delete a record from the database, so B also does not happen in this case. ejbLoad and ejbStore
methods are definitely called in the case of a CMP bean. ejbLoad is called before data from the table is loaded into the
bean, and ejbStore just before storing the bean's data into the database. These methods are automatically called by the
container at appropriate times in the case of CMP beans. So ejbFind,ejbLoad and ejbStore methods are called in this case.


--------------------------------------------------------------------


QUESTION NO : 62
QUESTION STATEMENT : The home of a Product CMP entity bean has a finder method that returns an Enumeration of all the products whose price falls below a certain value that is passed as the method argument. If there are no products in the database to match the above criteria what will be the result of a call to this finder method?

CHOICES :

a) EJBException is thrown
b) ObjectNotFoundException is thrown
c) NoSuchEntityException is thrown
d) An empty enumeration is returned


CORRECT ANSWER : d

EXPLANATION :
Choice D is correct.

Find methods that return an Enumeration or Collection type return an empty collection or enumeration if no matching beans can be found or throw a FinderException if an application error occurs. So in this case, when there are no matching products in the database, an empty enumeration is returned.

Find methods that return a single remote reference throw a FinderException if an application error occurs and an
ObjectNotFoundException if a matching bean cannot be found. The ObjectNotFoundException is a subtype of FinderException and is only thrown by find methods that return single remote references. Therefore, choice B is not correct.

The findByPrimaryKey() method returns only one remote reference since there is a one-to-one relationship between a primary key's value and an entity. NoSuchEntityException is a system exception thrown by the ejbLoad() method of an entity bean when the database row to be loaded is not found and also by the ejbStore() method when the database row to be updated cannot be found. It is a subclass of EJBException. Therefore, choices A and C are incorrect.

--------------------------------------------------------------------

QUESTION NO : 63
QUESTION STATEMENT : Which of the following happens as part of the passivation process of a CMP entity bean?

CHOICES :

a) The instance fields are serialized and held with the EJBObject
b) ejbPassivate() method of the bean is invoked
c) ejbStore() is invoked
d) Bean instance is disassociated from the EJB Object
e) ejbLoad() is invoked


CORRECT ANSWER : bcd

EXPLANATION :
Choices B, C and D are correct.

The container never serializes an instance of an Entity bean. For this bean, passivation involves moving the bean from the
ready state to the pooled state. Therefore, choice A is incorrect.

When an entity bean is passivated, the instance is logically disassociated from its remote object. Therefore, choice D is
correct.

ejbPassivate() is invoked as part of passivation and can be used to release any resources. ejbStore() is called by the
container to synchronize the bean instance's state with the database prior to passivating the bean. Therefore, choices B and
C are correct.

ejbLoad() is not invoked as part of passivation. Therefore, choice E is incorrect.


--------------------------------------------------------------------

QUESTION NO : 64
QUESTION STATEMENT : Which is the only method defined in the javax.ejb.Handle interface?

CHOICES :

a) getEJBHome
b) getEJBObject
c) getPrimaryKey
d) getHomeHandle


CORRECT ANSWER : b

EXPLANATION :
Choice B is correct.

The Handle is a serializable reference to the EJBObject. The Handle allows us to recreate an EJB object remote reference that points to the same type of session bean or the same unique bean that the handle came from. The Handle interface specifies only one method, getEJBObject(). Calling this method returns the EJB Object from which the handle was created. After getting the object back, we can narrow or cast it to the appropriate remote interface type.

The getEJBHome method is defined in the HomeHandle interface and the getPrimaryKey method in the EntityContext interface. The getHomeHandle method is defined in the EJBHome interface. Therefore, choices A, C, and D are incorrect.

The EJBObject.getHandle() method returns a Handle object.

--------------------------------------------------------------------

QUESTION NO : 65
QUESTION STATEMENT : Which of the following interfaces provide methods to remove ejbs?

CHOICES :

a) EJBObject
b) EJBContext
c) EJBHome
d) Context
e) SessionContext
f) EntityContext


CORRECT ANSWER : ac

EXPLANATION :
Choices A and C are correct.

EJBObject and EJBHome interfaces provide the remove() method which can be used to remove the session bean or entity bean.
EJBContext interface is the bean class's interface to the container system. It provides information about the security
identity and transaction status. It also provides access to environment variables and the bean's EJBHome. However, it does
not have methods to create, delete, or manipulate beans in any other way. Therefore, choice B is incorrect.

SessionContext and EntityContext are specializations of the EJBContext interface. EntityContext has methods to get an
EntityBean's object reference and primary key. SessionContext provides the session bean instance with an interface to the
container. Therefore, choices E and F are also incorrect.

Choice D is incorrect because Context is the starting point for any JNDI lookup. This interface represents a naming context,
which consists of a set of name-to-object bindings. It contains methods for examining and updating these bindings.

--------------------------------------------------------------------

QUESTION NO : 66
QUESTION STATEMENT : Which of the following are the benefits of MDB (Message Driven Beans) over standard JMS consumers?

CHOICES :

a) In case of a MDB, developer needs to create a MessageListener class that utilizes a server-wide session pool.
b) WebLogic Server container provides standard EJB services to MDBs.
c) MDBs benefit from the write-once, deploy-anywhere paradigm of EJBs.
d) MDBs can be associated with multiple Messaging Queues or Topics unlike standard JMS.


CORRECT ANSWER : bc

EXPLANATION :
Choices B and C are correct.

A message-driven bean is a special kind of EJB that acts as a message consumer in the WebLogic JMS messaging system. As with standard JMS message consumers, message-driven beans receive messages from a JMS Queue or Topic, and perform business logic based on the message contents. EJB deployers create listeners to a Queue or Topic at deployment time, and WebLogic Server automatically creates and removes message-driven bean instances as needed to process incoming messages.

Because message-driven beans are implemented as EJBs, they benefit from several key services that are not available to
standard JMS consumers. Most importantly, message-driven bean instances are wholly managed by the WebLogic Server EJB container. Using a single message-driven bean class, WebLogic Server creates multiple EJB instances as necessary to process large volumes of messages concurrently. This stands in contrast to a standard JMS messaging system, where the developer must create a MessageListener class that utilizes a server-wide session pool. Thus, choice A is incorrect.

WebLogic Server provides standard EJB services to MDBs, such as security services and automatic transaction management. Thus, choice B is correct.

Being implemented as EJBs, MDBS benefit from the write-once, deploy-anywhere quality of EJBs. Whereas a JMS MessageListener is tied to specific session pools, Queues, or Topics, message-driven beans can be developed independently of available server resources. Thus, Choice C is also correct.

It is not that MDBs are always advantageous as compared to standard JMS consumers. One limitation of MDBs compared to standard JMS listeners is that a given MDB deployment can be associated with only one Queue or Topic. If your application requires a single JMS consumer to service messages from multiple Queues or Topics, you must use a standard JMS consumer, or deploy multiple message-driven bean classes. Thus, Choice D is incorrect.

For details about MDBs on WLS, please refer http://edocs.bea.com/wls/docs60/ejb/reference.html


--------------------------------------------------------------------

QUESTION NO : 67
QUESTION STATEMENT : Which are the following two specifications of the OMG on which RMI over IIOP is based?

CHOICES :

a) Objects-by-reference
b) Objects-by-value
c) Java-to-IDL mapping
d) RMI-to-IIOP mapping


CORRECT ANSWER : bc

EXPLANATION :
Choices B and C are correct.

RMI over IIOP allows CORBA clients to access RMI objects and is based on two specifications of the OMG: Java-to-IDL mapping and Objects-by-value. The Java-to-IDL mapping specification defines how an IDL is derived from a Java remote interface. In the WebLogic RMI over IIOP implementation, the implementation class is run through the WebLogic RMI compiler or WebLogic EJB compiler with the -idl option. This creates an IDL equivalent of the remote interface. This IDL is then compiled with an IDL compiler to generate the classes required by the CORBA client.

The Objects-by-Value specification allows complex data types to be passed between the two programming languages involved. In order for an IDL client to support Objects-by-Value, the client should be developed in conjunction with an Object Request Broker (ORB) that supports Objects-by-Value.

--------------------------------------------------------------------

QUESTION NO : 68
QUESTION STATEMENT : Which of the following always happen when an EJBException is thrown by any method in a Message Driven Bean instance involved in a transaction?

CHOICES :

a) The instance is removed from memory
b) ejbRemove() method is called
c) finalize() method is called
d) Transaction is rolled back
e) InvalidTransactionException is thrown


CORRECT ANSWER : ad

EXPLANATION :
Choices A and D are correct.

When an EJBException (or any RuntimeException type) is thrown by any method in the MDB instance, the instance is immediately removed from memory and the transaction is rolled back.

ejbRemove() provides the MDB instance with an opportunity to clean up any resources it stores in its instance fields.
ejbRemove() is called at the end of the MDB's life cycle, before it is garbage collected. It may not be called if the EJB
server hosting the MDB fails or if an EJBException is thrown by the MDB instance in one of its other methods. The finalize
method is also called before garbage collection. There is no guarantee whether it would be called. Therefore, choices B and C are incorrect.

Choice E is also not applicable.

--------------------------------------------------------------------

QUESTION NO : 69
QUESTION STATEMENT : Which of the following are the similarities between stateless session beans and entity beans?

CHOICES :

a) Both support instance pooling.
b) Both support bean managed transactions
c) Both support container managed persistence
d) Both can be shared by multiple clients


CORRECT ANSWER : ad

EXPLANATION :
Choices A and D are correct.

Stateless session beans and entity beans support instance pooling. Instance pooling is a technique used by EJB servers to
create multiple copies of enterprise beans and then distribute them as needed. It reduces the resources needed at a time.
Stateless session beans and entity beans participate in instance pooling.

Only session beans support bean-managed transactions, entity beans do not. Therefore, choice B is not true.

When a bean's state is managed automatically by a persistence service, the container is responsible for synchronizing an
entity bean's instance fields with data in the database.This automatic persistence is called Container Managed Persistence.
It is not supported by session beans. Therefore, choice C is not true.

Both entity beans and stateless session beans can be shared by multiple clients since they do not retain the state of a
particular client. Therefore, choice D is also true.

--------------------------------------------------------------------

QUESTION NO : 70
QUESTION STATEMENT : Which of the following are true about the life cycle of a message driven bean?

CHOICES :

a) After the bean is instantiated, the setMessageDrivenContext() method is invoked by the container providing the MDB
instance with a reference to its EJBContext

b) The ejbCreate() method is invoked only once in the life cycle of the MDB.
c) MDBs are subject to activation and passivation
d) MDBs can maintain open connections to resources for their entire life cycles.


CORRECT ANSWER : abd

EXPLANATION :
Choices A, B, and D are correct.

The MDB instance's life cycle has two states: Does Not Exist and Method-Ready Pool. When an instance transitions from the Does Not Exist state to the Method-Ready Pool, three operations are performed on it. First, the bean instance is instantiated when the container invokes the Class.newInstance() method on the MDB class. Second, the setMessageDrivenContext() method is
invoked by the container providing the MDB instance with a reference to its EJBContext.Finally, the no-argument ejbCreate() method is invoked by the container on the bean instance. The MDB has only one ejbCreate() method, which takes no arguments.
The ejbCreate() method is invoked only once in the life cycle of the MDB.

MDBs are not subject to passivation and activation, so they can maintain open connections to resources for their entire life
cycles. Therefore, choice C is not true, while choice D is true.

--------------------------------------------------------------------

QUESTION NO : 71
QUESTION STATEMENT : Which of the following exceptions are thrown by the rollback() method of the UserTransaction interface?

CHOICES :

a) SecurityException
b) HeuristicRollbackException
c) SystemException
d) IllegalStateException
e) HeuristicMixedException
f) TransactionRolledbackException


CORRECT ANSWER : acd

EXPLANATION :
Choices A, C, and D are correct.

UserTransaction is an interface that is used for explicit transaction management using JTA.
The rollback() method is invoked to rollback the transaction and undo updates. The rollback() method can throw 3 different
checked exceptions. SecurityException is thrown if the thread using the UserTransaction object is not allowed to rollback the
transaction. IllegalStateException is thrown if the current thread is not associated with a transaction. SystemException is
thrown if the transaction manager encounters an unexpected error condition.


-------------------------------------------------------------------

QUESTION NO : 72
QUESTION STATEMENT : A client application gets the UserTransaction object and uses it to begin and commit a transaction. Within the same transaction context, it invokes two EJBs. Which of the following are valid transaction attributes for the enterprise beans so that the transaction is completed successfully?

CHOICES :

a) Required
b) Not Supported
c) RequiresNew
d) Mandatory
e) Supports
f) Never


CORRECT ANSWER : ade

EXPLANATION :
Choices A, D, and E are correct.

The only requirement for wrapping EJB calls within the same transaction context is that both the beans must support the
client transaction. The beans' trans-attribute element must be set to Required, Supports, or Mandatory. The transaction
attribute defines the transactional manner in which the container invokes enterprise bean methods.

If the attribute is set to Mandatory, it directs the container to always invoke the bean method within the transaction
context associated with the client.

If the transaction attribute is set to Supports, it directs the container to invoke the bean method within a transaction
context if the client invokes the bean method within a transaction, else without a transaction context.

The attribute value of Required directs the container to invoke the bean method within a transaction context if the client
invokes the bean method within a transaction, else start a new transaction.

Therefore, in these three cases, the client transactional context is being supported and followed.

If the transaction attribute is set to Not Supported, it directs the container to invoke bean methods without a transaction
context. The value of RequiresNew causes the methods to always execute within a new transactional context. Never causes an
exception to be raised when invoked from within a transactional context. Since these three attributes do not support the
client's transactional context, they cannot be used in the above situation.

--------------------------------------------------------------------


QUESTION NO : 73
QUESTION STATEMENT : You have a CMP entity bean whose data needs to be compressed before saving to the database and retrieved in the original form when needed. Which of the following callback methods would be appropriate to place the compressing and decompressing code?

CHOICES :

a) ejbCreate
b) ejbLoad
c) ejbPassivate
d) ejbActivate
e) ejbStore


CORRECT ANSWER : be

EXPLANATION :
Choices B and E are the correct.

The ejbStore method is called when the container decides that it is a good time to write the entity bean's data to the
database. In container-managed persistence, the bean's container-managed fields are automatically synchronized with the
database. In most cases, we will not need the ejbLoad() and ejbStore methods because persistence in container-managed beans is uncomplicated. We need to provide the ejbLoad and ejbStore callback methods in container-managed beans only if more sophisticated logic is needed when synchronizing container-managed fields.

Data intended for the database can be reformatted or compressed to conserve space; data just retrieved from the database can be used to calculate derived values for non-persistent properties. We can use the ejbStore() method to compress the data into the appropriate format before saving, since it will be called by the container at that time.
Therefore, choice E is correct.

To decompress and read the data back in the original form, we can use the ejbLoad() function also. Therefore, choice B is
also correct.

ejbCreate is not the right place for this, because it is called only when a new record is inserted, same applies for
ejbPostCreate. ejbPassivate is called before the bean is passivated ie; the bean instance returns to the pool. It is not
called before saving the persistent state of the bean. ejbActivate is called when the bean moves from the pooled state to the
ready state. Therefore, this is also not the place to put the formatting code.


--------------------------------------------------------------------

QUESTION NO : 74
QUESTION STATEMENT : Which of the following exceptions is thrown by the ejbStore() method of an entity bean when the database row to be updated is not found?

CHOICES :

a) NoSuchEntityException
b) EJBException
c) RemoteException
d) ObjectNotFoundException
e) FinderException


CORRECT ANSWER : a

EXPLANATION :
Choice A is correct.

The NoSuchEntityException exception is a system exception thrown by the ejbLoad() method of an entity bean when the database row to be loaded is not found and also by the ejbStore() method when the database row to be updated cannot be found. This is a system exception, which causes the container to rollback the transaction automatically.

EJBException is also a SystemException, but is called by the EJB methods only if any other system problem has occurred.

RemoteException is never thrown directly by the bean; the container throws this exception if the bean throws an EJBException.

ObjectNotfoundException is thrown by a finder method if a requested database row could not be found.

FinderException is the super class of ObjectNotFoundException


--------------------------------------------------------------------

QUESTION NO : 75
QUESTION STATEMENT : The JNDI name of an enterprise bean has been defined as "fruit" at deployment time. What syntax is used by an internal client to look up the ejb at runtime?

CHOICES :

a) java:comp/env/ejb/fruit
b) java:env/ejb/fruit
c) java:env/comp/fruit
d) java:comp/env/fruit


CORRECT ANSWER : d

EXPLANATION :
Choice D is correct.

The concept of JNDI Environment Naming Context (JNDI ENC) was introduced as a part of the container-bean contract. All deployed beans, environment properties, and external resources like data sources are mapped to a set of JNDI entries which exist in a namespace called the environment naming context (ENC) or default JNDI context. The default context exists in the namespace called "java:comp/env" and its subdirectories. When the bean is deployed, all the beans and resources it uses are mapped into this directory. So if the bean is given a jndi name of "fruit", to look up the resource we use the syntax
java:comp/env/fruit.

--------------------------------------------------------------------

QUESTION NO : 76
QUESTION STATEMENT : An instance of stateful session EJB when accessed simultaneously from more than one client on same VM results in RemoteException or EJBException. In case, the client is a Servlet thread, which of the following techniques can be used to avoid RemoteException/EJBException?

CHOICES :

a) Not possible.
b) Store the reference to EJB instance as an instance variable of the Servlet class.
c) Store the reference to EJB instance as a local variable of the Servlet class.
d) Make the Servlet client to be remote instead of internal to WebLogic server.


CORRECT ANSWER : c

EXPLANATION :
Choice C is correct.

An instance of a stateful session EJB can be accessed from only one client virtual machine at a time. Multiple client threads
from the same virtual machine can access the same instance of a stateful session EJB, but they must do so in a serial
fashion. If a client-invoked business method is in progress on an instance when another client-invoked call, from the same or
different client, arrives at the same instance of a stateful session bean class, the container may throw the
java.rmi.RemoteException to the second client, if the client is a remote client, or the javax.ejb.EJBException, if the client
is a local client. Thus, choice D is incorrect.

To avoid any exception, each Servlet should store a reference to a particular EJB instance in a local variable of the
Servlet's service() method. Please note that variables local to methods like service(), doGet(), doPost() are not shared
between different requests and are automatically thread safe. Thus, choice C is correct.

An instance variable unlike local variable is shared. Thus, Choice B is incorrect.

An implication of this rule is that an application cannot make loopback calls to a session bean instance.

This restriction does not apply to a stateless session bean because the container routes each request to a different instance
of the session bean class.


--------------------------------------------------------------------


QUESTION NO : 77
QUESTION STATEMENT : A client invokes a method on a Stateful Session bean after that bean has timed out. What will be the result?

CHOICES :

a) ObjectNotFoundException is raised
b) A new bean instance is instantiated to serve the client
c) NoSuchObjectException is raised
d) ApplicationException is thrown


CORRECT ANSWER : c

EXPLANATION :
Choice C is correct.

NoSuchObjectException is raised by a session bean in three situations. If the bean does not exist because it was already
removed by the container because of a remove method call or some other reason, this exception can be thrown when a method is invoked on the bean. Timeout period for a bean is declared at deployment time. If a bean times out, the container can remove the bean instance from the method ready state. In this case also, a method invocation on the bean results in
NoSuchObjectException. Session beans cannot survive server crashes, so if server is restarted after the bean creation, when
the method invocation happens, this exception is thrown. If the code in the bean method caused an error, or if the parameters
passed to the method are invalid, application exceptions or RemoteException is thrown.

--------------------------------------------------------------------

QUESTION NO : 78
QUESTION STATEMENT : Which of the following may NOT be included in the conversational state of a stateful session bean?

CHOICES :

a) SessionContext
b) EJBContext
c) transient variables
d) Handle
e) EJBHome
f) EJBObject


CORRECT ANSWER : bc

EXPLANATION :
Choices B and C are correct.

Transient variables and EJBContext type may not be included in the conversational state of a stateful bean. When a stateful
bean is passivated, the conversational state of the bean is written to the secondary storage associated with the EJBObject.
When the bean is activated, the saved state is restored.

A bean's conversational state should consist of only primitive values, objects that are serializable and these special types-
SessionContext, EJBHome, EJBObject, UserTransaction and Context (only when it references the JNDI ENC). Therefore, choices A, E, and F may be included in the conversational state of the bean.
Choice D can also be included because Handle is a serializable reference to the EJBObject. Transient variables will not be
preserved when the bean is passivated. Therefore, choice C may not be included.
Choice B cannot be included because EJBContext does not implement Serializable. So, it will not be preserved during bean
passivation.

--------------------------------------------------------------------

QUESTION NO : 79
QUESTION STATEMENT : Match the EJB functions given below with the functionality equivalent in SQL

A.) ejbStore() 1.) INSERT
B.) ejbLoad() 2.) UPDATE
C.) ejbCreate() 3.) SELECT

CHOICES :

a) A->1, B->2, C->3
b) A->2, B->1, C->3
c) A->3, B->2, C->1
d) A->1, B->3, C->2
e) A->2, B->3, C->1
f) A->3, B->1, C->2


CORRECT ANSWER : e

EXPLANATION :
Choice E is correct.

When the create() method on a home interface is invoked, the container delegates the create() method call to the bean
instance's matching ejbCreate() method. The ejbCreate() methods are used to initialize the instance state before record is
inserted into the database. The ejbCreate() method is analogous to INSERT. The ejbStore() method is invoked just before the container is about to write the bean container-managed fields to the database. It is analogous to the UPDATE command. The ejbLoad() is invoked just after the container has refreshed the bean container-managed files with its state from the
database. It is analogous to the SELECT command. Thus, choice E is correct and others are incorrect.


--------------------------------------------------------------------

QUESTION NO : 80
QUESTION STATEMENT : Which of the following statements are true regarding MDBs (Message Driven Beans) on Version 6.0 implementation of WebLogic App Server?

CHOICES :

a) MDBs support concurrent processing for both Topics and Queues.
b) MDBs support concurrent processing for only Topics.
c) MDBs support concurrent processing for only Queues.
d) MDBs support concurrent processing for neither Topics nor Queues.


CORRECT ANSWER : a

EXPLANATION :
Choice A is correct.

MDBs support concurrent processing for both Topics and Queues. Previously, only concurrent processing for Queues was
supported. To ensure concurrency, change the weblogic-ejb-jar.xml deployment descriptor max-beans-in-free-pool setting to a number greater than one. If this element is set to more than one, the container will spawn as many threads as specified.
WebLogic Server maintains a free pool of EJBs for every stateless session bean and message driven bean class. The
max-beans-in-free-pool element defines the size of this pool. By default, max-beans-in-free-pool has no limit; the maximum
number of beans in the free pool is limited only by the available memory.

For complete information about Deployment Descriptor properties on WLS, refer
http://edocs.bea.com/wls/docs60/ejb/reference.html


--------------------------------------------------------------------

QUESTION NO : 81
QUESTION STATEMENT : Which of the following information CANNOT be obtained using the EjbMetaData interface?

CHOICES :

a) Whether the EJB is a session or an entity bean
b) The home interface class of the EJB
c) The primary key class of the EJB
d) The remote interface class of the EJB
e) The bean class of the EJB


CORRECT ANSWER : e

EXPLANATION :
Choice E is correct.

The javax.ejb.EJBMetaData interface is implemented by the container vendor to provide a serializable class that contains
information about the bean. It has methods to get the home interface, remote interface, and primary key classes of the EJB.
It also has a method to get the information about the type of the bean i.e. whether it is a session bean or an entity bean.
There is no way to get the bean class using EJBMetaData because the bean class is not part of the client API and hence does
not belong to the metadata. The getEJBMetaData() method of the EJBHome interface returns an instance of EJBMetaData.


--------------------------------------------------------------------

QUESTION NO : 82
QUESTION STATEMENT : Which of the following interfaces does NOT have a method, which returns a reference to the home object of the associated enterprise bean?

CHOICES :

a) EJBContext
b) EJBMetaData
c) EJBObject
d) HomeHandle
e) Handle


CORRECT ANSWER : e

EXPLANATION :
Choice E is correct.

Handle interface provides the client with a serializable object that can be used to obtain a remote reference to a specific
bean. It has only one method getEJBObject, which returns the EJBObject of the bean.

The EJBContext interface is the bean class's interface to the container system. It provides access to the environment
variables and the bean's EJB home. EJBMetaData interface is implemented by the container vendor to provide a serializable
class that contains information about the bean. It also has a method, which returns a reference to the EJBHome. The EJBObject interface is inherited by the remote interface of the bean, it also has a method which returns the home object reference. The HomeHandle interface provides the client with a serializable object that can be used to obtain a remote reference to a bean's home. Therefore, except the Handle interface, all the others provide methods, which provide access to the home object of the bean.

--------------------------------------------------------------------

QUESTION NO : 83
QUESTION STATEMENT : Which of the following is NOT a difference between a message driven bean and a stateless session bean?

CHOICES :

a) Message driven beans process multiple JMS messages asynchronously, while stateless session beans process a serialized
sequence of method calls
b) The EJB container provides transaction services to stateless session beans, but not for message driven beans
c) Message driven beans have no home or remote interface unlike stateless session beans
d) Message driven beans cannot be created or removed because of client requests, unlike stateless session beans.


CORRECT ANSWER : b

EXPLANATION :
Choice B is correct because it is not a valid difference between MDBs and stateless session beans.

An MDB is a special kind of EJB that acts as a message consumer in the Weblogic JMS system.

Message-driven beans are different from stateless session EJBs (and other types of EJBs) in these ways. Message-driven beans process multiple JMS messages asynchronously, rather than processing a serialized sequence of method calls as in the case of other enterprise beans.

Message-driven beans have no home or remote interface. Therefore, they cannot be directly accessed by internal or external
clients. Clients interact with message-driven beans only indirectly, by sending a message to a JMS Queue or Topic. Only the
WebLogic Server container directly interacts with a message-driven bean by creating bean instances and passing JMS messages to those instances as necessary. In the case of session beans, clients can create and remove the bean by calling create() and remove() methods. WebLogic Server maintains the entire life cycle of a message-driven bean; instances cannot be created or removed because of client requests or other API calls.

The EJB container takes care of automatically managing the MDB's entire environment, including transactions, security,
resources, concurrency, and message acknowledgment. Therefore, statement B is not true and hence a correct choice.


-------------------------------------------------------------------

QUESTION NO : 84
QUESTION STATEMENT : Which of the following are true about stateful session beans?

CHOICES :

a) They support instance pooling
b) They cannot be shared by multiple clients
c) They do not support reentrance
d) They survive server crashes.


CORRECT ANSWER : bc

EXPLANATION :
Choices B and C are correct.

Stateful session beans maintain the conversational state of a client between method invocations. Therefore, they cannot be
shared by multiple clients. Instance pooling is a technique used by EJB servers to create multiple copies of enterprise beans
and then distribute them as needed. It reduces the resources needed at a time. Stateless session beans and entity beans
participate in instance pooling. Stateful session beans do not participate in pooling because they maintain the unique state
of each client and hence, cannot be reused.

Reentrance is the state when a thread of control attempts to reenter a bean instance. In EJBs, bean instances are
non-reentrant by default; which means that loopbacks are not allowed. Entity beans can be configured in the deployment
descriptor to allow reentrance at deployment time. Session beans can never be reentrant, and they throw a RemoteException if a loopback is attempted. Session beans cannot survive server crashes since they not saved to any persistent storage.


--------------------------------------------------------------------

QUESTION NO : 85
QUESTION STATEMENT : A client wants to preserve the reference to the EJBHome object of an enterprise bean instance and use it later. Which of the following can be serialized for this purpose?

CHOICES :

a) Home
b) Handle
c) HomeHandle
d) EJBHomeHandle
e) HomeObject


CORRECT ANSWER : c

EXPLANATION :
Choice C is correct.

A client can pass the HomeHandle object as arguments to another client, and the receiving client can use the handle to obtain
a reference to the same EJBHome object. Clients can also serialize the HomeHandle and store it in a file for later use. The
HomeHandle interface has only one method getEJBHome() which returns the EJBHome reference.

Once a client has obtained the EJBHome object for an EJB instance, it can create a handle to the home object by calling
getHomeHandle() method. getHomeHandle() returns a HomeHandle object, which can be used to obtain the home interface to the same EJB instance at a later time.


--------------------------------------------------------------------

QUESTION NO : 86
QUESTION STATEMENT : Which of the following statements are true regarding the identity of two EJBs?

CHOICES :

a) Two stateful session beans are identical if their data attributes are identical.
b) Two stateful session beans are identical if their session contexts are equal.
c) Two stateless session beans are identical if they are of the same type.
d) Two stateless session beans are identical if their session contexts are equal.
e) Two entity beans are identical if they have same primary key but different home interface.
f) Two entity beans are identical if they have different primary key but same home interface.


CORRECT ANSWER : bc

EXPLANATION :
Choices B and C are correct.

Since the stateful session beans maintain the conversational state of the clients, they are identical when their session
contexts are equal. Two stateful session beans may have identical data attributes, but if the session contexts are different,
they are not identical. Thus, choice A is incorrect and choice B is correct.

Since stateless beans do not retain the conversational state, they are considered identical if they are of the same type.
Thus, choice C is correct.

If two entity objects have the same home interface and primary key, they are considered identical. The EJB specification does
not mention object equality based on the = = operator. Also, if you compare two object references using the Java API,
Object.equals(Object obj), the result is unspecified. The only way to compare object equality is through the isIdentical
(EJBObject) API. Thus, choices E and F are incorrect.

--------------------------------------------------------------------

QUESTION NO : 87
QUESTION STATEMENT : If no matching beans are found, the findByPrimaryKey method defined in the home object of an entity bean will ...

CHOICES :

a) return a null reference
b) throw javax.ejb.FindException
c) throw javax.ejb.ObjectNotFoundException
d) throw RemoteException


CORRECT ANSWER : c

EXPLANATION :
Choice C is correct.

findByPrimaryKey is a standard method that all home interfaces for entity beans must support. With Container Managed
Persistence, implementations of find methods are generated automatically at deployment time. Find methods that return a
single remote reference throw a FinderException if an application error occurs and an ObjectNotFoundException if a matching bean cannot be found. The ObjectNotFoundException is a subtype of FinderException and is only thrown by find methods, which return single remote references. Find methods that return an Enumeration or Collection type return an empty collection of no matching beans can be found or throw a FinderException if an application error occurs.


--------------------------------------------------------------------

QUESTION NO : 88
QUESTION STATEMENT : What are the differences between select methods and finder methods of entity beans in EJB-QL?

CHOICES :

a) finder methods are defined in the home interface of an entity bean, so they are exposed to the client while select
methods are not
b) select methods can return values that are defined as cmp-types or cmr-types, while finder methods return the entity
bean's remote interface or a collection of objects implementing the entity bean's remote interface
c) select methods are never associated with a particular entity bean instance, while finder methods are always associated
with one instance
d) all of the above


CORRECT ANSWER : ab

EXPLANATION :
Choices A and B are correct.

Finder methods get either a single or a collection of entity bean instances from the persistence store through a relational
database. These methods are defined in the home interface(s) of an entity bean. Hence, they are exposed to the client. Select
methods exist in the entity bean as a special type of query method. They are not declared in the home interface; therefore,
they are not exposed to the client. The finder methods are not useful to access cmp-field, or any remote interface instance
defined in cmr-field. Using select methods, an entity bean returns an instance of cmp-field type, or the remote interfaces
represented by the cmr-field.

Select methods are usually two types.
ejbSelect<METHOD>
ejbSelect<METHOD>InEntity

The ejbSelect<METHOD> is not associated with a particular instance of the entity bean. ejbSelect<METHOD>InEntity is specific to the entity instance executed.


--------------------------------------------------------------------


QUESTION NO : 89
QUESTION STATEMENT : Which of the following methods from the MessageDrivenContext interface always cause exceptions if invoked?

CHOICES :

a) getEJBHome
b) getCallerPrincipal
c) getRollbackOnly
d) setRollbackOnly


CORRECT ANSWER : ab

EXPLANATION :
Choices A and B are correct.

The MessageDrivenContext simply extends the EJBContext; it does not add any new methods.Only the transactional methods which the MessageDrivenContext inherits from EJBContext are available to message-driven beans. The home methods - getEJBHome() and getEJBLocalHome() - throw a RuntimeException if invoked, because MDBs do not have home interfaces or EJB home objects. The security methods--getCallerPrincipal() and isCallerInRole()--also throw a RuntimeException if invoked on a MessageDrivenContext.

When an MDB services a JMS message there is no caller, so there is no security context to be obtained from the caller. The
getRollbackOnly and setRollbackOnly are for use by beans which support container managed transactions. The setRollbackOnly method gives a bean the power to veto a transaction. The getRollbackOnly method returns true if the current transaction has been marked for rollback.

--------------------------------------------------------------------

QUESTION NO : 90
QUESTION STATEMENT : Which are the possible values for the <destination-type> tag in the deployment descriptor for a message drive bean?

CHOICES :

a) javax.jms.Queue
b) javax.jms.Stack
c) javax.jms.Topic
d) javax.jms.Group


CORRECT ANSWER : ac

EXPLANATION :
Choices A and C are correct.

A message bean deployment can be associated with a queue or a topic. The <message-driven-destination> element designates the type of destination from which the MDB receives messages. The allowed values for this element are javax.jms.Queue and javax.jms.Topic. We can set the type to Queue as shown here.
<message-driven-destination> <destination-type>javax.jms.Queue</destination-type>
</message-driven-destination>When the MDB is deployed, the deployer will map the MDB so that it listens to a real queue on the network.

--------------------------------------------------------------------

QUESTION NO : 91
QUESTION STATEMENT : Which of the following are the requirements for the class of a Message Driven Bean according to EJB specification (EJB 2.0)?

CHOICES :

a) The class should implement javax.ejb.MessageDrivenBean interface
b) An EJB constructor is required, and it must not accept parameters.
c) onMessage() method is required, and it does not have any parameters.
d) ejbRemove() method is required and must not accept parameters.
e) finalize() method is required and should be protected.


CORRECT ANSWER : abd

EXPLANATION :
Choices A, B, and D are correct.

The EJB 2.0 specification provides detailed guidelines for defining the methods in a message-driven bean class. The class
should implement javax.ejb.MessageDrivenBean interface. An EJB constructor is required, and it must not accept parameters.
The constructor must not be declared as final or abstract.

The onMessage() method is required, it returns void and must take a single parameter of type javax.jms.Message. The throws clause (if used) must not include an application exception. onMessage() must not be declared as final or static. ejbRemove() is required and must not accept parameters. The throws clause (if used) must not include an application exception. ejbRemove() must not be declared as final or static. The EJB class cannot define a finalize() method.


--------------------------------------------------------------------


QUESTION NO : 92
QUESTION STATEMENT : Which of the following are true about DataSource objects?

CHOICES :

a) More than one datasource cannot use a single connection pool
b) A DataSource object can point to a Multipool, whatever be its type
c) DataSources are defined in the Administration console
d) Data Source objects can be defined with or without JTA


CORRECT ANSWER : cd

EXPLANATION :
Choices C and D are correct.

A Data Source object enables JDBC clients to obtain a DBMS connection. DataSource objects are defined and configured using the Administration Console. You can define multiple DataSources that use a single connection pool. This allows you to define both transaction and non-transaction-enabled DataSource objects that share the same database. Therefore, choice A is incorrect.

Each Data Source object points to a Connection Pool or MultiPool. Tx Data Sources cannot point to MultiPools, only Connection Pools, because MultiPools are not supported in distributed transactions. Therefore, choice B is incorrect. Data Source objects can be defined with or without JTA, which provides support for distributed transactions.

--------------------------------------------------------------------

QUESTION NO : 93
QUESTION STATEMENT : Which of the following does NOT happen when a client invokes the remove() method of the EJBHome of a CMP entity bean?

CHOICES :

a) The record in the database corresponding to the primary key passed to the remove() method is deleted.
b) The remote reference to the bean becomes invalid
c) ejbPassivate() method is invoked on the bean
d) unsetEntityContext() method is invoked on the bean
e) ejbRemove() method is invoked on the bean.

CORRECT ANSWER : cd

EXPLANATION :
Choices C and D are correct because they do NOT happen when a client invokes the remove() method of the EJBHome of a CMP entity bean.With entity beans, invoking one of the remove() methods on the bean's EJB Object or EJB Home, means that the entity's data is deleted in the database. Then, the ejbRemove() method is called, but not the ejbPassivate() method. Once the ejbRemove() method has finished, the bean instance is moved back into the instance pool and out of the ready state. The remote reference to the bean becomes invalid.

Choice C does not happen because ejbPassivate() is called only when the bean moves from the Ready state to the pooled state via passivation.

Choice D does not happen because unsetEJBContext() is invoked by the container when an entity bean instance leaves the
instance pool to be garbage collected.


--------------------------------------------------------------------

QUESTION NO : 94
QUESTION STATEMENT : For which of the following methods do we need to specify transaction attributes in a bean's deployment descriptor?

CHOICES :

a) For the methods defined in a session bean's remote interface
b) For the methods defined in a session bean's home interface.
c) For the methods defined in an entity bean's home interface.
d) For the onMessage method of a message driven bean.
e) For the methods defined in the EJBObject interface in the case of a session bean.


CORRECT ANSWER : acd

EXPLANATION :
Choices A, C, and D are correct.

The transaction attribute must be specified for the following methods.
For a session bean, the transaction attributes must be specified for the methods defined in the bean's remote interface and
all the direct and indirect superinterfaces of the remote interface, excluding the methods of the javax.ejb.EJBObject
interface.

Transaction attributes must not be specified for the methods of a session bean's home interface. For an entity bean, the
transaction attributes must be specified for the following:
1. Methods defined in the bean's remote interface and all the direct and indirect superinterfaces of the remote interface,
excluding the getEJBHome, getHandle, getPrimaryKey, and isIdentical methods
2. Methods defined in the bean's home interface and all the direct and indirect superinterfaces of the home interface,
excluding the getEJBMetaData and getHomeHandle methods
For a message-driven bean, the transaction attribute must be specified for the bean's onMessage method.


--------------------------------------------------------------------

QUESTION NO : 95
QUESTION STATEMENT : Which of the following CANNOT be done by a message driven bean?

CHOICES :

a) They can demarcate transaction boundaries either on their own or by having the container manage transactions
b) They can receive a transaction context from the client that sends a message.
c) They can send messages using JMS.
d) They can manage a process and interact with other beans as well as resources.


CORRECT ANSWER : b

EXPLANATION :
Choice B is correct because it is NOT true.

As with other enterprise bean types, message-driven beans can demarcate transaction boundaries either on their own (using
bean-managed transactions) or by having the WebLogic Server container manage transactions (container-managed transactions).
In either case, a message-driven bean does not receive a transaction context from the client that sends a message. WebLogic
Server always calls a bean's onMessage() method by using the transaction context specified in the bean's deployment
descriptor.

MDB can also send messages using JMS. Like a session bean, the MDB can access any other entity or session bean and use that bean to complete a task. In this way, the MDB fulfills its role as an integration point in B2B application scenarios. MDB can manage a process and interact with other beans as well as resources.

--------------------------------------------------------------------

QUESTION NO : 96
QUESTION STATEMENT : What happens when a bean-managed transaction method of an enterprise bean is invoked by a client that is already involved in a transaction?

CHOICES :

a) RemoteException is thrown
b) Result depends on the transaction context of the client
c) Client's transaction is suspended until the bean method returns
d) Bean method is invoked in the client's transactional context.


CORRECT ANSWER : c

EXPLANATION :
Choice C is correct.

When a bean managed transaction method is invoked by a client that is already involved in a transaction, the client's
transaction is suspended until the bean method returns. This suspension occurs whether the bean managed transaction bean
explicitly starts its own transaction within the method, or the transaction was started in a previous method invocation. The
client transaction is always suspended until the bean managed transaction method returns.

--------------------------------------------------------------------

QUESTION NO : 97
QUESTION STATEMENT : For a stateful session bean implementing SessionSynchronization interface, which of the following methods is always invoked when a transaction is committed or rolled back in a transactional method invoked on the bean?

CHOICES :

a) beforeBegin
b) afterBegin
c) beforeCompletion
d) afterCompletion


CORRECT ANSWER : d

EXPLANATION :
Choice D is correct.

When a transactional method is invoked on a bean, the bean becomes part of the transaction. This causes the afterBegin()
callback method to be invoked. When the afterBegin() method is done, the business method originally invoked by the client is
executed on the bean instance. If the transaction is committed, the bean will be notified through its beforeCompletion
method. The afterCompletion() method is always invoked whether the transaction ended successfully with a commit or
unsuccessfully with a rollback. There is no such method called beforeBegin.

--------------------------------------------------------------------

QUESTION NO : 98
QUESTION STATEMENT : Which of the following transaction attributes are valid for a Message Driven Bean that uses container-managed transactions?

CHOICES :

a) Mandatory
b) Required
c) Supports
d) NotSupported
e) RequiresNew


CORRECT ANSWER : bd

EXPLANATION :
Choices B and D are correct.

Since no client provides a transaction context for calls to a message driven bean, beans that use container managed
transactions should be deployed using the Required or NotSupported transaction attributes.

For a message-driven bean, the transaction attribute must be specified for the bean's onMessage method. The container invokes a message driven bean method with its transaction attribute set to Required with a valid transaction context. Since there is no client transaction context available for a message-driven bean, the container automatically starts a new transaction
before the dequeuing of the JMS message, which is before the invocation of the onMessage method. The container invokes a
message-driven bean method, which has its transaction attribute set to NotSupported with an unspecified transaction context.
If the onMessage method invokes other enterprise beans, the Container passes no transaction context with the invocation.


--------------------------------------------------------------------

QUESTION NO : 99
QUESTION STATEMENT : A session bean's business method has the transaction attribute set to Mandatory. A client attempts to invoke the bean method without a transaction context. What will be the result?

CHOICES :

a) Container creates a new transaction context and invokes the bean method from within that context.
b) Container invokes bean methods without a transaction context.
c) TransactionRequiredException is thrown to the client.
d) TransactionNotSupportedException is thrown to the client


CORRECT ANSWER : c

EXPLANATION :
Choice C is correct.

The transaction attribute defines the transactional manner in which the container invokes enterprise bean methods. This
attribute is set for individual methods in a bean. Setting the transaction attribute to Mandatory means the bean method must
always be made part of the transaction scope of the calling client. If a client invokes a bean method from within a
transaction context, the container invokes the bean method within the client transaction context. If the calling client is
not part of a transaction, the invocation will fail, throwing TransactionRequiredException because there is no transaction
scope.


--------------------------------------------------------------------

QUESTION NO : 100
QUESTION STATEMENT : Which of the following transaction isolation levels is the least restrictive in terms of concurrent data access by transactions?

CHOICES :

a) Read Uncommitted
b) Read Committed
c) Repeatable Read
d) Serializable


CORRECT ANSWER : a

EXPLANATION :
Choice A is correct.

Transaction isolation describe how locking is applied to data within a transaction. The value of transaction isolation level
of Read Uncommitted is the least restrictive in the sense that the transaction can read uncommitted data. Bean methods with
this isolation level can read uncommitted changes. This level allows dirty reads, non-repeatable reads, and phantom reads.

If the isolation level of a method is set to Serializable, the transaction has exclusive read and update privileges to data,
other transactions can neither read nor write the same data.
Dirty reads, non-repeatable reads and phantom reads are prevented. This is the most restricted isolation level, so it ensures
that the data is always consistent. If this isolation level is chosen, then all transaction must wait in line to execute.
This can result in a system, which is very slow. So, this isolation level should be avoided wherever it is not necessary.

The isolation level value of Repeatable read prohibits dirty reads and non-repeatable reads, but it allows phantom reads.
Read committed level prohibits dirty reads, but allows non-repeatable reads and phantom reads. Read uncommitted level allows dirty reads, non-repeatable reads, and phantom reads.

--------------------------------------------------------------------