JAVA / NOTES{ }↗Java19 Oct 2025
The RandomGenerator API, introduced in JDK 17, provides a simpler and more flexible way to work with random number generation by centralizing the different strategies for producing random numbers under a single interface (RandomGenerator). This allows developers to access multiple random number generation algorithms in a standardized manner. Additionally, it improves upon the legacy java.util.Random […]
JAVA / NOTES{ }↗Java18 Oct 2025
Using records with generics in Java allows you to create immutable data structures while also providing the benefits of generics, such as type safety and flexibility. Since Java 16, the record feature was introduced, and it can be combined with generics like other classes. Here’s an example of how to use records with generics. Syntax […]
JAVA / NOTES{ }↗Java18 Oct 2025
The String class in Java provides the methods strip(), isBlank(), and lines(), which were introduced in Java 11. These methods are useful for managing whitespaces, checking for blank strings, and processing multi-line strings. 1. strip() The strip() method removes leading and trailing whitespaces from a string. Unlike trim(), it uses Unicode-aware whitespace handling, making it […]
JAVA / NOTES{ }↗Java17 Oct 2025
Compact constructors in records are a concise way to initialize and validate fields of a record in Java. Unlike standard constructors, compact constructors omit the parameter list, as they operate directly on the record’s declared components. Here’s how to use compact constructors in records: 1. Syntax: A compact constructor is declared without parentheses after the […]
JAVA / NOTES{ }↗Java17 Oct 2025
In Java, sealed classes are a feature introduced in Java 15 (as a preview and finalized in Java 17) that allows you to control inheritance by specifying which classes or interfaces can extend or implement a given class or interface. This makes your class hierarchy more predictable and easier to reason about. Using sealed classes […]
JAVA / NOTES{ }↗Java16 Oct 2025
Enhanced instanceof pattern matching, introduced in Java 16 (as a preview feature) and finalized in Java 17, allows you to combine type checking with type casting, reducing boilerplate code and making it more concise and readable. Here’s how you can use enhanced instanceof pattern matching: Basic Usage: Instead of separately checking if an object is […]