Overview

Chapter 1. Introduction to reactive programming

This opening chapter welcomes readers coming from curiosity, prior use, or even skepticism about RxJava, and sets expectations for learning to “think in Rx” rather than merely memorizing syntax. It frames the book’s focus on RxJava 2 for Android, outlines what background helps (basic UI and Java, including lambdas), and explains why Java and RxJava are practical teaching choices. The author emphasizes the broader reactive landscape while keeping the scope on Android, previewing a hands-on, example-driven approach with exercises that build intuition for reactive design.

The chapter positions reactive programming among familiar paradigms—contrasting OOP’s stateful objects and FP’s declarative precision with FRP and Rx’s dataflow orientation. At RxJava’s core is a publish–subscribe model where observables emit values and subscribers react, with operators transforming data “in transit.” This mindset naturally handles asynchrony—time becomes a first-class concern, operations are decoupled, and edge cases are addressed explicitly rather than left to “gray code.” Visual tools like marble diagrams help reason about streams, sequence, and timing, reinforcing the idea that applications can be viewed as pipelines of inputs and outputs.

To anchor the concepts, the chapter walks through a live search example on Android: treating text input as a stream, filtering out short queries, and applying a debounce to wait for a brief pause before querying, all while ensuring UI work happens on the main thread. Using RxBindings to convert UI events into observables, the example shows how operators like filter and debounce encode business rules succinctly and robustly, illustrating how reactive code scales better by making timing, threading, and data transformation explicit. The chapter closes by encouraging readers to model inputs as streams, practice with small exercises, and learn to formulate problems in reactive terms—the key to finding simple, composable solutions with RxJava.

FAQ

What is reactive programming, and where does RxJava fit in?Reactive programming views an app as a flow of data and events that you transform and route. RxJava is the Java member of the ReactiveX family that provides Observables and a rich set of operators to compose event-driven, asynchronous code declaratively.
How do OOP, FP, FRP, and Rx differ?OOP centers on objects that encapsulate state and behavior. FP emphasizes pure functions and predictable transformations, which scale well with complex state. FRP extends FP with time-varying values and explicit relationships that “react” to changes. Rx (Reactive Extensions) is an umbrella for dataflow-style reactive libraries; FRP can be considered reactive, but not all reactive code is FRP.
Why use RxJava 2 for Android?It’s widely adopted, production-proven, and its concepts transfer across platforms. RxJava 2 refines the API (for example, disallowing nulls and introducing additional reactive types) and, together with RxAndroid and RxBinding, integrates naturally with Android UI work.
What are Observables and Subscribers in Rx?An Observable emits values over time (for example, text change events from an EditText). Subscribers (observers) listen to those emissions. Between the two, you compose operators that transform, filter, merge, or time-shift the data before it reaches the subscriber.
How does RxJava simplify asynchronous operations?In Rx, every step in a chain can be asynchronous by default. Because steps are decoupled, the next operator doesn’t need to know when the previous completes. This makes background work, timing, and concurrency feel natural instead of being special-case code.
What is debounce, and when should I use it?Debounce waits for a period of silence before emitting the most recent item. It’s perfect for UI inputs like live search: you can ignore rapid keystrokes and only trigger a search after the user pauses (often combined with a length filter to avoid short queries).
How do I safely integrate Rx chains with Android UI threads?Compose your chain after the view hierarchy exists (for example, in onCreate or onViewCreated), do it once, and before updating the UI, switch back to the main thread with observeOn(AndroidSchedulers.mainThread()). Time-based operators may work off the main thread, so always marshal UI work back to it.
What are marble diagrams, and why are they useful?Marble diagrams visualize events over time as circles on a left-to-right timeline. They help you reason about how operators like filter, delay, and debounce transform the timing and sequence of emitted items.
What should I know before starting with this book?You should be comfortable with basic UI development concepts and able to read Java (including Java 8 lambdas). You don’t need prior experience with reactive, FP, or OOP patterns, and Git is optional (though helpful for browsing examples).
How do I set up an Android project for RxJava 2?Use Android Studio, add RxJava 2, RxAndroid, and RxBinding dependencies to your Gradle build, and enable Java 8 language features for lambdas. Example projects and solutions are available from the book’s Manning page and the accompanying GitHub repository.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$399.99
only $33.33 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • RxJava for Android Developers ebook for free
choose your plan

team

monthly
annual
$49.99
$399.99
only $33.33 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • RxJava for Android Developers ebook for free