It's close to an year now JDK 7 or Java 7 has been released, still programmer ask What is new in Java 7 ? What is the best feature introduced in JDK7, where is the list of all Java 7 new feature etc. I thought to let's document Top 5 new features introduced in Java 7 for easy reference, this will not only answer What is new in Java 7 but also provide a quick overview of What are those features in Java 7. Java 7 introduced many new features in Java programming language like try catch with resource, String in Switch etc but it also make lot of change on Java Development API by introducing new File API in Java and several other minor changes. E.g. you can now find hidden files from Java program without applying any hack. anyway let's see my list of Top 5 Java 7 features :
Top 5 new features in Java 7Here is my favorite Top 5 new Java 7 features introduce in Java programming language on release 7. There are many more features in Java 7 which is introduced along with these front-line feature like File API changes which is also worth exploring.
Allow using String in Switch case
You can not use String in Switch or case statement prior to Java 7. Talk of allowing String in Switch case was growing ever since Enum was introduced in Java 5, though you can use Enum in Switch case, you can not do the same with String which is more common than Enum in Java programming language. from JDK 7 you can use String in Switch case, see How to use String in Switch case in Java7 for more details.
Multiple Exception in one catch block
This is the first feature which comes in my mind when people ask What is new in Java 7 feature ? can you name few new feature introduced in JDK 7 release? From JDK 7 you can catch multiple Exception in one catch block. This is called multi-catch block feature of Java 7. This is a significant improvement Java 7 made in Exception handling because it will reduce clutter in Exception handling code in Java. In order to learn how to catch multiple Exception in once catch block in Java 7, see that article. It explains this new Java 7 feature beautifully.
Automatic resource management or ARM blocks
Similar to previous Java 7 feature, Automatic resource management (ARM blocks) also known as try with resource block is another significant improvement in area of Exception handling in Java. ARM blocks allows automatic closing of resource e.g. Files, Streams etc, opened inside try block. Resource needs to implement Closeable interface in Java. See How to use ARM block in Java 7 for more details.
Fork Join framework in Java 7
Another new feature which you can use to answer Java interview question What is new in Java 7 ? Fork join framework exists even before Java 7 but as a separate JSR. It has been added as new feature in Java 7 to make it part of standard Java 7 core library. Fork join framework allows you to write code which can take advantage of multiple cores present in modern servers. See How to use fork join framework in Java 7 for code example and guide on using fork join framework.
Diamond operator <> for type inference
Every since Java 5 introduced Generics in Java, programmers are complaining that its very verbose and generate duplicate code, which is true because while creating object of parameterized class in java you need to provide type parameters in both left and right hand side. Diamond operator <> is a new Java 7 feature which provides type inference while creating object of Generic classes. Though you can achieve type inference without using Java 7 as well by creating Factory method in Java, Diamond operator is easy way to achieve type inference in Java 7.
These were my list of Top 5 new features introduced in Java 7 release and now you can answer What is new in Java 7. These were some of the most popular new features of JDK 7. Many production system is still running on various JDK 6 update but I assume they will also slowly upgrade to Java 7. Now days even talk of Java 8 is growing as it may introduced closures in Java, which was earlier planned to be release in Java 7 release along with these new features.
Other Java tutorials from Java67 blog:
Write a Java program to find factorial of a number using recursion