UTIL PACKAGE / NOTES</>↗Util Package02 May 2025
When working with Java’s Optional in high-frequency code paths, it’s essential to understand and avoid the performance pitfalls associated with its usage. Although Optional provides functional-style coding benefits and helps prevent NullPointerException, it introduces additional overhead due to extra object creation and functional programming constructs. Here are some recommendations to ensure optimal performance: 1. Avoid […]
JSCH / NOTES</>↗JSch01 May 2025
To download a file from an SSH server using JSch SFTP, you can use the ChannelSftp class from the JSch library. Below is an example of how to achieve this: Code Example: Downloading a file using JSch SFTP The JSch library is used to establish an SSH connection to an SFTP server and transfer files. […]
UTIL PACKAGE / NOTES</>↗Util Package01 May 2025
Writing Optional-aware utility methods in Java involves keeping in mind the design of the Optional class, which is meant to represent potentially absent values in a neat, declarative way. Good utility methods avoid nulls and integrate smoothly with the existing Optional API. Here are a few practices and examples to guide you: 1. Use Optional […]
UTIL PACKAGE / NOTES</>↗Util Package01 May 2025
Using Optional with custom monads or functional programming libraries can enhance code readability and handle null-like scenarios effectively. Here’s how you can integrate Optional with custom monads or functional programming libraries: 1. Understanding Optional in Functional Context Optional is essentially a simplified monad used to represent the presence or absence of a value. Custom monads […]
UTIL PACKAGE / NOTES</>↗Util Package30 Apr 2025
When using Optional in domain models, especially within the context of Java, it’s important to model the absence and presence of values in a way that conveys clear intent—making your code expressive, safe, and unambiguous. Below are the best practices to model absence and presence with Optional in domain models effectively: When to Use Optional […]
JAVA 10 / NOTES</>↗Java 1030 Apr 2025
In Java 10, the Optional.orElseThrow() method was enhanced to become the preferred method for retrieving a value from an Optional when the value is present, and throwing an exception otherwise. Let’s explore how this works. Enhanced Optional.orElseThrow() Prior to Java 10, the Optional class provided: orElse() – Retrieves the value if present or returns a […]