Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What are Java 7 ARM Feature and multi-catch block?

user-image
Question added by Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution
Date Posted: 2014/03/10
Maria Thomas
by Maria Thomas , Tech Lead , J P Morgan Chase

Java7 ARM feature uses the concept of "try with resources". The try block now has the syntax of a method wherein the resources that will be acted upon are inserted.

Eg:

FileReader fis;

try(fis = new FileReader("c:\\\\file1.txt")){

      //code for reading from file

}catch(IOException ioex){

     //handle exception 

}

 

As can be seen above, there is no need to close the resources explicitly in finally block. Java7 takes care of this. So it has reduced the lines of code required and made it easier for the developer.

 

Multi-catch:

Java7 introduced multi catch statements in which one can use a single catch block to specify multiple exceptions that should be caught separated by pipe operator.

Eg:

try(fis = new FileReader("c:\\\\File.text"){

   //Database operations also

}catch(IOException | SQLException ex){

   //exception handling code

}

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.