Diamond Operator
Map<String, List<Trade>> trades = new TreeMap <> ();
Using strings in switch statements
compared against the case label by using the String.equals() method
Automatic resource management
Resources such as Connections, Files, Input/OutStreams, etc. should be closed manually by the developer by writing bog-standard code.
try (BufferedReader br = new BufferedReader(new FileReader(path)); PrintWriter pw = ...) {
pw.println(br.readLine());
}
Behind the scenes, the resources that should be auto closed must implement java.lang.AutoCloseable interface.
Numeric literals with underscores
int million = 1_000_000
Improved exception handling
try {
} catch(ExceptionOne | ExceptionTwo | ExceptionThree e) {
}
New file system API (NIO 2.0)
There were methods such as delete or rename that behaved unexpected in most cases. Working with symbolic links was another issue.
The NIO 2.0 has come forward with many enhancements. It’s also introduced new classes to ease the life of a developer when working with multiple file systems.
Path path = Paths.get("c:\\Temp\\temp");
Files.deleteIfExists(path);
Files.copy(..)
Files.move(..)
Files.createSymbolicLink(..)
File change notifications
The WatchService API lets you receive notification events upon changes to the subject (directory or file).
Fork and Join
Basically the Fork-Join breaks the task at hand into mini-tasks until the mini-task is simple enough that it can be solved without further breakups. It’s like a divide-and-conquer algorithm. One important concept to note in this framework is that ideally no worker thread is idle. They implement a work-stealing algorithm in that idle workers “steal” the work from those workers who are busy.
The core classes supporting the Fork-Join mechanism are ForkJoinPool and ForkJoinTask. The ForkJoinPool is basically a specialized implementation of ExecutorService
Supporting dynamism
This makes VM changes to incorporate non-Java language requirements. A new package, java.lang.invoke, consisting of classes such as MethodHandle, CallSite and others, has been created to extend the support of dynamic languages.
http://radar.oreilly.com/2011/09/java7-features.html
No comments:
Post a Comment