Free Programming Books
Free download ebooks on computer and programming

Free Java Ebook "Beginning J2EE 1.4: From Novice to Professional" Sample Chapter

Beginning J2EE 1.4
Download free chapter 8: EJB Fundamentals
Download chapter

The Java 2 Enterprise Edition (J2EE) is an extremely powerful platform for developing enterprise-level Java-based applications, primarily for the server. This book shows you how to harness that power, guiding you through the details of how the pieces of the J2EE platform fit together.

This book goes further than just showing you how to code a JSP or an EJB: It explains when and where to use these APIs, what their strengths and weaknesses are, and perhaps most important, how to employ the best practices for using them. Specific topics covered include:

  • Creating dynamic clients using JSP and servlets
  • Connecting and using databases through Java Database Connectivity (JDBC)
  • Implementing business tiers using EJB
  • Using Web services and XML in your enterprise applications
This book also contains hands-on tutorials, clear explanations, and working code examples that will take you to the next step-from writing client-side desktop applications to writing enterprise applications. You will learn how to use the individual APIs and tools in the J2EE platform, and how to bring these together to create your own enterprise applications.

< < prev next > >

Why Use EJBs?

Not too long ago, when system developers wanted to create an enterprise application, they would often start by "rolling their own" (or purchasing a proprietary) application server to support the functionality of the application logic layer. Some of the features of an application server include:

  • Client communication-The client, which is often a user interface, must be able to call the methods of objects on the application server via agreed-upon protocols.
  • Session state management-You'll recall our discussions on this topic in the context of JSP and servlet development back in Chapter 5.
  • Transaction management-Some operations, for example when updating data, must occur as a unit of work. If one update fails, they all should fail. Recall that transactions were discussed in Chapter 7.
  • Database connection management-An application server must connect to a database, often using pools of database connections for optimizing resources.
  • User authentication and role-based authorization-Users of an application must often log in for security purposes. The functionality of an application to which a user is allowed access is often based upon the role associated with their user ID.
  • Asynchronous messaging-Applications often need to communicate with other systems in an asynchronous manner, that is, without waiting on the other system to respond. This requires an underlying messaging system that provides guaranteed delivery of these asynchronous messages.
  • Application server administration-Application servers must be administered. For example, they need to be monitored and tuned.
The Enterprise JavaBeans specification defines a common architecture, which has prompted several vendors to build application servers that comply with this specification. Now we can get off-the-shelf application servers that comply with a common standard, benefiting from the competition (in areas such as price, features, and performance) among those vendors. Some of the more common commercial Enterprise JavaBeans application servers are: WebLogic (BEA), Sun ONE (Sun), and WebSphere (IBM).

There are also some very good open-source entries in this market such as JBoss and JOnAS. As you know, Sun provides a freeware Reference Implementation (J2EE SDK) of the J2EE 1.4 and EJB 2.1 specifications that may be used to develop as well as to test an application for compliance with those specifications. The Reference Implementation may not, however, be used to deploy production systems.

The Sun Reference Implementation was used to develop all of the examples and exercises contained in this book.

These application servers, in conjunction with the capabilities defined in the EJB specification, support all of the features listed above and many more. Since they all support the EJB specification, we can develop full-featured enterprise applications and still avoid application server, operating system, and hardware platform vendor lock-in.

Yes, things sure have improved! We now have a standard, specifications-based way to develop and deploy enterprise-class systems. We are approaching the Java dream of developing an application that can run on any vendor platform as-is. This is in contrast to the vendor-specific way we used to develop where each server had its own way of doing things, and where the developer was locked into the chosen platform once the first line of code was written!

For more information on the EJB specification, see the http://java.sun.com/products/ejb/docs.html web site.