The Java 7 has introduced lots of features than their previous editions. In fact, they have introduced the other programming language features in this release. This post will give you the basic features for the programmers and in future posts, we will come up with the new features respective to the File handling.

Here we go

Strings in switch
Previous release does not allow us to use the Strings in Switch statements. But they have added in this release. For example,
public void processTrade(Trade t) {
String status = t.getStatus();
switch (status) {
case NEW:

Resources management

Whenever we use any resources [like FileOutputStream, Connection, etc], its the responsibility of the user to clean up the resources. In JDK 7, they have introduced the resource management. Here is the snippet, to clean the resource.

try (FileOutputStream fos = new FileOutputStream("movies.txt");
DataOutputStream dos = new DataOutputStream(fos)) {
dos.writeUTF("Java 7 Block Buster");
} catch (IOException e) {
// log the exception



Exception Handling

Java 7 introduced multi-catch functionality to catch multiple exception types using a single catch block.

try {
catch (ExceptionOne | ExceptionTwo | ExceptionThree e) {
// log and deal with all Exceptions


Numeric Literals

We might have faced a situation to input the number to the java programs if the number has more digits. JDK 7 has introduced to put the _ [Underscore] for the digits like one below.

int million  =  1_000_000

Tuned on.. We will have more posts explaining the new features of the Java. Happy programming.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

clear formSubmit