Preface
With the introduction of Java 8, many functional programming techniques have been added to the language. However, functional programming may seem unfamiliar to developers who are used to using imperative and object-oriented techniques. The new additions to Java 8 offer the opportunity to develop more maintainable and robust applications than that offered by earlier versions of Java.
The goal of this book is to introduce functional programming techniques to developers who are not familiar with this technology. You will be guided through the use of functional programming techniques with the help of numerous examples. Older imperative and object-oriented approaches will be illustrated and contrasted with equivalent functional programming solutions.
What this book covers
Chapter 1, Getting Started with Functional Programming, introduces the essential elements of functional programming as supported by Java 8. This includes the introduction of functional terms complemented by Java 8 examples.
Chapter 2, Putting the Function in Functional Programming, covers the types of functions found in functional programming languages such as high-order functions, first-class functions, and pure functions. The use of lambda expressions in support of functions is explained.
Chapter 3, Function Composition and Fluent Interfaces, addresses how to use functional composition. Also covered are fluent interfaces and the use of default methods.
Chapter 4, Streams and the Evaluation of Expressions, covers the basics of their creation and use. Streams are an important addition to Java.
Chapter 5, Recursion Techniques in Java 8, demonstrates recursion, a very useful functional programming technique. While not new to Java, we explore the topic in depth and examine the use of recursive lambda expressions.
Chapter 6, Optional and Monads, covers the use and the nature of monads in creating fluent interfaces and producing resilient code. The Optional class provides a better way of working with missing data.
Chapter 7, Supporting Design Patterns Using Functional Programming, illustrates design patterns. They play an important role in Java programming. The impact of the functional style of programming and lambda expressions is illustrated.
Chapter 8, Refactoring, Debugging, and Testing, demonstrates how these tools have been affected by the new functional programming techniques and how IDEs support them. These are valuable tools in the development process.
Chapter 9, Bringing It All Together, summarizes many of the functional programming techniques presented earlier that are used in the creation of a demonstration application. Such an application provides a concise illustration of how these techniques support the development of robust and maintainable software.
What you need for this book
Java SDK 1.8 is needed for the functional programming examples encountered in the book. Some of the examples use NetBeans 8.02 and Eclipse IDE for Java developers, Mars Release Version 4.5.0.
Who this book is for
This book is for developers who are already proficient in Java and want to learn how to use the functional programming features of Java 8. Familiarity with basic Java object-oriented programming concepts is all that is needed. You will learn how to apply lambda expressions and other functional programming techniques to create a more elegant and maintainable code.
Conventions
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 are shown are follows: "As you may remember, the forEach
method accepts a lambda expression which matches the Consumer
interface's accept
method."
A block of code is shown as follows:
list.forEach(new Consumer<String>() { @Override public void accept(String t) { System.out.println(t); } });
The output of code sequences is formatted as shown here:
Starting FPS Game Generating FPS Image Rendering FPS Image Updating FPS Game
New 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: "There is the text form as entered by the user such as: drop Axe."
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
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.
Customer support
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.
Downloading the example code
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. 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.
Errata
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
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.
Questions
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.