A session bean is an enterprise bean that provides a service to a particular user session. A session bean is typically created when the session needs one. Relative to entity beans, session beans are short-lived. A session bean can be of the following types.
An example is an enterprise bean that processes orders. Each order can be processed by an invocation of one method, such as processOrder(). All the information needed for processing is contained in the method parameters.
An example is an online shopping cart. The end user, through the client program, can order a number of items. The stateful session bean managing the interaction must accumulate items until the end user is ready to review the accumulated order, approve or reject items, and initiate processing of the lot. The stateful session bean has to store the unprocessed items and enable the end user to add more.
An example is a bean that is used to initialize data for an application that can be concurrently accessed by many clients.
Session beans can have local interfaces, remote interfaces, or both. Session beans are more likely to have remote interfaces than entity beans and message-driven beans, since they are usually the entry point for access from remote clients.
The interfaces handle client access to the session bean's methods. Modules that are included in the same enterprise application as the EJB module can access the session bean's modules through its local interfaces. Modules that are not in the same enterprise application must access the bean's methods through its remote interfaces.
For more information about the working with session beans, see Chapter 22 Enterprise Beans in the Java EE Tutorial: