JAVA / NOTES{ }↗Java15 Oct 2025
Using Optional in Java can help streamline and simplify null checks, avoiding potential NullPointerException issues and making the code more readable and elegant. Optional is particularly useful when you want to express the possibility of an absent value explicitly in the API and handle such scenarios gracefully. Here’s how you can use Optional for cleaner […]
JAVA / NOTES{ }↗Java14 Oct 2025
The Objects.requireNonNullElse method, introduced in Java 9, provides a safe and convenient way to handle null references by returning a default value if the provided object is null. This method ensures that you won’t get a NullPointerException in cases where you expect an object but want a fallback when it’s null. Syntax public static <T> […]
JAVA / NOTES{ }↗Java04 Oct 2025
The switch expression, introduced in Java 12 (as a preview feature) and became a standard feature in Java 14, provides a more concise and powerful way to use switch statements. Here’s how to use it effectively: Key Features of Switch Expressions Simpler Syntax: The new syntax allows the use of the -> syntax to eliminate […]
JAVA / NOTES{ }↗Java04 Oct 2025
In Java, records are special classes introduced in Java 14 (as a preview feature) and became a standard feature in Java 16. They are specifically designed to model immutable data carriers with minimal boilerplate code. A record in Java automatically generates boilerplate code such as constructors, getters, toString, equals, and hashCode methods, making it a […]
JAVA / NOTES{ }↗Java03 Oct 2025
Text blocks in Java, introduced in Java 15, provide a way to declare multi-line strings in a cleaner and more readable format compared to traditional string concatenation or line breaks (\n). They are enclosed using triple double quotes (""") and support multi-line content without requiring explicit escape characters for formatting. Key Features of Text Blocks […]
JAVA / NOTES{ }↗Java02 Oct 2025
The String::formatted method in Java is a concise way to format strings using placeholders, similar to the String::format method but with a cleaner syntax. It was introduced in Java 15, and it allows you to replace placeholders in a string with specified values. The syntax of the formatted method is straightforward: String formattedString = "Your […]