Skip to content

1. Introduction

The PDF of the document is available |HERE|.

The examples in the document are available |HERE|.

1.1. Context

This document is not intended for beginners but for users with solid experience in Java. It uses the following sources:

  1. [Reactive Programming] documentation;
  1. Java 8 lambda functions;
  2. Learning Reactive Programming With Java 8;
  3. Java 8 in Action;

Unlike other documents I have written, this one relies primarily on examples and delves only briefly into theory. However, each example is accompanied by an explanation, and there is a logical progression throughout the document.

ReactiveX is a set of libraries that facilitate asynchronous programming and the processing of the resulting data:

 
 
 

The Rx library has been implemented in many languages:

 

Here, we are focusing on the following libraries:

  • RxJava for the Java world;
  • RxAndroid, a specialization of RxJava for the Android environment;
  • RxSwing, a specialization of RxJava for the Swing environment;

The concepts of reactive programming are complex at first glance. That is why this document is not primarily intended for beginners. Nevertheless, I have made a great effort to explain the code used, and a novice can familiarize themselves with reactive programming using this document.

1.2. Tools Used

The following examples have been tested with the following environment:

  • Windows 10 Pro 64-bit machine;
  • JDK 1.8 (section 1);
  • IntelliJ IDEA Community Edition (Section 10.4);

1.3. Example code

The code for the following examples can be found |HERE| in the [dvp/examples] folder.

 

The [dvp/examples] folder [2] is a Gradle project containing most of the examples in this document. It can be opened by any IDE that supports the Gradle project manager [http://gradle.org/]. IntelliJ IDEA supports it natively. For Eclipse or NetBeans, a plugin is required. With IntelliJ IDEA Community Edition, you can proceed as follows:

The [examples] project is configured by the following [build.gradle] [4] file:


buildscript {
    repositories {
        mavenCentral()
    }
}

apply plugin: 'java'

jar {
    baseName = 'examples-01'
    version = '0.0.1-SNAPSHOT'
}

repositories {
    mavenCentral()
}

dependencies {
    compile('io.reactivex:rxswing:0.25.0')
    compile('io.reactivex:rxjava:1.1.3')
    compile('com.fasterxml.jackson.core:jackson-databind:2.7.3')
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.9'
}
  • lines 18–22: the project’s Gradle dependencies (libraries to download);
  • line 19: the library required for the Swing example discussed in section 2;
  • line 20: the RxJava library;
  • line 21: a JSON library;
  • lines 9–12: the characteristics of the JAR archive produced by compiling the project;

To download the dependencies required for the project, follow these steps [1-4]: