Book Image

Learning RxJava - Second Edition

By : Nick Samoylov, Thomas Nield
Book Image

Learning RxJava - Second Edition

By: Nick Samoylov, Thomas Nield

Overview of this book

RxJava is not just a popular library for building asynchronous and event-based applications; it also enables you to create a cleaner and more readable code base. In this book, you’ll cover the core fundamentals of reactive programming and learn how to design and implement reactive libraries and applications. Learning RxJava will help you understand how reactive programming works and guide you in writing your first example in reactive code. You’ll get to grips with the workings of Observable and Subscriber, and see how they are used in different contexts using real-world use cases. The book will also take you through multicasting and caching to help prevent redundant work with multiple Observers. You’ll then learn how to create your own RxJava operators by reusing reactive logic. As you advance, you’ll explore effective tools and libraries to test and debug RxJava code. Finally, you’ll delve into RxAndroid extensions and use Kotlin features to streamline your Android apps. By the end of this book, you'll become proficient in writing reactive code in Java and Kotlin to build concurrent applications, including Android applications.
Table of Contents (22 chapters)
1
Section 1: Foundations of Reactive Programming in Java
5
Section 2: Reactive Operators
12
Section 3: Integration of RxJava applications
Appendix B: Functional Types
Appendix E: Understanding Schedulers

What this book covers

Chapter 1, Thinking Reactively, covers a brief history of Reactive Extensions and RxJava, and describes how to set up your first RxJava project and build your first reactive application. It also touches on the differences between RxJava 1.x, 2.x, and 3.0.

Chapter 2, Observable and Observer, provides the foundation for the following presentation of RxJava by introducing the two main terms Observable and Observer. It also presents the Observable specializations of Single, Completable, Maybe, and Disposable.

Chapter 3, Basic Operators, presents the basic RxJava operators. This is necessary for understanding the more complex operators described in the chapters that follow.

Chapter 4, Combining Observables, starts the transition from making RxJava useful to making it powerful. It covers the operators that allow several source observables to be combined into one resulting Observable.

Chapter 5, Multicasting, Replaying, and Caching, explains what multicasting is, and how to replay and cache emissions. It also presents how to use the Subject object and automatic connections.

Chapter 6, Concurrency and Parallelization, explores more of the nuances of RxJava and how to effectively leverage concurrency.

Chapter 7, Switching, Throttling, Windowing, and Buffering, explains and demonstrates the buffering, windowing, throttling, and switching of emissions.

Chapter 8, Flowable and Backpressure, discusses different ways to cope with backpressure while processing reactive streams. Backpressure happens when data/events are produced faster than they can be consumed.

Chapter 9, Transformers and Custom Operators, explains how to compose new operators from existing ones, how to create a new one from scratch, and how to use rxjava2-extras and rxjava2-extensions for that purpose.

Chapter 10, Testing and Debugging, covers configuring JUnit, blocking subscribers, blocking operators, using TestObserver and TestSubscriber, manipulating time with TestScheduler, and debugging RxJava code.

Chapter 11, RxJava on Android, explains step by step how to create an Android project, how to configure Retrolambda, and how to use RxJava and RxAndroid using RxBinding and other RxAndroid binding libraries.

Chapter 12, Using RxJava with Kotlin, covers several miscellaneous but essential topics, including custom operators, as well as how to use RxJava with testing frameworks, Android, and the Kotlin language.

Appendix A, Introducing Lambda Expressions, provides a short introductory course on Java lambda expressions, which does not require any prior knowledge of the topic.

Appendix B, Functional Types, lists functional interfaces that are included in RxJava 1.*, RxJava 2.*, and RxJava 3.0 – listed with their single-method signature and an indication of which RxJava version has it.

Appendix C, Mixing Object-Oriented and Reactive Programming, presents a discussion on using object-oriented programming in conjunction with RxJava.

Appendix D, Materializing and Dematerializing, introduces the concepts of materializing and dematerializing, along with code examples that demonstrate how they can be used.

Appendix E, Understanding Schedulers, defines the purpose and functionality of schedulers and demonstrates their usage.