Loading…
Loading…
Language
Articles and problems tagged Java.
How Java's char type really works: character literals, escape sequences, the Unicode escape traps, code points vs UTF-16 code units, emojis and surrogate pairs, useful Character methods, plus the boolean type and why Java never treats numbers as true or false.
Write a Java annotation processor: AbstractProcessor, @SupportedAnnotationTypes, processing rounds, RoundEnvironment, the javax.lang.model element API, AnnotationMirror, Filer and Messager, plus how to register processors with javac, Maven and Gradle and why Lombok is different.
Read Java annotations at runtime with the AnnotatedElement API: getAnnotation, getAnnotationsByType, declared versus inherited annotations, and three hands-on tools built with reflection, an annotation-driven toString, a mini JUnit-style test runner and a record validator.
A practical guide to Java's standard annotations: @Override, @Deprecated with since and forRemoval, @SuppressWarnings, @SafeVarargs, @FunctionalInterface, @Serial and @Generated, plus the meta-annotations @Target, @Retention, @Documented, @Inherited and @Repeatable.
Create your own Java annotations with @interface: declare elements and default values, restrict where they apply with @Target and ElementType, choose SOURCE, CLASS or RUNTIME retention, and understand the Annotation interface, proxies and dynamically computed defaults.
Learn how Java annotations work: what they are for, element syntax and defaults, value and single-element shortcuts, repeated annotations, annotating declarations, packages and record components, type-use annotations on generics and arrays, and receiver parameters.
Run external programs from Java with ProcessBuilder and Process: commands and working directories, stdin/stdout/stderr pipes, redirects, environment variables, pipelines, exit codes, timeouts, destroy, onExit and inspecting any OS process with ProcessHandle.
Keep Java desktop apps responsive: why the UI thread must never block, how to run work in background threads, update components safely with EventQueue.invokeLater, and use SwingWorker's doInBackground, publish, process, done and cancel, plus JavaFX and Android equivalents.
Write non-blocking Java code with CompletableFuture: supplyAsync, thenApply, thenCompose, thenAccept, exceptionally, handle, timeouts, thenCombine, allOf and anyOf, completing futures yourself, cancellation and building clean asynchronous pipelines.
Update a Java ConcurrentHashMap atomically with compute, merge and computeIfAbsent, run parallel search, forEach and reduce bulk operations, build concurrent sets, use copy-on-write lists, parallelSort, parallelSetAll and parallelPrefix, and compare synchronization wrappers.
Coordinate Java threads without explicit locks: BlockingQueue put and take, offer and poll with timeouts, ArrayBlockingQueue, LinkedBlockingQueue, PriorityBlockingQueue, TransferQueue, DelayQueue, poison pills, ConcurrentSkipListMap and weakly consistent iterators.
Java's eight primitive types, with a deep dive into byte, short, int, long, float and double: their sizes and ranges, number literals (hex, binary, underscores), overflow, unsigned tricks, floating-point rounding errors, Infinity and NaN.
Turn a Java stream into a map with Collectors.toMap: key and value functions, Function.identity(), the duplicate-key IllegalStateException, merge functions, choosing TreeMap or LinkedHashMap, the null-value trap, toUnmodifiableMap and toConcurrentMap.
Get results out of a Java stream: iterator, forEach versus forEachOrdered, typed arrays with toArray(String[]::new), the differences between toList(), Collectors.toList() and toUnmodifiableList(), toSet, toCollection, joining and summarizingInt statistics.
How not to use Java Optional (get, isPresent, Optional fields and parameters), how to create Optionals with of, ofNullable and empty, how to chain Optional-returning methods with flatMap, and how Optional.stream drops missing values in a stream pipeline.
Use Java's Optional the right way: unwrap with orElse, orElseGet and orElseThrow (and why orElse evaluates eagerly), consume with ifPresent and ifPresentOrElse, and transform with map, filter and or, without ever calling get.
Get answers out of Java streams with the simple terminal reductions count, max, min, findFirst, findAny, anyMatch, allMatch and noneMatch. Learn why they return Optional, how short-circuiting works, the empty-stream rules and when findAny beats findFirst.
Cut, combine and reorder Java streams: limit and skip (with paging), takeWhile and dropWhile versus filter, Stream.concat, distinct, stable sorted with comparators, and peek for debugging, including why peek can silently not run with count().
The core Java stream transformations: filter keeps elements, map transforms them, flatMap flattens nested results and mapMulti pushes zero or more results without inner streams. Includes grapheme clusters, dropping nulls with ofNullable, and the primitive mapToInt and flatMapToInt.
Every way to get a Java stream: from collections, arrays and values, infinite streams with generate and iterate, ofNullable, String.lines, Pattern, Scanner, Files.lines, Stream.Builder and iterators, plus the noninterference rule and the Stream.of(int[]) trap.