JDK 7 · JSR 336

Java 7

Java SE 7 is JSR 336. Oracle’s specification index dates the release to July 2011. The language changes are the small Project Coin set. The larger library and JVM changes are NIO.2, Fork/Join, and invokedynamic.

Language

try-with-resources

Final · Language

A resource that implements AutoCloseable is closed when the try block ends, in reverse order of acquisition.

Related reading: Exceptions

Curriculum file: versions2Java7Features.java

Diamond operator

Final · Language

The constructor type arguments can be omitted when the variable’s type already supplies them.

Curriculum file: versions2Java7Features.java

Strings in switch

Final · Language

A switch can select on a string. The example uses the Java 7 form: colon labels and break, not arrow labels.

Related reading: Control flow

Curriculum file: versions2Java7Features.java

Binary literals and underscores

Final · Language

Integer literals can be written in binary, and underscores can separate digits.

Curriculum file: versions2Java7Features.java

APIs / Libraries

NIO.2

Final · APIs / Libraries

java.nio.file adds Path and Files for file-system work that the older File API did not cover well.

Related reading: File I/O and NIO

Fork/Join

Final · APIs / Libraries

A work-stealing pool for divide-and-conquer tasks. It is a library, not the virtual-thread API that arrives later.

Related reading: Concurrency

JVM / Runtime

invokedynamic

Final · JVM / Runtime

A JVM instruction for dynamic call sites. Java 8 lambdas later depend on this kind of linkage. It is not a new expression in Java 7 source.

Examples

  • versions2Java7Features.javaJava 7 example · Requires Java 7Try-with-resources, the diamond, a string switch, multi-catch, underscores, and binary literals. The switch uses colon labels and break.

Related reading

Historical notes

The Java 7 example uses only Project Coin syntax: diamond, try-with-resources, a colon string switch, multi-catch, underscores, and binary literals. It does not use lambdas or switch arrows.

Sources. Release month and JSR 336: Oracle Java SE specifications. Feature set: the Java versions reference and versions2Java7Features.java in this curriculum. Oracle Java SE specifications (leaves JavaMastery)

All versions