Project Coin: The Java Language
Has Evolved!
JULIEN PONGE
Three additions to the Java language in Java SE 7 will help you be more productive.
JAVA IN ACTION
Project Coin is an OpenJDK project that initiated the Java
language changes that were standardized as part of Java SE 7 under
JSR-334 in the Java Community
Process (JCP). The project is self-described as follows:
“The goal of Project
Coin is to determine
what set of small language changes should
be added to JDK 7. That
list is:
■ ■ Strings in switch
■ ■ Binary integral literals
and underscores in
numeric literals
■ ■ Multi-catch and more
precise rethrow
■ ■ Improved type inference for
generic instance creation
(diamond)
■ ■ try-with-resources statement
■ ■ Simplified varargs method
invocation”
This article is the first in a two-
part series covering each item
of Project Coin. The goal is to
present the immediate usage of
each feature, and also to provide
some background on the impli-
cations for implementing each
of them, especially since they all
maintain backward compatibil-
ity with prior versions of Java SE.
The impact of each change was
remarkably balanced
with a scientifically
sound analysis of mil-
lions of lines of existing
Java code.
/* The value 123 in decimal,
octal and hexadecimal */
byte decimal = 123;
byte octal = 0173;
byte hexadecimal = 0x7b;
by a combination of zeros and
ones up to the size of the underlying primitive type. The decimal
number 123 can be written as the
following binary literal:
// 123 in binary
byte binary = 0b01111011;
Java SE 7 allows
strings to be
used in switch
statements.
The rules are simple. A decimal
number is a literal comprising a
combination of digits between
0 and 9, an octal number starts
with a zero, and a hexadecimal
number starts with 0x. With the
advent of Java SE 7, you can now
specify a number as a binary lit-
eral by starting it with 0b followed
If fewer digits are provided than
expected for the underlying primi-
tive type, the missing digits are
considered to be at the beginning
of the representation, and they
are given a value of zero. Thus, the
ABOUT US
PHOTOGRAPH BY
MATT BOSTOCK/GETTY IMAGES
Binary Integral Literals
and Underscores
Prior to Java SE 7, numeric literals
could be specified either in
decimal, octal, or hexadecimal forms,
such as in the following:
blog
Julien Ponge provides a brief introduction to his
article about Project Coin.