UTIL PACKAGE / CATATAN</>↗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 / CATATAN</>↗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 […]
UTIL PACKAGE / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 […]