Home > Store

J2EE™ Tutorial, The

Register your product to gain access to bonus material or receive a coupon.

J2EE™ Tutorial, The

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 2002
  • Dimensions: 7-3/8x9-1/4
  • Pages: 528
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-79168-4
  • ISBN-13: 978-0-201-79168-6

You're familiar with Java™ programming, but now it's time for you to take it to the next level and begin creating enterprise applications with the Java™ 2 Platform, Enterprise Edition (J2EE™). The J2EE™ Tutorial is the hands-on, example-driven guide that offers unparalleled technical guidance into developing and deploying applications on the J2EE platform.

Written by the uniquely qualified members of the Java Software team at Sun Microsystems, The J2EE™ Tutorial uses the same effective interactive approach as the successful Java™ Tutorial collection. Throughout this book's development, hundreds of suggestions and volumes of feedback from both users and architects were integrated to ensure great writing and truly useful guidance.

Inside you'll find a smart mix of example programs—including source code—that are used to illustrate key J2EE concepts. In addition, clear explanations will help you make easy work of the range of technologies collected into the J2EE platform, including:

  • Enterprise JavaBeans™
  • Java™ Servlets
  • JavaServer Pages™
  • Java™ Message Service (JMS)
  • Java Naming and Directory Interface™ (JNDI)
  • XML
  • J2EE™ Connector Architecture
  • JavaMail™
  • JDBC™

When you're ready to create your own great enterprise applications, turn to the unmatched guidance, understanding, and experience you'll find only in The J2EE™ Tutorial.

The accompanying CD-ROM is filled with a wealth of valuable resources, including all three Java™ Tutorial books, the J2SE 1.3.1 and J2EE 1.3.1 software development kits, the Java BluePrints sample application and book, and Forte for Java Plugin for the J2EE SDK.



0201791684B03012002

Sample Content

Online Sample Chapter

J2EE Enterprise Bean Basics

Downloadable Sample Chapter

Click below for Sample Chapter(s) related to this title:
Sample Chapter 3

Table of Contents

Foreword.
Preface.
1. Overview.
Distributed Multitiered Applications.
J2EE Components.

J2EE Clients.
Web Components.
Business Components.
Enterprise Information System Tier.
J2EE Containers.
Container Services.

Container Types.
Packaging.
Development Roles.
J2EE Product Provider.

Tool Provider.
Application Component Provider.
Application Assembler.
Application Deployer and Administrator.
Reference Implementation Software.
Database Access.

J2EE APIs.
Simplified Systems Integration.
Tools.

2. Getting Started.
Setting Up.
Getting the Example Code.

Getting the Build Tool (ant).
Checking the Environment Variables.
Starting the J2EE Server.
Starting the deploytool.
Creating the J2EE Application.
Creating the Enterprise Bean.
Coding the Enterprise Bean.

Compiling the Source Files.
Packaging the Enterprise Bean.
Creating the J2EE Application Client.
Coding the J2EE Application Client.

Compiling the Application Client.
Packaging the J2EE Application Client.
Specifying the Application Client's Enterprise Bean Reference.
Creating the Web Client.
Coding the Web Client.

Compiling the Web Client.
Packaging the Web Client.
Specifying the Web Client's Enterprise Bean Reference.
Specifying the JNDI Names.
Deploying the J2EE Application.
Running the J2EE Application Client.
Running the Web Client.
Modifying the J2EE Application.
Modifying a Class File.

Adding a File.
Modifying the Web Client.
Modifying a Deployment Setting.
Common Problems and Their Solutions.
Cannot Start the J2EE Server.

Compilation Errors.
Deployment Errors.
J2EE Application Client Runtime Errors.
Web Client Runtime Errors.
Detecting Problems With the Verifier Tool.
Comparing Your EAR Files with Ours.
When All Else Fails.

3. Enterprise Beans.
What Is an Enterprise Bean?
Benefits of Enterprise Beans.

When to Use Enterprise Beans.
Types of Enterprise Beans.
What Is a Session Bean?
State Management Modes.

When to Use Session Beans.
What Is an Entity Bean?
What Makes Entity Beans Different from Session Beans?

Container-Managed Persistence.
When to Use Entity Beans.
What Is a Message-Driven Bean?

What Makes Message-Driven Beans Different from Session and Entity Beans?
When to Use Message-Driven Beans.
Defining Client Access with Interfaces.
Remote Access.

Local Access.
Local Interfaces and Container-Managed Relationships.
Deciding on Remote or Local Access.
Performance and Access.
Method Parameters and Access.
The Contents of an Enterprise Bean.
Naming Conventions for Enterprise Beans.
The Life Cycles of Enterprise Beans.
The Life Cycle of a Stateful Session Bean.

The Life Cycle of a Stateless Session Bean.
The Life Cycle of an Entity Bean.
The Life Cycle of a Message-Driven Bean.

4. A Session Bean Example.
The CartEJB Example.
Session Bean Class.

Home Interface.
Remote Interface.
Helper Classes.
Running the CartEJB Example.
Other Enterprise Bean Features.
Accessing Environment Entries.

Comparing Enterprise Beans.
Passing an Enterprise Bean's Object Reference.

5. Bean-Managed Persistence Examples.
The SavingsAccountEJB Example.
Entity Bean Class.

Home Interface.
Remote Interface.
Running the SavingsAccountEJB Example.
deploytool Tips for Entity Beans with Bean-Managed Persistence.
Mapping Table Relationships for Bean-Managed Persistence.
One-to-One Relationships.

One-to-Many Relationships.
Many-to-Many Relationships.
Primary Keys for Bean-Managed Persistence.
The Primary Key Class.

Primary Keys in the Entity Bean Class.
Getting the Primary Key.
Handling Exceptions.

6. Container-Managed Persistence Examples.
Overview of the RosterApp Application.
The PlayerEJB Code.
Entity Bean Class.

Local Home Interface.
Local Interface.
A Guided Tour of the RosterApp Settings.
RosterApp.

RosterClient.
RosterJAR.
TeamJAR.
Method Invocations in RosterApp.
Creating a Player.

Adding a Player to a Team.
Removing a Player.
Dropping a Player from a Team.
Getting the Players of a Team.
Getting a Copy of a Team's Players.
Finding the Players by Position.
Getting the Sports of a Player.
Running the RosterApp Example.
Setting Up.

Deploying the Application.
Running the Client.
deploytool Tips for Entity Beans with Container-Managed Persistence.
Specifying the Bean's Type.

Selecting the Persistent Fields and Abstract Schema Name.
Defining EJB QL Queries for Finder and Select Methods.
Generating SQL and Specifying Table Creation.
Specifying the Database JNDI Name, User Name, and Password.
Defining Relationships.
Primary Keys for Container-Managed Persistence.
The Primary Key Class.

Primary Keys in the Entity Bean Class.
Generating Primary Key Values.

7. A Message-Driven Bean Example.
Example Application Overview.
The J2EE Application Client.
The Message-Driven Bean Class.
The onMessage Method.

The ejbCreate and ejbRemove Methods.
Running the SimpleMessageEJB Example.
Starting the J2EE Server.

Creating the Queue.
Deploying the Application.
Running the Client.
deploytool Tips for Message-Driven Beans.
Specifying the Bean's Type and Transaction Management.

Setting the Message-Driven Bean's Characteristics.
deploytool Tips for JMS Clients.
Setting the Resource References.

Setting the Resource Environment References.
Specifying the JNDI Names.

8. Enterprise JavaBeans Query Language.
Terminology.
Simplified Syntax.
Example Queries.
Simple Finder Queries.

Finder Queries That Navigate to Related Beans.
Finder Queries with Other Conditional Expressions.
Select Queries.
Full Syntax.
BNF Symbols.

BNF Grammar of EJB QL.
FROM Clause.
Path Expressions.
WHERE Clause.
SELECT Clause.
EJB QL Restrictions.

9. Web Clients and Components.
Web Client Life Cycle.
Web Application Archives.
Creating a WAR File.

Adding a WAR File to an EAR File.
Adding a Web Component to a WAR File.
Configuring Web Clients.
Application-Level Configuration.

WAR-Level Configuration.
Component-Level Configuration.
Deploying Web Clients.
Running Web Clients.
Updating Web Clients.
Internationalizing Web Clients.

10. Java Servlet Technology.
What Is a Servlet?
The Example Servlets.
Troubleshooting.
Servlet Life Cycle.
Handling Servlet Life-Cycle Events.

Handling Errors.
Sharing Information.
Using Scope Objects.

Controlling Concurrent Access to Shared Resources.
Accessing Databases.
Initializing a Servlet.
Writing Service Methods.
Getting Information from Requests.

Constructing Responses.
Filtering Requests and Responses.
Programming Filters.

Programming Customized Requests and Responses.
Specifying Filter Mappings.
Invoking Other Web Resources.
Including Other Resources in the Response.

Transferring Control to Another Web Component.
Accessing the Web Context.
Maintaining Client State.
Accessing a Session.

Associating Attributes with a Session.
Session Management.
Session Tracking.
Finalizing a Servlet.
Tracking Service Requests.

Notifying Methods to Shut Down.
Creating Polite Long-Running Methods.

11. JavaServer Pages Technology.
What Is a JSP Page?
The Example JSP Pages.
The Life Cycle of a JSP Page.
Translation and Compilation .

Execution.
Initializing and Finalizing a JSP Page.
Creating Static Content.
Creating Dynamic Content.
Using Objects within JSP Pages.

JSP Scripting Elements.
Including Content in a JSP Page.
Transferring Control to Another Web Component.
Param Element.
Including an Applet.

Extending the JSP Language.

12. JavaBeans Components in JSP Pages.
JavaBeans Component Design Conventions.
Why Use a JavaBeans Component?
Creating and Using a JavaBeans Component.
Setting JavaBeans Component Properties.
Retrieving JavaBeans Component Properties.

13. Custom Tags in JSP Pages.
What Is a Custom Tag?
The Example JSP Pages.
Using Tags.
Declaring Tag Libraries.

Types of Tags.
Defining Tags.
Tag Handlers.

Tag Library Descriptors.
Simple Tags.
Tags with Attributes.
Tags With Bodies.
Tags That Define Scripting Variables.
Cooperating Tags.
Examples.
An Iteration Tag.

A Template Tag Library.
How Is a Tag Handler Invoked?

14. Transactions.
What Is a Transaction?
Container-Managed Transactions.
Transaction Attributes.

Rolling Back a Container-Managed Transaction.
Synchronizing a Session Bean's Instance Variables.
Methods Not Allowed in Container-Managed Transactions.
Bean-Managed Transactions.
JDBC Transactions.

JTA Transactions.
Returning without Committing.
Methods Not Allowed in Bean-Managed Transactions.
Summary of Transaction Options for Enterprise Beans.
Transaction Timeouts.
Isolation Levels.
Updating Multiple Databases.
Transactions in Web Components.

15. Security.
Overview.
Security Roles.
Declaring and Linking Role References.

Mapping Roles to J2EE Users and Groups.
Web-Tier Security.
Protecting Web Resources.

Controlling Access to Web Resources.
Authenticating Users of Web Resources.
Using Programmatic Security in the Web Tier.
Unprotected Web Resources.
EJB-Tier Security.
Declaring Method Permissions.

Using Programmatic Security in the EJB Tier.
Unprotected EJB-Tier Resources.
Application Client-Tier Security.
Specifying the Application Client's Callback Handler.
EIS-Tier Security.

Configuring Sign-On.
Container-Managed Sign-On.
Component-Managed Sign-On.
Configuring Resource Adapter Security.
Propagating Security Identity.
Configuring a Component's Propagated Security Identity.

Configuring Client Authentication.
J2EE Users, Realms, and Groups.
Managing J2EE Users and Groups.
Setting Up a Server Certificate.


16. Resource Connections.
JNDI Names and Resource References.
deploytool Tips for Resource References.
Database Connections for Enterprise Beans.
Coded Connections.

Connection Pooling.
Mail Session Connections.
Running the ConfirmerEJB Example.
URL Connections.
Running the HTMLReaderEJB Example.


17. J2EE Connector Architecture.
About Resource Adapters.
Resource Adapter Contracts.

Administering Resource Adapters.
The Black Box Resource Adapters.
Transaction Levels.

Properties.
Configuring JDBC Drivers.
Resource Adapter Tutorial.
Setting Up.

Deploying the Resource Adapter.
Testing the Resource Adapter.
Common Client Interface.
Overview of the CCI.

Programming with the CCI.
Writing a CCI Client.
CCI Tutorial.

18. The Duke's Bank Application.
Enterprise Beans.
Session Beans.

Entity Beans.
Helper Classes.
Database Tables.
Protecting the Enterprise Beans.
Application Client.
The Classes and Their Relationships.

BankAdmin Class.
EventHandle Class.
DataModel Class.
Web Client.
Design Strategies.

Web Client Life Cycle.
Protecting the Web Resources.
Internationalization.
Building, Packaging, Deploying, and Running the Application.
Adding Groups and Users to the Realm.

Starting the J2EE Server, deploytool, and Database.
Compiling the Enterprise Beans.
Packaging the Enterprise Beans.
Compiling the Web Client.
Packaging the Web Client.
Compiling the J2EE Application Client.
Packaging the J2EE Application Client.
Packaging the Enterprise Archive File.
Opening the Enterprise Archive File.
Reviewing JNDI Names.
Mapping the Security Roles to Groups.
Deploying the Duke's Bank Application.
Creating the Bank Database.
Running the J2EE Application Client.
Running the Web Client.

Appendix A: HTTP Overview.
HTTP Requests.
HTTP Responses.

Appendix B: J2EE SDK Tools.
J2EE Administration Tool.
Cleanup Tool.
Cloudscape Server.
Starting Cloudscape.

Stopping Cloudscape.
Running the Interactive SQL Tool.
Cloudscape Server Configuration.
Deployment Tool.
J2EE Server.
Key Tool.
Packager Tool.
EJB JAR File.

Web Application WAR File.
Application Client JAR File.
J2EE Application EAR File.
Specifying the Runtime Deployment Descriptor.
Resource Adapter RAR File.
Realm Tool.
Examples.
runclient Script.
Syntax.

Example.
Accessing a Remote Server.
Preventing the User Name and Password Prompts 443Verifier Tool.
Command-Line Verifier.

Stand-Alone GUI Verifier.

Appendix C: Examples.
Glossary.
About the Authors.
Index. 0201791684T03292002

Preface

The Java™ Tutorial has been an indispensable resource for many programmers learning the Java programming language. This tutorial hopes to serve the same role for developers encountering the Java™ 2 Platform, Enterprise Edition (J2EE™) for the first time. It follows an example-oriented focus similar to The Java™ Tutorial.

Who Should Use This Tutorial

This tutorial is intended for programmers interested in developing and deploying J2EE applications. It covers the technologies comprising the J2EE platform and describes how to develop J2EE components and deploy them on the J2EE Software Development Kit (SDK).

This tutorial is not intended for J2EE server or tool vendors. It does not explain how to implement the J2EE architecture, nor does it explain the internals of the J2EE SDK. The J2EE specifications describe the J2EE architecture and can be downloaded from

http://java.sun.com/j2ee/docs.html#specs

About the Examples

This tutorial includes many complete, working examples. See Examples (page 445) for a list of the examples and the chapters where they appear.

Prerequisites for the Examples

To understand the examples, you will need a good knowledge of the Java programming language, SQL, and relational database concepts. The topics in The Java™ Tutorial listed in List P-1 are particularly relevant.

List P-1 Prerequisite Topics
JDBC™ http://java.sun.com/docs/books/tutorial/jdbc
Threads http://java.sun.com/docs/books/tutorial/essential/threads
JavaBeans™http://java.sun.com/docs/books/tutorial/javabeans
Security http://java.sun.com/docs/books/tutorial/security1.2

Downloading the Examples

If you are viewing this online and you want to build and run the examples, you need to download the tutorial bundle from

http://java.sun.com/j2ee/download.html#tutorial

Once you have installed the bundle, the example source code is in the j2eetutorial/examples/src directory, with subdirectories ejb for enterprise bean technology examples, web for Web technology examples, and connector for connector technology examples. For most of the examples, the bundle also includes J2EE application Enterprise Archive (EAR) files, which are located in the j2eetutorial/examples/ears directory.

How to Build and Run the Examples

This tutorial documents the J2EE SDK version 1.3. To build, deploy, and run the examples you need a copy of the J2EE SDK 1.3 and the Java 2 Platform, Standard Edition (J2SE™) SDK 1.3.1 (earlier versions were called JDK). You can download the J2EE SDK from

http://java.sun.com/j2ee/download.html#sdk

and the J2SE 1.3.1 from

http://java.sun.com/j2se/1.3/

The examples are distributed with a configuration file for version 1.3 of ant, a portable make tool. The ant utility is hosted by the Jakarta project at the Apache Software Foundation. You can download ant from

http://jakarta.apache.org/builds/jakarta-ant/release/v1.3/bin

To build the tutorial examples, follow these steps:

  1. Download and install the J2SE SDK 1.3.1, J2EE SDK 1.3, and ant.
  2. The installation instructions for the J2SE SDK, J2EE SDK, and ant explain how to set the required environment variables. Verify that the environment variables have been set to the values noted in List P-2.
  3. Go to the j2eetutorial/examples directory.
  4. Execute ant target. For example, to build all the examples, execute ant all; to build theWeb layer examples, execute ant web. The build process deposits the output into the directory j2eetutorial/examples/build.
List P-2 Settings for Environment Variables
JAVA_HOME  The location of the J2SE SDK installation.
J2EE_HOME  The location of the J2EE SDK installation
ANT_HOME  The location of the ant installation.
PATH  Should include the bin directories of the J2EE SDK, J2SE SDK, and ant installations.

Related Information

This tutorial provides a concise overview of how to use the central component technologies in the J2EE platform. For more information about these technologies, see the Web sites listed in List P-3.

List P-3 Information Sources
Enterprise JavaBeans™ (EJB™)   http://java.sun.com/products/ejb
Java Servlet  http://java.sun.com/products/servlets
JavaServer Pages™ (JSP™)  http://java.sun.com/products/jsp

The J2EE platform includes a wide variety of APIs that this tutorial only briefly touches on. Some of these technologies have their own tutorials, which are listed in List P-4.

List P-4 Other Tutorials
Java Message Service (JMS)  http://java.sun.com/products/jms/tutorial/
Java Naming and Directory Interface™ (JNDI)   http://java.sun.com/products/jndi/tutorial/
Java API for XML Processing (JAXP)   http://java.sun.com/xml/jaxp/dist/1.1/docs/tutorial/index.html

For complete information on these topics, see the Web sites in List P-5.

List P-5 Other Web Sites
J2EE Connector   http://java.sun.com/j2ee/connector
JAXP  http://java.sun.com/products/jaxp
JavaMail™  http://java.sun.com/products/javamail
JMS  http://java.sun.com/products/jms
JNDI  http://java.sun.com/products/jndi
JDBC™  http://java.sun.com/products/jdbc

Once you have become familiar with the J2EE technologies described in this tutorial, you may be interested in guidelines for architecting J2EE applications. The Java BluePrints illustrate best practices for developing and deploying J2EE applications. You can obtain the Java BluePrints from

http://java.sun.com/blueprints

How to Print This Tutorial

To print this tutorial, follow these steps:

  1. Ensure that Adobe Acrobat Reader is installed on your system.
  2. Download the PDF version of this book from

    http://java.sun.com/j2ee/download.html#tutorial

  3. Click the printer icon in Adobe Acrobat Reader.

Typographical Conventions

List P-6 lists the typographical conventions used in this tutorial.

P-6 Typographical Conventions
  • Italic  Emphasis, titles, first occurrence of terms
  • Monospace  URLs, code examples, file names, command names, programming language keywords
  • Italic monospace  Programming variables, variable file names

Menu selections indicated with the right-arrow character →, for example, First→Second, should be interpreted as: select the First menu, then choose Second from the First submenu.



0201791684P03292002

Index

Click below to download the Index file related to this title:
Index

Updates

Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership