Tagged articles
2 articles
Page 1 of 1
Senior Brother's Insights
Senior Brother's Insights
Apr 11, 2021 · Backend Development

Why Try-with-Resources Outperforms Try-Catch-Finally in Java

Java developers often close resources manually using try-catch-finally, but since JDK 7 the try‑with‑resources construct automates this process; this article explains the traditional pattern, demonstrates the new syntax, shows how to implement custom Closeable classes, and reveals the compiler‑generated bytecode that preserves original exceptions via addSuppressed.

CloseableException HandlingJDK7
0 likes · 10 min read
Why Try-with-Resources Outperforms Try-Catch-Finally in Java
360 Quality & Efficiency
360 Quality & Efficiency
May 15, 2017 · Fundamentals

Special Cases in Java Resource Closing: Utilities, Return Patterns, Non‑Closeable Streams, Nested Streams, JDBC Statements, and Sockets

This article, the fifth in a static code scanning series, explains six special scenarios—custom close utilities, methods returning resources, streams that need not be closed, nested stream closures, JDBC statement/result set relationships, and socket streams—that complicate determining whether Java resources have been properly closed.

CloseableIO StreamsJDBC
0 likes · 9 min read
Special Cases in Java Resource Closing: Utilities, Return Patterns, Non‑Closeable Streams, Nested Streams, JDBC Statements, and Sockets