RxJava Ninja: Introduction to Reactive Programming

Tompee Balauag
Familiar Android
Published in
3 min readJul 30, 2018
“A person's hand holding up a tiny fern-like leaf against an empty path through a meadow” by Luke Porter on Unsplash

This entirely new series is about an in-depth look at the Reactive Extensions in Java and we will kick it off with the topic of What is Reactive Programming.

The complete list of the articles for this series can be found at the end of this article (and will be updated as more articles become available).

What is Reactive Programming

Wikipedia defines it as follows.

Reactive programming is a declarative programming paradigm concerned with data streams and the propagation of change.

To understand it better, let’s temporarily forget our notion of imperative and object-oriented programming and open ourselves to a new way of modeling the world around us.

You wake up in the morning and look at your clock. Time is constantly changing. You get out of your house and see the cars moving, people walking and some of them stop and converge at the intersection. You drop your package at the post and watch the delivery status change from time to time. You order a cup of coffee at your favorite bar and pay with your credit card and watch your balance change. The point here is that, in some degree, you can observe that things and information are in motion. And these movements, brought about by events, happens either independent of each other or caused by one another.

Reactive programming builds upon this premise that objects do not only contain properties and state, but can also propagate changes. This allows you to observe on objects and “react” on those changes. How does this look like in programming point of view? Check out this imperative approach at addition.

This will add a and b and will print the sum. But any changes in the operands will not update the sum anymore. You need to explicitly invoke the add operation again to update the sum value. In reactive programming, since objects are known to cause change, you can observe them and just write a declarative code describing the reaction to the changes, which is in this case, summation.

RxJava

RxJava is the implementation of the Reactive Extensions for the Java Virtual Machine. Reactive Extensions is a set of API that uses observable streams for asynchronous programming. The complete overview is available here and I encourage you to check it for better context. Take note that we will be working with RxJava2, not its predecessor.

In this series, we will try to look at RxJava2’s most common and useful operators and features and take a peek on how they work under the hood.

The next article will focus on the basic building blocks of RxJava, the observables and the observers.

Check out the other articles in this series.

  1. Introduction to Reactive Programming
  2. Building your first Observables and Observers
  3. In Depth Observables and Observers
  4. Marble Diagrams and Operators
  5. Observable Factories Part 1
  6. Observable Factories Part 2
  7. Single, Maybe and Completable
  8. Hot and Cold Observables
  9. Filtering Operators Part 1
  10. Filtering Operators Part 2

--

--