top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Explain Java 7 ARM feature and multi-catch block?

+1 vote
717 views
Explain Java 7 ARM feature and multi-catch block?
posted Nov 10, 2017 by Jon Deck

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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

}
answer Nov 29, 2017 by Manikandan J
...