Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Knowledge base

Knowledge base

Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.

Entries: 5788

Java

OptionalDouble: fallback or value retrieval

OptionalDouble represents a double value or its absence. Learn how orElse differs from getAsDouble.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Optional.empty: practical reference

Optional.empty: practical reference: Optional.empty() returns an empty Optional<T> representing absence, with its type parameter inferred from the invocation context.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Optional.filter: practical reference

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.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Optional.flatMap: practical reference

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.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Optional.ifPresent: practical reference

Optional.ifPresent: practical reference: Optional.ifPresent(action) invokes the Consumer exactly once with the present value and performs no action for an empty Optional.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Optional.ifPresentOrElse: practical reference

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.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Optional.map: practical reference

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().

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Optional.of: practical reference

Optional.of: practical reference: Optional.of(value) creates an Optional with a necessarily present non-null value and preserves its inferred generic type.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Optional.ofNullable: practical reference

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.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Optional.orElse: practical reference

Optional.orElse: practical reference: Optional.orElse(other) returns the present value, or the supplied other object when the Optional is empty.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Optional.orElseGet: practical reference

Optional.orElseGet: practical reference: Optional.orElseGet(supplier) returns the present value and invokes the supplier only for an empty Optional, returning its result.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Optional.orElseThrow: practical reference

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.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

OutOfMemoryError — memory allocation failure

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.

Intermediate · Java SE 21; repository runtime, production runtime not attested
Java

PhantomReference — phantom references

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.

Advanced · Java SE 21; repository runtime, production runtime not attested