Java 8 in Action
Manning Publications (Verlag)
978-1-61729-199-9 (ISBN)
- Titel ist leider vergriffen;
keine Neuauflage - Artikel merken
Put simply, the new features in Java 8 are the biggest change to Java in the 18 years since Java 1.0 was released. Nothing has been taken away, so all your existing Java code continues to work—but the new features provide powerful new idioms and design patterns to help you write clearer, more concise code. At first you might think (as with all new features), “Why are they changing my language again?” But then, after a bit of practice, comes the revelation that you’ve just used the features to write shorter, clearer code in half the time you expected—and you realize you could never go back to “old Java” again.
This book, Java 8 in Action: Lambdas, streams, and functional-style programming, is written to get you over that initial hump of “sounds good in principle, but it’s all a bit new and unfamiliar” and into coding like a native.
“Perhaps,” you might think, “but lambdas, functional programming—aren’t those the sort of things that bearded sandal-wearing academics talk about in their ivory towers?” They might, but Java 8 has incorporated just the right balance of ideas into Java to gain many of their advantages in a way that’s comprehensible to ordinary Java programmers. And this book tells the story from the ordinary-programmer viewpoint, with an occasional “how this arose” for perspective.
“Lambdas—that sounds Greek to me!” Yes, it might, but it’s a great idea for enabling you to write concise Java programs. Many of you are familiar with event handlers and callbacks, where you register an object containing a method to be used when some event happens. Lambdas make this sort of idea much more widely usable in Java. Put simply, lambdas, and their friends, method references, provide the ability to concisely pass code or methods as arguments to be executed in the middle of doing something else. You’ll see in this book how this idea occurs more frequently than you might think: from simply parameterizing a sort method with code to do the comparison to expressing complex queries on collections of data using the new Streams API.
“Streams—what are they?” They’re a great new Java 8 addition. They behave like collections but have several advantages that enable new styles of programming. First, if you’ve ever programmed using a database query language such as SQL, you’ll recognize that it enables queries to be written in a few lines that would take many lines in Java. Java 8 streams support this concise database-queries style of programming—but with Java syntax and none of the need to know about databases! Second, streams are designed so that not all their data needs to be in memory (or even computed) at once. Thus you can process streams that are too big to fit in your computer memory. But Java 8 can optimize operations on streams in a way that Java can’t do for collections—for example, it can group together several operations on the same stream, so that the data is traversed only once instead of expensively traversing it multiple times. Even better, Java can automatically parallelize stream operations for you (unlike collections).
“And functional-style programming, what’s that?” It’s another style of programming, just like object-oriented programming, but centered on using functions as values, just as we mentioned previously when discussing lambdas.
What’s great about Java 8 is that it incorporates many of the best ideas from functional programming into the familiar Java syntax. The fine design choices enable you to see functional-style programming in Java 8 as an additional set of design patterns and idioms to enable you to write clearer, more concise code in less time. Think of it as having a wider range of weapons in your programming armory.
Oh yes, in addition to these features that lean on big conceptual additions to Java, we also explain the many other useful Java 8 features and updates such as default methods, the new Optional class, CompletableFuture, and the new Date and Time API.
But hey, this is an overview, and it’s time now for us to leave you to read the book.
Raoul-Gabriel Urma is a PhD candidate in Computer Science at the University of Cambridge. He holds a MEng degree in Computer Science from Imperial College London and graduated with first-class honors, having won several prizes for technical innovation. He has collaborated with large companies such as Google, eBay, Oracle, and Goldman Sachs, as well as worked on several startup projects. In addition, Raoul has authored over 10 peer-reviewed technical articles and given over 20 talks at international developer conferences.
Mario Fusco is a senior software engineer at Red Hat working on the core development of Drools, the JBoss rule engine. He has vast experience as a Java developer, having been involved in (and often leading) many enterprise-level projects in several industries ranging from media companies to the financial sector. Among his interests are functional programming and domain-specific languages. By leveraging these two passions he created the open source library lambdaj with the goal of providing an internal Java DSL for manipulating collections and allowing a bit of functional programming in Java.
Alan Mycroft is Professor of Computing in the Computer Laboratory of Cambridge University, where he has been a faculty member since 1984. He’s also a fellow at Robinson College, a cofounder of the European Association for Programming Languages and Systems, and a cofounder and trustee of the Raspberry Pi Foundation. He has degrees in Mathematics (Cambridge) and Computer Science (Edinburgh). He’s the author of around 100 research papers and has supervised more than 20 PhD theses. His research centers on programming languages and their semantics, optimization, and implementation. He maintains strong industrial links, having worked at AT&T Laboratories and Intel Research during academic leave, as well as spinning out Codemist Ltd., which built the original ARM C compiler under the Norcroft name.
preface
acknowledgments
about this book
about the authors
about the cover illustration
Part 1 Fundamentals
Chapter 1 Java 8: why should you care?
Why is Java still changing?
Functions in Java
Streams
Default methods
Other good ideas from functional programming
Summary
Chapter 2 Passing code with behavior parameterization
Coping with changing requirements
Behavior parameterization
Tackling verbosity
Real-world examples
Summary
Chapter 3 Lambda expressions
Lambdas in a nutshell
Where and how to use lambdas
Putting lambdas into practice: the execute around pattern
Using functional interfaces
Type checking, type inference, and restrictions
Method references
Putting lambdas and method references into practice!
Useful methods to compose lambda expressions
Similar ideas from mathematics
Summary
Part 2 Functional-style data processing
Chapter 4 Introducing streams
What are streams?
Getting started with streams
Streams vs. collections
Stream operations
Summary
Chapter 5 Working with streams
Filtering and slicing
Mapping
Finding and matching
Reducing
Putting it all into practice
Numeric streams
Building streams
Summary
Chapter 6 Collecting data with streams
Collectors in a nutshell
Reducing and summarizing
Grouping
Partitioning
The Collector interface
Developing your own collector for better performance
Summary
Chapter 7 Parallel data processing and performance
Parallel streams
The fork/join framework
Spliterator
Summary
Part 3 Effective Java 8 programming
Chapter 8 Refactoring, testing, and debugging
Refactoring for improved readability and flexibility
Refactoring object-oriented design patterns with lambdas
Testing lambdas
Debugging
Summary
Chapter 9 Default methods
Evolving APIs
Default methods in a nutshell
Usage patterns for default methods
Resolution rules
Summary
Chapter 10 Using Optional as a better alternative to null
How do you model the absence of a value?
Introducing the Optional class
Patterns for adopting Optional
Practical examples of using Optional
Summary
Chapter 11 CompletableFuture: composable asynchronous programming
Futures
Implementing an asynchronous API
Make your code non-blocking
Pipelining asynchronous tasks
Reacting to a CompletableFuture completion
Summary
Chapter 12 New Date and Time API
LocalDate, LocalTime, Instant, Duration, and Period
Manipulating, parsing, and formatting dates
Working with different time zones and calendars
Summary
Part 4 Beyond Java
Chapter 13 Thinking functionally
Implementing and maintaining systems
What’s functional programming?
Recursion vs. iteration
Summary
Chapter 14 Functional programming techniques
Functions everywhere
Persistent data structures
Lazy evaluation with streams
Pattern matching
Miscellany
Summary
Chapter 15 Blending OOP and FP: comparing Java 8 and Scala
Introduction to Scala
Functions
Classes and traits
Summary
Chapter 16 Conclusions and where next for Java
Review of Java 8 features
What’s ahead for Java?
The final word
appendix A Miscellaneous language updates
appendix B Miscellaneous library updates
appendix C Performing multiple operations in parallel on a stream
appendix D Lambdas and JVM bytecode
index
Zusatzinfo | black & white illustrations, figures |
---|---|
Sprache | englisch |
Maße | 177 x 245 mm |
Gewicht | 721 g |
Einbandart | kartoniert |
Themenwelt | Mathematik / Informatik ► Informatik ► Datenbanken |
Informatik ► Programmiersprachen / -werkzeuge ► Java | |
Informatik ► Software Entwicklung ► Objektorientierung | |
Informatik ► Software Entwicklung ► SOA / Web Services | |
Mathematik / Informatik ► Informatik ► Theorie / Studium | |
Mathematik / Informatik ► Informatik ► Web / Internet | |
Schlagworte | Java 8 • Java 8 (Programmiersprache); Handbuch/Lehrbuch |
ISBN-10 | 1-61729-199-4 / 1617291994 |
ISBN-13 | 978-1-61729-199-9 / 9781617291999 |
Zustand | Neuware |
Haben Sie eine Frage zum Produkt? |
aus dem Bereich