Learning Reactive Programming with Java 8

Book description

Learn how to use RxJava and its reactive Observables to build fast, concurrent, and powerful applications through detailed examples

  • Learn about Java 8's lambdas and what reactive programming is all about, and how these aspects are utilized by RxJava

  • Build fast and concurrent applications with ease, without the complexity of Java's concurrent API and shared states

  • Explore a wide variety of code examples to easily get used to all the features and tools provided by RxJava

  • In Detail

    Whether you are a Java expert or at a beginner level, you'll benefit from this book, because it will teach you a brand new way of coding and thinking.

    The book starts with an explanation of what reactive programming is, why it is so appealing, and how we can integrate it in to Java. It continues by introducing the new Java 8 syntax features, such as lambdas and function references, and some functional programming basics. From this point on, the book focuses on RxJava in depth. It goes through creating Observables, transforming, filtering, and combining them, and concurrency and testing to finish with extending the library itself.

    This book is a definite tutorial in RxJava filled with a lot of well-described examples. It explains reactive programming concepts in plain and readable language, without scientific formulas and terms.

    What You Will Learn

  • Discover what reactive programming is and how you can benefit from it

  • Get to grips with the new functional features of Java 8 and some functional theory

  • Create RxJava Observable instances from virtually any data source

  • Transform, filter, and accumulate your data using various RxJava operators

  • Combine multiple data sources in one dataset, using custom logic

  • Write concurrent programs with ease, scheduling actions on various workers

  • Learn about unit testing asynchronous RxJava logic

  • Extend RxJava by writing your own operators and factory methods

  • Table of contents

    1. Learning Reactive Programming with Java 8
      1. Table of Contents
      2. Learning Reactive Programming with Java 8
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. An Introduction to Reactive Programming
        1. What is reactive programming?
        2. Why should we be reactive?
        3. Introducing RxJava
          1. Downloading and setting up RxJava
          2. Comparing the iterator pattern and the RxJava Observable
          3. Implementing the reactive sum
        4. Summary
      9. 2. Using the Functional Constructions of Java 8
        1. Lambdas in Java 8
          1. Introducing the new syntax and semantics
          2. Functional interfaces in Java 8 and RxJava
        2. Implementing the reactive sum example with lambdas
        3. Pure functions and higher order functions
          1. Pure functions
          2. Higher order functions
          3. RxJava and functional programming
        4. Summary
      10. 3. Creating and Connecting Observables, Observers, and Subjects
        1. The Observable.from method
        2. The Observable.just method
        3. Other Observable factory methods
        4. The Observable.create method
        5. Subscribing and unsubscribing
        6. Hot and cold Observable instances
          1. The ConnectableObservable class
        7. The Subject instances
        8. Summary
      11. 4. Transforming, Filtering, and Accumulating Your Data
        1. Observable transformations
          1. Transformations with the various flatMap operators
          2. Grouping items
          3. Additional useful transformation operators
        2. Filtering data
        3. Accumulating data
        4. Summary
      12. 5. Combinators, Conditionals, and Error Handling
        1. Combining the Observable instances
          1. The zip operator
          2. The combineLatest operator
          3. The merge operator
          4. The concat operator
        2. The conditional operators
          1. The amb operator
          2. The takeUntil(), takeWhile(), skipUntil(), and skipWhile() conditional operators
          3. The defaultIfEmpty( ) operator
        3. Handling errors
          1. The return and resume operators
          2. The retrying technique
        4. An HTTP client example
        5. Summary
      13. 6. Using Concurrency and Parallelism with Schedulers
        1. RxJava's schedulers
          1. Debugging Observables and their schedulers
          2. The interval Observable and its default scheduler
          3. Types of schedulers
            1. The Schedulers.immediate scheduler
            2. The Schedulers.trampoline scheduler
            3. The Schedulers.newThread scheduler
            4. The Schedulers.computation scheduler
            5. The Schedulers.io scheduler
            6. The Schedulers.from(Executor) method
          4. Combining Observables and schedulers
            1. The Observable<T> subscribeOn(Scheduler) method
            2. The Observable<T> observeOn(Scheduler) operator
          5. Parallelism
        2. Buffering, throttling, and debouncing
          1. Throttling
          2. Debouncing
          3. The buffer and window operators
          4. The backpressure operators
        3. Summary
      14. 7. Testing Your RxJava Application
        1. Testing using simple subscription
        2. The BlockingObservable class
        3. The aggregate operators and the BlockingObservable class
        4. Testing with the aggregate operators and the BlockingObservable class
        5. Using the TestSubscriber class for in-depth testing
        6. Testing asynchronous Observable instances with the help of the TestScheduler class
        7. Summary
      15. 8. Resource Management and Extending RxJava
        1. Resource management
          1. Introducing the Observable.using method
        2. Caching data with Observable.cache
        3. Creating custom operators with lift
        4. Composing multiple operators with the Observable.compose operator
        5. Summary
      16. Index

    Product information

    • Title: Learning Reactive Programming with Java 8
    • Author(s): Nickolay Tsvetinov
    • Release date: June 2015
    • Publisher(s): Packt Publishing
    • ISBN: 9781785288722