type=page
status=published
title=What Is an Enterprise Bean?
next=ejb-intro002.html
prev=ejb-intro.html
~~~~~~
= What Is an Enterprise Bean?


[[GIPMB]]

[[what-is-an-enterprise-bean]]
What Is an Enterprise Bean?
---------------------------

Written in the Java programming language, an enterprise bean is a
server-side component that encapsulates the business logic of an
application. The business logic is the code that fulfills the purpose of
the application. In an inventory control application, for example, the
enterprise beans might implement the business logic in methods called
`checkInventoryLevel` and `orderProduct`. By invoking these methods,
clients can access the inventory services provided by the application.

The following topics are addressed here:

* link:#GIPLK[Benefits of Enterprise Beans]
* link:#GIPKN[When to Use Enterprise Beans]
* link:#GIPNM[Types of Enterprise Beans]

[[GIPLK]]

[[benefits-of-enterprise-beans]]
Benefits of Enterprise Beans
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For several reasons, enterprise beans simplify the development of large,
distributed applications. First, because the EJB container provides
system-level services to enterprise beans, the bean developer can
concentrate on solving business problems. The EJB container, rather than
the bean developer, is responsible for system-level services, such as
transaction management and security authorization.

Second, because the beans rather than the clients contain the
application's business logic, the client developer can focus on the
presentation of the client. The client developer does not have to code
the routines that implement business rules or access databases. As a
result, the clients are thinner, a benefit that is particularly
important for clients that run on small devices.

Third, because enterprise beans are portable components, the application
assembler can build new applications from existing beans. Provided that
they use the standard APIs, these applications can run on any compliant
Java EE server.

[[GIPKN]]

[[when-to-use-enterprise-beans]]
When to Use Enterprise Beans
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You should consider using enterprise beans if your application has any
of the following requirements.

* The application must be scalable. To accommodate a growing number of
users, you may need to distribute an application's components across
multiple machines. Not only can the enterprise beans of an application
run on different machines, but also their location will remain
transparent to the clients.
* Transactions must ensure data integrity. Enterprise beans support
transactions, the mechanisms that manage the concurrent access of shared
objects.
* The application will have a variety of clients. With only a few lines
of code, remote clients can easily locate enterprise beans. These
clients can be thin, various, and numerous.

[[GIPNM]]

[[types-of-enterprise-beans]]
Types of Enterprise Beans
~~~~~~~~~~~~~~~~~~~~~~~~~

link:#GIPLZ[Table 35-1] summarizes the two types of enterprise beans.
The following sections discuss each type in more detail.

[[sthref150]][[GIPLZ]]

Table 35-1 Enterprise Bean Types

[width="75%",cols="35%,65%"]
|=======================================================================
|*Enterprise Bean Type* |*Purpose*
|Session |Performs a task for a client; optionally, may implement a web
service

|Message-driven |Acts as a listener for a particular messaging type,
such as the Java Message Service API
|=======================================================================
