About this tutorial
The goal of this tutorial is to give you a practical introduction to the basics of Enterprise JavaBeans (EJB) programming and development. EJB components are at the heart of the Java 2 Platform, Enterprise Edition (J2EE) framework, which is the Java language's extremely successful solution to the needs of enterprise applications. EJB technology provides a standard server-side component model for J2EE application servers, or containers.
This tutorial covers stateless and stateful session beans, entity beans using bean-managed persistence (BMP) and container-managed persistence (CMP), and message-driven beans. Along the way, the tutorial also touches on JDBC, transaction handling with the Java Transaction API (JTA), and the Java Message Service (JMS), and uses these technologies in the sample code. Complete examples based on functional Web applications are discussed throughout the tutorial and a link for the full download of the code is provided in Resources.
After working through the tutorial, you should:
- Understand EJB technology concepts and terminology
- Understand how EJB components work cooperatively with J2EE containers
- Understand the process and requirements for creating EJB components
- Have a solid foundation for developing your own Enterprise JavaBean and J2EE applications
While the tutorial is an introduction to development with EJB technology, this is not entry-level material; you should be an intermediate or higher level Java programmer with some understanding of JDBC to get the most out of it and fully understand the code examples. You will also need to know how servlets and JavaServer Pages (JSP) technology work to understand the client code. However, you can read the material purely to gain an overview of what EJB technology is about and how J2EE and EJB components work together.
The tutorial covers EJB technology as of the J2EE 1.3.1 SDK and the EJB 2.0 specification. At the time of writing, a beta release of J2EE 1.4 and a draft of the 2.1 EJB specification had just been released. Appendix D: What's new in the EJB 2.1 specification? briefly reviews the new capabilities.
In short, if you are a reasonably experienced Java programmer interested in increasing your skill set and understanding the Java platform's approach to enterprise applications, this tutorial is for you.
If you intend to create your own J2EE and EJB applications or want to understand the flow and rationale for the example applications, I suggest going through the tutorial in the following order:
- Read the J2EE/EJB technology overview .
- Read Appendix A: Installing and running J2EE.
- Read Appendix B: Deployment.
- Read Appendix C: About the example applications.
- Then continue with the tutorial at Session beans overview.
The Resources present a list of tutorials, articles, and other references that expand upon the material presented here.
Code samples and installation requirements
To compile and run the example code, and to get hands-on experience in creating EJB components and J2EE applications, you will need both the J2SE and J2EE SDKs, as well as a source code editor or IDE.
The examples were tested using J2SE 1.4.1 and the J2EE 1.3.1 SDK Reference Implementation (J2EE RI) on Windows NT 4.0, Service Pack 6a. The applications have also been proven to run properly, with the appropriate deployment, under JBoss 3.0.4 on both Windows NT and SuSe Linux.
You should be aware that the example programs focus on EJB development for the relevant section, and have not been optimized for production use. Any introductory and most intermediate material suffers this limitation due to the need to zero in on the target topic without the litter of numerous real-world considerations. That's certainly true here, due to the breadth of the areas covered, and many best practices had to be left undone or unmentioned to keep the tutorial understandable and to a reasonable size. The upshot is that you will learn enough to get started with J2EE and EJB technology, but you should look to the Resources and other references before embarking on production-quality applications. In particular, if you want to be more than just a "follow the IDE wizard" EJB developer, you will find yourself frequently reviewing the EJB specification.
Even so, you should read through the example explanations whether or not you intend to review the code or run the applications. These discussions mention specific techniques, and often expand or augment the relevant tutorial section.
The classes, Enterprise Archive (EAR) files, and source code for the examples used in the tutorial are available separately in gsejbExamples.jar. The JAR contains a main directory named gsejbExamples, with subdirectories named Alice, MetricCvt, Survey1, Survey2, Survey3, and SurveyResults, each of which corresponds to an example application. You can also see the applications in action before, or instead of, deploying them yourself at conceptGO's Community page.

