Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: Explain the concept of 'try-with-resources' in Java.
Answer: 'try-with-resources' is a feature introduced in Java 7 to automatically close resources like files or sockets when they are no longer needed.

Example:

try (FileReader fr = new FileReader("file.txt")) { /* code that uses fr */ }
Is it helpful? Yes No

Most helpful rated by users:

©2026 WithoutBook