Category Archives for Java

Speacial Observables: Single, Maybe and Completable

October 12, 2018

There are a few special Observables available in RxJava: Single, Maybe and Completable. Single Single is an Observable that will emit only one item: it consolidates onNext() and onComplete() into a single event, so on subscribing to a Single, we can provide a Lambda for the onSuccess() and to the optional onError(): import io.reactivex.Single; public […]

Observable factories

October 11, 2018

There are various factory methods available to create Observables. In this post we will go through some of them. Observable.range() and rangeLong() In a previous post, we created an Observable using an IntStream. To emit a consecutive range of integers, there is a shorter solution available: import io.reactivex.Observable; public class Main { public static void […]

Cold and Hot Observables

October 10, 2018

A major characteristic of Observables is how they behave when there are multiple Observers. Based on this, we differentiate between Hot and Cold Observables. Cold Observables You can imagine Cold Observables like a DVD disk with a movie on it. Each viewer of the DVD can watch the whole movie at any time. Similarly, Cold […]

Differences between RxJava’s Observables and Java’s Streams

October 8, 2018

Stream processing libraries such as RxJava’s Observables and Java’s Streams are quite similar in their APIs for pipeline building. The main differences are how they handle multi-threading and the composition of said pipelines. Main differences Streams are pull-based, Observables are push-based. Streams can be used only once, Observables can be subscribed to multiple times. Using […]

Reactive Programming – Intro

October 7, 2018

Why? Why do we need Reactive programming? We all know the phrase: “If it is not broken don’t fix it”. So what is the problem for which we need a solution? Because if there is no problem, we don’t need a solution. That we need asynchronous programming, we can all agree. So the question is, […]

Power of two check, Stream gotcha

October 1, 2017

Recently I came across a rather simple and innocent looking question which highlighted an issue you might run into when using Streams. The question was: how could you decide if a number is a power of two? If you are interested only in the possible issue, jump to the gotcha. Possible solutions Division by two […]

Optimizing Streams: Autoboxing

September 18, 2017

What is Autoboxing and why should I care? Java 8 Streams are powerful tools, but as with any tools, you have to use them properly. To use any tool in a professional way, you have to understand how that tool works. In Java variables can be grouped into two big categories: primitives and objects.For example:¬†int […]