JDK 7 Will Change the Way
You Write Code—Today!
New features in JDK 7 reduce errors and make several difficult or tedious tasks easier.
HERB SCHILDT
JAVA IN ACTION
Having written extensively about the Java language since
its original 1.0 version, I have
watched it evolve, mature, and
grow with every major release.
Each new version added features
that responded to the needs and
desires of the programmers who
used the language. This process of
ongoing refinement and adaptation helped secure the dominance
of Java in the world of programming. It also kept the language
fresh, vibrant, and alive.
One thing I have always found
interesting about the evolution
of Java is that sometimes it took
quite a while for a new feature to
really catch on—to
fully mainstream.
The best example
of this is generics,
which were added by
JDK 5. Generics fundamentally expanded
the power of the
language and the reliability of programs.
They also added a
completely new syntax element
and a new way to think about
writing Java code. Because gener-
ics were such a large change, it
took some time before the use of
generics became commonplace.
For many
programmers, the
Project Coin changes
will be the most
important new
features in JDK 7.
But here’s the interesting thing.
Although these new features are
collectively referred to as small,
the effects of these features will
be quite large in terms of the code
they affect. Simply put: for many
programmers, the Project Coin
changes will be the most important new features in JDK 7.
To understand why, let’s consider the following list of Project
Coin additions.
■ ■ An expanded try statement,
called try-with-resources, supports the automatic closing of a
resource, such as a file stream.
■ ■ Type inference (via diamond) is
provided when constructing a
generic instance.
■ ■ Enhanced exception handling,
in which two or more unrelated
exception types can be caught
by a single type, was added,
plus better type checking for
exceptions that are rethrown.
■ ■ A string can now control a
switch statement.
■ ■ There is support for binary
integer literals with the new
prefix 0b or 0B—for example,
0b1010.
ABOUT US
blog
Binary Literals and Underscores
in Numeric Literals
Let’s begin with the two features
that would seem, justifiably, to be