Skip to main content

EJB FAQs

What are the design goals of the Enterprise JavaBeansTM architecture?
The Enterprise JavaBeans specification defines a standard architecture for implementing the business logic of multi-tier applications as reusable components. In addition to Enterprise JavaBeans components, the architecture defines three other entities:servers,containers, and clients. This architecture incorporates several design goals: Enterprise JavaBeans servers are designed to wrap around legacy systems to provide fundamental services for "containers and the components they contain"

Enterprise JavaBeans containers are designed to handle details of "component" life-cycle, transaction, and security management Component developers are free to focus on business logic, since containers provide services automatically by interceding in component method calls. A simple set of callback interfaces are all that a developer needs to implement to participate in container provided services. A client’s view of an Enterprise JavaBean remains the same regardless of the container it is deployed in. Any container in which an Enterprise JavaBean is deployed presents the same interfaces to the client. This extends to containers from different vendors, running against different servers and different databases, on diverse systems on a network. This client transparency ensures wide scalability for multi-tier applications.



1)What is Enterprise JavaBeans?
a)EJB architecture is component architecture for the develeopment and deployment of component-based distributed business applications.EJB the widely adopted serverside component architecture for Java2 platform,Enterprise ediition(J2EE),versatile,reusable and portable across middleware.



2)Is Ejb a product?
a)No, Ejb is a specification,Enterprise JavBeans defines the EJB component architecture and the interfaces between the EJB enabled server and the component.
3)who are ejb product owners?
a)EJB is not a product it is a specification implemented by Sun with participation from many key vendors in the industry.Vendors like IBM,BEA,Sun and Oracle etc., are providing products that implement the EJB specification.




4)what are the main features in EJB?
a) EJB architecture is inherently transactional,distributed,portable,multiered and secure.
EJB components are serverside components written entirely in the java.
EJB components contain business logic only no system level programing.
System level services such as transactions,security,Life cycle,threading,persistence,etc are automatically managed by the EJB Component by the EJB server.
EJB architecture is wire-protocol neutral Any protocol can be utilized:HTTP,IIOP,DCOM etc.



5)what is current EJB version?
a)EJB2.0 is currently in the Expert Group phase of the JCP(Java Community process) specification development.




6)what are the key features to be included in EJB 2.0?
a)

7)What about RMI/IIOP?
a)



8)How Client contact the Bean?
a)The Client view is provided through two interface—the home interface and the remote interface.These interfaces are provided by classes constructed by the container when a bean is deployed, based on information provided by the bean




9)why doesn’t the client interact with an EnterPrise JavaBean directly?
a)To the client. there appears to be direct interaction with an EnterPrise JavaBean through the home and remote interface.The Container interacts between client and component,Completely concealing both bean instance and its own actions from the clients.



10)What methods are developers required to implement the Enterprise JavaBeans Architecture?
a)There are three categoriesof EJB methods.First, the bean implements methods to those in its home interface containeing methods,second abean implements business logic methods corresponding to those provided by its remote interface.Finally a bean implements methods for interacting with the container.But these methods are not intended for client access, they are hidden by the container.


11)What are the basic types of Enterprise JavaBeans?
a)There are two types of Enterprise beans- session beans and entity beans represending different types of business logic abstactions. Sesssion beans represent behaviors associated with client sessions,they are generally implemented to perform a sequence of tasks with in the context of a transaction.A Session bean is a logical extension of the client program, running process on the Clients behalf remotely on the server.
Entity beans reprsent specific data or collection of data, such as a row in a relational database. Entity bean methods provided operations for action on the data represented by the bean.An entity bean is persistent,it services as long as its data remains in the database.



12)How does a Client find and connect to a specific enterprise bean?
a)A client accesses an Enterprise JavaBean by looking up the class implemnting its home interface by name through JNDI.It then uses methods of the home interface to acquire access to an instance of the class implementing the remote interface.



13)How does a Client find and connect to a specific enterprise bean write the coding?
a) Context ct=new InitialContext();
HaiHome home=(HaiHome)ct.lookup("hai");
HaiRemote remote=home.create();
then remote.Business methods..



14)What general services does a container provide for an Enterprise JavaBean component?
a) A Container provides Enterprise JavaBeans Components with services of several types First it provides services for lifecycle management and instance pooling/cache Pooling(SFSB), including creation,activation,passvation, and destroy.Secod it interacts methods in a bean to enforce transction and security constraints.It enforce policies and restrictions on bean instances, such as reentrance rules security polices , and some others.



15)What classes and interfaces does a session bean developer define?
a)The Session bean developer defines the home and remote interfce that represent the client views of the bean.Developers also create a class that implements both SessionBean and SessionSynchronization interfaces , as well as methods corresponding to those in the beans home and remote interfaces.



16)what are main interfaces in EJB required ?
a)javax.ejb pacakage contains mainly SessionBean,EntityBean Interfaces


17)What are abstract methods in SessionBean ?
a)
public void setSessionContext(SessionContext ct)
public void ejbActivate()
public void ejbPassivate()
public void ejbRemove()



18)What are the abstract methods in EntityBean ?
a)
public void setEntityContext(EntityContext ct)
public void unSetEntityContext()
public void ejbActivate()
public void ejbPassivate()
public void ejbRemove()
public void ejbLoad()
public void ejbStore()


19)What are types in SessionBeans?
a) SessionBeans are mainly two types Stateless and Stateful



20)what are distinction between a stateless and stateful?
a) Stateless beans are beans that don’t maintain state across method calls.They are generally intended to perform individual operations automatically.Any instance of stateless bean can be used by any client at any time. Stateful session beans maintain state within and between transactions. Each Stateful session bean is associated with a specific client.Containers can automatically save and retrieve a beans state in the process of managing instance pools of stateful beans.


21)How do Stateful Session beans maintain consistency across transaction updates?
a) Stateful session beans maintain data consistency by updating their fields each time a transaction is committed.To keep informed of changes in transation status, a stateful session bean implements the SessionSynchronization interface.The Container then calls methods of this interface as it initiates and completes transactions involving the bean.
22)Can’t stateful session beans persistent?
a)Session beans are not designed to be persistent, whether stateful or stateless.A stateful session bean instance typically can’t survive system failures and other destructive events.
23) Is it possible to maintain persistence temporarly in stateful sessiionbeans?
a)yes,it is possible using Handle

24)What Classes and interfaces does an entity bean developer provide?
a) The Entity bean developer defines the home and remote interfaces that represent the cleint view of the bean.Developers also create a class that implements the EntityBean interface, as well as methods corresponding to those in the bean’s home and remote interface.
In addition to defininf create methods in the EJBHome interface, the entity bean develpoers must also implement finder methods.

25)What are types in EntityBeans?
a) EntityBeans are mainly two types BeanManaged and ContainerMAnaged

26)what’s a finder method?
a)A finder method provides a way to access an entity bean by its contents.
Finder methods are designed to be introspected and displayed by devleopment and deployment tools. The principal finder method that must be implement by all entity bean is finderByPrimaryKey.In addition to this method the developer must also implement a primaryKey class to provide each entity bean with a unique,serializable identity.
27)What is the difference between container-managed and beanmanaged persistence?
a)In bean managed persistenece, the bean is entirely responsible for storing and retriving its instance data.The EntityBean interface provides methods for the container to notify an instance when it needs to store or retrieve its data.
In container managed persistence, entity bean data is automatically maintained by the container using a mechanism of its choosing.
28)How is an entity bean created?
a)An entity bean can be created in two ways: by direct action of the client in which a create method is called on the bean’s home interfce or some other action that adds data to the database that the bean type represents.
29)How does the clent get a reference to an existing entitybean?
a)A client can get a reference to an existiing entity bean in several ways:
Receiving the bean as paramater in a method call
Looking the bean uo through a finder method of hte home interface
30) How does a container manages access from multiple transactions on an entiy bean?
a)Container can acquire an exclusive lock on the instances’s sate in the database and serializable acess from multiple transaction to this instance.
31)How do u determine whether two entity beans are the same?
a)By invoking the EntityBen.isIdentical method.This method should be implemented by the entitybean developer to determine when two reference are to the same object.
32)What are the transaction management benefits of the Enterprise JavaBeans architecture?
a)The Enterprise JavaBeans architecture provides automatic support for distributed transations in component based applications.Such distributed transactions can automatically update data in multiple databases.



33) Does Enterprise JavaBeans allow alternatives to container-manged transactions?
a)In addition to container-managed transactions, an Enterprise JavaBeans can participate in client-managed and bean-manged transactions.
34)What transaction attributes do Enterprise JavaBean containers support?
a) A container supports the following value for the transaction attribute of an Enterprise JavaBean.
TX_NOT_SUPPORTED
TX_BEAN_MANAGED
TX_REQUIRED
TX_SUPPORTS
TX_REQUIRES_NEW
TX_MANDATORY
35)Explaine the Transaction attributed?
a)A container supports the following value for the transaction attribute of an Enterprise JavaBean.
2TX_NOT_SUPPORTED NOTSUPPORTED
The bean runs outside the context of a transaction.Existing transactions are suspended for the duration of method calls.
TX_BEAN_MANAGED NEVER
The bean demarks its own transactions boundaries through the JTA UserTransation interface.
TX_REQUIRED REQUIRED
Method calls require a transaction context.If one exists ,it will be used;if none exists,one will be created
TX_SUPPORTS SUPPORTS
Method calls use the current transaction context if one exists,but don’t create one if none exists.
TX_REQUIRES_NEW REQUIRESNEW
Continers create new transactions before each method call on the bean, and commit transacions before returing.
TX_MANDATORY
Method calls require a transacion context.If none exists, an exception is thrown.
36)What levels of transaction isolation does the Enterprise JavaBeans specification support?
a)The Entderprise JavaBeans specification defines four supported levels of transaction isolation:
TRANSACION_READ_COMMITED
TRANSACION_READ_UNCOMMITED
TRANSACION_REPETABLE_READ
TRANSACION_READ_SERIALIZABLE
EJB COMPONENTS DON’T SUPPORT THE JDBC ISOLATION LEVEL TRANSACTION_NONE
37)What is the relationship betwen Enterprise JavaBeans component architecture and XML technology?
a)EJB defines a standard for portable business logic and XML technology defines a standard for portable data.
38)How do you configure a session bean for bean-manged transactions?
a) By set transaction-type in the xml file.

39)How do you configure a session bean for bean-manged transactions?
a) By set transaction-attribute in the xml file or int he deployment descriptor.
41)Is is possible for an EJB client to marshall an object of class java.lang.Class to an EJB?
a)Technically yes, spec. compliant NO! "The enterprise bean must not attempt to query a class to

42)Is it possible to write two EJB’s that share the same Remote and Home interfaces, and have different bean classes?
if so, what are the advantages/disadvantages?
a)Sharing interfaces might be possible, but not trivial.
If you deploy with Sun Deployment Tool 1.2.1 you will get a
java.lang.ClassCastException: MyBean2EJB_EJBObjectImpl ...

43)Is it possible to specify multiple JNDI names when deploying an EJB?
a)No. To achieve this you have to deploy your EJB multiple times each specifying a different JNDI name. ..
44)What is the status of the UML-EJB Mapping Specification ?
a)It is currently > in the expert group stage, meaning that the CAll For > Experts (CAFE) was issued and replies were received. ...

45)Is it legal to have static initializer blocks in EJB?
a)Although technically it is legal,static initializer blocks are used to execute some piece of code before executing any constructor or method while instantiating ...

46)In CMP how can I define a finder method equivalent to a ‘SELECT * FROM BANKS ‘
Weblogic 5.1.0 - Define the following Finder syntax in your weblogic-ejb-jar.xml deployment descriptor.

47)Is it possible to access a CORBA object from a EJB?
a)I am using VisiBroker 4.0 for myCORBA objects and J2EE 1.2.1 for my EJB. then These properties can be set on the commandline (using -Dorg. or using a file named orb.properties. Java:API:EJB, Java:API:CORBA Robert Castaneda ...

48)How can we interact with COM/DCOM components from a EJB component ?
a)A list of tools that integrate Java with the Microsoft platform is
available here. These tools can be used, as long as they stay within
the EJB specification requirements .

49)Is it possible to stop the execution of a method before completion
in a SessionBean?

a)Threads inside an EJB, One possible solution (that requires coding) would be to setting the transaction
50) What is a major difference SessionBean and EntityBean?
a) *SB’s state can be shared by only one client at a time. - persistence storage device is .ser file
*EB’s state can be shared by multiple clients, because as its persistence storage device is DB.
*Used to maintain client’s state persistent in the SB’s instance vars
51) What is the TX operational difference SessionBean and EntityBean?
a) SB may or may not be used for TX operational operations,even they are used for TXs bean developer itself responsible to update the bean values into DB.
b)EBs are specially designed for TX operations where bean develope is only responsible for updating bean values,where the bean values were updated into DB by executing one addditional funtion called ejbStore().
52)Who execute TX operation funtion?
a)Container for every regular intervals and interval time is the refreshMinutes property in JDBC Connection Pool Management.


53) What is the TX operational difference SessionBean and EntityBean?
a) SB may or may not be used for TX operational operations,
even they are used for TXs bean developer itself responsible to update the bean values into DB.
b)EBs are specially designed for TX operations
where bean develope is only responsible for updating bean values,
where the bean values were updated into DB by executing one additional funtion called ejbStore().
54)which beans are TX which are not?
a)
*SB are used for TX & Non Tx operations
*EBs are only used for TX operations.
55)what is the Entitybean flow control?
a)
1) Client obtains Home object reference.
2) Client to obtains Remote reference uses h.findByPrimaryKey(Object o)
Note: In place of Object any Object sub class type of reference can be passed as an argument.
3) The request of client received by HomeImpl class findByPrimaryKey(o)
b) It then checks the number of instance created in the container with the max beans in cache value,
if instances are less then container creates one new EJB instance
56)what are the Factors that influences ejbStore()?
a)
1) For every refereshMinutes interval
2) Before ejbPassivate()
3) Before ejbRemove()
57)In EBs the DB state is more consistent than SBs why?
a) by executing ejbLoad() & ejbStore()
58) In EBs the DB state is more consistent than SBs why?
a) by executing ejbLoad() & ejbStore()
59) what are the Factors that influences ejbLoad()?
a)
1) next to ejbFindByPrimaryKey()
2) after ejbActivate()
3) There is one property in DD file under called
600
Class c=Class.forName("qualified classname");
Object o=c.newInstance();
SBank sb=(simplebank.SBank)o;
sb.setEntitycContext(ec);
sb.ejbFindByPrimaryKey(i);
For the result of above funtion execution if bean doesn’t throws FinderException the container returns Remote object , if Exception found the same exception thrown back to the client.


The Industry-Backed Server-Side Component Architecture
Since its introduction over two years ago, Enterprise JavaBeansTM technology has maintained unprecedented momentum among platform providers and enterprise development teams alike. That’s because the EJBTM server-side component model simplifies development of middleware components that are transactional, scalable, and portable. Enterprise JavaBeans servers reduce the complexity of developing middleware by providing automatic support for middleware services such as transactions, security, database connectivity, and more.
As an example, consider transaction management. In the past, developers have had to either write and maintain transaction management code, or rely on third-party transaction management systems, generally provided through proprietary, vendor specific APIs. In contrast, Enterprise JavaBeans technology enables components to participate in transactions—including distributed transactions—simply by specifying which objects and methods are transactional. The EJB server itself handles the underlying transaction management details, so developers can focus specifically on the business purpose of the objects and methods. And because EJB technology is based on the Java programming language, components can be deployed on any platform and operating system that supports the Enterprise JavaBeans standard, and any operting system.
The Enterprise JavaBeans technology model delivers benefits that address the most pressing concerns of enterprise development teams. These include reduced time to market for mission-critical applications, effortless scalability and portability, reduced reliance on hard to find developer skill sets, and an overall increase in developer productivity. EJB technology reduces the cost of developing enterprise scale applications, while protecting an organization’s existing investment in IT resources.

3)What’s the client view of an Enterprise JavaBeans component?
The client view is provided through two interfaces—the home interface and the remote interface. These interfaces are provided by classes constructed by the container when a bean is deployed, based on information provided by the bean. The home interface provides methods for creating a bean instance, while the remote interface provides the business logic methods for the component. By implementing these interfaces, the container can intercede in client operations on a bean, and offers the client a simplified view of the component.
4)Why doesn’t the client interact with an Enterprise JavaBean directly?
To the client, there appears to be direct interaction with an Enterprise Java Bean through the home and remote interfaces. However, Enterprise JavaBeans architecture is designed to enable clients and components to exist in different runtimes on different systems on a network. The container intercedes between client and component, completely concealing both the bean instance and its own actions from the clients.

5)What methods are developers required to implement the Enterprise JavaBeans architecture?
There are three categories of Enterprise JavaBeans methods. First, the bean implements methods corresponding to those in its home interface—methods largely for creating, locating and accessing instances of the bean. Second, a bean implements business logic methods corresponding to those provided by its remote interface. Finally, a bean implements methods for interacting with the container. Since these methods aren’t intended for client access, they are hidden by the container.

6)What specific services does a container provide for an entity bean?
As with session beans, the tools for a container generate additional classes for an entity bean at deployment time to implement the home and remote interfaces. These classes enable the container to intercede in all client calls on the same entity bean. The container also generates the serializable Handle class, providing a way to identify the entity bean within a specific life cycle. These classes can be implemented to mix in container-specific code for performing customized operations and functionality. In addition to these custom classes, each container provides a class to provide metadata to the client. Finally, where specified by a particular bean, a container manages persistence of selected fields of the entity bean.

7)What’s the difference between container-managed and bean-managed persistence?
In container-managed persistence, entity bean data is automatically maintained by the container using a mechanism of its choosing. For example, a container implemented on top of an RDBMS may manage persistence by storing each bean’s data as a row in a table. Or, the container may use Java programming language serialization for persistence. When a bean chooses to have its persistence container managed, it specifies which of its fields are to be retained.
In bean-managed persistence, the bean is entirely responsible for storing and retrieving its instance data. The EntityBean interface provides methods for the container to notify an instance when it needs to store or retrieve its data.
8)How is an entity bean created?
An entity bean can be created in two ways: by direct action of the client in which a create method is called on the bean’s home interface, or by some other action that adds data to the database that the bean type represents. In fact, in an environment with legacy data, entity objects may "exist" before an Enterprise JavaBean is even deployed.
9)How does the client get a reference to an existing entity bean?
A client can get a reference to an existing entity bean in several ways:
receiving the bean as a parameter in a method call
looking the bean up through a finder method of the home interface
obtaining the bean as a handle, a runtime specific identifier generated for a bean automatically by the container
10)How do you determine whether two entity beans are the same?
By invoking the EntityBean.isIdentical method. This method should be implemented by the entity bean developer to determine when two references are to the same object. Note that the equals and hashCode methods of Object are undefined for entity beans, since clients don’t directly access bean instances within a container.

11)How does a container manage access from multiple transactions on an entity bean?
Containers manage multiple transactions in one of two ways. First, the container can instantiate multiple instances of the bean and let the transaction management of the DBMS handle transaction processing issues. Or, the container can acquire an exclusive lock on the instance’s state in the database, and serialize access from multiple transactions to this instance.
12)How do enterprise beans handle concurrent and loopback calls on entity beans?
Concurrent calls in the same transaction context on the same Enterprise JavaBean component are illegal and may lead to unpredictable results. A bean can be marked as non-reentrant by its deployment descriptor. This allows the container to detect and prevent illegal concurrent calls from clients. On the other hand, some entity beans may require loopback calls: that is, calls where bean A is invoked, in turn invoking bean B, which then invokes a method call on bean A. This kind of concurrency is tricky and is best avoided.
TRANSACTION SUPPORT

14)What are the transaction management benefits of the Enterprise JavaBeans architecture?
The Enterprise JavaBeans architecture provides automatic support for distributed transactions in component based applications. Such distributed transactions can atomically update data in multiple databases, possibly even distributed across multiple sites. The Enterprise JavaBeans model shifts the complexities of managing these transactions from the application developer to the container provider.
Does Enterprise JavaBeans allow alternatives to container-managed transactions?
In addition to container-managed transactions, an Enterprise JavaBean can participate in client-managed and bean-managed transactions.
15)What transaction attributes do Enterprise JavaBean containers support?
A container supports the following values for the transaction attribute of an Enterprise JavaBean.
Not Supported
The bean runs outside the context of a transaction. Existing transactions are suspended for the duration of method calls.
Required
Method calls require a transaction context. If one exists, it will be used; if none exists, one will be created.
Supports
Method calls use the current transaction context if one exists, but don’t create one if none exists. Requires New
Containers create new transactions before each method call on the bean, and commit transactions before returning.
Mandatory
Method calls require a transaction context. If none exists, an exception is thrown.
Never
Method calls require that no transaction context be present. If one exists, an exception is thrown.
16)How do bean-managed transactions work?
When a bean with bean managed transactions is invoked, the container suspends any current transaction in the client’s context. In its method implementation, the bean initiates the transaction through the JTA UserTransaction interface. In stateful beans, the container associates the bean instance with the same transaction context across subsequent method calls until the bean explicitly completes the transaction. However, stateless beans aren’t allowed to maintain transaction context across method calls. Each method invocation must complete any transaction it initiates.

Comments

Popular posts from this blog

Asynchronous Vs. Synchronous Communications

Synchronous (One thread):   1 thread -> |<---A---->||<----B---------->||<------C----->| Synchronous (multi-threaded):   thread A -> |<---A---->| \ thread B ------------> ->|<----B---------->| \ thread C ----------------------------------> ->|<------C----->|

WebSphere MQ Interview Questions

What is MQ and what does it do? Ans. MQ stands for MESSAGE QUEUEING. WebSphere MQ allows application programs to use message queuing to participate in message-driven processing. Application programs can communicate across different platforms by using the appropriate message queuing software products. What is Message driven process? Ans . When messages arrive on a queue, they can automatically start an application using triggering. If necessary, the applications can be stopped when the message (or messages) have been processed. What are advantages of the MQ? Ans. 1. Integration. 2. Asynchrony 3. Assured Delivery 4. Scalability. How does it support the Integration? Ans. Because the MQ is independent of the Operating System you use i.e. it may be Windows, Solaris,AIX.It is independent of the protocol (i.e. TCP/IP, LU6.2, SNA, NetBIOS, UDP).It is not required that both the sender and receiver should be running on the same platform What is Asynchrony? Ans. With messag

Advantages & Disadvantages of Synchronous / Asynchronous Communications?

  Asynchronous Communication Advantages: Requests need not be targeted to specific server. Service need not be available when request is made. No blocking, so resources could be freed.  Could use connectionless protocol Disadvantages: Response times are unpredictable. Error handling usually more complex.  Usually requires connection-oriented protocol.  Harder to design apps Synchronous Communication Advantages: Easy to program Outcome is known immediately  Error recovery easier (usually)  Better real-time response (usually) Disadvantages: Service must be up and ready. Requestor blocks, held resources are “tied up”.  Usually requires connection-oriented protocol