Locale Aware Number Formatting
Render numbers and currency per locale with NumberFormat so grouping and decimal conventions come from the locale, not hand-rolled strings.
Page 7 of 7
Render numbers and currency per locale with NumberFormat so grouping and decimal conventions come from the locale, not hand-rolled strings.
Copy and move files with the NIO Files API using REPLACE_EXISTING and ATOMIC_MOVE options so interrupted operations leave no partial state.
Chain Optional flatMap and map steps to validate and transform input, failing with a typed exception instead of nested null checks.
Run external commands safely through ProcessBuilder argument lists with streamed output, a hard timeout, and destroyForcibly cleanup.
Build a thread-safe memoizing cache where ReentrantReadWriteLock lets concurrent readers share access while writers take the exclusive side.
Run a recurring heartbeat with scheduleAtFixedRate, cancel it from another task, and shut the scheduler down without leaking threads.
Collect count, sum, min, average, and max in one stream pass with IntSummaryStatistics instead of four separate loops.
Fan out thousands of blocking tasks onto Java 21 virtual threads with Executors.newVirtualThreadPerTaskExecutor and time the run against the platform pool.
Find the leftmost position where a sorted Java array can accept a target using a binary search lower bound variant.
Generate a Gray code sequence of n bits in Java using bit manipulation where consecutive values differ by one bit.
Implement a Java bloom filter with k hash functions for probabilistic membership testing.
Implement a Java binary search tree supporting insert and delete using in-order successor for two-child nodes.
Compute single source shortest paths in a weighted Java graph using Dijkstra with PriorityQueue.
Compute the Levenshtein edit distance between two Java strings with insert, delete, and substitute operations.
Find the shortest path in an unweighted Java graph using BFS with a predecessor map for path reconstruction.
Sort a Java array by building a max heap in place then repeatedly extracting the maximum to the end.
Solve the 0-1 knapsack problem in Java using dynamic programming with a rolling array for space optimization.
Compute the longest common subsequence of two Java strings using dynamic programming with table reconstruction.
Count inversions in a Java array using a modified mergesort that counts crossings during the merge step.
Sort a Java array in place using quicksort with median-of-three pivot selection to avoid worst-case behavior.
Find all occurrences of a pattern in Java text using Rabin Karp with a rolling hash for O(n+m) average time.
Build a Java trie from a word list supporting prefix search and autocomplete suggestions ranked by frequency.
Implement a Java disjoint set union find with path compression and union by rank for near constant amortized time.
Chain async operations with CompletableFuture thenCompose for dependent async stages.
Use pattern matching with switch on sealed types for exhaustive handling.
Define immutable records with compact constructors for validation in Java applications.
Group and partition streams with Collectors for functional data aggregation.
Auto-close resources with try-with-resources and handle suppressed exceptions.
Run a batch on a fixed thread pool with invokeAll and a deadline, inspect completed futures, and shut the executor down cleanly.
Validate and normalize a Java record in its compact constructor, default missing display names, and defensively copy a role list.
Aggregate sales with Collectors groupingBy, TreeMap ordering, and teeing to compute count and average in one pass over a Java stream.
See how Java closes resources in reverse order and attaches a failing close to the primary exception as a suppressed throwable.
Demonstrates common ArrayList operations including add, remove, iterate, sort, and filter with practical examples for managing a list of items.
Uses CompletableFuture to compose asynchronous operations with thenApply, thenCompose, thenCombine, and exception handling for non-blocking pipelines.
Defines custom annotations with different retention policies and demonstrates runtime annotation processing via reflection for metadata-driven behavior.
Defines a custom exception hierarchy with domain-specific exceptions, demonstrating proper exception chaining, message formatting, and multi-catch handling.
Uses the java.time API to work with dates, times, durations, periods, and formatting, demonstrating modern date-time manipulation and parsing.
Uses ScheduledExecutorService to run delayed and periodic tasks, demonstrating fixed-rate and fixed-delay scheduling with proper shutdown handling.
Demonstrates reading and writing files using Java NIO with Path, Files, and BufferedReader, including proper resource management and exception handling.
Implements a generic Box class with type bounds, demonstrating how generics provide compile-time type safety while working with constrained type parameters.
Demonstrates HashMap operations including put, get, merge, computeIfAbsent, and iteration with entrySet, keySet, and forEach methods.
Demonstrates connecting to a database using JDBC, executing parameterized queries with PreparedStatement, and processing ResultSet with proper resource cleanup.
Demonstrates lambda expressions with built-in functional interfaces like Predicate, Function, Consumer, and Supplier for concise and readable code.
Demonstrates LinkedList operations including addFirst, addLast, peek, poll, and bidirectional iteration with ListIterator for queue and deque patterns.
Demonstrates four types of method references (static, instance, arbitrary object, constructor) to create concise and readable functional expressions.
Demonstrates serializing and deserializing objects to JSON format, showing how to persist and transfer structured data between application components.
Demonstrates using Optional to handle potentially absent values safely, with map, flatMap, filter, orElse, and ifPresent operations to avoid NullPointerExcep...
Uses Java pattern matching with switch expressions and type patterns to handle different object types concisely without explicit casts or instanceof checks.
Demonstrates Java record classes as concise immutable data carriers with automatic constructors, accessors, equals, hashCode, and toString methods.
Uses Pattern and Matcher classes to validate email addresses, extract groups, replace text, and split strings with regular expressions.
Demonstrates sealed classes and interfaces to create restricted class hierarchies, enabling exhaustive pattern matching and domain modeling with known subtypes.
Demonstrates advanced Stream collectors including groupingBy, partitioningBy, counting, joining, and teeing for complex data aggregation and transformation.
Shows how to process collections using Java Streams with map, filter, reduce, and collect operations to transform and aggregate data efficiently.
Demonstrates efficient string manipulation using StringBuilder for concatenation, insertion, deletion, and reversal operations in performance-critical code.
Demonstrates Java text blocks for multi-line string literals with proper indentation handling, template formatting, and SQL/JSON/HTML generation.
Creates a fixed thread pool to execute multiple tasks concurrently, demonstrating proper resource management with try-with-resources and shutdown handling.
Demonstrates try-with-resources with custom AutoCloseable objects, ensuring proper resource cleanup even when exceptions occur during resource usage.