Introduction to Enterprise Java Beans (EJB)
By
Dr. Jaspreet Singh Bajaj
Introduction to Enterprise Java Beans (EJB)
Enterprise Java Beans (EJB) is one of the several Java APIs for standard
manufacture of enterprise software.
EJB is a server-side software element that summarizes business logic of an
application.
To run EJB application we need an application server (EJB Container) such as
Jboss, Glassfish, Weblogic, Websphere etc. It performs:
1. Life cycle management
2. Security
3. Transaction management
4. Object pooling
EJB application is deployed on the server, so it is called server side component also.
Types of Enterprise Java Beans
There are three types of EJB:
1. Session Bean:
(i) Stateful Session bean
(ii) Stateless Session bean :
2. Message Driven Bean:
3. Entity Bean:
(i) Bean Managed Persistence :
(ii) Container Managed Persistence :
1. Session Bean: Session bean contains business logic that can
be invoked by local, remote or webservice client. There are two
types of session beans:
(i) Stateful session bean and (ii) Stateless session bean.
(i) Stateful Session bean :
Stateful session bean performs business task with the help of
a state. Stateful session bean can be used to access various
method calls by storing the information in an instance
variable.
Some of the applications require information to be stored across
separate method calls. E.g. In a shopping site, the items chosen
by a customer must be stored as data is an example of stateful
(ii) Stateless Session bean :
Stateless session bean implement business logic without
having a persistent storage mechanism, such as a state
or database and can used shared data. Stateless session
bean can be used in situations where information is not
required to used across call methods.
2. Message Driven Bean: Like Session Bean, it contains the
business logic but it is invoked by passing message.
3. Entity Bean: It summarizes the state that can be
remained in the database. It is deprecated. Now, it is
replaced with JPA (Java Persistent API). There are two
types of entity bean:
(i) Bean Managed Persistence :
In a bean managed persistence type of entity bean, the
programmer has to write the code for database calls. It
persists across multiple sessions and multiple clients.
(ii) Container Managed Persistence :
Container managed persistence are enterprise bean that
persists across database. In container managed
persistence the container take care of database calls.
When to use Enterprise Java Beans
1.Application needs Remote Access. In other words,
it is distributed.
2.Application needs to be scalable. EJB applications
supports load balancing, clustering and fail-over.
3.Application needs encapsulated business
logic. EJB application is differentiated from
demonstration and persistent layer.
Advantages of Enterprise Java Beans
1. EJB repository yields system-level services to enterprise beans,
the bean developer can focus on solving business problems.
2. The beans rather than the clients contain the application’s
business logic, the client developer can focus on the presentation
of the client..
3. Enterprise Java Beans are portable elements, the application
assembler can build new applications from the beans that already
exists.
Disadvantages of Enterprise Java Beans
1. Requires application server
2. Requires only java client. For other language client,
you need to go for webservice.
3. Complex to understand and develop EJB applications.
Difference between Javabeans and
Enterprise Javabeans
S.No
JavaBeans Enterprise JavaBeans
.
Even though EJB is a component technology, it neither
1. Javabeans is a component technology to create reconstructs nor enhances the original JavaBean
universal Java components. specification.
An external interface called a properties
A deployment descriptor is given in Enterprise JavaBeans
interface is given in JavaBeans, that allows a
2. builder tool to describes the functionality of a to interpret the functionality to an external builder tool
bean. or IDE.
Enterprise JavaBeans are categorized into three types –
3. There is no further category of Java Beans.
session beans, message driven beans and entity beans.
JavaBeans have not any definite support exists EJBs may be transactional and transactional support is
4. for transactions. provided by the EJB servers.
Difference between Javabeans and
Enterprise Javabeans
S.No
JavaBeans Enterprise JavaBeans
.
JavaBeans are designed for a single process and EJBs are remotely executable components or business
5. are localized objects.
JavaBeans may be visible or non-visible
6. components.Visual GUI component (Button, An EJB is a non-visual isolated object.
listbox, graphics) are examples of JavaBeans.
JavaBeans has components bridges.A JavaBeans ActiveX controls are designed for the desktop so EJB
7.
can also be arranged as an ActiveX control. cannot be deployed as an ActiveX control.
JavaBeans are mainly designed to run on the
8. client side whereas one can develop server side EJBs are deployed on the server-side only.
JavaBeans.