Supplemental files and examples for this book can be found at http://examples.oreilly.com/9780596006204/. Please use a standard desktop web browser to access these files, as they may not be accessible from all ereader devices.
All code files or examples referenced in the book will be available online. For physical books that ship with an accompanying disc, whenever possible, weve posted all CD/DVD content. Note that while we provide as much of the media content as we are able via free download, we are sometimes limited by licensing restrictions. Please direct any questions or concerns to .
Preface
This book is a companion volume to my previous books Java in a Nutshell, Java Foundation Classes in a Nutshell, and Java Enterprise in a Nutshell. While those books are quick-references at heart, they also include accelerated introductions to various Java programming topics and example code, usually in the form of program fragments. I wrote Java Examples in a Nutshell to pick up where those books leave off, providing a suite of complete working examples, ready to compile and run, suitable for novice Java programmers and experts alike.
The first edition of this book came about when Java 1.1 was released at more than double the size of Java 1.0. While I was busy writing additional examples for the second edition of Java in a Nutshell, the engineers at Sun were busy turning Java into something that could no longer fit in a nutshell. With its quick-reference section expanding so much, Java in a Nutshell could no longer hold many examples. The examples in Java in a Nutshell were one of its most popular features, and it was hard to have to cut them.
This book is the result of those cuts, and I am glad that we made the decision we did. Given the freedom to devote an entire book to examples, I was able to write the examples I really wanted to write. I was able to go into more depth than I ever would have before, and I found myself really enjoying the exploration and experimentation that went into developing the examples. For the second edition of the book, I had the pleasure of exploring and experimenting with new parts of the Java API: Swing, Java 2D, servlets, and XML. And for the third edition, I got to play around with New I/O, Java Sound, and several new minor APIs, such as logging and preferences. I hope you will use these examples as a starting point for your own explorations, and that you feel some of the same excitement I felt while writing them.
As its name implies, this book teaches by example, which is how many people learn best. There is not a lot of hand-holding, nor will you find detailed documentation of the exact syntax and behavior of Java statements. This book is designed to work in tandem with Java in a Nutshell, Java Foundation Classes in a Nutshell, and Java Enterprise in a Nutshell. You'll probably find those volumes quite useful while studying the examples here. You may also be interested in the other books in the O'Reilly Java series. Those books are listed at http://java.oreilly.com.
This book is organized into four parts. Chapters contain examples of server-side or "enterprise" APIs and complement the book Java Enterprise in a Nutshell.
You can read the chapters in this book in more or less whatever order they strike your interest. There are some interdependencies between the chapters, however, and some chapters really ought to be read in the order they are presented. For example, it is important to read are aimed at programmers just starting out with Java. Seasoned Java programmers will probably want to skip them.
By their very nature, nontrivial programming examples are rarely about only a single topic, and there are many examples here there could be placed in more than one chapter. The final chapter of this book is a special in which you can look up a class, method, or programming topic and find examples that cover that topic. This example index is distinct from, and provided in addition to, the regular index that appears at the back of the book.
New in This Edition
Readers of the second edition will find this edition much improved. New chapters cover the New I/O API and the Java Sound API. The chapters on servlets and XML have been completely overhauled, and there are many new and improved examples throughout the book. To save typing, the package prefix for all examples has changed from the correct but awkward "com.davidflanagan.examples" to the succinct and easy "je3".
Java Examples Online
The examples in this book are available online, so you don't have to type them all in yourself ! You can download them from the author's web site, at http://www.davidflanagan.com/javaexamples3, or from the publisher's site, http://www.oreilly.com/catalog/jenut3. As typos and bugs are reported, you will also find an errata list at the publisher's site. The examples are free for noncommercial use. If you want to use them commercially, however, I ask that you pay a nominal commercial licensing fee. Visit http://www.davidflanagan.com/javaexamples3 for licensing details.
Related Books from O'Reilly
O'Reilly publishes an entire series of books on Java. These books include Java in a Nutshell, Java Foundation Classes in a Nutshell, and Java Enterprise in a Nutshell, which, as mentioned earlier, are quick-reference companions to this book.
A related reference work, written and published by the author, is Jude , an innovative software package that combines the popular quick-reference format of Java in a Nutshell with the definitive javadoc documentation from Sun, and with the instant search and navigation commands of an online help application. See http://www.davidflanagan.com/Jude for details.
You can find a complete list of Java books from O'Reilly at http://java.oreilly.com. Individual chapters in this book refer to specific books that may help you understand that material in more detail.
Conventions Used in This Book
The following formatting conventions are used in this book:
ItalicUsed for emphasis and to signify the first use of a term. Italic is also used for commands, email addresses, web sites, FTP sites, file and directory names, and newsgroups.
BoldOccasionally used to refer to particular keys on a computer keyboard or to portions of a user interface, such as the Back button or the Options menu.
Constant Width
Used in all Java code and generally for anything that you would type literally when programming, including keywords, data types, constants, method names, variables, class names, and interface names. Also used for command lines and options that should be typed verbatim on the screen, as well as tags that might appear in an HTML document.
Constant Width Italic
Used for the names of method parameters and generally as a placeholder to indicate an item that should be replaced with an actual value in your program. Also used for variable expressions in command-line options.