ConcurrentHashMap: atomic counter initialization and entry traversal
Use `computeIfAbsent` to initialize a `LongAdder` atomically for a missing key, then use `forEach` to read counts without depending on traversal order.
CKTIS / Java
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Use `computeIfAbsent` to initialize a `LongAdder` atomically for a missing key, then use `forEach` to read counts without depending on traversal order.
Use `get` to read, `put` to write unconditionally, and `merge` to update one key atomically, for example when threads share a counter.
Wait for a state change in a loop, carry forward the remaining nanosecond budget, and choose whether to wake one waiter or all of them.
Invoke a specific constructor in Java SE 21 and distinguish lookup or invocation failures from exceptions thrown by the constructor itself.
Select the single `@Inject` constructor or fall back to a no-argument constructor when none is marked. Check parameter types and access before invoking it.
Use a one-shot counter to open a start gate or wait for a fixed number of signals. Learn both await overloads, how interruption works, and when writes become visible across threads.
AEADBadTagException means that a Cipher operating in an AEAD mode, such as GCM or CCM, could not verify the authentication tag. Reject the data rather than treating it as successfully decrypted.
Cipher provides encryption and decryption through Java cryptographic providers. AES-GCM protects data confidentiality and detects modifications; correct use requires a unique IV for each key and verification of the authentication tag.
GCMParameterSpec supplies Cipher with an initialization vector and authentication tag length. The object itself neither encrypts data nor ensures IV uniqueness.
The javax.crypto.Mac class computes a message authentication code using a secret key. Learn how to select HmacSHA256, initialize it with a key, and finish the computation with doFinal.
SecretKeySpec wraps existing key bytes and an algorithm name. It copies the data but does not check its cryptographic validity.
Synchronize a fixed number of threads between phases, run one shared action before they proceed, and distinguish timed from untimed waits.
DataInputStream reads primitive values and strings from a binary stream. You must know the field order and encoding; it does not parse numbers written as text.
DataOutputStream writes primitive values and strings to a binary stream in a defined format. Learn the byte widths, byte order, and limitations of writeUTF.
Read fields in the same order you wrote them. See how Java SE 21 lays out numeric values and why the `writeUTF` limit counts encoded bytes, not characters.
Choose a pattern and locale to control the text, and a resolver style to control date validation. Learn why `MM` differs from `mm` and when to use `uuuu` instead of `yyyy`.
Build a formatter for `yyyy-MM-dd HH:mm z` with an explicit `Locale.ENGLISH`, and learn where the time zone in the output comes from.
Learn to insert, inspect, and remove elements at either end of a `Deque`, and know when to expect `false`, `null`, or an exception.
Compare two primitive `double` values by reading the sign of the result. Learn how the method distinguishes signed zeros and places `NaN` last in ascending order.
Double.max(a, b) returns the greater of two double values, with special rules for NaN and signed zero.
Build a stream of primitive doubles, select CPU loads at or above `0.50`, and calculate the count and mean separately for all readings and for high readings.
Create a duration from a minute count or two points in time, add another duration, and read the total in minutes or hours.
Build a transition map for a single enum type, read and update mappings, and iterate over entries in enum declaration order. Learn when a null lookup means a transition is missing.
Create an empty EnumMap with Day.class, store and retrieve values, and see why replacing a value for an existing key does not change the number of entries.