JavaThe yield statement supplies a value to the nearest enclosing switch expression. It is useful in a block arm that executes several statements before producing its result. In Java SE 21, yield is a contextual keyword.
Intermediate · Java SE 21; repository runtime, production runtime not attestedJavaThe null literal denotes a reference that does not point to any object. It has the special null type and can be assigned to variables of reference types, but not to variables of primitive types.
Basic · Java SE 21; repository runtime, production runtime not attestedJavamain: practical reference: The Java launcher invokes a public static void main(String[] args) method on the selected class after loading, linking, and class initialization.
Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtimeJava`close()` releases an object's resources. A try-with-resources statement calls it automatically, but the interface does not require a repeated call to have no effect.
Intermediate · Java SE 21JavaUse `getSimpleName()` for a short type label in a report. For a nested type, the result leaves out both the package and the enclosing type names.
Intermediate · Java SE 21Java`Collection.size()` returns an element count as an `int`. The expression `repo.all().size()` counts the elements in the collection returned by `all()`.
Intermediate · Java SE 21JavaStore changes in a `Deque` and remove the newest one first. Check that the history has an entry before each call to `pop()`.
Intermediate · Java SE 21Java`Iterable.iterator()` returns an iterator. Support for successive passes does not guarantee that overlapping passes are independent or that each call returns a new iterator object.
Intermediate · Java SE 21JavaCheck whether an iterator has another element, retrieve it, and optionally remove it. Distinguish iterator exhaustion, an invalid call sequence, and unsupported removal.
Intermediate · Java SE 21Java`List.add(E)` appends one element to the existing list and returns `true` if the call completes normally. Not every list supports adding elements.
Intermediate · Java SE 21JavaCheck whether a list holds an element equal to a given value before adding a task name or marking the task complete.
Intermediate · Java SE 21JavaRemove the first occurrence of a value, such as a subscriber name, and use the `boolean` result to tell whether anything was removed. Contrast this with removal by index.
Intermediate · Java SE 21JavaFind the absolute difference between two `double` values and check whether it falls within a tolerance, including at the boundary.
Intermediate · Java SE 21JavaDefine Person equality by name and age, distinguish it from reference identity, and implement a matching hashCode method.
Intermediate · Java SE 21JavaObjects that are equal according to `equals()` must have the same hash code. The reverse does not hold: matching hash codes do not prove equality.
Intermediate · Java SE 21JavaUse `Objects.equals(a, b)` to compare objects according to their `equals` rules, even when one or both arguments may be `null`.
Intermediate · Java SE 21Java`Objects.hash` combines values into one `int` hash code. Learn how `Object...` handles mixed arguments, when boxing occurs, and how to stay consistent with `equals`.
Intermediate · Java SE 21JavaCheck a required parameter: `Objects.requireNonNull` returns the same reference if it isn't `null` and normally throws `NullPointerException` if it is. You can supply a custom message.
Intermediate · Java SE 21JavaGive an object a readable description and see how `println(Object)` prints it without an explicit call to `toString()`.
Intermediate · Java SE 21JavaAdd items to the tail of a FIFO queue, take them from the head, and check that the queue is not empty before calling `remove()`.
Intermediate · Java SE 21JavaCheck whether an element belongs to a set and tell whether an addition or removal changed it. Use `LinkedHashSet` to track completed lessons without duplicates and in insertion order.
Intermediate · Java SE 21JavaUse `String.valueOf` to turn a value into text. Learn why a missing exception message becomes the string `"null"`, while passing the bare `null` literal throws an exception.
Intermediate · Java SE 21Java`Throwable.getCause()` returns the immediate cause. Call it on each successive object to walk from the outer exception to the last available cause.
Intermediate · Java SE 21JavaRead the message from a specific exception, handle a missing message, and distinguish the primary exception from its causes and suppressed exceptions.
Intermediate · Java SE 21