InterviewSolution
| 1. |
What Is Try-with-resources Or Arm In Java 7? |
|
Answer» Java 7 introduced a new form of try known as try-with-resources for Automatic Resource MANAGEMENT (ARM). Here resource is an object that must be closed after the program is finished with it. Example of resources would be an opened file handle or database connection etc. Before the introduction of try-with-resources we had to explicitly close the resources once the try block completes normally or abruptly. try { try-with-resources helps in reducing such BOILER plate code. Let's see the same example using try-with-resources. try(BufferedReader br = new BufferedReader(new FileReader("C:\test.txt"))) { Java 7 introduced a new form of try known as try-with-resources for Automatic Resource Management (ARM). Here resource is an object that must be closed after the program is finished with it. Example of resources would be an opened file handle or database connection etc. Before the introduction of try-with-resources we had to explicitly close the resources once the try block completes normally or abruptly. try { try-with-resources helps in reducing such boiler plate code. Let's see the same example using try-with-resources. try(BufferedReader br = new BufferedReader(new FileReader("C:\test.txt"))) { |
|