Preface

       Professional Java        Enterprise Java        Commercial Java

These are all terms that are commonplace in programming discussions these days—and for good reason. Gone are the days when Java was considered a toy language for creating web games, futilely trying to catch up to its “big brothers,” C and C++. While AWT and Swing (and now SWT) are important parts of the Java language, Java has also evolved to take on more far-ranging tasks—database interaction, financial management, e-commerce, and more. Its speed is comparable to C, and its APIs are farreaching. As a result, the core language has undergone significant stabilization, and Java 1.3, and then 1.4, were largely steps towards maturing the platform, rather than radically changing it.

Enter Java 5.0—code-named Tiger. Actually, it’s Java 5, version 1.5. Well, it’s the J2SE, which I suppose makes it Java 2, Standard Edition, 5, version 1.5. Confusing enough for you? Thankfully, whatever the thing is called, the additions are worthy of all the hubbub; this isn’t your father’s Java (or to be more accurate, it’s not your slightly older brother’s Java) anymore.

Looking more like a completely new product than just a revision of an older language, Tiger is chock-full of dramatic changes to what you know as simply Java. You can’t just read through the release notes and figure this one out; and since the new features are a lot more important than all the oddities about its versioning, I’ll just call it Tiger throughout the book, and sidestep Java 2 version 5...er...version 1.5...well...as I said, Tiger.

Whatever Tiger ends up being called officially, it introduces so many new features to the language that it took nearly 200 pages to cover them— and you’ll find that each page of this book is dense with code, example, and terse explanation. There isn’t any wasted space. In fact, that’s precisely what you’re holding in your hands—a concise crash course in the next evolution of Java, Tiger. By the time you’re through, you’ll be typing your lists, taking your overloading to an entirely new level, writing compile-time checked annotations, and threading more efficiently than ever. And that doesn’t take into account how much fun it is to type all sorts of new characters into your source code. You haven’t lived until @, <, >, and % are strewn throughout your editor...well, maybe that’s just me wanting to have a little more fun at the workplace. Whatever your reason for getting into Tiger, though, you’ll find more tools at your disposal than ever before, and far more change in any version of Java since its initial 1.0 release. Fire up your code editor, buckle your seat belts, and get ready to hit the ground running.

Let’s tame the Tiger.

Organization

This book is set up to be something of a cross between a learning exercise (where you would read from front to back), and a cookbook (where you can skip around without concern). For the most part, you can feel free to look through the table of contents or index, and find what you’re looking for. However, as many of the subjects in this book are interrelated (such as generics, the for/in statement, and autoboxing), you may find yourself reading an article that assumes knowledge from a previous section of the book. In these cases, just browse the referenced chapter, and you should be all set. A little extra learning is a good thing anyway, right?

How This Book Was Written

This book is the result of an unusual, but fruitful collaboration between David Flanagan and Brett McLaughlin. David was at work on the fifth edition of Java in a Nutshell, but was eager to get coverage of the major language changes in Tiger out sooner than the production schedule for that book allowed. Brett, meanwhile, was the driving editorial force behind this innovative new series of Developer’s Notebooks, and was eager to include a title on Tiger in the series.

The process went like this:

  • David researched the new features of Tiger and wrote about them for Java in a Nutshell. He sent drafts of his new material to Brett.

  • Brett feverishly ripped those chapters apart, rewrote almost everything, added new examples, and reassembled everything into the Developer’s Notebook format.

The result is a book almost entirely written by Brett, based on research done by David. The tone of the writing and the engaging style of the book is Brett’s, and readers of this book and Java in a Nutshell will be hard-pressed to find any duplication of prose. In a few cases, Brett has used code samples that also appear in Java in a Nutshell, and in each case that fact is mentioned in the margin.

About the Examples

This book has hundreds of code examples, spread throughout its pages. While some complete code listings are shown in the text, other examples are shown only in part. While some readers may enjoy typing in these programs on their own, many of us just don’t have the time. Because of this, every single example, and almost all of the partial examples, are ready for compilation in Java source files, ready for download.

Additionally, the process of compilation (especially class path issues) remains one of Java’s most problematic features. To help you out, an Ant buildfile is included with the samples, called build.xml. You’ll need to download and install Ant (available at ant.apache.org ) to take advantage of this buildfile, and I strongly urge you to do just that. Ant installation is easy, and you can always refer to Ant: The Definitive Guide (O’Reilly) if you need assistance. Your directory structure should look something like this:

   <basedir>
     |
     +--src (contains build.xml)
     |
     +--classes

Tip

This is all taken care of for you if you just download the code and unzip it.

Navigate to your local src directory, and type ant. You’ll get an error if you don’t have Ant set up properly. Otherwise, you should see something like the following:

   ${basedir}\code\src>ant
   Buildfile: build.xml
   
   compile:
        [echo] Compiling all Java files...
       [javac] Compiling 41 source files to code\classes
       [javac] Note: code\src\com\oreilly\tiger\ch06\DeprecatedTester.java
                  uses or overrides a deprecated API.
       [javac] Note: Recompile with -Xlint:deprecation for details.
       [javac] Note: Some input files use unchecked or unsafe operations.
       [javac] Note: Recompile with -Xlint:unchecked for details.
       
   BUILD SUCCESSFUL
   Total time: 9 seconds

I’ll leave it to you to explore the other targets within build.xml; there are also notes in most chapters about targets that apply to that chapter, or to a specific example. All this code is heavily tested, and mildly documented. Just make sure you’ve got Tiger as the first Java compiler on your classpath, or you’ll get all sorts of nasty errors!

You may download this sample code, as well as check out errata, view related resources and online articles, and see the latest on this book, at www.oreilly.com/catalog/javaadn/ . Check this site often, as lots of new content may be available as time goes by and we update the examples.

Conventions Used in This Book

Italic is used for:
  • Pathnames, filenames, program names, compilers, options, and commands

  • New terms where they are defined

  • Internet addresses, such as domain names and example URLs

Boldface is used for:
  • Particular keys on a computer keyboard

  • Names of user interface buttons and menus

Constant width is used for:
  • Anything that appears literally in a JSP page or a Java program, including keywords, data types, constants, method names, variables, class names, and interface names

  • Command lines and options that should be typed verbatim on the screen

  • All JSP and Java code listings

  • HTML documents, tags, and attributes

Constant width italic is used for:
  • General placeholders that indicate that an item is replaced by some actual value in your own program

Constant width bold is used for:
  • Text that is typed in code examples by the user

Tip

This icon designates a note, which is an important aside to the nearby text.

Warning

This icon designates a warning relating to the nearby text.

How to Contact Us

Please address comments and questions concerning this book to the publisher:


   O’Reilly Media, Inc.
   1005 Gravenstein Highway North
   Sebastopol, CA 95472
   (800) 998-9938 (in the United States or Canada)
   (707) 829-0515 (international or local)
   (707) 829-0104 (fax)

We have a web page for this book, where we list errata, examples, or any additional information. You can access this page at:

www.oreilly.com/catalog/javaadn/

To comment or ask technical questions about this book, send email to:

For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our web site at:

www.oreilly.com/

Acknowledgments from Brett

The “I” you see in these pages is me—for better or for worse, I came up with this series, and am thrilled to be able to bring one of the first books in the series to you. But, that leads me to the enormously talented group of folks who made that possible.

There was a time when I loved writing acknowledgements, because I got to thank everybody involved in helping me get through another book. Of course, now I realize that there are so many people I forget to thank, that I’m a little scared...I guess that’s the Oscar-acceptance-paranoia working itself out. In any case, any book such as this truly is a tremendous effort by a ton of people, and I couldn’t go without at least trying to name most of them.

To Mike Loukides, who edits most of my books (this being the exception), and Mike Hendrickson, who’s just all-around smart—thanks for paving the way for these new, inventive, cool little notebooks. I think you’ve done the programming world a real service with them. I need to thank David Flanagan for doing all the heavy lifting; the Sun folks, especially at CAP, for letting me see JDK 1.5 early on; and guys like Hans Bergsten, Bruce Perry, Bob McWhirter, and Steve Holzner for writing good books and letting me spend less time editing than I deserve to.

Finally, in trying to keep things brief (you’ll think I’m funny because of that, right?), I owe the biggest debt to my family, as is always the case. My wife, Leigh, only gripes occasionally when I’m working at 9:00 at night. Of course, that’s mostly because she’s exhausted from chasing the two bits of inspiration I have; my older son, Dean, and my younger son, Robbie. When you guys can read, you’ll see your names here, so thank the readers for the college fund, OK?

Acknowledgments from David

Thanks first and foremost to Brett for his enthusiasm, and for working overtime and pulling this book together so quickly. Thanks also to Mike Loukides for supporting the endeavor, and to Deb Cameron, my editor for Java in a Nutshell, for allowing me the time to work on it.

Get Java 5.0 Tiger: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.