Chapter 2. Reactive Extensions

This chapter will guide you through the core concepts related to Reactive Extensions and RxJava. You will become very comfortable with Observable<T>, Observer<T>, and Subscriber<T> and a few helpful utility methods called operators. Observable is the core API RxJava, so make sure you understand how it works and what it represents. Throughout this chapter, you will learn what Observable really is and how to create it and interact with it. The knowledge you gain is essential to idiomatically provide and consume reactive APIs based on RxJava. RxJava was designed to ease the pain of asynchronous and event-driven programming, but you must understand some core principles and semantics in order to take advantage of that. When you grasp how Observable collaborates with client code, you will feel a lot of power under your fingertips. After reading this chapter, you will be capable of creating simple streams of data, ready to be combined and composed in very interesting ways.

Anatomy of rx.Observable

rx.Observable<T> represent a flowing sequence of values. It is the abstraction that you will use all of the time. Because these values often appear over a wide time range, we tend to think about an Observable as a stream of events. If you look around you will find many examples of streams:

  • User interface events

  • Bytes transferred over the network

  • New orders in online shopping

  • Posts on social-media websites

If you want to compare Observable<T> ...

Get Reactive Programming with RxJava now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.