Introduction
Definition
- AsynchronousIt implies that the different parts of a program run simultaneously.
- Event-BasedThe program executes the code based on the events generated while the program is running. For example, a button click triggers an event and then the program’s event handler receives this event and does some work accordingly.
- Observable sequencesObservable and Flowable take some items and pass onto their subscribers. So, these items are called as Observable sequences or Data Stream.
- RxJava frees us from the callback hell by providing the composing style of programming. We can plug in various transformations that resemble the Functional programming.
RxJava uses Observer and observable pattern where the subject all the time maintains its Observers and if any change occurs, then it notifies them by calling one of their methods.
3 O's of RxJava

The stream abstraction is implemented through three main constituents - Observables, Observers, and Operators. Observables emit data and observers consume that emitted data. Emissions from Observable objects can further be modified, transformed, and manipulated by chaining Operator calls.
Before implementing some code, we must add a gradle in our build.gradle.
- // reactive
- implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
- // Because RxAndroid releases are few and far between, it is recommended you also
- // explicitly depend on RxJava's latest version for bug fixes and new features.
- implementation 'io.reactivex.rxjava2:rxjava:2.1.7'
Observable
- Observable<Integer> observable = Observable.create(new Observable.OnSubscribe<Integer>() {
- @Override public void call(Subscriber<? super Integer> subscriber) {
- subscriber.onNext(1);
- subscriber.onNext(2);
- subscriber.onNext(3);
- subscriber.onCompleted();
- }
- });
- Observable.just(1, 2, 3); // 1, 2, 3 will be emitted, respectively
Observer
Observer is another component of RxJava. Observers are subscribed to the Observables whenever there is a change or an event of interest occurs it immediately notifies by the following events.

Join the conversation! Your thoughts help the community grow.