Tagged articles
17 articles
Page 1 of 1
java1234
java1234
Mar 3, 2026 · Backend Development

One‑Line Java Time Tracker: Millisecond Precision and Up to 300% Faster Performance

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.

Exception HandlingFunctional InterfaceJava
0 likes · 13 min read
One‑Line Java Time Tracker: Millisecond Precision and Up to 300% Faster Performance
Java Tech Enthusiast
Java Tech Enthusiast
Oct 10, 2024 · Fundamentals

Understanding Try-with-Resources in Java: A Comprehensive Guide

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.

Exception HandlingJDK7Java
0 likes · 10 min read
Understanding Try-with-Resources in Java: A Comprehensive Guide
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
May 20, 2024 · Backend Development

How to Fix Resource Leaks When Streaming Files in SpringBoot 3.2

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 DownloadResponseEntitySpringBoot
0 likes · 7 min read
How to Fix Resource Leaks When Streaming Files in SpringBoot 3.2
Cognitive Technology Team
Cognitive Technology Team
May 9, 2022 · Backend Development

Proper Ways to Close Resources in Java

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.

Exception HandlingJavabest practices
0 likes · 3 min read
Proper Ways to Close Resources in Java
Programmer DD
Programmer DD
Oct 2, 2021 · Fundamentals

What New APIs Does Java 9 Bring? Collections, Streams, Optional, and More

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.

HttpClientJava 9Stream API
0 likes · 7 min read
What New APIs Does Java 9 Bring? Collections, Streams, Optional, and More
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
Java Backend Technology
Java Backend Technology
Feb 6, 2021 · Backend Development

Master Java Exception Handling: 10 Best Practices Every Developer Should Follow

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.

Exception HandlingJavabest practices
0 likes · 10 min read
Master Java Exception Handling: 10 Best Practices Every Developer Should Follow
Selected Java Interview Questions
Selected Java Interview Questions
Jan 11, 2021 · Backend Development

Best Practices for Exception Handling in Java

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.

best-practicesexception-handlinglogging
0 likes · 10 min read
Best Practices for Exception Handling in Java
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Dec 29, 2020 · Fundamentals

Understanding Java Syntactic Sugar: Generics, Autoboxing, Enums, Inner Classes, Varargs and More

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.

AutoboxingEnumsGenerics
0 likes · 17 min read
Understanding Java Syntactic Sugar: Generics, Autoboxing, Enums, Inner Classes, Varargs and More
vivo Internet Technology
vivo Internet Technology
Oct 20, 2020 · Fundamentals

Understanding Java Try‑with‑Resources: Syntax, Bytecode, and Best Practices

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.

Exception HandlingJDK 9Java
0 likes · 17 min read
Understanding Java Try‑with‑Resources: Syntax, Bytecode, and Best Practices
Programmer DD
Programmer DD
Oct 15, 2020 · Backend Development

Elegant Java Exception Handling with Lambdas and Try‑With‑Resources

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 InterfaceJavaLambda
0 likes · 5 min read
Elegant Java Exception Handling with Lambdas and Try‑With‑Resources
Programmer DD
Programmer DD
Sep 18, 2020 · Backend Development

How to Hide Try‑Catch: Elegant Exception Handling with Java Lambdas

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.

Exception HandlingFunctional InterfaceLambda
0 likes · 5 min read
How to Hide Try‑Catch: Elegant Exception Handling with Java Lambdas
Architecture Digest
Architecture Digest
Sep 10, 2020 · Fundamentals

Elegant Exception Handling in Java Using Functional Interfaces and Lambda Expressions

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 ParameterizationException HandlingFunctional Interface
0 likes · 5 min read
Elegant Exception Handling in Java Using Functional Interfaces and Lambda Expressions
360 Quality & Efficiency
360 Quality & Efficiency
May 8, 2017 · Backend Development

Why and How to Manually Close Java Resource Objects

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.

Backend DevelopmentGarbage CollectionJava
0 likes · 5 min read
Why and How to Manually Close Java Resource Objects