The fifth edition of this book covers Java 5.0. As its incremented version number attests, this new version of Java has a lot of new features. The three most significant new language features are generic types, enumerated types, and annotations, which are covered in a new chapter of their own. Experienced Java programmers who just want to learn about these new features can jump straight to Chapter 4.
Other new language features of Java 5.0 are:
for/instatement for easily iterating through arrays and collections (this statement is sometimes called “foreach”).
Autoboxing and autounboxing conversions to automatically convert back and forth between primitive values and their corresponding wrapper objects (such as
Integerobjects) as needed.
Varargs methods to define and invoke methods that accept an arbitrary number of arguments.
Covariant returns to allow a subclass to override a superclass method and narrow the return type of the method.
import staticdeclaration to import the
staticmembers of a type into the namespace.
Although each of these features is new in Java 5.0, none of them is large enough to merit a chapter of its own. Coverage of these features is integrated into Chapter 2.
In addition to these language changes, Java 5.0 also includes changes to the Java platform. Important enhancements include the following:
java.utilcollections classes have been converted to be generic types, providing support for typesafe collections. This is covered in Chapter 4.
java.utilpackage also includes the new
Formatterclass. This class enables C-style formatted text output with
format( )methods. Examples are included in Chapter 5. The
java.util.Formatterentry in the quick reference includes a detailed table of formatting options.
The new package
java.util.concurrentincludes important utilities for threadsafe concurrent programming. Chapter 5 provides examples.
These packages support Java 5.0 annotations and the instrumentation, management, and monitoring of a running Java interpreter. Although their position in the
java.langhierarchy marks these packages as very important, they are not commonly used. Annotation examples are provided in Chapter 4, and a simple instrumentation and management example is found in Chapter 5.
New packages have been added to the
javax.xml.validationsupports document validation with schemas.
javax.xml.xpathsupports the XPath query language. And
javax.xml.namespaceprovides simple support for XML namespaces. Validation and XPath examples are in Chapter 5.
In a mostly futile attempt to make room for this new material,
I’ve had to make some cuts. I’ve
removed coverage of the packages
org.ietf.jgss from the quick reference.
standards have not caught on in core Java APIs and now appear to be
relevant only for Swing and related graphical APIs. As such, they are
no longer relevant in this book. The
java.security.acl package has been deprecated
since Java 1.2 and I’ve taken this opportunity to
remove it. And the
org.ietf.jgss package is of
interest to only a very narrow subset of readers.
Along with removing coverage of
the quick reference section, I’ve also cut the
chapter on JavaBeans from Part I of this book. The material on
JavaBeans naming conventions from that chapter remains useful,
however, and has been moved into Chapter 7.
Get Java in a Nutshell, 5th Edition 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.