Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1




|Views: 123|Likes:
Published by Adarsh
Enterprise Java Beans Question And Answers
Enterprise Java Beans Question And Answers

More info:

Published by: Adarsh on Jul 21, 2009
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





1.Why EJB ?
 The benefit to application developers is that they can focus onwriting the business logic without worrying much aboutimplementing the surrounding framework.
 The main difference between JavaBeans and EJB is that when youuse JavaBeans to create a server application, you have to buildthe entire server framework. With EJB the framework is providedfor you; you simply have to conform to its APIs.
It follows the Java’s “Write once and run anywhere” concept. It isplatform independent.
It makes distributed programming (RMI/CORBA) easier.
All the transaction processing is taken care by the EJB server.
It follows the multithreaded architecture.
What is the EJB architecture like ?
It is logically a three-tier architecture consisting of mainly TheClient The EJB server and The Databases.
 The EJB bean resides in the container , which in turn reside onthe EJB server.
A program on the client side makes remote calls to the EJBs.Theclient can never communicate directly with the EJB beans.
It talks to the EJB bean through the Home and Remote interfacesprovided by the container.3.What is the role of the container ?
An container is an enviroment in which the EJBs execute.
It can contain one or more EJB classes.
 The container is resposible for generating the implementations of the Home and Remote interfaces.
Clients can never connect to the EJB bean itself , rather theyconnect to the representation of the EJB(EJBObject) provided bythe container , which then forwards the clients request to theEJB.
 The container provides the following facilities :
Swapping to and from secondary storage(for session beans).
Persistence management (for entity beans).
Creation and lookup of the Home object through the JNDI(Java Naming & Directory Interfaces) accessible namespace.
Supports management of multiple Instances.
Implementation of certain basic security services.
Support for transactions management.4.What does the Home interface do ?
 The EJBHome object must implement the home interface.
 This interface contains the methods used by the clients to createand remove the instances of the EJB.
 The home interface is the client’s initial point of contact withyour EJB components.
For the client to access the EJB , an instance of the EJB is createdfrom one or more create() methods of the Home interface.
 The ejbCreate() methods defined in the EJB must also bedeclared with matching signatures in the Home interface.
Returns a reference to a EJB by creating or finding it.5.What does the Remote interface do ?
 The EJBObject class must implement the remote interface.
Once the client has used the home interface to gain access toEJB ,it uses this interface to invoke the business methods definedin the EJB class.
Clients can never get a reference to the EJBs class , only theEJBObject class.
 The EJB container uses the remote interface for your bean togenerate both the client-side stub and server-side proxy objectthat passes client calls to your EJB object.6.What is the EJB class?
EJBHome and EJBObject interfaces and classes control access tothe EJB class.
 The EJB is the class that the developer writes to provideapplication functionality or business logic.
 The methods in this bean are never invoked directly from theclient.The client calls the EJBs methods indirectly through theEJBObject which acts as a proxy.
 The developer has the option of creating either a Session bean orEntity bean.7.What are Session beans ?
A session bean is an EJB bean where each instance of a sessionbean is created through its home interface and is private to theclient.
 The life time of a session bean is that of its client.
 This allows it to maintain the clients state. E.g. Shopping cart .
Represents a transient conversation with a client.
It is relatively short lived. Only for the duration of singleclient/server session.
If the server or client crashes , the session bean is gone.
Might use an entity bean to make a call , in that case the sessionbean is the client.
 The container may optionally implement a swapping mechanismto move the instances of the session beans from the memory tosecondary storage.
 This can be done by serialization of the bean.
 The method ejbPassivate()-(passivation means the process of swapping out the bean) and ejbActivate()-(activation means theprocess of restoring the bean) allow the container to tell thebean that it is about to be swapped out and that it has justswapped in.
If the bean is currently in a transaction , it will not bepassivated(swapped out).8.What are two types of session beans ?
A session beans deployment descriptor must declare the beanas either a stateless or stateful one.
 The two types of session beans are Stateless and Statefulsession beans.
Stateless session bean:-
It is one that does not keep track of the state information between method calls.
Stateless session beans are not swapped.
Since they do not maintain state there is nothing to preserve.
It can also be shared by multiple incoming clients.
Essestially a bean with no instance variables.
Stateful session bean :-
It is one that keeps track of the stateinformation between method calls or a conversation.
Essentially a bean with instance variables.
Maintains a user session.
Since there is conversation between methods the state has tobe preserved.9.What is an Entity bean ?
 They are used to represent persistent data.
An entity bean can be defined to represent a row in a databasetable , where each instance of the bean represents a specificrow.
It is long lived. Exists across client session.
Unlike session beans creating an entity bean means that a newrow is created in the database. So in addition to the create() ,theHome interface will also have finder methodslike( findByPrimaryKey() ).
 The finder method will return a unique identifier , or a primarykey to the container.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->