A Subject is a consumer and an Observable at the same time. It means that it can listen for values from other Observables (subscribe to Observable), and it can produce values for other subscribers. So, for example, the following code is valid with a Subject:
Subject<String> subject = ...;
subject.subscribe(v -> log(v));
Observable.just("1")
.subscribe(subject);
We can see that, on the second line, we were able to subscribe to the subject successfully, and it means that it acts as Observable here. On the third line, we made the subject listen to the changes that this other Observable will produce.
As we will see later, this can come in extremely handy when we want to connect individual Observables without creating direct dependencies between them. In a sense, the Subject often acts as a mediator.
For example, sometimes we might want to react to certain changes, but we are not sure when they will happen and who will produce them, meaning that the source of the changes could be dynamic. Thus, we want to have a dedicated source of such data with ways to write to that source later.
As we will see in the following sections, there are four different Subjects and each of them is used best on various occasions.