Welcome to Functional Programming for Java Developers
Why should a Java developer learn about functional programming (FP)? After all, hasnt functional programming been safely hidden in academia for decades? Isnt object- oriented programming (OOP) all we really need? This book explains why functional programming has become an important tool for the challenges of our time and how you, a Java developer, can use it to your advantage.
) is difficult to do well and few developers are good at it. As well see, functional programming offers better strategies for writing robust, concurrent software.
An example of the greater need for horizontal scalability is the growth of massive data sets requiring management and analysis, the so-called big data trend. These are data sets that are too large for traditional database management systems. They require clusters of computers to store and process the data. Today, its not just Google, Yahoo!, Facebook, and Twitter who work with big data. Many organizations face this challenge.
(OReilly). Scala is a JVM language, a potential successor to Java, with the goal of bringing object-oriented and functional programming into one coherent whole. Clojure is the other well-known functional language on the JVM. It is a Lisp dialect that minimizes the use of OOP in favor of functional programming. Clojure embodies a powerful vision for how programming should be done.
Fortunately, you dont have to adopt a new language to enjoy many of the benefits of functional programming. Back in early 1990s, I used an object-oriented approach in the C software I wrote, until I could use C++. Similarly, if youre working with an object-oriented language, like Java, you can still apply many of the ideas from functional programming.
Unfortunately, much of the literature on functional programming is difficult to understand for people who are new to it. This short book offers a pragmatic, approachable introduction to functional programming. While aimed at the Java developer, the principles are general and will benefit anyone familiar with an object-oriented language.
I assume that you are well versed in object-oriented programming and you can read Java code. Youll find some exercises at the end of each chapter to help you practice and expand on what youve learned.
Because this is a short introduction and because it is difficult to represent some functional concepts in Java, there will be several topics that I wont discuss in the text, although I have added glossary entries, for completeness. These topics include currying , partial application , and comprehensions . Ill briefly discuss several other topics, such as combinators , laziness , and monads , to give you a taste of their importance. However, fully understanding these topics isnt necessary when youre new to functional programming.
I hope you find functional programming as seductive as I did. Let me know how it goes!
You can learn more at the books catalog page (http://oreilly.com/catalog/9781449311032/).
Conventions Used in This Book
The following typographical conventions are used in this book:
ItalicIndicates new terms, URLs, email addresses, filenames, and file extensions. Many italicized terms are defined in the .
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
Tip
This icon signifies a tip, suggestion, or general note.
Caution
This icon indicates a warning or caution.
Using the Code Examples
This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from OReilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your products documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: Functional Programming for Java Developers , by Dean Wampler (OReilly). Copyright 2011 Dean Wampler, 978-1-449-31103-2.
.
Some of the code examples were adapted from examples provided with the Akka distribution, copyright 2009-2011 Scalable Solutions AB. The Akka code base is covered by the Apache 2 License.
Getting the Code Examples
You can download the code examples from http://examples.oreilly.com/9781449311032/. Unzip the files to a convenient location. See the README
file in the distribution for instructions on building and using the examples.
Note that some of the files wont actually compile, because they introduce speculative concepts that arent supported by current compilers or libraries. Those files end with the extension .javax
. (The build process skips them.)
Safari Books Online
Note
Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly.
With a subscription, you can read any page and watch any video from our library online. Read books on your cell phone and mobile devices. Access new titles before they are available for print, and get exclusive access to manuscripts in development and post feedback for the authors. Copy and paste code samples, organize your favorites, download chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features.