Tagged articles
try-with-resources
21 articles · Page 1 of 1
This article covers Java exception hierarchy, checked vs unchecked exceptions, try-with-resources best practices, custom exception design, and generics type erasure with bridge methods, wildcard bounds, and the PECS principle for interview preparation.
Checked vs UncheckedExceptionsGenerics
0 likes · 23 min read

This guide diagnoses database connection pool exhaustion by distinguishing connection leaks from genuine high concurrency, demonstrating log analysis for HikariCP and Druid, verifying leaks via SHOW PROCESSLIST and pool metrics, fixing code with try-with-resources, tuning key HikariCP parameters, and enabling leak detection to pinpoint exact leak locations.
Connection LeakConnection PoolDruid
0 likes · 10 min read

This article presents twenty practical rules for handling exceptions in Java, covering why catching RuntimeException is discouraged, how to avoid using exceptions for control flow, proper use of finally blocks, logging best practices, custom exception design, and early input validation to keep applications stable and maintainable.
Best PracticesJavaLogging
0 likes · 19 min read

This article explores Java exception handling from basic try‑catch‑finally syntax, through multi‑catch and try‑with‑resources, to designing custom business exceptions, offering concrete code examples, logging tips, global handlers, and performance considerations for robust backend development.
Javacustom exceptionsexception handling
0 likes · 18 min read


java1234Mar 3, 2026 · Backend Development
The article shows how to replace repetitive System.currentTimeMillis() timing code with a concise TimeTracker utility that leverages try‑with‑resources, functional interfaces, and flexible exception handling to achieve millisecond‑level measurement and dramatically improve code readability and performance.
Functional InterfaceJavaPerformance Monitoring
0 likes · 13 min read

This article explains how to compress large objects with GZIP before storing them in Redis, demonstrates the pitfalls of not closing streams, shows how Java's try‑with‑resources simplifies resource management, and provides best‑practice code examples to prevent hidden IO exceptions.
BackendGZIPJava
0 likes · 7 min read

This article introduces a concise and elegant Java TimeTracker utility class that leverages AutoCloseable, try‑with‑resources, and functional interfaces to provide flexible performance monitoring, automatic duration calculation, and configurable exception handling while reducing repetitive timing code.
AutoCloseableJavaUtility Class
0 likes · 14 min read

This guide explains Java's try-with-resources statement introduced in JDK 7, showing how it automatically closes AutoCloseable resources, eliminates boilerplate finally blocks, manages closure order and suppressed exceptions, avoids common decorator pitfalls, and provides best‑practice examples for robust production code.
AutoCloseableJDK7Java
0 likes · 10 min read

This article explains why using a wrong Content‑Type header and not closing the InputStream when returning a Resource in SpringBoot 3.2 causes file‑handle leaks, and demonstrates three solutions—including try‑with‑resources, direct HttpServletResponse streaming, and custom Resource implementations—to safely download files even under high concurrency.
File DownloadResource LeakResponseEntity
0 likes · 7 min read

The article explains best practices for safely closing resources in Java, including using finally blocks, null checks, separate try‑catch for each resource, avoiding return or System.exit in finally, not throwing exceptions from finally, and preferring try‑with‑resources with code examples.
Best PracticesJavaexception handling
0 likes · 3 min read

This article demonstrates how to combine multiple exception types in a single catch block and how to employ Java's try‑with‑resources construct to automatically close resources, providing complete code examples drawn from Nacos's BaseDatabaseOperate class.
JDBCJavabackend development
0 likes · 5 min read

Java 9 introduces several notable enhancements—including immutable collection factories, expanded Stream operations like ofNullable, iterate, takeWhile, dropWhile, new Optional methods, simplified try‑with‑resources, private interface methods, a modern HttpClient, and preliminary Flow support—each illustrated with concise code examples for developers transitioning from earlier Java versions.
HttpClientOptionalStream API
0 likes · 7 min read

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.
CloseableJDK7Java
0 likes · 10 min read

This article explains why exception handling in Java is challenging and presents ten practical best‑practice guidelines—including using finally or try‑with‑resources, declaring specific exceptions, documenting throws, providing clear messages, catching specific exceptions first, avoiding Throwable, logging properly, and preserving original causes—to write more robust and maintainable code.
Best PracticesJavaLogging
0 likes · 10 min read

This article presents nine essential Java exception handling best practices, including using finally blocks or try‑with‑resources for resource cleanup, specifying precise exception types, documenting throws clauses, providing descriptive messages, catching specific exceptions first, avoiding catching Throwable, not ignoring exceptions, and correctly wrapping exceptions without losing the original cause.
Loggingbest-practicesexception-handling
0 likes · 10 min read

This article explains the concept of syntactic sugar in Java, covering generics, autoboxing/unboxing, enums, inner classes, variable‑length arguments, enhanced for‑loops, switch on strings, conditional compilation, assertions, try‑with‑resources, and string concatenation, with code examples and byte‑code analysis.
AutoboxingGenericsVarargs
0 likes · 17 min read

The article explains Java’s try‑with‑resources feature as syntactic sugar that the compiler rewrites into a try‑finally structure with sophisticated exception handling, demonstrates the generated bytecode, clarifies AutoCloseable versus Closeable, and offers best‑practice guidelines for reliable resource management.
AutoCloseableBest PracticesJDK 9
0 likes · 17 min read

This article demonstrates how to simplify Java exception handling by using behavior parameterization, lambda expressions, and functional interfaces together with try‑with‑resources, turning noisy try‑catch blocks into clean, reusable code for both checked and unchecked exceptions.
Functional InterfaceIOJava
0 likes · 5 min read

This article explains how to replace verbose try‑catch blocks in Java with behavior‑parameterized lambda expressions and functional interfaces, providing a cleaner way to handle both runtime and checked exceptions while also demonstrating file‑reading using try‑with‑resources and lambdas.
Functional Interfaceexception handlinglambda
0 likes · 5 min read

This article explains how to simplify Java exception handling by leveraging behavior parameterization, lambda expressions, and functional interfaces, demonstrating a clean wrapper for checked exceptions and a try‑with‑resources file‑to‑string conversion that keeps business logic free of boilerplate try‑catch blocks.
Behavior ParameterizationFunctional InterfaceJava
0 likes · 5 min read

This article explains why Java developers must manually close resource objects such as streams and database connections, discusses the limitations of garbage collection, and presents best‑practice techniques like finally blocks, try‑with‑resources, and utility libraries for proper resource management.
Garbage CollectionJavabackend development
0 likes · 5 min read
