Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn Java 12 Programming

You're reading from   Learn Java 12 Programming A step-by-step guide to learning essential concepts in Java SE 10, 11, and 12

Arrow left icon
Product type Paperback
Published in Apr 2019
Publisher Packt
ISBN-13 9781789957051
Length 690 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Nick Samoylov Nick Samoylov
Author Profile Icon Nick Samoylov
Nick Samoylov
Arrow right icon
View More author details
Toc

Table of Contents (25) Chapters Close

Preface 1. Section 1: Overview of Java Programming FREE CHAPTER
2. Getting Started with Java 12 3. Java Object-Oriented Programming (OOP) 4. Java Fundamentals 5. Section 2: Building Blocks of Java
6. Exception Handling 7. Strings, Input/Output, and Files 8. Data Structures, Generics, and Popular Utilities 9. Java Standard and External Libraries 10. Multithreading and Concurrent Processing 11. JVM Structure and Garbage Collection 12. Managing Data in a Database 13. Network Programming 14. Java GUI Programming 15. Section 3: Advanced Java
16. Functional Programming 17. Java Standard Streams 18. Reactive Programming 19. Microservices 20. Java Microbenchmark Harness 21. Best Practices for Writing High-Quality Code 22. Java - Getting New Features 23. Assessments 24. Other Books You May Enjoy

RxJava

We will use RxJava 2.2.7 (http://reactivex.io) in our examples. It can be added to the project by the following dependency:

<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.2.7</version>
</dependency>

Let's first compare two implementations of the same functionality using the java.util.stream package and the io.reactivex package. The sample program is going to be very simple:

  • Create a stream of integers 1,2,3,4,5.
  • Filter only even numbers (2 and 4).
  • Calculate a square root of each of the filtered numbers.
  • Calculate the sum of all the square roots.

Here is how it can be implemented using the java.util.stream package:

double a = IntStream.rangeClosed(1, 5)
.filter(i -> i % 2 == 0)
.mapToDouble(Double::valueOf)
...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image