This chapter presents an overview of the J2EE architecture and Enterprise JavaBeans architecture. We'll begin with the concepts behind the J2EE architecture and how the J2EE components help you design distributed applications. Next, we'll discuss the J2EE application server and the role of the container in each server. This helps you understand how enterprise beans fit into the big picture.
There's a lot of terminology that goes along with enterprise beans, so this chapter is a good place to define terms. We'll start with the concepts behind session beans (stateless and stateful), entity beans, and message-driven beans. We'll help you understand how entity beans with bean-managed and container-managed persistence interact with a database. You'll also learn about bean life cycles, entity relationships, interfaces (home, local home, remote, and local) and asynchronous messaging.
This chapter is meant as an overview, so some of the topic discussions will be brief. Others will be explained in more detail. There will, of course, be much more to talk about when we start designing enterprise systems in later chapters. Let's start with the J2EE architecture, which is the foundation of enterprise beans.
2.1 The J2EE Architecture
The J2EE platform gives you a multitiered application model to develop distributed components. Although any number of tiers is possible, a three-tier architecture is typical. Figure 21 shows the approach.
Figure 21 Three-Tier J2EE Architecture
The client machine supports web browsers, Java applets, and stand-alone applications. A client application may be as simple as a command line program running as an administrator client or a graphical user interface created from Java Swing or AWT (Abstract Window Toolkit) components. Regardless, J2EE applications encourage thin clients in the presentation tier. A thin client is a lightweight interface that does not perform database queries, implement business logic, or connect to legacy code. These types of "heavyweight" operations preferably belong to other tiers.
The J2EE server machine is the center of the architecture. This middle tier contains web components and business objects managed by the application server. The web components dynamically process user requests and construct responses to client applications. The business objects implement the logic of a business domain. Both components are managed by a J2EE application server that provides important system services for these components, such as security, transaction management, naming and directory lookups, and remote connectivity. By placing these services under control of the J2EE application server, client components focus only on presentation logic. And, business objects are easier for developers to write. Furthermore, the architecture encourages the separation of business logic from presentation logic (or model from view).
The database server machine handles the database back end. This includes mainframe transactions, databases, Enterprise Resource Planning (ERP) systems, and legacy code. Another advantage of the three-tier architecture is that older systems can take on a whole new "look" using the J2EE platform. This is the approach many businesses are taking as they migrate their legacy systems to the web in a modern distributed computing environment.