Aricles related to

Java

How to generate a stream of random numbers in Java

From time to time you end up with the need of generating some random numbers. In Java, the Random class has been the go-to solution for this type of work. Random serves several helpful methods for creating random ints, doubles and longs. However, if you wanted a sequence of random…


Java 9: Cleaning up your default methods using private interface methods

Java 8 brought huge changes — one of them being the default interface methods. These methods changed interfaces as we knew them — we could now define default implementations in the interface itself. If you use these default methods heavily in your applications, you'll quickly figure out one thing — it doesn't really…


Java 9 - Making the Stream API even better

One of the first things I check out when looking at a new language is if it got a good collection API. I find that a good way of working with collections usually result in cleaner code that is easier to understand and reason about. That's why I was glad…


Java 8: Creating a custom Collector for your Stream

In the previous post we looked at different implementations of the Collector interface. As you saw, there is a wide range of collectors available out of the box. However — sometimes you need something special that you simply have to make yourself. So today we’re going to look at how…


Java 8: Accumulate the elements of a Stream using Collectors

I’ve earlier written about the Stream API and how you can write more declarative code by using it. In this article I want to focus on the different ways of accumulating the elements of a Stream using Collectors. This is made possible by using collect — a method in the…



Java 8: New features in ConcurrentHashMap

The java.util.concurrent got a massive overhaul with the release of Java 8. We’ve been introduced to whole new classes like CompletableFuture that brought a long awaited improvement to asynchronous work. We’ve also seen a lot of new methods being introduced in already existing classes and interfaces…


Java 8: Writing asynchronous code with CompletableFuture

Java 8 introduced a lot of cool features, whereas lambdas and streams caught much of the attention. What you may have missed is the CompletableFuture. You probably already know about Futures A Future represents the pending result of an asynchronous computation. It offers a method — get — that returns the result…