Java 7 - New and Noteworthy
Why bother?
- Java 6 is outdated and will not be updated anymore. Using it is a security risk.
- Java 7 offers some great new features.
New and Noteworthy Features in Java 7
In this section
MatthesRieke and
DanielNuest quickly mention some features that shold become part of our daily software development because the considerably improve the code. More information can be found in the links at the bottom.
java.nio
Use it instead of java.io - much easier to use and very useful (convenience) functionality for file and folder watching, file copying.
Base class to start with: Paths.java and it's static methods.
More info:
String switch statements
The same as int or enum switches, use it instead of if-else chains.
try-with-resource
Java 7 can take care to "finally" close streams (interface
AutoCloseable) instead of manually haven if!=null and try with in a finally statement...
I could be harder to get the actual exception.
Multicatch
Make catch statements a lot easier to read and limit duplication of code and you are not tempted to capture the generic Exception.
Fork and join
... vll. Zur XML Erzeugung? Tasks mit xmlbeans, joins in stax...
If you have a task you can divide and conquer you can use the fork/join framework to manage this task in many threads.
See
http://docs.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html
Diamond Operator
Makes instantiations short and readable (can even be warned about by the compiler): Write
Map<String, List<Trade>> trades = new TreeMap <> ();
instead of
Map<String, List<Trade>> trades = new TreeMap <String, List<Trade>> ();
.
More Resources and Documentation