A Brief History
A number of years ago, object oriented programming took the programming world by storm, because it promised to help us deal with the ever growing complexity. But as time goes on, we find that while many of the principles taught in object oriented programming can be quite useful, there are a growing number of situations where they are inadequate.In time, functional programming began to make a comeback, not to replace object oriented programming, but rather in many cases to compliment and enhance it. In particular, reactive programming, a "functional event-driven programming approach" began to grow in popularity.
While there are multiple reactive frameworks available, including Akka and Sodium, the one that we will be focusing on here is called Reactive Extensions (also known as ReactiveX or Rx). Reactive Extensions was initially developed at Microsoft by Erik Meijer for .NET, but over the years it has been ported to many other languages.
The port for Java, called RxJava, was developed primarily by Ben Christensen from Netflix and David Karnok. RxJava 1.0 was released in November 2014 and RxJava 2.0 was released in November 2016. RxJava has been the core that other JVM based Rx ports were built off of.
What is Rx?
The core idea behind Rx is that "events are data and data are events". While the world is full of objects, the objects themselves are less important than the actions they perform, and the actions performed against them. In particular, how these events act and interact when they come together tends to be where we place the greatest value. Reactive programming strives to clearly model these events.Even static sources of data, such as a book or a music cd, can be thought of in terms of events. While the information in a book does not change, the act of reading it is an action, an event occurring between the book and the person reading it. Each word read is a stream of information flowing to the reader. Playing music from a cd works in a similar fashion. Data is read from the disk sequentially and played for the listener to hear. Rx uses this concept to treat data as events, in turn allowing us to use the same powerful tools in both cases.
Now RxJava is fairly similar to Java 8 streams, at least in syntax. So what's the major difference between these two? In essense, Java 8 streams pull, whereas RxJava observables push. Why is this important? Because both data and events can be pushed. What it means is that the observable is in control of when the data is sent. In this way it more resembles the listener pattern with a syntax similar to streams.