|Exploring Java:By Patrick Niemeyer & Joshua Peck|
source ref: ebookjava.html
This book is about the Java language and programming environment. If you've been at all active on the Internet in the past year, you've heard a lot about Java. It's one of the most exciting developments in the history of the Internet, rivaling the creation of the World Wide Web. Java became the darling of the Internet programming community as soon as the alpha version was released. Immediately, thousands of people were writing Java applets to add to their Web pages. Interest in Java only grew with time, and support for Java in Netscape Navigator guaranteed it would be a permanent part of the Net scene.
What, then, is Java? Java is a language for network programming that was developed by Sun Microsystems. It's already in widespread use for creating animated Web pages. However, this is only the start. The Java language and environment are rich enough to support entirely new kinds of applications, like dynamically extensible browsers. There has been talk about new kinds of computer platforms (Java terminals or Java pads) that download all their software over the network. In the coming years, we'll see what Java is capable of doing; fancy Web pages are fun and interesting, but they certainly aren't the end of the story. If Java is successful (and that isn't a foregone conclusion), it could change the way we think about computing in fundamental ways.
This book sets out to give you a head start on a lot of Java fundamentals. Exploring Java attempts to live up to its name by mapping out the Java language, its class libraries, programming techniques, and idioms. We'll dig deep into interesting areas, and at least scratch the surface of the rest. Other titles in the O'Reilly & Associates Java series will pick up where we leave off and provide more comprehensive information on specific areas and applications of Java.
Whenever possible, we'll provide meaningful, realistic examples and avoid simply cataloging features. The examples are simple but hint at what can be done. We won't be developing the next great "killer Internet app" in these pages, but we hope to give you a starting point for many hours of experimentation and tinkering that will lead you to learn more on your own.
A lot has happened in the year since the first edition of this book. We're now up to release 1.1.1 of Java, which has many more features than the 1.0 release. Java 1.1 adds many, many new features, in addition to many extensions to the features of Java 1.0. It's clear that Java is changing the way we think about computing in fundamental ways; we don't regret that prophecy at all. It's becoming more and more clear as time goes on that Java is central to the way software will be written in the future.
This edition of Exploring Java tries to give you the flavor of Java 1.1. With a few exceptions, we have uncompromisingly rooted out all deprecated features from Java 1.0. For example, the chapters covering AWT all use the new event model; we don't even mention the 1.0 event model. The new event model is far and away superior to the old one; there's no need for nostalgia. The one section in which we allowed ourselves to use deprecated features was the chapter covering Networking. In the best of all possible worlds, you would write your clients and servers to work with Unicode character streams, using Java's Reader and Writer classes. But this isn't the best of all possible worlds, and most software still uses byte-oriented ASCII. There's no sense in touting a language designed for portability if programs written in that language would have difficulty talking to older clients and servers around the net. So we cut ourselves some slack where network I/O streams are concerned.
We wish we could say that this was "the second edition" of our book. But that would be a lie. Actually, this is edition 1.9 (well, more like 1.78). We have updated everything in the first edition to reflect the best current practice, and we have added discussions of the most important new features. However, the deadline for the CD-ROM didn't let us finish a few things that we'd really like to add. In particular, the "real" second edition will have material on:
We may add some more topics if we get to them. However, we also want to keep this book reasonably compact. It's our feeling that thousand page tutorials aren't much help. Furthermore, Java's growing so fast that we have to place limits somewhere: by the end of the year, there should be 2D, 3D, sound, commerce, and many other features available.
This book divides roughly into three sections:
If you're like us, you don't read books from front to back. If you are really like us, you usually don't read the preface at all. However, on the off chance that you will see this in time, here are a few suggestions.
If you are an experienced programmer who has to learn Java in the next five minutes, you are probably looking for the examples. You might want to start by glancing at the tutorial in Chapter 2, A First Applet. If that doesn't float your boat, you should at least look at the information in Chapter 3, Tools of the Trade, which tells you how to use the compiler and interpreter, and gives you the basics of a standalone Java application. This should get you started.
Chapter 9, Network Programming is essential if you are interested in writing advanced networked applications. This is probably the most interesting and important part of Java. Unfortunately, we are still waiting for Sun to release a production version of HotJava, or for someone else to release a browser that implements all of Java's networking features. Until then, you can still write interesting standalone applications that use the Net. Maybe you'll even write the browser we're waiting for.
 Just before this book went to press, Sun released a "pre-beta 1" version of HotJava. That's definitely good news, though the pre-beta version doesn't support downloadable content and protocol handlers. These are promised for the "real" beta release.
Chapters 13 and 14 discusses Java's graphics features. You will need to read this if you are interested in animation and other live displays.
There are many online sources for information about Java. Sun Microsystem's official Web site for Java topics is http://www.javasoft.com/; look here for the latest news, updates, and Java releases. www.javasoft.com is where you'll find the Java Developers Kit (JDK), which includes the compiler, the interpreter, and other tools. Another good source of Java information, including free applets, utility classes, and applications, is the Gamelan site, run by EarthWeb; its URL is http://www.gamelan.com/.
You should also visit O'Reilly & Associates' Java site at http://www.ora.com/info/java. There you'll find information about other books in O'Reilly's Java series, and a pointer to the home page for Exploring Java, http://www.ora.com/catalog/expjava/, where you'll find the source code and examples for this book.
The comp.lang.java newsgroup can be a good source of information, announcements, and a place to ask intelligent questions.
The font conventions used in this book are quite simple.
Italic is used for:
Boldface is used for:
Typewriter Font is used for:
In the main body of text, we always use a pair of empty parentheses after a method name to distinguish methods from variables and other creatures.
In the Java source listings, we follow the coding conventions most frequently used in the Java community. Class names begin with capital letters; variable and method names begin with lowercase. All the letters in the names of constants are capitalized. We don't use underscores to separate words in a long name; following common practice, we capitalize individual words (after the first) and run the words together. For example: thisIsAVariable, thisIsAMethod(), ThisIsAClass, and THISISACONSTANT.
Many people contributed to putting this book together under a schedule that became increasingly rushed as time passed. Thanks to their efforts, we gave birth to something we can all be proud of.
Foremost we would like to thank Tim O'Reilly for giving us the opportunity to write this book. Special thanks to Mike Loukides, the series editor, whose endless patience and experience got us through the difficult parts and to Paula Ferguson, whose organizational and editing abilities got the material into its final form. It's due largely to Mike and Paula's tireless efforts that this book has gotten to you as quickly as it has. We could not have asked for a more skillful or responsive team of people with whom to work.
Particular thanks are due to our technical reviewers: Andrew Cohen, Eric Raymond, and Lisa Farley. All of them gave thorough reviews that were invaluable in assembling the final draft. Eric contributed many bits of text that eventually found their way into the book.
Speaking of borrowings, the original version of the glossary came from David Flanagan's book, Java in a Nutshell. We also borrowed the class hierarchy diagrams from David's book. These diagrams were based on similar diagrams by Charles L. Perkins. His original diagrams are available at http://rendezvous.com/java/.
Thanks also to Marc Wallace and Steven Burkett for reading the book in progress. As for the crowd in St. Louis: a special thanks to LeeAnn Langdon of the Library Ltd. and Kerri Bonasch. Deepest thanks to Victoria Doerr for her patience and love. Finally, thanks for the support of the "lunch" crowd: Karl "Gooch" Stefvater, Bryan "Butter" O'Connor, Brian "Brian" Gottlieb, and the rest of the clan at Washington University.
Many people in O'Reilly's production and design groups contributed their blood, sweat, and tears to the project. Mary Anne Weeks Mayo was production editor and copy editor, and had the stress-filled job of working under a very tight deadline with chapters arriving asynchronously (which means at random and later than expected). Seth Maislin wrote the index, and Stephen Spainhour adapted David Flanagan's glossary for this book. Chris Reilley converted rough diagrams into professional technical illustrations. Erik Ray, Ellen Siever, and Lenny Muellner converted HTML files into SGML and made sure we could convert electrons into paper without mishap. Lenny also implemented a new design for this book, which was created by Nancy Priest. Hanna Dyer created the back cover; Edie Freedman designed the front cover.