Loading…
Loading…
Language
Articles and problems tagged Java.
Use Java 24's stream gatherers, the extension point for intermediate operations. Group elements with windowFixed and windowSliding, compare neighbors, fold and scan sequentially, run blocking calls on virtual threads with mapConcurrent, and chain gatherers with andThen.
Master Java's Stream.reduce in its three forms: reduce with an Optional result, with an identity value, and with an accumulator and combiner. Learn why the operation must be associative, what a wrong identity does in parallel, and when to use the three-argument collect instead.
Learn how Java collectors work inside: the supplier, accumulator, combiner and finisher functions, the IDENTITY_FINISH, UNORDERED and CONCURRENT characteristics, building collectors with Collector.of, wrapping a downstream collector and the parallel bugs a bad combiner causes.
Process the groups of a Java groupingBy with downstream collectors: counting, summingInt, averagingInt, maxBy, mapping, joining, filtering, flatMapping, collectingAndThen, summarizingInt, reducing, nested groupingBy and teeing for two results in one pass.
Group Java stream elements with Collectors.groupingBy and split them in two with partitioningBy. Covers classifier functions, choosing TreeMap or EnumMap, why partitioningBy always has both keys, the null-key error and groupingByConcurrent for parallel streams.
Share data between Java threads without bugs: memory visibility and volatile, final fields, AtomicInteger and compareAndSet, LongAdder, lazy holder initialization, safe publication, lock-ordering deadlocks, ThreadLocal, InheritableThreadLocal and ScopedValue.
Make threads wait for a condition safely with Condition.await and signalAll, then learn Java's built-in alternative: synchronized methods and blocks, intrinsic locks, wait and notifyAll, choosing lock objects, client-side locking, and the monitor concept.
Why unsynchronized threads corrupt shared data, shown step by step with a lost-update race, and how to fix it with ReentrantLock: the lock/try/finally idiom, critical sections, reentrancy and hold counts, tryLock, fair locks, and the mistakes that cause bugs.
Coordinate many concurrent tasks in Java: invokeAll to wait for every result, invokeAny to take the first success, timeouts, ExecutorCompletionService for results in completion order, structured concurrency, and the fork-join framework with RecursiveTask, RecursiveAction and work stealing.
Run tasks that return results with Callable and Future, then let an ExecutorService manage threads: fixed, cached and single-thread pools, virtual-thread-per-task executors, get with timeouts, cancellation, Future.state and resultNow, closing executors, and throttling with semaphores.
Everything about Java thread properties: virtual threads and carrier threads (Java 21), cooperative cancellation with interrupt, handling InterruptedException correctly, daemon threads, names and IDs, uncaught exception handlers, priorities, and thread builders and factories.
The Java thread life cycle explained: the six Thread.State values, what moves a thread between NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING and TERMINATED, how platform and virtual threads are scheduled, join with timeouts, and why stop, suspend and resume are gone.
Start your first Java threads: what threads are compared with processes, putting a task in a Runnable, starting it with Thread.start, waiting with join, why calling run() is a bug, Java 21 thread builders, and why you shouldn't subclass Thread. Includes a two-thread bank transfer example.
Java 1.0's legacy collections and what to use today: Hashtable vs HashMap, Enumeration and how to convert it, Properties files with defaults and UTF-8, system properties, why Stack lost to ArrayDeque, and BitSet with a sieve of Eratosthenes example.
The algorithms in java.util.Collections and Arrays: stable sorting with comparators, shuffling, binary search and insertion points, min, max, reverse, rotate, removeIf and replaceAll, set operations with retainAll and removeAll, toArray, and writing your own generic algorithms.
List.of, Set.of, Map.of and copyOf versus Collections.unmodifiableList, Arrays.asList, subList and range views, reversed views, newSetFromMap, and checked and synchronized wrappers. Learn which give independent copies and which give live windows, plus the null and ordering pitfalls.
Master Java map views (keySet, values, entrySet) and Map.Entry, then the specialized maps and sets: LinkedHashMap with access order and an LRU cache, SequencedMap, EnumSet and EnumMap, IdentityHashMap, and WeakHashMap with its garbage-collector tricks.
A practical guide to Java's Map interface: HashMap versus TreeMap, put, get and getOrDefault, iterating with forEach, and updating entries the modern way with merge, compute, computeIfAbsent and putIfAbsent. Includes word counting, multimaps, and the null-value pitfalls.
Learn Java's Queue, Deque and PriorityQueue: offer/poll/peek versus add/remove/element, ArrayDeque as a fast queue and stack, Java 21 sequenced methods, and how a binary heap gives a priority queue O(log n) add and remove, with job scheduling and top-k examples.
How Java's HashSet and TreeSet work: hash codes, buckets, collisions, load factor and rehashing, HashSet.newHashSet, the danger of mutating set elements, red-black tree sorted sets, comparators that disagree with equals, and NavigableSet methods like floor, ceiling and headSet.