Book Image

Learning RxJava

By : Thomas Nield
Book Image

Learning RxJava

By: Thomas Nield

Overview of this book

RxJava is a library for composing asynchronous and event-based programs using Observable sequences for the JVM, allowing developers to build robust applications in less time. Learning RxJava addresses all the fundamentals of reactive programming to help readers write reactive code, as well as teach them an effective approach to designing and implementing reactive libraries and applications. Starting with a brief introduction to reactive programming concepts, there is an overview of Observables and Observers, the core components of RxJava, and how to combine different streams of data and events together. You will also learn simpler ways to achieve concurrency and remain highly performant, with no need for synchronization. Later on, we will leverage backpressure and other strategies to cope with rapidly-producing sources to prevent bottlenecks in your application. After covering custom operators, testing, and debugging, the book dives into hands-on examples using RxJava on Android as well as Kotlin.
Table of Contents (21 chapters)
Title Page
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Kotlin basics


Although Kotlin has a standalone compiler and can work with Eclipse, we are going to use Intellij IDEA.

A Kotlin project is structured much like a Java project. Following a standard Maven convention, you typically put your Kotlin source code in a /src/main/kotlin/ folder instead of a /src/main/java/ folder. The Kotlin source code is stored in text files with a .kt extension instead of .java. However, Kotlin files do not have to contain a class sharing the same name as the file.

Creating a Kotlin file

In Intellij IDEA, import your Kotlin project, if you haven't already. Right-click on the /src/main/kotlin/ folder and navigate to New | Kotlin File/Class, as shown in the following figure:

Figure 12.1: Creating a new Kotlin file

In the following dialog, name the file Launcher and then click on OK. You should now see the Launcher.kt file in the Project pane. Double-click on it to open the editor. Write the following "Hello World" Kotlin code, as shown here, and then run it by clicking...