having to rewrite your code; these concerns are taken care of by EJB container vendors via
features like thread safety, distributed transactions, pooling, passivation, asynchronous pro-
cessing, messaging, and remoting. You can count on doing minimal optimization or mov-
ing your application to a distributed, clustered server farm by doing nothing more than a
bit of configuration.
We expect that by now you're getting jazzed about EJB and you're eager to learn more.
So let's jump right in and see how you can use EJB to build the business logic tier of your
applications, starting with the beans.
1.2. Understanding EJB types
In EJB-speak, a component is a bean . If your manager doesn't find the Java “coffee bean”
play on words cute either, blame Sun's marketing department. Hey, at least you get to hear
people in suits use the words “Enterprise” and “bean” in close sequence as if it were per-
As we mentioned, EJB classifies beans into two types based on what they're used for:
• Session beans
• Message-driven beans
Each bean type serves a purpose and can use a specific subset of EJB services. The real
purpose of bean types is to safeguard against overloading them with services that cross
wires. This is kind of like making sure the accountant in the horn-rimmed glasses doesn't
get too curious about what happens when you touch both ends of a car battery terminal at
the same time. Bean classification also helps you understand and organize an application in
a sensible way; for example, bean types help you develop applications based on a layered
architecture. Let's start digging a little deeper into the various EJB component types, start-
ing with session beans.
1.2.1. Session beans
A session bean is invoked by a client to perform a specific business operation, such as
checking the credit history of a customer. The name session implies that a bean instance is