Object.wait() and Object.notifyAll(): waiting for a condition
Guard shared state with one monitor, recheck the condition in a `while` loop, and remember that `notifyAll()` neither releases the lock nor hands it to a waiter.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Guard shared state with one monitor, recheck the condition in a `while` loop, and remember that `notifyAll()` neither releases the lock nor hands it to a waiter.
OptionalDouble represents a double value or its absence. Learn how orElse differs from getAsDouble.
Optional.empty: practical reference: Optional.empty() returns an empty Optional<T> representing absence, with its type parameter inferred from the invocation context.
Optional.filter: practical reference: Optional.filter(predicate) returns an Optional describing a present value that satisfies the predicate, empty when it does not, and stays empty for an empty receiver.
Optional.flatMap: practical reference: Optional.flatMap(mapper) returns the Optional produced by the mapper without another wrapper for a present value, and returns empty for an empty receiver.
`Optional.get()` returns the contained value when one is present. Calling it on an empty `Optional` throws `NoSuchElementException`.
Optional.ifPresent: practical reference: Optional.ifPresent(action) invokes the Consumer exactly once with the present value and performs no action for an empty Optional.
Optional.ifPresentOrElse: practical reference: Optional.ifPresentOrElse(action, emptyAction) invokes the Consumer with the present value or runs the Runnable when absent; exactly one branch is selected.
Check whether an `Optional` contains a value without retrieving it. Use `isPresent()` when you need a `boolean` and `ifPresent(...)` when you only want to act on the value if it exists.
Optional.map: practical reference: Optional.map(mapper) applies the Function to a present value and wraps a non-null result, while a null result or empty receiver yields Optional.empty().
Optional.of: practical reference: Optional.of(value) creates an Optional with a necessarily present non-null value and preserves its inferred generic type.
Optional.ofNullable: practical reference: Optional.ofNullable(value) returns Optional.empty() for null and retains a non-null value in the same way as Optional.of.
Optional.orElse: practical reference: Optional.orElse(other) returns the present value, or the supplied other object when the Optional is empty.
Optional.orElseGet: practical reference: Optional.orElseGet(supplier) returns the present value and invokes the supplier only for an empty Optional, returning its result.
Optional.orElseThrow: practical reference: Optional.orElseThrow returns the present value; the no-argument form throws NoSuchElementException when empty, while the supplier form throws the supplied exception.
OutOfMemoryError signals a JVM memory allocation problem. It is a subtype of Error, not Exception, and needs no throws declaration. It does not automatically mean a memory leak or merely a full Java heap.
Compile a regular expression into a `Pattern` object, then reuse that pattern to check more than one input.
`Pattern.matcher` creates a new `Matcher` for the given input. Reuse one compiled pattern across multiple texts while keeping their matching state separate.
Find the calendar period between two dates and read its components. If you need the total number of days, calculate it directly from the dates.
PhantomReference<T> supports notification of changes in an object's reachability without exposing it through get(). It works with ReferenceQueue; the example demonstrates deterministic, manual enqueueing.
Use `Phaser` to synchronize tasks across repeated phases, admit a worker during an active phase, and terminate the barrier when the last party leaves.
Combine two predicates into one reusable condition. The second predicate is evaluated only if the first returns `true`.
`negate()` returns a predicate for the same input type that reverses the original test result without changing the original predicate.
`Predicate.not()` reverses a condition and returns a predicate you can pass to methods such as `Stream.filter`. It has been available since Java 11.