Edition 1.4 Bible
James McGovern, Rahim Adatia, Yakov Fain,
Jason Gordon, Ethan Henry, Walter Hurst,
Ashish Jain, Mark Little, Vaidyanathan Nagarajan,
Harshad Oak, Lee Anne Phillips
Edition 1.4 Bible
James McGovern, Rahim Adatia, Yakov Fain,
Jason Gordon, Ethan Henry, Walter Hurst,
Ashish Jain, Mark Little, Vaidyanathan Nagarajan,
Harshad Oak, Lee Anne Phillips
About the Authors
James McGovern is currently employed as an enterprise architect for Hartford
Financial Services. He is the coauthor of The Practical Guide to Enterprise
Architecture (Prentice Hall, 2003), Java Web Services Architecture (Morgan
Kaufmann, 2003), and Xquery — Kick Start (Sams Publishing, 2003). James has 16
years of experience in information technology. He is a member of the Java
Community Process, the IEEE, and the Worldwide Institute of Software Architects.
He holds industry certifications from Microsoft, Cisco, and Sun.
Rahim Adatia has been programming since he got his first computer — a TRS-80 —
way back in the beginning of the ’80s. Fortunately, he didn’t stagnate there and pro-
gressed on to developing large-scale enterprise architectures using C/C++, UML,
CORBA, J2EE/EJB/Java, and now C# and .NET. He has applied his more than 15
years of experience to leading implementations at Charles Schwab, Williams
Communications, Valtech, Nortel Networks, Corel Corporation, Lokah Limited, and
T-Mobile International, to name a few. Most recently, he has focused on the wireless
middleware market, where he has led product development using Web services,
J2EE, and .NET. He is also a delegate for T-Mobile International at the Open Mobile
Alliance standards body. Rahim has contributed to numerous books and articles
throughout his career, including the books Professional EJB and J#, and is actively
reviewing other titles. He can be reached at email@example.com.
Yakov Fain has more than 20 years of experience in information technology and is
an experienced architect, developer, instructor, and mentor. He is the author of The
Java Tutorial for the Real World. Yakov is the principal of Smart Data Processing, Inc.
(http://www.smartdataprocessing.com), whose clients include major Wall
Street companies. He is a Sun Certified Java 2 Programmer and a Sybase Certified
Jason Gordon is a software engineer for Verizon and serves as lead for the Global
Email system team. While at Verizon he has played a variety of roles, including
systems architect for the eBusiness Technology Integration and eInfrastructure
group and key developer of the EDGE project, which helped provide a Web-based
infrastructure to facilitate the merger of Bell Atlantic and GTE into Verizon. Jason
also served as a member of Verizon’s XML-Task Force and collaborated on several
wireless and Web-services initiatives within the company. In addition to being an
active technical author, Jason also currently serves as the national technology
coordinator for the National Society of Black Engineers. He can be reached at
firstname.lastname@example.org or http://www.jtgordon.com.
Ethan Henry has most recently worked as the manager of training services at
Sitraka. In previous positions he was a developer, product manager, and Java evan-
gelist. He has written numerous articles for Java Report, Dr. Dobbs Journal, Java
Developers Journal, and Web Techniques. He has been a technical reviewer of
multiple books, including Enterprise Java Beans by Valesky, Java How to Program by
Dietel and Dietel, Professional JSP by Wrox, and Java Language API Superbible from
the Waite Group all the way back in 1996.
iv About the Authors
Walter Hurst is the chief technology officer and founder of Wakesoft. He is widely
recognized as a leader in the design and implementation of large-scale distributed
enterprise applications. At Wakesoft, Walter was the product architect and author
before becoming more involved in company strategy and industry leadership. He is
a frequent speaker at conferences and often writes for technical publications.
During his career he has been involved in the design, architecture, and implementa-
tion of distributed business systems for many Fortune 1000 companies as an inde-
pendent consultant and also, while at Xpedior and Andersen Consulting, Walter
received a B.S. in computer engineering from the University of Michigan. When he
needs a break from technology, Walter volunteers as a scuba diver for the Steinhart
Aquarium in San Francisco, where he cleans the shark tank.
Ashish Jain is an enterprise consultant/architect with over ten years of IT experi-
ence. He currently works for BEA Systems Professional Services. In this capacity,
Ashish assists BEA customers in designing and implementing their e-business
strategies using solutions based on J2EE. He holds several industry certifications
from SUN and BEA. He is an active member of local J2EE-user groups and a board
member of the Denver BEA-user group. He holds a degree in electronics engineering
from BITS Pilani, India.
Mark Little is Head of Transactions Technology for Arjuna Technologies Limited, a
company that spun off from Hewlett-Packard to concentrate on developing transac-
tions technologies for J2EE and Web services. Prior to this, Mark was a distin-
guished engineer/architect in HP’s Arjuna Labs in England, where he led the HP
Transaction Service and HP Web Services Transaction teams. He is one of the pri-
mary authors of the OMG Activity Service Specification. He is a member of the
expert group for the work in J2EE: JSR 95 and JSR 117, and is the specification lead
for JSR 156 (Java API for XML Transactions). Mark is active on the OTS Revision
Task Force and the OASIS Business Transactions Protocol specification. He is the
coauthor of an upcoming book, Transaction and Java for Systems Professionals
(Prentice Hall). He has been published in many industry magazines, including
Doctor Dobbs, The Java Developers Journal, the Web Services Journal,
Developer.com, and Application Development Advisor. Mark holds a Ph.D. in com-
puter science from the University of Newcastle.
Vaidyanathan Nagarajan, a.k.a Nathan, is the coauthor of a recent book, Xquery —
Kick Start (Sams Publishing). He coauthored Professional EJB for Wrox in summer of
2001. He has seven years of experience in information technology. Prior to joining
Hartford Life Insurance as an enterprise developer, he worked as a consultant to
Netscape Professional Services. He has an M.B.A. in General Management from a
leading business school in the New England area. He is a former student of the
Indian Institute of Technology, Mumbai, India. His main interests include program-
ming in Java, robotics using Lego Mindstorms, writing, reading, and cartooning. If
he is not thinking about design patterns or Java, he will be modeling a robot in his
robotic lab. He can be reached at email@example.com.
vAbout the Authors
Harshad Oak holds a master’s degree in computer management and is a Sun
Certified Java Programmer and a Sun Certified Web Component Developer. He has
been part of several J2EE projects at i-flex Solutions and Cognizant Technology
Solutions. He is also a regular contributor of articles to developer Web sites like
Lee Anne Phillips has a long history in computer networking and interface design,
having created beaucoup systems-firmware and machine-language hardware-inter-
face routines before the appearance of Java and other sensible tools to relieve the
burdens of a suffering humanity. She attended the University of California at
Berkeley. Lee Anne is the author of many books and articles on computer-related
subjects, including Special Edition Using XML, Practical HTML 4, and about a fifth of
HTML 4.0 Unleashed Professional Reference Edition. An extended list may be seen on
her Web site: www.leeanne.com.
Valerie H. Perry
S. B. Kleinman
Mary Beth Wakefield
Vice President & Executive Group
Vice President and Executive
Vice President and Publisher
Joseph B. Wikert
Executive Editorial Director
Graphics and Production Specialists
Quality Control Technicians
Media Development Specialist
Proofreading and Indexing
TECHBOOKS Production Services
Something about this book needs to be short, so I guess it’s going to have to be
the foreword. Seriously, though, this is a very good book. In fact, it’s the best
introduction to J2EE that I’ve seen. It’s well written, covering all the information you
need to succeed with J2EE. And it’s presented in an order that makes sense — the
chapters provide an end-to-end overview of J2EE. The book starts by showing you
how to build the frontend of your application, then describes your connectivity
options, then shows you how to build your business logic using Enterprise
JavaBeans (EJB), and finally explains how to connect to the backend databases. In
other words, this book is architecturally layered.
Why should you read this book? First, because the authors know what they’re talk-
ing about and can explain it in ways that you can understand. Second, because it
really does cover the fundamentals of J2EE incredibly well. The first five parts of
this book are oriented toward people learning to work with J2EE technology, and in
my opinion they do an incredibly good job of explaining exactly what you need to
know. Third, because the book goes beyond J2EE. Part VI is a great overview of
using Web services with J2EE, a critical issue most developers need to understand.
Part VII is a great overview of common J2EE patterns, and Part VIII covers such
important topics as performance and frameworks. In many ways this book is a
“one-stop shop” for J2EE information.
In the end the thing that I like most about this book is that it’s practical. Yes, it’s
pretty darn big, but as a result it provides a significant amount of real-world advice.
Isn’t that what good books are supposed to do?
Scott W. Ambler
Senior consultant, Ronin International, Inc. (http://www.ronin-intl.com)
Author, Agile Modeling, Agile Database Techniques
Coauthor, Mastering EJB 2/e
The process of writing a book is more time-consuming than anyone could ever
imagine. Luckily, the author team was composed of very talented people who
made the experience enjoyable. Some doubted that we could complete a book of
this magnitude on schedule without sacrificing quality. That you are reading it now
means that we were successful in our undertakings.
This book is the result of many people’s efforts. We would first like to thank our
acquisitions editor, Jim Minatel, for providing insight into the publishing industry in
general, and for allowing us to challenge the typical book-production process and
to focus on writing a good book instead of simply following a publishing formula.
The team would also like to thank Neil Romanosky for his efforts in making Wiley a
little more agile.
We would also like to acknowledge authors we have worked with in the past and
hope to work with in the future, including Sameer Tyagi, Martin Fowler, Sunil
Mathew, James Linn, Michael Stevens, Elias Jo, Vikas Sharan, John Crupi, Steven
Graham, Erich Gamma, Paul Reed, Tim Howes, Kent Beck, Jeff Sutherland, Marty
Biggs, Alistair Cockburn, Ed Roman, Nitin Narayan, Marty Biggs, Chris Caserio, Kurt
Cagle, Per Bothner, and Jeff Ryan.
To our peers in the industry who maintain a sense of speed, agility, and balance
James McGovern — First, I must thank my wife, Sherry, and my son, little James,
for putting up with me for the past several months while I’ve kidnapped and held
myself hostage in my dungeon (office) working on this book. I know they would
have liked to have me around more, but writing this book is something I really
needed to do. Thank you for your support.
I would like to acknowledge my Connecticut family: Daisy May, Pamela, Annika,
Demesha, Aunt Jesse, and the little doggie Pinto. Universal greetings to my Trinidad
family: Soogia, Kello Ricky (Kenrick), Robby (Kiley), Kelon, and Keifer, and to my
United Kingdom family: Nicholas, Ian, and Alex.
Finally, thanks to my father James Sr. and mother Mattie Lee, who gave me the
courage to start and the discipline to finish.
Rahim Adatia — I would like to thank James McGovern, Jim Minatel, and Mark
Enochs for all their hard work in developing this book. Thank you for your patience.
I would also like to thank the professors and colleagues I have worked with at the
University of Ottawa, Valtech (U.K. and U.S.A.!), BEA, and T-Mobile International.
Last but not least, I would like to thank my family and friends who have been there
to support and encourage me — I know that I can be difficult at times (did I say
that?). Thank you for your strength.
Yakov Fain — I’d like to thank my family — Natalia, Yuri, and David — for their love
and support. I’d also like to thank a wonderful teacher and a lovely lady, Dr. Alice S.
Koutkova, and close friends of our family, Dora and Felix Rubinchik.
Jason Gordon — I would like to thank GOD for giving me guidance and strength. I
would also like to acknowledge the following people: Abby, Jerry, Marvin, Charlie
Lindahl, Beth, Mitch, Kyle, Lisa, The Jamisons, and my entire family. A special
thanks to my Mother who has been there every time I needed her. I would like to
thank MaryKim for her encouraging words and advice. I would like to thank Lee
Felts who gave me the inspiration to write. I would like to thank Kyle for his support
and guidance. Last but not least . . . thanks to Mr. Starbucks and his friend Mr.
Caffeine! You guys are awesome!
Ethan Henry—I’d like to thank my family, especially my wonderful wife Margit, for
helping me work on this book, my colleagues at Sitraka (now Quest Software), the rest
of the author team, and the fine people at Wiley who helped pull everything together.
Walter Hurst — For all the effort required writing my chapter, I would first like to
thank my wife, Christine. This chapter is just one more instance where I had to
work hard on nights and weekends, and her cheerful support is what made it all
possible. I would also like to thank James McGovern for inviting me to write the
chapter; this book would not be possible without a lead author organizing the many
required writers, which is a task probably very akin to herding cats. The concepts
contained within this chapter I have learned indirectly from thought leaders in the
industry, directly from my time at Sage IT Partners, and even more definitely since
founding Wakesoft. There are too many individuals to list them, but they know who
they are. Thank you.
Ashish Jain — I would like to thank my wife Nishma and our son Eshan for their
love and patience and support. I would also like to thank my colleagues at BEA,
Chris John and Bob Webster, for their useful and insightful comments.
Mark Little — I would like to thank my wife Paula and two sons, Daniel and Adam
(who was born during the writing of this book) for their support and love. They
have put up with my disappearances into the book-writing world many times over
the past few months, and I know it can’t have been easy. My entire family has given
all the effort over the many years meaning and ensured that I stayed sane. Lots of
love to Adam, who thinks his rattle and toys are far more important than Java
Vaidyanathan Nagarajan — I would like to thank my wife Padma and my parents,
Nagarajan and Geetha, for encouraging me to put in my best effort in contributing
to this book. This book is dedicated to Padma, Geetha, Nagarajan, Vedham, all my
family members, and my best friends the Srinivasans (Arun and Sujata) who have
supported me in being what I am. A special mention goes to James McGovern for
giving me an opportunity to work with him and for introducing me to the world of
writing technical books. Thanks to those Asterix comics (by the time I completed
writing this book, I have collected all the Asterix collection except for one) and
Dilbert strips for making the creative juices run fresh in me every morning. I would
also like to take a moment to thank my friend and colleague, Thomas Nordlund, for
prototyping the source code for the session-authenticator pattern.
Harshad Oak — I wish to thank my father, Baba, without whose affection, support,
inspiration, and experiments at the art of cooking Indian food, nothing would have
been possible. I also wish to thank my dear sister Charu for always being there for
me, and Sangeeta for helping me with my writing and painstakingly reviewing my
work. Thanks to Jim and Mark for being a big help throughout this project and to
Laura and Stacey for playing an important part in my writing endeavors.
Lee Anne Phillips — My deepest thanks to Alison Eve Ulman, who provided needed
support and advice throughout the development of the chapter on JAAS, and to my
editors, whose tactful suggestions rarely failed to be either right on the mark or an
indication of a needed new direction for the phrase or discussion in question. Any
remaining errors or infelicitous explanations are entirely my own responsibility, the
creation of a book being a cooperative enterprise, especially this one that ulti-
mately depends on the imagination and skill of the author.
The world of information technology is evolving rapidly. Enterprise applications
must deliver services that meet the needs of the global business environment,
ensure that users’ data remains private, protect the integrity of enterprise data, and
ensure that business transactions are accurate and processed quickly. Enterprises
today need to extend their reach, reduce their costs, and lower the response times
of their services to customers, employers, and suppliers. Typically, applications
that do these things must combine enterprise information systems (EIS) with new
business functions that deliver services to a broad range of users.
J2EE reduces the cost and complexity of developing multi-tier enterprise services.
J2EE applications can be rapidly deployed and easily enhanced as the enterprise
responds to competitive pressures.
This book provides leading-edge but practical examples to illustrate how J2EE can
be applied to existing business and technology initiatives. The book focuses on
thinking concretely about the specifications that comprise J2EE, while providing
solutions to today’s problems.
This book is ideal for those who prefer personal interaction to processes and tools,
responding to change to following a plan, and techniques that work to comprehen-
sive documentation. Some of the respective authors’ anecdotal experiences will
periodically appear. This will make for an easier read and allow the reader to con-
nect and become involved.
Whom this book is for
J2EE is the foundation of many large-scale application-development projects. As
major corporations shift away from expanding the spaghetti code contained within
their monolithic mainframe systems, they are looking for an architecture that will
prevent them from making past mistakes again. J2EE is the answer. The author
team, as writers and buyers of many of today’s information-technology books,
wanted to write something different from what is currently on the shelves. This
book is targeted toward architects and senior developers who understand the fun-
damentals of Java and want to take the next step. The driving goals are to provide a
complete overview of the major J2EE technologies and to show how they can be
used to solve non-trivial business problems.
If you are a developer, an architect, or even a project manager, you will appreciate
our attempt to bring you a no-frills introduction to J2EE. The author team has
worked many long hours to bring you the ultimate guide that explains everything
you need to know about J2EE. This book provides examples that clearly illustrate
how the technologies contained within can be applied to existing business and
technology undertakings. Where appropriate, this book will provide additional
sources of information.
Each author has enjoyed the freedom to provide anecdotal experiences where
appropriate, as all knowledge is beneficial. This book should be considered a
trusted advisor and an authoritative source of J2EE information.
What this book covers
The Java 2 Platform, Enterprise Edition (J2EE) defines the standard for developing
n-tier enterprise applications using Java. J2EE simplifies enterprise applications by
basing them on standardized modular components and providing for those compo-
nents a complete set of services that handle the complexities automatically.
N-tier applications are difficult to build. Usually building such an application
requires people with a variety of skills and an understanding of both modern and
legacy code and data. Enterprise applications typically use heterogeneous
approaches to systems development and require the integration of tools from a
variety of vendors and the merging of disparate application models and standards.
This book covers the various components of J2EE that are used to build enterprise
n-tier applications, including the following:
✦ JavaServer Pages (JSP)
✦ Enterprise JavaBeans (EJB)
✦ Java Messaging Service (JMS)
✦ Java Naming and Directory Interface (JNDI)
✦ Java Authentication and Authorization Service (JAAS)
✦ Java Connector Architecture (JCA)
✦ And more . . .
The author team recommends that the chapters in this book be read in order, as
each chapter builds upon previous chapters. If reading the chapters in order is not
viable, reading a particular section in a single sitting may be a better choice.
What this book is not!
The purpose of this book is to cover the various components of J2EE. Understanding
J2EE requires a working knowledge of the basics of Java. This book’s coverage of
Java will be limited to coverage of the APIs required for advanced J2EE features. All
the examples within this book use Java, so it is important to minimally understand
the principles of another object-oriented language such as C++ or Smalltalk.
The authors have avoided recommending software-development processes, pro-
ject-management discipline, software architecture, or naming conventions. We
believe that our readers are better served by other books that cover these topics.
What you’ll need
To gain the most benefit from this book, you’ll need a workstation loaded up with
the following software:
✦ An application server that supports Sun’s J2EE SDK, version 1.4
✦ A relational database, such as Microsoft SQL Server or Oracle
✦ An integrated development environment (IDE) for Java, such as Borland
JBuilder (http://www.borland.com) or Eclipse (http://www.eclipse.org)
✦ An SMTP-compliant mail server, if you plan to write applications that will pro-
cess incoming or outgoing electronic mail
Conventions used in this book
This book uses the following conventions when it explains how to do something on
✦ Italic type introduces new technical terms.
✦ Bold type indicates a new section of code that has been introduced into an
existing code listing, or something you should type.
✦ Monospace font is for output you see on your computer.
✦ Keystroke combinations are separated by plus signs (+). For example,
Ctrl+Alt+Del means “press the Ctrl, Alt, and Delete keys together.”
✦ When using the mouse, assuming you’re right-handed, the term click refers to
pressing the left mouse button once. The term double-click refers to pressing
the left mouse button twice. The term right-click refers to pressing the right
mouse button once. The term drag refers to holding down the left mouse but-
ton and pulling the pointer to where you want it to be. If you are left-handed,
adjust these instructions to match your mouse setup.
The companion Web site
Be sure to visit the companion Web site for this book at http://www.wiley.com/
compbooks/mcgovern, where you can download code listings and program exam-
ples covered in this book. These are also available at http://www.j2eebible.com.
Any source code shown in the examples is free, and you may use it as your heart
desires, with the sole restriction that you may not claim you are the author. Neither
the publisher, the authors, or their respective employers provide any form of war-
ranty on the code contained within this book, nor do they guarantee its usefulness
for any particular purpose.
The author team and editors have worked long hours to bring you a comprehensive
guide to J2EE. If you find any mistakes in this book, we would appreciate your con-
tacting us at our respective e-mail addresses. We equally appreciate any comments,
suggestions, praise, or letters of admiration you have for this book.
This book will use for its examples a fictitious airline company and magazine pub-
lisher. Any example companies, organizations, products, domain names, e-mail
addresses, people, places, and events depicted in these examples are fictitious. No
association with any real company, organization, product, domain name, e-mail
address, person, place, or events is intended or should be inferred.
✦ ✦ ✦ ✦
In This Part
and the J2EE Platform
✦ ✦ ✦ ✦
P A R T
Java and the
Java 2 Enterprise Edition, or J2EE, is a package of specifi-
cations aligned to enable the development of multi-tier
enterprise applications. The specifications outline the various
components needed within a J2EE enterprise system, the
technologies for accessing and providing services, and even
the roles played during the development, deployment, and
runtime lifecycle. The combination of these specifications
introduced faster and more streamlined development pro-
cesses, to the software industry, that have been mapped onto
common software methodologies such as RUP, XP, and others.
J2EE has fast become the de facto standard for developing and
deploying enterprise systems. It represents Sun’s attempt to
take their Java mantra of “Write Once, Run Anywhere” to the
next level and make it “Write Once, Deploy Anywhere.” While
using it is not as easy as dropping new code fragments into
existing code, J2EE has made significant strides in easing the
burden on the developers and deployers of a system.
This chapter will introduce J2EE. At the time of this writing
J2EE 1.4 is in beta but it should be in public release by the
time this book is published.
Reviewing a Brief History of Java
In 1995, Sun released Java, a fully object-oriented program-
ming language. While most of the concepts within Java were
not new, it did meld many features, such as memory manage-
ment and garbage collection from Smalltalk and the syntax of
C/C++, into a new easy-to-learn programming language.
11C H A P T E R
✦ ✦ ✦ ✦
In This Chapter
Reviewing a brief
history of Java
origin of J2EE
the J2EE APIs
new in J2EE 1.4
the future of J2EE
✦ ✦ ✦ ✦
4 Part I ✦ Introduction
Java brought the concept of a virtual machine into the mainstream. Traditionally,
programs written in a particular language, such as C, were compiled directly for
the operating system on which the program would run. In order for companies to
support multiple-target runtime environments, a new build environment became
necessary for each target — for example, Windows95, HP-UX, Solaris, and so on.
However, Java is not compiled completely, but instead is compiled to an intermedi-
ary stage as Java bytecodes. At runtime, the Java bytecodes are executed within a
virtual machine, which is a piece of software that interprets the bytecodes in run-
time into the native binary for the operating system.
The virtual machine is responsible for allocating and releasing memory, ensuring
security, and optimizing the execution of the Java bytecodes, among other functions.
This has indeed created a new market simply for virtual machines for various oper-
ating systems. As long as a virtual machine is available for a particular operating
system, the Java bytecodes should be able to be executed on it, assuming that all
the Java APIs are implemented. Figure 1-1 shows the stages that Java code must go
through before being executed on a target machine.
Figure 1-1: Java Virtual Machine compilation
* Not all APIs shown
5Chapter 1 ✦ Understanding Java and the J2EE Platform
Around 1998, Sun updated the Java specification and introduced Java 1.2 along with
the accompanying libraries, making Java not only a language, but also a platform —
Java 2 Standard Edition (J2SE). Prior to the release of J2SE, Java had gone through
the number of revisions and new libraries were not necessarily introduced in a con-
certed manner, making it difficult for developers to understand. Prior to the J2SE,
the Java Development Kit (JDK) was the primary package that was installed, and
developers would choose which additional libraries they would want such as Java
Database Connectivity (JDBC) or Swing. This led to inconsistent environments mak-
ing it difficult to port code since the deploying party would not be guaranteed of
the libraries on the deployment platform.
JDBC is the topic of Chapter 18.
With J2SE, Sun attempted to fix the problem by bundling the various libraries into
a single unit. J2SE provided libraries for GUI support, networking, database access,
and more. J2SE is also the foundation for the J2EE.
Examining the Origin of (J2EE)
J2SE was sufficient for developing stand-alone applications, but what was missing
was a standard way to develop and deploy enterprise applications — one similar to
the standard method for using the Common Object Request Broker Architecture
(CORBA). While J2SE already included enterprise-level APIs such as Remote Method
Invocations (RMI), too much was still left undefined — such as persistence, transac-
tion management, security, and so on. This resulted in a plethora of architectures
J2EE, introduced in 1998, defines a multi-tier architecture for enterprise information
systems (EIS). By defining the way in which multi-tier applications should be devel-
oped, J2EE reduces the costs, in both time and money, of developing large-scale
enterprise systems. Figure 1-2 illustrates the J2EE architecture, highlighting the new
additions within the 1.4 release.
The J2EE platform specifies the logical application components within a system and
defines the roles played in the development process.
6 Part I ✦ Introduction
Figure 1-2: J2EE Architecture (source: Javasoft)
Four application components are defined within the J2EE platform. They are as
✦ Application clients (Standalone Java clients)
✦ Applets (Java code which executes within a browser)
✦ Web components (JSPs, Servlets)
✦ Server components (EJBs, J2EE API implementations)
A product does not need to support all types of components; the norm is to provide
an implementation to support a particular component type. However, all compo-
nents are similar in that they run within a container. The container is responsible
for providing the runtime environment, the mechanism for identifying and under-
standing the file formats used for deployment, and the standard services for appli-
cation components to use.
The four application components are discussed in the following sections.
Clients are generally stand-alone applications written in Java. They run within a vir-
tual machine and can use the J2EE standard services to access components located
within another tier. The J2EE standard services are usually provided on the client
via an installation of J2SE, or along with the distribution of the application itself.
Runtime VM Interpretation
Intermediate compilationIntermediate compilation
Runtime VM interpretation
7Chapter 1 ✦ Understanding Java and the J2EE Platform
Applets are similar to application clients, but execute within a Web browser. Initially
applets garnered extensive attention, as they were seen as a means of making Web
pages more dynamic. Most Web browsers have an embedded Java Virtual Machine
(JVM); however, the Java plugin can be used to force the browser to use a particu-
lar version of JVM.
Although the term can be misleading, Web components do not execute on the client
side. Web components are server-side components, generally used to provide the
presentation layer to be returned to a client. Two types of Web components exist:
Java Server Pages (JSPs) and Java servlets. Very basically, JSPs are similar to regular
HTML pages but contain embedded Java code while Java servlets are Java classes
that use Java’s I/O application programming interfaces (APIs) to output HTML to
the client. Both JSPs and servlets can be used to output other format types.
Server components come in the form of Enterprise JavaBeans (EJBs). EJBs execute
within a container that manages the runtime behavior of the EJB. EJBs are usually
where the business logic for an enterprise system resides.
The roles specified within the J2EE are those played during the development and
deployment cycles of an enterprise application. While the roles are distinct, in real-
ity multiple roles tend to be filled by the same organization. The following roles are
discussed in this section:
✦ J2EE product provider
✦ Application component provider
✦ Application assembler
✦ System administrator
✦ Tool provider
✦ System component provider
The J2EE product provider
A J2EE product provider is a company that provides a product that implements a
part of the J2EE specification. For example, one company may provide a product that
implements the J2EE container for EJBs, and another may provide a product that pro-
vides an implementation for a JMS server.
8 Part I ✦ Introduction
The application component provider
An application component provider is a developer who creates a component that is
intended to reside within one of the J2EE containers. The application component
provider develops application components adhering to the J2EE API specifications
with the intention that the component will be deployed within a J2EE Server. This
enables a developer to select a different J2EE product provider without modifying
the component. Application component providers develop a range of components,
including EJBs, HTML pages, and other Web components.
The application assembler
An application assembler generally uses various application components to create
a single application for distribution. Generally, in a large project, one team will be
responsible for developing the Web components, another for the business-logic
components, and perhaps another for the data-object components. The application
assembler would package the various components and then distribute them as an
enterprise archive (.ear) file.
The deployment of an enterprise application nearly always requires a different
configuration for each rollout. J2EE has taken this into consideration by specifying
the role of deployer. The deployer is responsible for configuring the applications
developed by the application assembler for execution within a platform provided
by the J2EE product provider.
The system administrator
A system administrator generally uses tools provided by a tool provider to monitor
the runtime environment and to ensure that services are performing optimally.
Various tools are available on the market, ranging from those which allow for moni-
toring the system as a whole, to runtime inspection on individual services to help
determine where bottlenecks may reside.
The tool provider
The J2EE specification also provides tools to make development easier and to moni-
tor the runtime environment. Tools vary from integrated development environments
to runtime-performance products.
The system-component provider
Many system components are available for the J2EE architecture. The J2EE archi-
tecture provides ways to introduce these new components for accessing services
such as existing messaging systems, transaction services, and others, such as
billing systems that may be industry-specific. Using the connector architecture is
one way to introduce these new components.
9Chapter 1 ✦ Understanding Java and the J2EE Platform
In addition to specifying the lifecycle roles, the J2EE also recommends the usage of
the model-view-controller (MVC) design pattern to ease the burden on developing
Working with the Model-View-Controller
The MVC paradigm provides a pattern for separating the presentation logic (view),
business logic (control), and data objects (model). J2EE’s architecture maps onto
the MVC nicely. Typically, entity beans are used to provide the model logic, while a
mix of entity beans and session beans are used to provide the control logic, and
Web components are used to implement both control and presentation logic. In
practice, however, the separation of the three types of logic is not as distinct, and
additional patterns are often needed to support the development cycle. Figure 1-3
shows how the three different logical functional blocks work together.
Figure 1-3: MVC pattern
Sun has provided guidelines in the form of Java BluePrints. A sample application,
Java Adventure Builder, has been developed specifically for J2EE 1.4 and you can
download it from http://www.javasoft.com.
The M in MVC refers to the data object model. For example, in an airline ticketing
service you may have the concept of a booking, which in the real world is repre-
sented by a paper ticket. The model deals with issues such as how the booking
is represented within the software system, where it is persisted, and how it is
accessed. For example, the booking may be held within a relational database within
Manipulates User interactions