RxJava - Subjects

As per the Reactive, a Subject can act as both Observable as well as Observer.

A Subject is a sort of bridge or proxy that is available in some implementations of ReactiveX that acts both as an observer and as an Observable. Because it is an observer, it can subscribe to one or more Observables, and because it is an Observable, it can pass through the items it observes by reemitting them, and it can also emit new items.

There are four types of Subjects −

Sr.No. Subject & Description

Publish Subject

Emits only those items which are emitted after time of subscription.

2 Replay Subject

Emits all the items emitted by source Observable regardless of when it has subscribed the Observable.


Behavior Subject

Upon subscription, emits the most recent item then continue to emit item emitted by the source Observable.


Async Subject

Emits the last item emitted by the source Observable after it's completes emission.