Below you will find pages that utilize the taxonomy term “Java”
Jumping the queue? Yes, but in constant time
The Problem
Classic interview setup: you walk in, sit down, and the interviewer says:
“Design a
FastQueueclass. It stores entries, where each entry has along idand aString family.You need three operations, all in O(1) time:
add(entry),removeLast(), andremoveLast(family).Space complexity is O(N) for all operations.”
Let’s unpack that. You have a queue of entries, each tagged with a family group. At any point, you can eject the oldest entry within a given family, all in constant-time.
JUnit 5 Tricks Recap
JUnit: Lay of the Land & Mutation testing
Alright, what do we know about unit tests?
- A unit test verifies an individual unit of code works as expected,
- It is small, fast and isolate a single functionality
They are generally named based on what the test verifies, e.g. testInvalidAccountIdThrowsException; they are independent
from each other even though grouped in the
same class as related tests.
We create them in the same package structure as the source code but under the src/test/java directory. With Maven,
tests can be run using lifecycle phases like test, install, etc.
We all need a Holiday Destination Finder
Tiptoeing Through the Asynch Door with the CompletionStage Interface JSE17
When it comes to holidays, I’m as spontaneous as they come. I enjoy not planning and picking the best option available just before or even while traveling.
So I needed a holiday… and a reason to explore Java’s async magic.

We’ll get to this Holiday Finder but first let’s get the theory out of the way, shall we?
Diving Right In
Considering two API calls A & B, API A is called first, and then API B. This is what synchronous code does: it waits before executing the next task and things run in order. However, could the thread blocked on the API response be doing some other work instead?
Lambdas & Single Abstract Method Interfaces
Quick Tour of Java Functional Interfaces
A functional interface is an interface with just one abstract method, such as Runnable, Comparator, Callable, etc. The main benefit of functional interfaces, with the introduction of lambdas in Java 8, is that they allow you to pass behavior (code) to a function the same way you’d pass data (objects) to a method. This means we can pass a lambda expression when a method is accepting a functional interface. Since there is only one function to override, it is possible to infer which function to implement when using a lambda expression.
When Strings go wrong
Encoding for Web apps internationalisation
Some theory about Information Content & Entropy
Encoding is the process of converting data from one form into another using an unambiguous mapping. It can refer to transforming human-readable characters into a machine-readable format. The main question it raises is: how many bits do I need to encode ‘a’ (and the rest of the characters)?
The Information Content (Shannon information) quantifies the amount of “uncertainty” associated with a particular piece of information.
`x = Pépin, y = x` I'm Pépin too, says y
Pass-by-Value or Reference: the Great Debate
Background on Heap and Stack
The stack referred to when talking about memory is the same as the run-time call stack. It is
composed of stack frames and stores things. It controls the function calls and program execution by
storing in its frames the function parameters, the return address, local variables - among other things.
The stack has a fixed-size so in some cases, for instance deep recursion, it can run out of memory.
Remember this one time you forgot a stopping condition in your code and got a StackOverflowError or
RecursionError: that’s the call stack telling you it’s full.
Stack frames only exist during the execution of a function. This means everything stored in it becomes
unavailable after the function has returned. This makes the allocation and de-allocation of memory
automatic, which helps prevent memory leaks.
topic=logFormatting context=distributedSystems
Structured logging in Java for distributed systems
Where do applications log end up anyway?
Applications typically write to standard output. Logs can either be handled
by the app’s supervising process or be passed to the next supervision
layer to be processed. For example Kubernetes collects logs
written to stdout and stderr by containers and stores them in node-specific
log files (usually /var/log/containers based on name).
From there, they can be accessed by tools like kubectl logs.