There are a number of features in Java 7 that will please developers. Things such as strings in switch statements, multi-catch exception handling, try-with-resource statements, the new File System API, extensions of the JVM, support for dynamically-typed languages, the fork and join framework for task parallelism, and a few others will certainly be embraced by the community.
Below I outline the features and provide examples where appropriate. A zip file containing code snippets used in this post can be downloaded here.
Java 7 includes a few new language features via Project Coin. These features are quite handy for a developer.
You may have noted on many occasions your IDE complaining of types when working with Generics. For example, if we have to declare a map of trades using Generics, we write the code as follows:
Map<String, List<Trade>> trades = new TreeMap<String, List<Trade>> ();
The not-so-nice thing about this declaration is that we must declare the types on both the sides, although the right-hand side seems a bit redundant. Can the compiler infer the types by looking at the left-hand-side declaration? Not unless you’re using Java 7. In 7, it’s written like this:
Map<String, List<Trade>> trades = new TreeMap <> ();
How cool is that? You don’t have to type the whole list of types for the instantiation. Instead you use the
<> symbol, which is ...