1Z0-811 Exception Handling and Development Tools Practice Question
Which of the following is the best practice for resource management in Java?
⚠ Common exam trap
Oracle often tests the misconception that garbage collection handles all resource cleanup, but the trap here is that candidates forget external resources (like I/O streams) are not managed by the garbage collector and require explicit closure via try-with-resources or finally blocks.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use try-with-resources statement.
The try-with-resources statement (introduced in Java 7) automatically closes each resource declared in its header when the block exits, whether normally or due to an exception. This eliminates the need for explicit cleanup code and ensures that resources implementing `AutoCloseable` are closed reliably, preventing resource leaks.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Close resources in a finally block without null checks.
Why it's wrong here
Null checks are needed to avoid NullPointerException.
- ✗
Rely on garbage collection to close resources.
Why it's wrong here
Garbage collection does not close resources like streams.
- ✓
Use try-with-resources statement.
Why this is correct
Try-with-resources automatically closes AutoCloseable resources.
- ✗
Use a try-catch block and close resources in the catch block.
Why it's wrong here
Resources should be closed in finally or by try-with-resources.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.