UTIL PACKAGE / NOTES</>↗Util Package30 Apr 2025
When dealing with legacy APIs that do not use Optional but may return values or null, you can gracefully handle them in modern Java by using java.util.Optional to wrap and process the returned values. Here are some best practices for handling these scenarios: 1. Wrap the Legacy API Response Using Optional.ofNullable Legacy APIs might return […]
JSCH / NOTES</>↗JSch29 Apr 2025
Uploading a file to a remote server using JSch’s SFTP functionality can be achieved by leveraging the JSch library, which is a Java implementation of the SSH2 protocol. Here’s an example of how you can upload a file to a remote server with JSch: Steps to Follow: Create a JSch instance to manage the SSH […]
UTIL PACKAGE / NOTES</>↗Util Package29 Apr 2025
Returning Optional values in fluent APIs can be done effectively by following best practices that align with readability, usability, and intention. Here’s an overview of how to work with Optionals in fluent API design: Approach 1: Use Optional in Terminal Methods (End of the Chain) In a fluent API, it’s common to terminate the chain […]
JAVA 10 / NOTES</>↗Java 1029 Apr 2025
In Java 10, a significant enhancement was introduced to the java.util.stream.Collectors class: new utility methods to create unmodifiable collections such as lists and sets. One notable method is Collectors.toUnmodifiableList(). This method allows you to efficiently create immutable lists during stream processing, adding to the immutability features provided by Java 9 and earlier versions. Here’s how […]
UTIL PACKAGE / NOTES</>↗Util Package29 Apr 2025
Using Optional as a method parameter in Java is discouraged because it goes against the intended purpose of Optional and can lead to inefficiencies, poor readability, and unintended complications in the code. Here’s why it matters and how to avoid using Optional as a method parameter. Why Should You Avoid Optional as a Method Parameter? […]
JSCH / NOTES</>↗JSch28 Apr 2025
When using the JSch library for SSH connections in Java, it is essential to handle connection errors gracefully to ensure your application remains robust and can recover effectively from issues like authentication failures, host connectivity issues, or unexpected disconnections. Here’s a structured way to handle connection errors gracefully using JSch: Steps to Handle Errors Gracefully […]