ebook img

Java 2 Enterprise edition Bible PDF

705 Pages·2002·3.11 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Java 2 Enterprise edition Bible

Java 2 Enterprise Edition Bible Justin Couch and Daniel H. Steinberg Published by Hungry Minds, Inc. 909 Third Avenue New York, NY 10022 http://www.hungryminds.com/ Copyright © 2002 Hungry Minds, Inc. All rights reserved. No part of this book, including interior design, cover design, and icons, may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording, or otherwise) without the prior written permission of the publisher. Library of Congress Catalog Card Number: 2001093855 ISBN: 0-7645-0882-2 10 9 8 7 6 5 4 3 2 1 1B/SY/QT/QS/IN Distributed in the United States by Hungry Minds, Inc. Distributed by CDG Books Canada Inc. for Canada; by Transworld Publishers Limited in the United Kingdom; by IDG Norge Books for Norway; by IDG Sweden Books for Sweden; by IDG Books Australia Publishing Corporation Pty. Ltd. for Australia and New Zealand; by TransQuest Publishers Pte Ltd. for Singapore, Malaysia, Thailand, Indonesia, and Hong Kong; by Gotop Information Inc. for Taiwan; by ICG Muse, Inc. for Japan; by Intersoft for South Africa; by Eyrolles for France; by International Thomson Publishing for Germany, Austria, and Switzerland; by Distribuidora Cuspide for Argentina; by LR International for Brazil; by Galileo Libros for Chile; by Ediciones ZETA S.C.R. Ltda. for Peru; by WS Computer Publishing Corporation, Inc., for the Philippines; by Contemporanea de Ediciones for Venezuela; by Express Computer Distributors for the Caribbean and West Indies; by Micronesia Media Distributor, Inc. for Micronesia; by Chips Computadoras S.A. de C.V. for Mexico; by Editorial Norma de Panama S.A. for Panama; by American Bookshops for Finland. For general information on Hungry Minds' products and services please contact our Customer Care department within the U.S. at 800-762-2974, outside the U.S. at 317-572-3993 or fax 317-572-4002. For sales inquiries and reseller information, including discounts, premium and bulk quantity sales, and foreign-language translations, please contact our Customer Care department at 800-434-3422, fax 317-572-4002 or write to Hungry Minds, Inc., Attn: Customer Care Department, 10475 Crosspoint Boulevard, Indianapolis, IN 46256. For information on licensing foreign or domestic rights, please contact our Sub-Rights Customer Care department at 212-884-5000. For information on using Hungry Minds' products and services in the classroom or for ordering examination copies, please contact our Educational Sales department at 800-434-2086 or fax 317- 572-4005. For press review copies, author interviews, or other publicity information, please contact our Public Relations department at 317-572-3168 or fax 317-572-4168. For authorization to photocopy items for corporate, personal, or educational use, please contact Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, or fax 978-750-4470. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK. THE PUBLISHER AND AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. THERE ARE NO WARRANTIES WHICH EXTEND BEYOND THE DESCRIPTIONS CONTAINED IN THIS PARAGRAPH. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS. THE ACCURACY AND COMPLETENESS OF THE INFORMATION PROVIDED HEREIN AND THE OPINIONS STATED HEREIN ARE NOT GUARANTEED OR WARRANTED TO PRODUCE ANY PARTICULAR RESULTS, AND THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY INDIVIDUAL. NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES. Trademarks: Hungry Minds and the Hungry Minds logo are trademarks or registered trademarks of Hungry Minds, Inc. Java is a trademark or registered trademark of Sun Microsystems, Inc. All other trademarks are the property of their respective owners. Hungry Minds, Inc., is not associated with any product or vendor mentioned in this book. Credits Acquisitions Editors Greg Croy Grace Buechlein Project Editor Michael Koch Technical Editors David M. Williams Ramesh Krishnaswamy Copy Editor S. B. Kleinman Editorial Manager Mary Beth Wakefield Vice President and Executive Group Publisher Richard Swadley Vice President and Executive Publisher Bob Ipsen Vice President and Publisher Joseph B. Wikert Editorial Director Mary Bednarek Project Coordinator Regina Snyder Graphics and Production Specialists Beth Brooks, Sean Decker, Joyce Haughey, Gabriele McCann, Barry Offringa, Heather Pope, Betty Schulte, Rashell Smith, Ron Terry, Jeremey Unger, Erin Zeltner Quality Control Technician Laura Albert, John Greenough, Andy Hollandbeck, Angel Perez, Marianne Santy, Proofreading and Indexing TECHBOOKS Production Services About the Authors Justin Couch has been a professional Java programmer since early 1996 and hasn't looked back since. His travels have taken him through all realms of the Java world — from writing parts for the VRML specification (leading working groups and authoring the External Authoring Interface) to the IETF — working on the URN specifications. The applications realm he has worked on has gone through a similar wide variety — from mobile distributed applications to large-scale Web site hosting and electronic display systems. His main programming interests are virtual reality and the distributed systems required to run them. He currently runs the Java 3D community site (http://www.j3d.org/) and the Java 3D Programmers FAQ (http://www.j3d.org/faq/). When not programming Justin's interests are music (classical and electronic), gliding, and attempting to shorten his life by riding motorcycles. Daniel H. Steinberg is the director of Java Offerings at Dim Sum Thinking. A trainer and consultant, he has been teaching and writing about Java since 1996. Daniel has covered Java on the Macintosh for JavaWorld magazine and the O'Reilly Network's Mac DevCenter. He managed the Mac FAQ at jGuru and served as editor of developerWorks Java Technology Zone and of the CodeMasters Challenge for JavaWorld magazine. Although he does Java development for and on platforms other than Mac OS X, he's happier on his Mac. Daniel has been working with Colleges and Universities to help their faculty and students keep up with the quickly changing technology. His current interests have led him to lead sessions in refactoring and extreme programming. Mostly Daniel enjoys being a dad and hanging out with his wife, two daughters, and black Lab. Uma Veeramani, author of Chapters 18 and 19, is a software programmer and member of the technical staff at a security software company in Austin, TX. Her prior experience was as a Java developer in the financial services industry. She has experience working on a number of platforms and languages, including Java, ASP, C++, etc. Uma was a gold medallist at the University of Madras, India, and graduated with degrees in physics and computer applications. Bruce Beyeler, author of Chapter 22, is the owner of Arizona Software Insights, a Java consulting and training company. Bruce has been consulting and training (corporate and collegiate) in Java for over four years and has 15+ years of experience developing software systems. He specializes in embedded systems, communications, and application integration. Bruce has led numerous projects ranging from embedded applications to J2EE projects in a variety of industries such as aerospace, automotive, telephony, and e-commerce. Bruce is currently working on his Ph.D. in computer science at Arizona State University, where his emphasis is embedded systems and communications. Mike Jasnowski, author of Chapter 23, is a senior software engineer at eXcelon Corporation in Burlington, MA, and has XML and Java coming out of his ears. He works as leader of the project that develops Web-based tools for administering eXcelon's Business Process Manager. He has been involved with computers and software for over 18 years, dating back to the days before Java and XML, when he wrote some of his first programs on a TRS-80 and Apple IIe. Mike has worked on a variety of operating systems, including Multiple Virtual Storage (MVS), Linux, Windows, and Virtual Machine (VM), in addition to a variety of programming languages. He worked for Sprint for over nine years as a systems programmer and moved on to work in the healthcare and finance industries as a software engineer before finally landing at eXcelon. He is the lead author of Java, XML, and Web Services Bible (Hungry Minds, Inc., 2002), and he contributed three chapters to the book Developing Dynamic WAP Applications (Manning Press, 2001). He's also written articles for Java Developers Journal and XML Journal. He lives in Amherst, New Hampshire, with his wife Tracy, his daughter Emmeline, and a host of pets. To Alan, John, and Steve, for getting me into this mess and then getting me back out of it! — Justin Couch To Stephen Wong, for arguing with me every day for two years until I began to get it. — Daniel H. Steinberg Table of Contents Java 2 Enterprise Edition Bible Preface Part I Getting Started Chapter 1 -Defining the Enterprise Chapter 2 -Introducing Enterprise Applications Part II Delivering Content Chapter 3 -Creating Dynamic Content with Servlets Chapter 4 -Using JavaServer Pages Chapter 5 -Sending and Receiving Mail with JavaMail Part III Finding Things with Databases and Searches Chapter 6 -Interacting with Relational Databases Chapter 7 -Using JDBC to Interact with SQL Databases Chapter 8 -Working with Directory Services and LDAP Chapter 9 -Accessing Directory Services with JNDI Part IV Communicating Between Systems with XML Chapter 10 -Building an XML Foundation Chapter 11 -Describing Documents with DTDs and Schemas Chapter 12 -Parsing Documents with JAXP Chapter 13 -Interacting with XML Using JDOM Chapter 14 -Transforming and Binding Your XML Documents Part V Abstracting the System Chapter 15 -Exploring the RMI Mechanism Chapter 16 -Introducing Enterprise JavaBeans Chapter 17 -Using Advanced EJB Techniques Chapter 18 -Introducing CORBA Chapter 19 -CORBA Applications in the Enterprise Chapter 20 -Why Dream of Jini? Part VI Building Big System Chapter 21 -Implementing Web Services Chapter 22 -JMS Chapter 23 -Managing Transactions with JTA/JTS Chapter 24 -System Architecture Issues Chapter 25 -J2EE Design Patterns Appendix A -Installing the J2EE Reference Implementation Appendix B -J2EE API Version Requirements Appendix C -J2EE Vendors and Systems Glossary Index Preface Welcome to Java 2 Enterprise Edition Bible. This book, which is a follow−up to Java 2 Bible, is for readers who wish to know more about the enterprise market. Enterprise programming is a hot topic these days, as more and more companies decide they need an online presence to complement their existing bricks−and−mortar version. This online presence is more than just a couple of Web pages; it extends to a complete electronic catalogue and purchasing system. XML is one of the biggest drivers of the enterprise market. As companies are starting to realize they need to work together to smooth out the supply−chain management, they are building their second− or third−generation systems. They are doing this in collaboration with their suppliers and partners. To build these systems they need interoperability, and whole industries are springing up around this need alone. Need to add a new partner or supplier? Just ask for the XML DTD. Very quickly you can now include the new functionality in your system. Throughout this book we will reference various commercial sites that you will be familiar with as examples of how large−scale businesses are integrating not only their own Web sites, but also those of partners and suppliers, into one single system. Order your computer from Dell and you can track it through every stage of the build process. Then, once it has hit the courier, you can use the Dell site to trace the courier's information about its progress. Dell doesn't use just one courier, either — yet your experience is identical regardless of which one is used. What this Book Aims to Do The aim of this book is to introduce you to all the enterprise Java APIs. Many books are floating around that deal with specific elements of the J2EE specification — Enterprise Java Beans and XML being the most prevalent. Yet what these titles fail to address is the whole collection of other interfaces that you as a Java programmer might find useful. For example, did you know that an API exists for e−mail and newsgroup handling as part of J2EE? As a programmer, I like to stay informed about all of the possible options. If I know about them, I can investigate them further if they sound useful. If I don't know about them, I might be missing some very important information that might have made my life much easier. Therefore, the aim of this book is to give you as broad an understanding as possible of the APIs that can be useful in creating an enterprise−level application. The primary focus is on the J2EE specification, but we also introduce other libraries where we feel they will benefit your application. We do not try to cover every topic in great depth. We leave that for other books. What we do is cover each topic in sufficient detail that you can get started with simple programs and then know the right questions to ask next. J2EE is a huge specification. If we were to cover it all in depth, you would need to cart the volumes of the book on a trolley. No doubt you already have a bookshelf full of programming books and don't need a lot more. Use this book as the introduction to all the parts of J2EE, and then consult other books that treat specific areas of knowledge in depth. Who this Book Is For This book is aimed at the intermediate to advanced programmer. We assume that you already have some Java programming under your belt. We don't spend any time introducing the programming language, and we 1 Preface assume you know how to compile and debug a Java application in your favorite development environment. If you are looking for a beginner−level Java book then we can recommend the Java 2 Bible (ISBN 0−7645−4632−5) written by Aaron Walsh, Justin Couch, and Daniel H. Steinberg. For the intermediate programmer, this book will introduce all the various technologies available to you as a J2EE programmer. Perhaps you have never used J2EE before, so this book will show you where to start and what order to approach your learning in. For the more advanced programmer, this book can serve as a guide to expanding your horizon over the more concentrated areas of programming. Use it as a guide to exploring more possibilities within the area that you have already been working on, or new ways to address a problem. Finally, you can use it to learn about new areas that you have not heard of before. Because of the breadth of J2EE, it is always possible that new topics exist that you haven't heard of. Even after six−plus years of Java programming experience, I am constantly finding new items popping up to learn about. How to Use this Book This book is divided into a number of parts. Each part is a self−contained area that focuses on just one piece of the enterprise puzzle. Within each part, each chapter will stand alone if you know the underlying technology. Our approach is to cover all the parts of developing an enterprise application. That is, we don't follow just the Java APIs, but introduce the fundamentals of the technology that Java operates on. We believe that for you to be the best developer, you must have a solid understanding of the foundations. In fact, many of the enterprise APIs demand it. If you don't understand how an XML document is structured, and the terms involved, you will find it very hard to use the XML−parsing APIs, or to define how to load Enterprise Java Beans on your Web server. We recommend reading the parts of the book that are useful for what you need to do now. There is no need to read it from cover to cover. If you haven't written an enterprise application before then we highly recommend you look at Part I of the book. After that, feel free to roam to the sections that best suit your needs. If we need another part of the book to help explain a piece of technology, we'll give you a cross reference to the appropriate chapter. This book is comprised of six parts that lead you from the front end of the system to the back end. Each part covers a number of topics. We can summarize these parts as follows. Part I: Getting Started The introductory parts show you around the enterprise space and the various parts of the J2EE specification: why you would want to use it, what constitutes an "enterprise" application, and some examples. The advanced user can skip this part and head into the more specific chapters. Part II: Delivering Content Here we focus on the APIs that are used to deal with an external user — receiving input and sending output back. It is all about presentation. Rarely is there application logic in these parts. They are more about assembling pieces of pre−built logic into some correct order and then presenting the output to the user. More 2 Preface often than not, the output is presented in a Web page, but (as you will see) there is more to this part than just making a pretty Web site. Part III: Finding Things with Databases and Searches At the heart of every enterprise system is a database. In that database is a lot of information. In fact, so much, that without having some form of search capability, you would find it almost impossible to do in anything else with your application. The database has many forms other than the Oracle or MS Access that you are used to. Specialized databases exist for many different purposes, and sometimes using Oracle alone is the wrong solution. Part IV: Communicating Between Systems with XML As e−commerce systems become more and more complex, the ability to seamlessly talk between systems becomes more important. It will be an extremely rare situation when you as the developer have to build the complete end−to−end system. It is almost guaranteed that you will need to integrate third−party software into the end product. The technology most commonly used for this purpose is XML. As a text−based structured data format, it works wonderfully well for this. However, to make the most out of XML requires an awful lot of knowledge, and so we devote an entire part of the book to learning everything about XML. Part V: Abstracting the System When system complexity or load grow high enough, a simple two−tier application will no longer handle your demands. To help alleviate this problem, a range of different technologies have been introduced over the years to allow you to abstract the raw data sources into collections of business logic. These collections can be used in many different forms to present a range of applications to the end user. Part VI: Building Big Systems Moving up to the really huge systems that you might see in a site like Amazon.com demands even more of your application. The skills and knowledge needed to implement these solutions is often very specialized. How often will you get a complete system failure today? Most likely never, so you have to know how to build applications that can deal with partial failures and still continue to operate normally. This part is devoted to the Java technologies needed to deal with such applications. Appendixes While code and examples are extremely useful, there are many other pieces of information that you need to know. The appendices cover Sun's Reference Implementation of the J2EE specification, listings of products and vendors of J2EE systems, and also a glossary of terms to help you through all those acronyms. 3 Part I: Getting Started Chapter List Chapter 1: Defining the Enterprise Chapter 2: Introducing Enterprise Applications 1

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.