#java Clear
Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Java Functional Interfaces — Function / Predicate / Consumer / Supplier
The four core single-method interfaces in `java.util.function`. They're the parameter types for streams, Optional methods, CompletableFuture, and countless library APIs.
Java Text Blocks (Java 15+)
Multi-line string literals with proper indentation handling. Stop concatenating newlines by hand. The compiler removes the common leading whitespace automatically.
Java ConcurrentHashMap — Thread-Safe Map
The default thread-safe map. Better than `Collections.synchronizedMap` — segmented locking allows multiple readers AND writers. Use `compute`, `merge`, `putIfAbsent` for atomic compound updates.
Java CountDownLatch — Wait for N Events
Block one or more threads until a count of events occurs. Set the count up front; each event calls `countDown()`; waiters call `await()`. Classic "wait until all workers are ready" pattern.
Java java.time — Instant, LocalDate, ZonedDateTime
Java 8's `java.time` package replaced the broken `Date`/`Calendar`. Three types you actually use: `Instant` (UTC moment), `LocalDate` (date with no tz), `ZonedDateTime` (date+time in a zone).
Java Jackson — Basic ObjectMapper
`com.fasterxml.jackson.databind.ObjectMapper` is the JSON standard for Java. Construct once (it's expensive + thread-safe) and reuse for every serialization in your app.
Java Jackson — Annotations (rename, ignore, etc)
Field-level annotations let you map between snake_case JSON and camelCase Java, skip nulls, never serialize secrets, set defaults on missing fields.
Java java.time — Format and Parse
`DateTimeFormatter` replaces `SimpleDateFormat` (which was not thread-safe). Constants for the common formats; pattern strings for custom layouts.
Java Wildcards — extends vs super (PECS)
Producer-Extends, Consumer-Super. `? extends T` is read-only (you can take items OUT). `? super T` is write-only (you can put items IN). Lets generic APIs accept a wider range of types.
Java Generic Class with Type Parameter
Stamp out type-safe containers and helpers — same class body, multiple element types. The `<T>` declaration is what makes it generic.
Java Generic Method + Bounded Type Parameters
A method can have its own type parameter independent of the class. `<T extends Comparable<T>>` constrains T to types that can be compared.
Java Path Operations — Resolve, Relativize, Normalize
`Path` (NIO) replaces `File` for new code. Operator-like methods compose paths cleanly across OSes — and the underlying file isn't touched until you do I/O.
Java java.time — Duration and Period
`Duration` for elapsed time (hours/minutes/seconds). `Period` for calendar amounts (days/months/years). Don't mix — calendar math respects month lengths and DST; clock math doesn't.
Java Collectors.partitioningBy — Split by Predicate
Special case of groupingBy when the key is boolean — returns a `Map<Boolean, List<T>>` for the "true" and "false" buckets. Slightly more efficient than groupingBy.
Java Collectors.groupingBy — Group by Key
Like SQL GROUP BY for streams. Produces a `Map<K, List<V>>` (or any downstream collector you specify). Indispensable for analytics-style aggregations.
Java Optional with Streams
`Optional::stream` (Java 9+) bridges optionals into the Stream API — collect all the `Some` values from a list of optionals, drop the empties, in one pipeline.
Java Collectors.toMap with Merge Function
`toMap` builds a `Map<K, V>` from a stream. The 3-arg form takes a merge function for handling duplicate keys — without it, duplicates throw IllegalStateException.
Java Stream.generate / iterate — Infinite Streams
Build streams from a seed + a function. `generate(supplier)` calls the supplier each time; `iterate(seed, next)` applies a unary op. Always pair with `limit` to bound them.