HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

EJB 2.0 is the latest release of the Enterprise JavaBean specification. The major releases of the EJB specification have been 1.0, 1.1, and 2.0. EJB 2.0 adds several crucial features to version 1.1, including message-driven beans, local interfaces, an enhanced container-managed persistence, and EJB-QL (Query Language).

The figure below illustrates the class hierarchy for EJB 2.0 and the interfaces that are included. The main interfaces for EJBs are packaged under javax.ejb; they're standard extensions to the core Java classes.

The javax.ejb package defines the interfaces you need to extend your application's components. By definition, Enterprise JavaBean is a specification for distributed architecture. In Java terms, this means that a Java class running in one JVM should be able to communicate with an EJB component in another via an RMI call. First, let's look at the EJBObject and EJBHome interfaces, which are shown in the middle pane of the figure. These interfaces extend the java.rmi.Remote interface. The Remote interface serves to identify interfaces whose methods may be invoked from a nonlocal virtual machine. Any object that's a remote object must implement this interface.

As you probably know, EJBs can only run inside a J2EE EJB container. The container abstracts many of the low-level services from the application developer (you). One set of services that it abstracts is the life-cycle management of the EJBs. The EJBHome interface is used to create this abstraction and can be accessed remotely to create or find the actual EJB component. The methods are invoked by the remote client, but are executed by the container.

Figure 1
Figure 1

The EJBObject interface is used to define the business methods for your EJB component. The interface defines methods to access the actual EJB class and to remove it when it's no longer needed. The EJBObject is a delegator interface that delegates the actual execution of the business objects to the enterprise bean.

The latest release of the EJB specification adds classes and interfaces to support the concept of colocated EJBs (local interfaces). As you can see in the left pane of the figure, the local interfaces (EJBLocalObject and EJBLocalHome) don't extend the java.rmi.Remote interface. You can't use them to access distributed objects. The local interfaces were added to the EJB specification in 2.0 so that component accesses to EJB components within the same JVM don't have to be done through RMI, which is very expensive since each call requires a distributed call.

The enterprise bean interfaces are illustrated on the left side of the figure. These interfaces were added to the EJB specification in 2.0. Local interfaces support the concept of colocated EJBs (local interfaces). The local interfaces (EJBLocalObject and EJBLocalHome) don't extend the java.rmi.Remote interface so you can't use them to access distributed objects. Other than that, the EJBLocalObject is the equivalent of the EJBObject, and the EJBLocalHome is the equivalent of EJBHome. Note that the same EJB component can implement both interfaces simultaneously, thus allowing remote access through RMI and local access through a local method call.

The right pane of the figure shows the interfaces used to create the actual implementation class. The EnterpriseBean interface is a serializable interface for creating the EJB component. The three types of EJBs supported in 2.0 are EntityBean, SessionBean, and MessageDrivenBean. Each of these extends the EntityBean interface.

As an application developer, for each enterprise JavaBean in your application, you need to extend the appropriate home and remote interfaces (local/remote) and provide an implementation for the appropriate enterprise bean (entity/session/messagedrivenbean).

Details on developing the interfaces and classes for your application's EJBs will be covered in subsequent FAQs.

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.