Found 1 Articles for Java Generics

Automatic resource management in Java

Samual Sam
Updated on 18-Jun-2020 12:13:37

547 Views

automatic resource management or try-with-resources is a new exception handling mechanism that was introduced in Java 7, which automatically closes the resources used within the try-catch block.ResourceA resource is an object which is required to be closed once our program finishes. For example, a file is read, database connection and so on.UsageTo use the try-with-resources statement, you simply need to declare the required resources within the parenthesis, and the created resource will be closed automatically at the end of the block. Following is the syntax of the try-with-resources statement.Syntaxtry(FileReader fr = new FileReader("file path")) {        // use the resource ... Read More

1
Advertisements