Latest in branch Java SE 7
7u351
Released 19 Jul 2022
(3 years ago)
SoftwareJava/Java SE
VersionJava SE 7
Status
End of life
Class file version51.0
Initial release7
11 Jul 2011
(14 years ago)
Latest release7u351
19 Jul 2022
(3 years ago)
End of
premier support
Jul 2022
(Ended 3 years, 9 months ago)
End of
extended support
Unavailable
Release noteshttps://www.oracle.com/java/technologies/javase/7-support-relnotes.html#R170_351
Documentationhttps://docs.oracle.com/javase/7
Downloadhttps://www.oracle.com/java/technologies/javase/javase7-archive-downloads.html
Java/Java SE Java SE 7 ReleasesView full list

What Is New in Java 7

Java 7, codenamed Dolphin, delivered a substantial set of language enhancements, new APIs, and performance improvements. This release focused on developer productivity with better syntax and new I/O capabilities. The changes make code more readable and efficient for everyday tasks.

Category Key Changes
Language Features Strings in switch, Binary literals, Multi-catch, try-with-resources, Diamond operator
New I/O (NIO.2) New file system API, Path object, File change notifications, Files utility class
Concurrency Fork/Join Framework, Phasers, TransferQueue
Client & Web JLayer pane, Nimbus look-and-feel updates, Better applet support
Internationalization Unicode 6.0 support, Locale enhancement
Security New TLS algorithms, ECC support, Disable crypto algorithms

What are the key language improvements in Java 7?

Java 7 introduced several syntactic sugars that reduce boilerplate code. The diamond operator simplifies generic instantiation, while multi-catch allows handling multiple exception types in a single block. These features make the code less verbose and easier to maintain.

Diamond Operator

You no longer need to repeat generic types on the right-hand side of an assignment. The compiler infers it from the left-hand side declaration.

// Pre-Java 7
Map<String, List<Integer>> map = new HashMap<String, List<Integer>>();
// Java 7
Map<String, List<Integer>> map = new HashMap<>();

Try-With-Resources

This statement automatically closes resources like streams or connections, eliminating messy finally blocks. It helps prevent resource leaks, a common source of bugs.

try (BufferedReader br = new BufferedReader(new FileReader("file.txt"))) {
    return br.readLine();
} // br is closed automatically here

Strings in Switch

Switch statements now support String objects, which is compiled to efficient bytecode using hash codes. This is cleaner than chaining if-else statements for string comparisons.

String s = ...;
switch(s) {
    case "foo": processFoo(); break;
    case "bar": processBar(); break;
}

How did Java 7 improve file I/O operations?

The NIO.2 API (JSR 203) completely overhauled file handling. It replaces the old File class with a more powerful Path object and provides a comprehensive Files utility class. This new API offers better error handling, symbolic link support, and access to file attributes.

The Path Object

Path is a much more flexible representation of a file path than File. It works across different file systems and provides methods for path manipulation.

Path path = Paths.get("/home", "user", "doc.txt");
Path absolutePath = path.toAbsolutePath();

The Files Utility Class

This class contains static methods for all common file operations, like reading, writing, copying, and checking properties. It often does in one line what required many lines with the old API.

List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
Files.copy(sourcePath, destinationPath);

Watching a Directory

NIO.2 provides a watch service that lets your application get notified when files in a directory are created, modified, or deleted. This is great for building tools that need to react to file changes.

WatchService watcher = FileSystems.getDefault().newWatchService();
Path dir = Paths.get("/home/user");
dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE);

What new concurrency tools were added?

The Fork/Join framework is the star addition for parallel processing. It's designed to efficiently divide a task into smaller subtasks and then combine the results. This framework is the backbone of parallel operations in the JDK itself.

ForkJoinPool

This is a special thread pool that uses work-stealing to maximize CPU utilization. Worker threads that run out of tasks can "steal" work from other threads' queues, keeping all cores busy.

Phaser

A more flexible cyclic barrier for synchronizing threads. Unlike a CyclicBarrier, a Phaser allows a dynamic number of parties to register and synchronize, which is useful for complex multi-phase tasks.

TransferQueue

An extension of BlockingQueue where producers can wait for consumers to receive elements. This provides more control over hand-offs between threads in producer-consumer scenarios.

FAQ

Is try-with-resources just syntactic sugar?
No, it's more than that. It provides automatic resource management by calling close() in a finally block, but it also suppresses exceptions thrown in the try block if another exception is thrown during closing, which is hard to do correctly by hand.

Should I completely stop using the java.io.File class?
For new code, yes, you should prefer the java.nio.file API. The old File class has several design flaws and limitations that NIO.2 fixes. However, much legacy code still uses it, and the two APIs are interoperable.

What's the main advantage of the Fork/Join framework over ExecutorService?
Work-stealing. Fork/Join is optimized for computationally intensive tasks that can be broken down recursively. The ExecutorService is more general-purpose. Fork/Join typically delivers better performance for these specific recursive problems.

Can I use strings in a switch statement with case-insensitive matching?
No, the switch statement is case-sensitive. You would need to convert your string to lower or upper case first before the switch and in each case label to achieve case-insensitive matching.

Did Java 7 change how generics work?
It didn't change the core erasure model, but the diamond operator (<>) made instantiating generics much less verbose. The compiler does more type inference, which is a nice quality-of-life improvement for developers.

Releases In Branch Java SE 7

VersionRelease date
7u35119 Jul 2022
(3 years ago)
7u34302 May 2022
(4 years ago)
7u34119 Apr 2022
(4 years ago)
7u33118 Jan 2022
(4 years ago)
7u32119 Oct 2021
(4 years ago)
7u31120 Jul 2021
(4 years ago)
7u30120 Apr 2021
(5 years ago)
7u29119 Jan 2021
(5 years ago)
7u28120 Oct 2020
(5 years ago)
7u27114 Jul 2020
(5 years ago)
7u26114 Apr 2020
(6 years ago)
7u25114 Jan 2020
(6 years ago)
7u24115 Oct 2019
(6 years ago)
7u23116 Jul 2019
(6 years ago)
7u22116 Apr 2019
(7 years ago)
7u21115 Jan 2019
(7 years ago)
7u20116 Oct 2018
(7 years ago)
7u19117 Jul 2018
(7 years ago)
7u18117 Apr 2018
(8 years ago)
7u17116 Jan 2018
(8 years ago)
7u16117 Oct 2017
(8 years ago)
7u15118 Jul 2017
(8 years ago)
7u14118 Apr 2017
(9 years ago)
7u13117 Jan 2017
(9 years ago)
7u12118 Oct 2016
(9 years ago)
7u11119 Jul 2016
(9 years ago)
7u10119 Apr 2016
(10 years ago)
7u9923 Mar 2016
(10 years ago)
7u9705 Feb 2016
(10 years ago)
7u9519 Jan 2016
(10 years ago)
7u9120 Oct 2015
(10 years ago)
7u8514 Jul 2015
(10 years ago)
7u8014 Apr 2015
(11 years ago)
7u7914 Apr 2015
(11 years ago)
7u7620 Jan 2015
(11 years ago)
7u7520 Jan 2015
(11 years ago)
7u7214 Oct 2014
(11 years ago)
7u7114 Oct 2014
(11 years ago)
7u6704 Aug 2014
(11 years ago)
7u6515 Jul 2014
(11 years ago)
7u6028 May 2014
(12 years ago)
7u5515 Apr 2014
(12 years ago)
7u5114 Jan 2014
(12 years ago)
7u4515 Oct 2013
(12 years ago)
7u4010 Sep 2013
(12 years ago)
7u2518 Jun 2013
(12 years ago)
7u2116 Apr 2013
(13 years ago)
7u1704 Mar 2013
(13 years ago)
7u1519 Feb 2013
(13 years ago)
7u1301 Feb 2013
(13 years ago)
7u1113 Jan 2013
(13 years ago)
7u1011 Dec 2012
(13 years ago)
7u916 Oct 2012
(13 years ago)
7u730 Aug 2012
(13 years ago)
7u614 Aug 2012
(13 years ago)
7u512 Jun 2012
(13 years ago)
7u426 Apr 2012
(14 years ago)
7u314 Feb 2012
(14 years ago)
7u212 Dec 2011
(14 years ago)
7u118 Oct 2011
(14 years ago)
711 Jul 2011
(14 years ago)