| # Java 1.1 Unleashed ## Dedication To Mahsheed, who is the closest thing to perfect I've found. --Michael Morrison ## Acknowledgments I would like to thank Beverly Eppink for being such a great editor and for taking all my personal crises in stride. A big thanks goes to Alice Martina Smith, for being so incredibly easy to work with...again! I'd also like to thank all the contributing authors, who are truly responsible for making this book as rich in content as it is. I would like to thank my family and friends, especially my mom and dad, who simply are the best. Thanks also goes out to the folks at Cumberland Transit Skate Shop, who are generous enough to help sponsor my skateboarding endeavors. Finally, I'd like to thank the wooden bowl at XXX Sports (`www.xxxsports.com`), which taught me by way of a fractured wrist that I'm really not as invincible as I once thought. --Michael Morrison ## About the Authors ### Lead Author: Michael Morrison (`mmorrison@thetribe.com`, `www.thetribe.com`) is a writer and skateboarder living in Nashville, Tennessee. Michael is the author of Presenting JavaBeans and Teach Yourself Internet Game Programming with Java in 21 Days, he is also a contributing author to Teach Yourself Java in 21 Days, Professional Reference Edition, and Late Night Visual J++. When not working late into the night by the sounds of Miles Davis and Phish, Michael enjoys skateboarding on ramps of all shapes and sizes. Michael single-handedly (pun intended) wrote Chapters 2, 3, 4, 5, 9, 10, 12, 20, 30, 38, 39, 40, 41, 47, 53, and 57. ### Contributing Authors: Jerry Ablan (`munster@mcs.net`) is best described as a computer nut. He has been involved with computers since 1982, has programmed in many languages, and is a senior software engineer at the Chicago Board Options Exchange. He lives in a Chicago suburb with his wife, Kathryn, and when not playing WarCraft II with his friends, working, writing, or otherwise cavorting, Jerry and his brother, Dan, operate NetGeeks (`http://www.netgeeks.com`), an Internet consulting firm. He is the author of Developing Intranet Applications with Java, coauthor of the Web Site Administrator's Survival Guide, and a contributing author to Special Edition: Using Java; Platinum Edition: Using CGI, HTML, and Java; and Intranets Unleashed. Jerry wrote Chapter 49. Michael Afergan (`mikea@ai.mit.edu`) began working with Java as early as the spring of 1995 through his research work at the MIT AI Labs. Since then, he has carefully studied its growth and developed practical applets for companies as an independent consultant. Michael is the author of Java Quick Reference and has taught Java overseas to both managers and programmers. Although only 19, Michael has been programming for 11 years and has even taught a class on computer science at MIT. Captain of his high-school wrestling team, he is currently attending Harvard University. Michael wrote Chapter 27. Billy Barron (`billy@metronet.com`; `http://www.utdallas.edu/~billy`) is currently a new technology specialist for the University of Texas at Dallas and has an M.S. in computer science from the University of North Texas. He has written and edited so many books that he can't remember them all anymore. Some examples are Netscape 3 Unleashed, Web Site Administrator's Survival Guide, and Tricks of the Internet Gurus. Billy revised Chapter 11 and Appendixes A and C. Chris Burdess, originally trained in cognitive science, started using Java to develop platform-independent neural network models of mammalian midbrain and cerebellar reflexes. He is currently working as an analyst and developer of intelligent systems and human-computer interaction methodologies on the Internet. For further biographical information and interests, you may consult his Web site at `http://www.dog.net.uk`. Chris revised Chapter 14. Eric Burke is currently working on a Java development environment for a major Silicon Valley computer manufacturer. He received his master's degree in computer engineering from Purdue University in December 1994. In addition to programming in Java, Eric coaches youth football and is cofounder of a Web site devoted to mountain biking at `http://www.mtbinfo.com`. Eric wrote Chapter 15. Eddie Burris is currently a research associate at the University of Missouri at Kansas City. He has an M.S. degree from Michigan State University and over 14 years of experience as a software engineer including appointments at IBM and Los Alamos National Research Lab. In addition to working with cutting-edge information technologies, Eddie enjoys listening to and restoring vintage radios from the 1930s. His home page on the World Wide Web is located at `http://sol.cstp.umkc.edu/~burris/`. Eddie wrote Chapter 17. Bruce Campbell lives in Seattle, Washington, and works with Internet technologies related to 3D collaboration such as VRML. Having gained an appreciation for information flow and sharing in large corporations, he enjoys envisioning the future effects of computer networking on information-access efficiency. Admittedly utopian in his outlook, he enjoys discussing appropriate uses of new technologies for the betterment of society. Bruce revised Chapter 45. Rogers Cadenhead (`rcade@airmail.net`, `http://www.perfect.com/rogers`) is a Web developer, computer programmer, and writer who created the multiuser games Czarlords and Super Video Poker. Thousands of readers see his work on the Fort Worth Star-Telegram question-and- answer column "Ask Ed Brice." Rogers has developed Java applets for Tele-Communications, Inc., and other clients, and is the author of Teach Yourself Java 1.1 in 24 Hours and the co- author of Teach Yourself SunSoft's Java Workshop in 21 Days. Rogers wrote Chapter 1. David R. Chung (`dchung@inav.net`, `http://soli.inav.net/~dchung`) is a senior programmer in the Church Software Division of Parsons Technology in Hiawatha, Iowa. His current projects include Windows and the Internet, and he moonlights teaching C and C++ to engineers for a local community college. In his spare time, David enjoys bicycling, teaching adult Sunday school, rollerblading, skiing, windsurfing, preaching in a nursing home, tennis, two-player and six-player volleyball, playing the clarinet, and speaking French. He is the father of six children whose names all begin with J and has contributed to Tricks of the Java Programming Gurus. David wrote Chapters 7 and 22 and was the original author of Chapter 14. Justin Couch (`justin@vlc.com.au`, `http://www.vlc.com.au/~justin`) works as a software engineer for ADI Ltd. He also runs The Virtual Light Company, a small VRML and Java Web publishing company located in Sydney, Australia. Coauthor of Laura Lemay's Web Workshop: 3D Graphics and VRML 2, Justin is an active member of both the VRML standards and Java-VRML mailing lists. Currently, he is involved in research on using VRML to create seamless worlds on the Internet and can be found most days in the CyberGate community Point World under the name Mithrandir. When not pushing the limits, he relaxes by playing bassoon, clarinet, and going gliding. Justin was the original author of Chapter 45. Rick Darnell (`darnell@montana.com`), a contributing author to FrontPage Unleashed and Microsoft Internet Explorer 3 Unleashed, is a midwest native currently living with his wife and two daughters in Missoula, Montana. He began his career in print at a small weekly newspaper after graduating from Kansas State University with a degree in broadcasting. While spending time as a freelance journalist and writer, Rick has seen the full gamut of personal computers--since starting out with a Radio Shack Model I in the late 1970s. When not in front of his computer, he serves as a volunteer firefighter and member of a regional hazardous materials response team. Rick wrote Chapters 8 and 46 and Appendix D. Mike Fletcher (`lemur1@mindspring.com`) graduated from the Georgia Institute of Technology in 1994 and now works for BellSouth Wireless' AIN Services Group as a systems administrator. Mike was a contributing author to the first two editions of Java Unleashed. He once played tuba on stage with Jimmy Buffet, and his interests include reading science fiction and juggling. Mike wrote Chapters 13, 35, 36, 37, 54 and 55, and was the original author of Chapters 24 and 25. Michael Girdley (`girdleyj@allwilk.com`, `http://www.cs.lafayette.edu/~girdleyj/`) contributed to Web Programming with Java and is the chief consultant at Allwilk Consulting (`http://www.allwilk.com/`), an organization specializing in Web site creation and Java programming. He is currently pursuing a Bachelor of Science degree in computer science at Lafayette College in Easton, Pennsylvania, and will earn his fourth varsity letter in 1996-1997 as a member of the varsity swimming team. Originally from San Antonio, Texas, Michael hopes to find a job or go to graduate school after possibly graduating on time in May 1997. Michael was an original coauthor of Chapter 11. K.C. Hopson is President of Geist Software and Services, Inc., an independent consulting firm in the Baltimore/ Washington D.C. metro area. He was a lead architect of the software used in Bell Atlantic's Stargazer interactive television system and has developed a variety of Intranet applications. K.C. has a bachelor's degree in applied mathematics from the University of California at Irvine, and a masters in computer science from the University of Maryland, Baltimore County. He writes regularly about Java and Internet tools and can be reached at `chopson@universe.digex.net`. You can also visit his home page at `http://www.universe.digex.net/~chopson`. K.C. wrote Chapter 23 and coauthored Chapter 51. Steve Ingram (`singram@mnsinc.com`) is a computer consultant in the Washington D.C. metro area specializing in Internet communications and object-oriented design. Coauthor of Developing Professional Java Applets and contributor to Tricks of the Java Gurus, Steve holds an electrical engineering degree from Virginia Tech. He was the architect behind the language for Bell Atlantic's Stargazer interactive television project, where he first encountered Java. When he's not working, Steve likes to sail the Chesapeake Bay with his wife, Anne, and their two children. Steve wrote Chapters 26, 32, and 33, coauthored Chapter 51, and revised Chap- ters 24 and 25. Corey Klaasmeyer (`corey@webset.com`) is a professional software engineer and active partner in WebSet Technologies, an Intranet software development firm. He teaches object-oriented programming in Java at Denver University. Corey wrote Chapter 18. John J. Kottler (`73157.335@compuserve.com`, `jkottler@aol.com`, or `jay_kottler@msn.com`) has been programming for fourteen years and has spent the past six years developing applications for the Windows platform. He has programmed multimedia applications for more than two years and has spent this past year developing for the Web. His knowledge includes C/C++, Visual Basic, Lotus Notes, PowerBuilder, messaging-enabled applications, multimedia and digital video production, and Web page development. John contributed to Presenting ActiveX, Web Publishing Unleashed, Netscape 2 Unleashed, and Programming Windows 95 Unleashed; he codeveloped the shareware application virtual monitors. A graduate of Rutgers University with a degree in computer science, he enjoys rollerblading, cycling, and playing digital music in his spare time. John wrote Chapter 48. Laura Lemay (`lemay@lne.com`, `http://www.lne.com/lemay/`)is the author of several best- selling books about the Internet and the World Wide Web, including Teach Yourself Java in 21 Days and Teach Yourself Web Publishing with HTML. After receiving her degree in technical writing from Carnegie-Mellon University in 1989, she wrote documentation at various Silicon Valley software companies before writing her first book in 1994. She also writes a monthly column on HTML and Web page design for Web Techniques Magazine. Laura has won awards of merit and excellence from the Society of Technical Communication for her work and has spoken to diverse audiences ranging from programmers to industry pundits to librarians to junior high school girls. She makes frequent appearances and lectures in the San Francisco Bay area. Laura is the original author of Appendixes A and C. Richard Lesh (`rich@micros.umsl.edu`) is an instructor with the microcomputing program at the University of Missouri at St. Louis. He has developed a variety of applications for the Macintosh, PC, and various UNIX platforms. A number of software products he has developed are in national distribution, including PLANMaker, a business plan-building product, and a number of screen-saver modules published by Now Software in Now Fun! and by Berkeley Systems in After Dark. Richard was an original contributor to Chapter 11. Tim Macinta (`twm@mit.edu`) is currently working towards a degree in computer science and electrical engineering at the Massachusetts Institute of Technology. He has been working with Java since the summer of 1995 when he joined Dimension X, one of the leaders in Java development. While at Dimension X, Tim developed the first commercial-quality Java chat applet along with several applets for commercial sites such as the Disney and Monopoly sites. More recently, he has been using Java to write several client/server applications (SMTP, POP, and IRC, to name a few) from the ground up. After graduating from MIT, Tim plans to start a company whose sole purpose will be to grab market share from Microsoft. Tim wrote Chapter 50. Qusay H. Mahmoud is a graduate student in computer science at the University of New Brunswick at Saint John, Canada. This term, he is teaching a course on multimedia and the information highway. As part of his thesis, he developed a distributed computing system over the Web using Java, and he is in the process of writing up the thesis. His interests include computer networks, distributed objects, and cryptography and network security. You can reach him at `qusay@garfield.csd.unbsj.ca`. Qusay wrote Chapter 16. Jim Mathis is a freelance Java and JavaScript consultant by night and a communications systems architect by day. He has been active in the Internet community from its very beginnings, wrote one of the first implementations of TCP/IP, and served on the Internet Activities Board. He received his B.S. from Stanford University in electrical engineering during that most interesting time when the Internet was being created. He is interested in object-oriented technology and the impact of CORBA on the Internet. You can contact Jim at `jmathis@ais.net`. Jim wrote Chapter 31. Tim F. Park (`tpark@corp.webtv.net`) is a recent graduate of the Stanford Graduate School of Electrical Engineering. Now employed by a major computer company in Silicon Valley, he is currently working on a Java 3D graphics library for the Internet. Tim contributed to Tricks of the Java Programming Gurus, and his interests include distributed computing, computer graphics, and mountain biking. Tim wrote Chapter 28. Charles L. Perkins (`virtual@rendezvous.com`) is the founder of Virtual Rendezvous (`http://rendezvous.com/java`), a company building a Java-based service that fosters socially focused, computer-mediated, real-time filtered interactions between people's personas in the virtual environments of the near future. In previous lives, he has evangelized NeXTSTEP, Smalltalk, and UNIX, and has degrees in both physics and computer science. Charles is the author of Appendix B. Shelley Powers has her own company, YASD, and is a freelance writer. She also provides Web/Internet training and consulting. She contributed to two Java books by Sams Publishing and has coauthored several other books, including ones about JavaScript, PowerBuilder 5.0, and CGI/Perl. She is currently working on other books about Web authoring technology. She contributes articles to various online magazines and has a regular column on scripting with NetscapeWorld. Shelley originated in Portland, Oregon, but moved to Vermont in 1997. She can be reached at `shelleyp@yasd.com`; her site is at `http://www.yasd.com`. Shelley wrote Chapters 19, 42, 43, and 44. George Reese (`borg@imaginary.com`) holds a degree in philosophy from Bates College in Lewiston, Maine. He currently works as a lead systems analyst for Carlson Marketing Group's Internet and intranet development team. In addition, he does consulting through Caribou Lake software, where he markets a Java persistence library. His Java writing has appeared in several Sams titles as well as in articles for the Java Developer's Journal. He was the creator of the first JDBC driver, the mSQL-JDBC driver for the MiniSQL database engine. George lives in Bloomington, Minnesota, with his two cats, Gypsy and Misty. George wrote Chapter 29. Chris Seguin (`seguin@uiuc.edu`) completed a B.S. in mathematics at the University of Delaware in 1991. On June 25, 1994, he married his long-time sweetheart, Angela DiNunzio. Chris is currently working toward a Ph.D. at the University of Illinois in computer science. He is currently employed by NCSA and is working on a collaborative software project called Habanero (`http://www.ncsa.uiuc.edu/SDG/Software/Habanero/`). His research interests include creating artificial neural networks and developing collaboration tools. Chris wrote Chapter 21. Jeff Shockley is the data processing manager at Total Response, Inc., an Indiana-based integrated marketing firm. Jeff has designed client/server systems and written multiple applications in languages such as C++, Visual Basic, Java, and SQLWindows. He is also experienced in Oracle and SQL Server databases, and has been a technical editor on topics such as Java programming, Visual Basic programming, Web databases, Web page design, and client/server technologies. Jeff lives in Indianapolis with his wife, Larryssa, and his three daughters, Lindi, Danielle, and Erin. You can reach him with e-mail at `shockle@totalresponse.com` or visit `http:\\www.totalresponse.com` to see what he does daily. Jeff revised Appendix C. William R. Stanek (`director@tvpress.com`,`http://tvp.com/`) is a leading Internet technology expert and a working professional who directs an Internet start-up company called The Virtual Press. As a publisher and writer with over ten years experience on networks, William brings a solid voice of experience about the Internet and electronic publishing to his many projects. He has been involved in the commercial Internet community since 1991 and was first introduced to Internet e-mail in 1988 when he worked for the government. His years of practical experience are backed by a solid education: a master of science in information systems and a bachelor of science in computer science. He is the author of Sams.net's Netscape ONE Developer's Guide, Web Publishing Unleashed, and Microsoft FrontPage Unleashed. William wrote Chapter 56. Glenn Vanderburg (`glv@vanderburg.org`, `http://www.vanderburg.org/~glv/`) is a software architect with BusinessWorks, Inc., where he is using Java to support multimedia educational systems. Glenn lives in Plano, Texas, with his wife, Deborah. He holds a B.S. degree in computer science from Texas A&M University. Glenn is the lead author of Maximum Java 1.1 and is interested in using Java to build dynamically extensible, upgradable network applications. Glenn wrote Chapters 34 and 52. Eric Williams (`williams@sky.net`, `http://www.sky.net/~williams`) is a team leader and software engineer for Sprint's Long Distance Division. Although he is currently focusing on C++ and Smalltalk development, Eric is active in the Java community, contributing to the `comp.lang.java` newsgroup and delivering presentations about Java to various user groups. Eric is also responsible for identifying a Java 1.0.1 security flaw related to sockets and DNS. Eric wrote Chapter 6. # Tell Us What You Think! As a reader, you are the most important critic and commentator of our books. We value your opinion and want to know what we're doing right, what we could do better, what areas you'd like to see us publish in, and any other words of wisdom you're willing to pass our way. You can help us make strong books that meet your needs and give you the computer guidance you require. Do you have access to CompuServe or the World Wide Web? Then check out our CompuServe forum by typing `GO SAMS` at any prompt. If you prefer the World Wide Web, check out our site at `http://www.mcp.com`. Note: If you have a technical question about this book, call the technical support line at 317-581-3833. As the publishing manager of the group that created this book, I welcome your comments. You can fax, e-mail, or write me directly to let me know what you did or didn't like about this book--as well as what we can do to make our books stronger. Here's the information: FAX: 317-581-4669 E-mail: `newtech_mgr@sams.mcp.com` Mail: Mark Taber Sams.net Publishing 201 W. 103rd Street Indianapolis, IN 46290 # Introduction Just over a year and a half after its inception, Java is still the dominant technology bringing interactive content to the World Wide Web. In a world where just about everyone has his or her own opinion about where the future of the Web is headed, this is no small feat. JavaSoft, the division of Sun Microsystems responsible for Java, has managed to stay ahead of the development curve and rapidly improve Java to accommodate the ever-changing environment known as the Web. Even so, Java is still a young technology and has plenty of room to evolve to meet the demands of Web developers. The release of Java 1.1 marks a significant step forward for Java. The fact that Java is an evolving technology has played a critical role in its wide acceptance by Web developers; many developers who struggled with limitations in earlier releases of Java should feel reassured by the abundance of new features included in the latest 1.1 release. This confidence depends greatly on JavaSoft's willingness and desire to solicit input from experts in the field when expanding Java to solve new problems and provide new features. Since initially releasing Java, JavaSoft has been steadily improving Java to meet the needs of the demanding Web community. Even with Java 1.1 out the door, JavaSoft still has big plans for even more Java-related technologies. Our goal in this edition of Java 1.1 Unleashed is to explore the Java technology from a variety of angles so that you can see the bigger picture of what Java has to offer as a Web technology. Our contention is that if you understand Java in its entirety, you will be much better suited to make decisions regarding its efficient use in your own Web development projects. Beyond that, we also thought it would be a lot of fun to chart some new territory and see for ourselves what Java could do. As you will see, Java 1.1 presents plenty of new territory to chart! In this book, you learn about the following topics related to the Java 1.1 technology: Getting started with Java The Java language The standard Java programming packages The Java Advanced Windowing Toolkit (AWT) Networking with Java Java programming strategies Advanced Java programming Java archives JavaBeans software components Java databases Integrating Java with other technologies Applied Java Related Java technologies The book also contains extensive reference material covering the following topics: Java language summary Java class hierarchy diagrams Java resources Java class library ## Part I: Getting Started with Java Every exploration has to start somewhere--you're ready to begin learning about the vast world of Java. You want to know why Java is an object-oriented language and what this really means in a practical sense. You'd also like to know exactly where to begin as far as setting up your own Java development environment. ## Part II: The Java Language The cornerstone of the Java technology is the Java programming language. You understand Java in general terms, but you want to know more about the Java language and what it can do for you. You are curious about Java classes and how they relate to all the object-oriented hype you've heard about Java. You also want to know what in the world threads and exceptions are, and why so many people seem so worried about them. ## Part III: The Standard Java Programming Packages The real power of Java is spelled out in the standard Java programming packages. You're ready to move past the Java language and see exactly what Java provides in the way of specific programming features such as mathematical functions, I/O, networking, and security. You're also curious about graphical user interfaces and what kinds are available in the standard Java packages. ## Part IV: The Java Advanced Windowing Toolkit Although Java is certainly strong in many ways that aren't immediately obvious, its user interface and graphics support make up the first impression for most users and developers alike. The AWT encompasses all the visual characteristics of the Java environment, providing support for things such as fancy user interfaces and advances and advanced image processing. If you're familiar with the AWT in a previous version of Java, you're in for a treat; Java 1.1 is chock full of neat new enhancements. ## Part V: Networking with Java Can you possibly imagine a programming language for the Web that doesn't provide extensive support for networking? Of course not! You want to know all about networking with Java and exactly what it can do for you. You've heard a lot about client/server networking and want to know how it is supported in Java. You're also interested in writing a multiuser applet in Java. ## Part: VI Java Programming Strategies You realize the importance of smart programming and want to know some Java programming strategies to improve your development efficiency. You understand the inherent nature of programming bugs and want to know how to debug Java code. You want to employ a documentation strategy so that your code can be better maintained. You are also interested in speeding up your code, because performance is a very critical issue in Java programming. ## Part VII: Advanced Java Programming You are ready to press on to some more advanced areas of Java programming. More specifically, you want to learn about persistence and serialization, which are techniques for storing and retrieving the state of Java objects. You are also interested in how Java integrates with native C code, as well as finding out more about the Java virtual machine, Java security, and Java's new reflection services. ## Part VIII: Java Archives and JavaBeans The idea of bundling all the files and resources required for an applet or application into one compressed, secure entity is nothing short of a breakthrough in terms of safely and efficiently distributing Java products. JAR files are something you simply must learn about so that you can improve the distribution of your own applets. Have you ever wondered why building Java applications isn't as straightforward as building applications in other languages with visual development tools such as Visual Basic and Delphi? It's because earlier versions of Java didn't support a highly structured software component model for defining reusable components. JavaBeans, which is an integral part of Java 1.1, addresses this problem head-on. You won't believe how easy it is to build and use JavaBeans components. ## Part IX: Java Databases There has been lots of talk recently about how Java will support databases. Well, talk no more because Java 1.1 spells out exactly how Java supports databases with the JDBC API, which fully supports SQL (Structured Query Language) interaction with all major types of databases. Let the client/server Java madness begin! ## Part X: Integrating Java with Other Technologies Although Java is a pretty complete technology, there are still instances in which you may want to integrate Java with another technology such as VRML or ActiveX. You want to know some details surrounding the integration of Java with technologies such as VRML, ActiveX, JavaScript, and VBScript. ## Part XI: Applied Java A software development technology is only as useful as its range of application. Knowing this, you want to see some specific areas of application where Java can be used. More specifically, how can Java be applied to intranets, games, image processing, and internationalization? ## Part XII: Related Java Technologies You're interested in tying up some loose ends by learning about a variety of related Java technologies. More specifically, you want to find out more about just-in-time compilers, remote objects, Java server support, and what's in store for Java in the near future. Even though Java has come a long way, the story of Java is still very much being written. We can certainly use Java's past as a means of forecasting its future, but ultimately, we must keep an open mind and be willing to adapt to changes in Java as they unfold. In the meantime, there's a lot to learn and a lot of fun to be had with Java in the present. Knowing that, I encourage you to set out on your own exploration of Java using this book as your guide. Have fun! --Michael Morrison
| ©Copyright, Macmillan Computer Publishing. All rights reserved.