Preparing for Java and Spring Boot Interview?

Join my Newsletter, its FREE

5 Essential JDK 7 Features for Java Programmers

What is new in Java or JDK 7
It's close to a year now JDK 7 or Java 7 has been released, still, programmer asks what is new in Java 7 ? What is the best feature introduced in JDK7, where is the list of all Java 7 new features, 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 a resource, String in Switch, etc but it also makes a lot of changes on Java Development API by introducing a new File API in Java and several other minor changes. Like you can now find hidden files from the Java programs without applying any hack. anyway let's see my list of Top 5 Java 7 features :

Top 5 JDK 7 Features for Java Programmers

Here are my favorite Top 5 new Java 7 features introduced in the Java programming language on release 7. There are many more features in Java 7 which is introduced along with these front-line features like File API changes which are also worth exploring.

5 Essential JDK 7 Features for Java Programmers

1. 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.

2. Multiple Exception in one catch block
This is the first feature that comes to my mind when people ask What is new in Java 7 feature? can you name a few new features introduced in JDK 7 release? From JDK 7 you can catch multiple exceptions in one catch block. This is called the 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 exceptions in one catch block in Java 7, see that article. It explains this new Java 7 feature beautifully.

3. Automatic resource management or ARM blocks
Similar to the previous Java 7 feature, Automatic resource management (ARM blocks) also known as try with resource block is another significant improvement in the area of Exception handling in Java. ARM blocks allow automatic closing of resources e.g. Files, Streams, etc, opened inside try block. Resource needs to implement the Closeable interface in Java. See How to use ARM block in Java 7 for more details.

4. Fork-Join framework in Java 7
Another new feature that 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 a new feature in Java 7 to make it part of the standard Java 7 core library. Fork join framework allows you to write code that 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 the fork-join framework.

5. Diamond operator <> for type inference
Every since Java 5 introduced Generics in Java, programmers are complaining that it's very verbose and generates duplicate code, which is true because while creating an object of the parameterized class in java you need to provide type parameters on both left and right-hand sides. Diamond operator <> is a new Java 7 feature that provides type inference while creating objects of Generic classes. Though you can achieve type inference without using Java 7 as well by creating Factory method in Java, Diamond operator is an easy way to achieve type inference in Java 7.

These were my list of Top 5 new features introduced in the 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 systems are still running on various JDK 6 updates but I assume they will also slowly upgrade to Java 7. Now days even talk of Java 8 is growing as it may introduce 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
What is Synchronization in Java with Example


Feel free to comment, ask questions if you have any doubt.