Parallel Streams in Java 8 — Performance Engineering Guide
parallelStream() is not a universal performance switch. It can improve throughput for CPU-bound, independent workloads, and degrade latency badly in request/...
parallelStream() is not a universal performance switch. It can improve throughput for CPU-bound, independent workloads, and degrade latency badly in request/...
Date-time bugs are common in distributed systems:
Async code without clear failure policy becomes fragile quickly. This post focuses on robust CompletableFuture error handling and thread-pool design for prod...
CompletableFuture enables non-blocking service orchestration in Java 8. It is especially useful when an endpoint needs data from multiple downstream services.
Functional interfaces are not just lambda targets. In backend systems they help build reusable policies for validation, mapping, retries, and cross-cutting o...
Optional<T> makes absence explicit in API contracts. Used correctly, it reduces null-related defects and clarifies service-layer behavior. Used incorre...
Collectors are the aggregation engine of the Stream API. In backend code, they are used for:
Two Pointers is one of the most effective techniques for turning brute-force array/string solutions into linear-time solutions.
In most backend systems, a big part of business logic is data transformation:
Java 8 introduced lambda expressions, fundamentally changing how we write backend code.
The hardest part of design patterns is not implementation. It is choosing the right pattern and stopping before abstraction becomes ceremony.
Chain of Responsibility is attractive whenever one big validator starts turning into a wall of conditionals. The promise is simple: separate each rule, keep ...
State becomes useful when an object’s behavior changes meaningfully based on its current lifecycle stage. Without it, classes often fill up with conditionals...
Template Method is a good fit when the overall algorithm is stable, but one or more steps vary by subtype. It is especially common in parsing and import work...
Command turns an action into an object. That sounds simple, but it enables powerful capabilities:
Strategy is one of the most useful patterns in Java because many business rules are really just interchangeable algorithms selected at runtime.
Observer is about decoupling publishers from subscribers. It works well when one state change must trigger multiple downstream reactions that should not be h...
Teams often discover Proxy accidentally. They add authorization, then caching, then maybe rate limiting, and suddenly one object is standing between callers ...
Facade is useful when the caller should think in terms of one business action, but the system underneath still needs several subsystem calls to make that hap...
Decorator becomes useful when the base behavior is stable, but the way you wrap it keeps changing. That usually happens in systems where pricing, logging, va...
Adapter lets your application speak in its own language while wrapping external APIs that were never designed for your internal model. This is one of the mos...
Prototype is useful when creating a new object from scratch is expensive or when a predefined template should be copied and slightly adjusted. It is common i...
Builder is valuable when object construction is complex, optional fields are common, and you want the result to be immutable and readable. It is not useful f...
Abstract Factory is useful when you do not create just one object. You create a compatible family of objects that must vary together.
Factory Method solves a specific problem: object creation varies, but the surrounding workflow stays stable. That is common in backend systems that support m...
Singleton is the most overused pattern in Java. That does not make it useless. It means it must be applied carefully and only when a single shared instance i...
Most design patterns fail in production for a simple reason: the codebase violates basic design principles before the pattern is introduced. If responsibilit...
This series is written for engineers who already know Java syntax but want to improve how they structure code in real systems. The focus is not pattern memor...
This guide explains the intuition, optimized approach, and Java implementation for sort array by parity in java, with practical tips for interviews and produ...
This guide explains the intuition, optimized approach, and Java implementation for maximum subarray in java (kadane algorithm), with practical tips for inter...
Given a string containing only ()[]{}, return true if brackets are valid. A valid string must close in correct order and with correct bracket type.
Given an array nums of size n where values are in range [1, n], some numbers appear twice and others are missing. Return all missing numbers.
This guide explains the intuition, optimized approach, and Java implementation for move zeroes in java (stable in-place), with practical tips for interviews ...
Given an integer array where every value appears exactly twice except one value, return the value that appears once.
This guide explains the intuition, optimized approach, and Java implementation for maximum depth of binary tree in java, with practical tips for interviews a...
This guide explains the intuition, optimized approach, and Java implementation for remove duplicates from sorted list ii in java, with practical tips for int...
Given a sorted array, remove duplicates in-place so each unique value appears once. Return the number of unique elements.
Given a string, repeatedly remove adjacent equal characters until no such pair remains.
This guide explains the intuition, optimized approach, and Java implementation for palindrome number in java (without string conversion), with practical tips...
Given the head of a singly linked list, return its middle node. If the list has two middle nodes, return the second middle.
This guide explains the intuition, optimized approach, and Java implementation for longest substring without repeating characters in java, with practical tip...
This guide explains the intuition, optimized approach, and Java implementation for linked list cycle ii in java (find cycle start), with practical tips for i...
This guide explains the intuition, optimized approach, and Java implementation for first missing positive in java, with practical tips for interviews and pro...
This guide explains the intuition, optimized approach, and Java implementation for find first and last position of element in sorted array, with practical ti...
Given a rotated sorted array with distinct values, find the minimum element in O(log n).
This guide explains the intuition, optimized approach, and Java implementation for remove linked list elements in java, with practical tips for interviews an...
Given a sorted linked list, remove duplicate nodes so each value appears exactly once.
Given an array height, pick two indices i and j to form a container. Maximize area:
This guide explains the intuition, optimized approach, and Java implementation for binary search in java (iterative and recursive), with practical tips for i...
This guide explains the intuition, optimized approach, and Java implementation for add two numbers represented as linked list, with practical tips for interv...
This guide explains the intuition, optimized approach, and Java implementation for detect a loop in linked list (floyd cycle detection), with practical tips ...
Reverse a singly linked list using recursion.
This guide explains the intuition, optimized approach, and Java implementation for reverse linked list iteratively in java, with practical tips for interview...
This deep dive explains the problem model, concurrency contract, Java implementation, and real-world caveats you should know before using this pattern in pro...
Double-checked locking provides lazy initialization with lower synchronization overhead after initialization.
CyclicBarrier lets a fixed number of threads wait until all participants reach the same synchronization point.
A Semaphore controls how many threads can access a shared resource at the same time.
This is a learning-oriented implementation to understand worker threads, queueing, and task execution flow.
This post explains how a latch works internally using a simplified custom implementation.
BlockingQueue is a thread-safe queue from java.util.concurrent used heavily in producer-consumer systems.
This example validates that bean fields are not null using a custom class-level annotation.
Interview-style concurrency problem: ensure threads print in strict round-robin sequence.
invokeAll submits a collection of Callable tasks and waits until all complete.
DelayQueue is a specialized blocking queue where elements become available only after a delay expires.
Enums model a fixed set of constants with type safety and encapsulated behavior.
Varargs (...) lets a method accept zero or more arguments of the same type.