SummaryManning's bestselling Java 8 book has been revised for Java 9! In Modern Java in Action, you'll build on your existing Java language skills with the newest features and techniques.Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.About the TechnologyModern applications take advantage of innovative designs, including microservices, reactive architectures, and streaming data. Modern Java features like lambdas, streams, and the long-awaited Java Module System make implementing these designs significantly easier. It's time to upgrade your skills and meet these challenges head on!About the BookModern Java in Action connects new features of the Java language with their practical applications. Using crystal-clear examples and careful attention to detail, this book respects your time. It will help you expand your existing knowledge of core Java as you master modern additions like the Streams API and the Java Module System, explore new approaches to concurrency, and learn how functional concepts can help you write code that's easier to read and maintain. What's insideThoroughly revised edition of Manning's bestselling Java 8 in ActionNew features in Java 8, Java 9, and beyondStreaming data and reactive programmingThe Java Module SystemAbout the ReaderWritten for developers familiar with core Java features.About the AuthorRaoul-Gabriel Urma is CEO of Cambridge Spark. Mario Fusco is a senior software engineer at Red Hat. Alan Mycroft is a University of Cambridge computer science professor; he cofounded the Raspberry Pi Foundation.Table of ContentsPART 1 - FUNDAMENTALS Java 8, 9, 10, and 11: what's happening? Passing code with behavior parameterization Lambda expressions PART 2 - FUNCTIONAL-STYLE DATA PROCESSING WITH STREAMS Introducing streams Working with streams Collecting data with streams Parallel data processing and performance PART 3 - EFFECTIVE PROGRAMMING WITH STREAMS AND LAMBDASCollection API enhancements Refactoring, testing, and debugging Domain-specific languages using lambdasPART 4 - EVERYDAY JAVA Using Optional as a better alternative to null New Date and Time API Default methods The Java Module System PART 5 - ENHANCED JAVA CONCURRENCY Concepts behind CompletableFuture and reactive programming CompletableFuture: composable asynchronous programming Reactive programming PART 6 - FUNCTIONAL PROGRAMMING AND FUTURE JAVA EVOLUTIONThinking functionally Functional programming techniques Blending OOP and FP: Comparing Java and Scala Conclusions and where next for Java brief contents......Page 3 contents......Page 5 preface......Page 16 about this book......Page 18 --- Fundamentals......Page 23 So, what’s the big story?......Page 24 Why is Java still changing?......Page 27 Functions in Java......Page 33 Streams......Page 38 Default methods and Java modules......Page 42 Other good ideas from functional programming......Page 44 Summary......Page 46 Passing code with behavior parameterization......Page 47 Coping with changing requirements......Page 48 Behavior parameterization......Page 51 Tackling verbosity......Page 56 Real-world examples......Page 60 Summary......Page 62 Lambda expressions......Page 63 Lambdas in a nutshell......Page 64 Where and how to use lambdas......Page 67 Putting lambdas into practice: the execute-around pattern......Page 71 Using functional interfaces......Page 74 Type checking, type inference, and restrictions......Page 80 Method references......Page 85 Putting lambdas and method references into practice......Page 91 Useful methods to compose lambda expressions......Page 93 Similar ideas from mathematics......Page 97 Summary......Page 99 --- Functional-Style data processing with streams......Page 100 Introducing streams......Page 101 What are streams?......Page 102 Getting started with streams......Page 106 Streams vs. collections......Page 108 Stream operations......Page 113 Road map......Page 116 Summary......Page 117 Working with streams......Page 118 Filtering......Page 119 Slicing a stream......Page 120 Mapping......Page 124 Finding and matching......Page 128 Reducing......Page 131 Putting it all into practice......Page 137 Numeric streams......Page 141 Building streams......Page 146 Summary......Page 152 Collecting data with streams......Page 154 Collectors in a nutshell......Page 156 Reducing and summarizing......Page 158 Grouping......Page 166 Partitioning......Page 174 The Collector interface......Page 179 Developing your own collector for better performance......Page 185 Summary......Page 191 Parallel data processing and performance......Page 192 Parallel streams......Page 193 The fork/join framework......Page 204 Spliterator......Page 210 Summary......Page 218 --- Streams & Lambdas......Page 219 Collection API enhancements......Page 220 Collection factories......Page 221 Working with List and Set......Page 224 Working with Map......Page 226 Improved ConcurrentHashMap......Page 232 Summary......Page 233 Refactoring, testing, and debugging......Page 235 Refactoring for improved readability and flexibility......Page 236 Refactoring object-oriented design patterns with lambdas......Page 242 Testing lambdas......Page 251 Debugging......Page 253 Summary......Page 257 Domain-specific languages using lambdas......Page 258 A specific language for your domain......Page 260 Small DSLs in modern Java APIs......Page 267 Patterns and techniques to create DSLs in Java......Page 271 Real World Java 8 DSL......Page 285 Summary......Page 290 --- Everyday Java......Page 292 Optional as better alternative to null......Page 293 How do you model the absence of a value?......Page 294 Introducing the Optional class......Page 298 Patterns for adopting Optionals......Page 299 Practical examples of using Optional......Page 310 Summary......Page 314 New Date & Time API......Page 315 LocalDate, LocalTime, LocalDateTime, Instant, Duration, and Period......Page 316 Manipulating, parsing, and formatting dates......Page 321 Working with different time zones and calendars......Page 328 Summary......Page 331 Default methods......Page 332 Evolving APIs......Page 335 Default methods in a nutshell......Page 338 Usage patterns for default methods......Page 340 Resolution rules......Page 344 Summary......Page 350 Java Module System......Page 351 The driving force: reasoning about software......Page 352 Why the Java Module System was designed......Page 354 Java modules: the big picture......Page 357 Developing an application with the Java Module System......Page 358 Working with several modules......Page 361 Compiling and packaging......Page 363 Automatic modules......Page 367 Module declaration and clauses......Page 368 A bigger example and where to learn more......Page 370 Summary......Page 371 --- Enhanced Java Concurrency......Page 372 CompletableFuture & reactive programming......Page 373 Evolving Java support for expressing concurrency......Page 376 Synchronous and asynchronous APIs......Page 382 The box-and-channel model......Page 389 CompletableFuture and combinators for concurrency......Page 391 Publish-subscribe and reactive programming......Page 394 Reactive systems vs. reactive programming......Page 401 Summary......Page 402 CompletableFuture - composable asynchronous programming......Page 403 Simple use of Futures......Page 404 Implementing an asynchronous API......Page 407 Making your code nonblocking......Page 412 Pipelining asynchronous tasks......Page 418 Reacting to a CompletableFuture completion......Page 427 Summary......Page 430 Reactive programming......Page 432 The Reactive Manifesto......Page 433 Reactive streams and the Flow API......Page 437 Using the reactive library RxJava......Page 447 Summary......Page 457 --- Functional programming & future Java evolution......Page 458 Thinking functionally......Page 459 Implementing and maintaining systems......Page 460 What’s functional programming?......Page 463 Recursion vs. iteration......Page 469 Summary......Page 473 Functional programming techniques......Page 474 Functions everywhere......Page 475 Persistent data structures......Page 478 Lazy evaluation with streams......Page 483 Pattern matching......Page 490 Miscellany......Page 495 Summary......Page 498 Blending OOP and FP: Comparing Java and Scala......Page 499 Introduction to Scala......Page 500 Functions......Page 507 Classes and traits......Page 511 Summary......Page 513 Conclusions and where next for Java......Page 514 Review of Java 8 features......Page 515 The Java 9 module system......Page 518 Java 10 local variable type inference......Page 519 What’s ahead for Java?......Page 521 Moving Java forward faster......Page 528 The final word......Page 529 A.1 Annotations......Page 531 A.2 Generalized target-type inference......Page 534 B.1 Collections......Page 535 B.2 Concurrency......Page 538 B.3 Arrays......Page 540 B.4 Number and Math......Page 541 B.7 String......Page 542 Performing multiple operations in parallel on Stream......Page 543 C.1 Forking a stream......Page 544 C.2 Performance considerations......Page 551 D.1 Anonymous classes......Page 552 D.2 Bytecode generation......Page 553 D.3 Invokedynamic to the rescue......Page 554 D.4 Code-generation strategies......Page 555 index......Page 557 "A comprehensive and practical introduction to the modern features of the latest Java releases with excellent examples!" Oleksandr Mandryk, EPAM Systems Manning's bestselling Java 8 book has been revised for Java 9 and 10! In Modern Java in Action , you'll build on your existing Java language skills with the newest features and techniques. Modern applications take advantage of innovative designs, including microservices, reactive architectures, and streaming data. Modern Java features like lambdas, streams, and the long-awaited Java Module System make implementing these designs significantly easier. It's time to upgrade your skills and meet these challenges head on! Modern Java in Action connects new features of the Java language with their practical applications. Using crystal-clear examples and careful attention to detail, this book respects your time. It will help you expand your existing knowledge of core Java as you master modern additions like the Streams API and the Java Module System, explore new approaches to concurrency, and learn how functional concepts can help you write code that's easier to read and maintain. Inside: Thoroughly revised edition of Manning's bestselling Java 8 in Action New features in Java 8, Java 9, and beyond Streaming data and reactive programming The Java Module System Written for developers familiar with core Java features. Raoul-Gabriel Urma is CEO of Cambridge Spark. Mario Fusco is a senior software engineer at Red Hat. Alan Mycroft is a University of Cambridge computer science professor; he cofounded the Raspberry Pi Foundation. My Java code improved significantly after reading this book. I was able to take the clear examples and immediately put them into practice. Holly Cummins, IBM Hands-on Java 8 and 9, simply and elegantly explained. Deepak Bhaskaran, Salesforce A lot of great examples and use cases for streams, concurrency, and reactive programming. Rob Pacheco, Synopsys NARRATED BY SARAH DAWE AND LOU FERNANDEZ