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
1 and 2 are
introductions to the Java language itself, suitable for programmers
who are just learning Java. Chapters
3 through
10 cover the core Java
APIs. The APIs covered in these chapters are documented in
Java in a Nutshell. Chapters
11 through
17
form the third part of the book. These chapters demonstrate
Java''s graphics and graphical user interface APIs,
which are documented in Java Foundation Classes in a
Nutshell. Finally, Chapters
18 through
21 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
Chapter 3 before you read Chapter 5. Chapter 1 and
Chapter 2 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 "Index of
Examples" 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.