UTIL PACKAGE / NOTES</>↗Util Package28 Apr 2025
Integrating Optional with Java Streams can simplify many common scenarios when working with potentially absent values. Here are different techniques depending on your specific use case: 1. Use Optional in Stream Pipelines When you have an Optional and you want to integrate it into a Stream pipeline, you can use stream() from Java 9 onward. […]
BASIC / NOTES</>↗Basic28 Apr 2025
Type inference was introduced in Java 10 with the new var keyword, enabling developers to declare local variables without explicitly specifying their type. This feature can help create cleaner, more concise code by reducing boilerplate, though it should be used judiciously to maintain code readability. Here’s a guide on how to use type inference effectively […]
UTIL PACKAGE / NOTES</>↗Util Package28 Apr 2025
Combining multiple Optional objects in Java in a functional style is a common need, especially when working with potentially nullable values without resorting to null checks. Here are examples of some approaches you can use based on the scenario: 1. Combining If All Optionals Are Present If you want to combine values only when all […]
JSCH / NOTES</>↗JSch27 Apr 2025
To load a private key for SSH authentication using JSch (Java Secure Channel), you can use the addIdentity method available in the JSch class. This method allows you to specify the private key (and optionally, the public key or passphrase) used for key-based authentication. Here is an example of how to accomplish this: Example Code […]
UTIL PACKAGE / NOTES</>↗Util Package27 Apr 2025
In Java, you can use the Optional API to filter values based on a condition using the filter method. The filter method takes a predicate as an argument and applies it to the value contained in the Optional. If the predicate evaluates to true, the Optional is returned unchanged. If the predicate evaluates to false, […]
UTIL PACKAGE / NOTES</>↗Util Package27 Apr 2025
Using Optional in Java is a great way to refactor nested null checks into more readable and maintainable code. Below, I’ll explain how you can use Optional to replace deeply nested null checks step by step with examples. Example of Nested Null Checks Consider this code with deeply nested null checks: String streetName = null; […]