-
Book Overview & Buying
-
Table Of Contents
Learning RxJava
By :
Reactive programming is more than a technology or library specification. It is an entirely new mindset in how we solve problems. The reason it is so effective and revolutionary is it does not structure our world as a series of states, but rather something that is constantly in motion. Being able to quickly capture the complexity and dynamic nature of movement (rather than state) opens up powerful new possibilities in how we represent things with code.
When I first learned Java and object-oriented programming, I felt it was useful, but not effective enough. Although OOP is useful, I believed it needed to be paired with something else to be truly productive, which is why I keep an eye on C# and Scala. Only a few years later, Java 8 came out, and I put functional programming into practice for the first time.
However, something was still missing. I became fascinated with the idea of a value notifying another value of its change, and an event triggering another event in a domino effect. Was there not a way to model events in a fluent and functional way, much like Java 8 Streams? When I voiced this idea one day, somebody introduced me to reactive programming. What I was looking for was the RxJava Observable, which, at first glance, looked a lot like a Java 8 Stream. The two look and feel similar, but the Observable pushes not just data but also events. At that moment, I found exactly what I was looking for.
For me, as well as many others, a challenge in learning RxJava is the lack of documentation and literature. I was often left experimenting, asking questions on Stack Overflow, and trawling obscure issues on GitHub to become knowledgeable. As I used RxJava heavily for some business problems at work, I wrote several blog articles, sharing my discoveries on topics such as parallelization and concurrency. To my surprise, these articles exploded with traffic. Perhaps this should not have been surprising since these topics were sparsely documented anywhere else. When Packt approached me to write my second book, Learning RxJava, I jumped at the opportunity despite the work involved. Maybe, just maybe, this book can solve the documentation problem once and for all. Every fundamental concept, use case, helpful trick, and "gotcha" can be made accessible, and RxJava will no longer be considered an "advanced topic." I believe RxJava should be made accessible to professional developers of all skill levels, as it effectively makes hard problems easy and easy problems even easier. It may require a bit more abstract understanding, but the immediate productivity gained makes this small hurdle worthwhile.
As far as I know, this is the first published book covering RxJava 2.0, which has many major differences from RxJava 1.0. This book you are reading now is the comprehensive, step-by-step guide that I wish I had. It strives to not cut any corners or present code without thorough explanation. I hope it helps you quickly find value in RxJava, and you become successful in applying it to all your endeavors. If you have any concerns, feedback, or comments, you are welcome to reach out to me at [email protected].
Good luck!
Thomas Nield
Chapter 1, Thinking Reactively, introduces you to RxJava.
Chapter 2, Observables and Subscribers, talks about the core types in RxJava, including the Observable and Observer.
Chapter 3, Basic Operators, gives you a thorough introduction to the core operators that allow you to express logic quickly and make RxJava productive.
Chapter 4, Combining Observables, teaches you how to usefully combine multiple Observable sources together in a variety of ways.
Chapter 5, Multicasting, Replaying, and Caching, consolidates streams to prevent redundant work with multiple Observers, as well as replay and cache emissions.
Chapter 6, Concurrency and Parallelization, helps you discover how RxJava flexibly and powerfully enables concurrency in your application.
Chapter 7, Switching, Throttling, Windowing, and Buffering, develops strategies to cope with rapidly-producing Observables without backpressure.
Chapter 8, Flowables and Backpressure, utilizes the Flowable to leverage backpressure and keep producers from out-pacing consumers.
Chapter 9, Transformers and Custom Operators, teaches you how to reuse reactive logic and create your own RxJava operators.
Chapter 10, Testing and Debugging, leverages effective tools to test and debug your RxJava code bases.
Chapter 11, RxJava on Android, teaches you how to apply your RxJava knowledge and RxAndroid extensions to streamline your Android apps.
Chapter 12, Using RxJava for Kotlin New, takes advantage of Kotlin’s language features to enable expressive patterns with RxJava.
We will be using Java 8, so Oracle’s JDK 1.8 will be required. You will need an environment to write and compile your Java code (I recommend Intellij IDEA), and preferably a build automation system such as Gradle or Maven. Later in this book, we will use Android Studio.
Everything you need in this book should be free to use and not require commercial or personal licensing.
This book is for Java programmers who have a fundamental grasp of object-oriented programing and core Java features. You should be familiar with variables, types, classes, properties, methods, generics, inheritance, interfaces, and static classes/properties/methods. In the Java standard library, you should at least be familiar with collections (including Lists, Sets, and Maps) as well as object equality (hashcode()/equals()). If any of these topics sound unfamiliar, you may want to read Java: A Beginner’s Guide by Herbert Schildt to learn the fundamentals of Java. Also, Effective Java (2nd Edition) by Joshua Bloch is a classic book that should be on every Java developer’s shelf. This book strives to use the best practices cited by Bloch.
You do not need to be familiar with concurrency as a prerequisite. This topic will be covered from an RxJava perspective.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can also use several operators between Observable and Observer to transform each pushed item or manipulate them in some way".
A block of code is set as follows:
import io.reactivex.Observable;
public class Launcher {
public static void main(String[] args) {
Observable<String> myStrings =
Observable.just("Alpha", "Beta", "Gamma", "Delta",
"Epsilon");
}
}
Any output is written as follows:
Alpha
Beta
Gamma
Delta
EpsilonNew terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "You also have the option to use Maven, and you can view the appropriate configuration in The Central Repository by selecting the Apache Maven configuration information."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
SUPPORT tab at the top.Code Downloads & Errata.Search box.Code Download.Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Learning-RxJava. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at [email protected] with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.
Change the font size
Change margin width
Change background colour