Code, exercises and solutions from the book "Functional Programming in Java"
This repository contains code, exercises and solutions from the book “Functional Programming in Java”. Along with the book itself, it’s the
closest you’ll get to having your own private functional programming tutor without actually having one.
The code is available as a Gradle project that may be used by:
One may of course use only the source files to import them into any other editor and/or compile and run them from the command line. Running Gradle
commands will not be described here. If you choose this way, you should already know how to do it.
There are two ways to download this project. You may:
Note: Eclipse is not fully compatible with Java. Eclipse does not use the Oracle compiler. The compiler used by Eclipse is not fully compatible with the Oracle Java 8 compiler. This might change in the future, but at this time, not all chapter examples will run under Eclipse. You can use Eclipse Luna to edit and run the code through chapter 8. You can’t use Eclipse Mars. We have no information about if and when this will be fixed.
To import the project into Eclipse, you must first install the Gradle plug-in. To do this:
You will have to accept installing unverified software, and then restarting Eclipse.
You now need to import the fpinjava-parent
project into Eclipse:
fpinjava-parent
directoryTo import the project into intelliJ:
fpinjava-parent
directory.fpinjava-parent
project in the Project pane, right-click the project and select Open module settings.To import the project into Netbeans, you must first install the Gradle plug-in. To do this:
You will have to accept installing unsigned software, and then restarting NetBeans.
You now need to import the fpinjava-parent
project into NetBeans:
fpinjava-parent
project nameThe project should now be imported.
For each chapter, you will find two modules called chaptername-exercises
and chaptername-solutions
. Go to the first exercise in
the src/main/java
hierarchy. Here, you will find some code with either a comment saying “To be implemented” or method(s) with the
implementation replaced with a single line throwing a runtime exception. Just implement the missing code.
Note that code is often duplicated from one exercise to the another, so you should not look at the code for exercise 2 before doing exercise 1,
since exercise 2 will often contain the solution to exercise one.
To verify that your solution is working, go to the corresponding unit test, in the src/test/java
hierarchy of the same module. Right-click
on the test class (which has the same name as the exercise class with the addition of the Test
suffix) and select Run as JUnit test. The test should
succeed. If it doesn’t, fix your code and try again.
If you don’t find the correct solution to an exercise, you can look at the corresponding chaptername-solutions
module. You may run the solution
test to verify that the solution is working.
Lots of code is duplicated. This is done so that all exercises are made as independent as possible. However, code reused from previous chapters
is copied to the fpinjava-common
module and should be used from there.
Code modules are generally named after the chapter titles, and not the chapter numbers, which sometimes make them difficult to find. Here is the list of the modules:
Chapter 1: fpinjava-introduction
Chapter 2: fpinjava-usingfunctions
Chapter 3: fpinjava-makingjavafunctional
Chapter 4: fpinjava-recursion
Chapter 5: fpinjava-lists
Chapter 6: fpinjava-optionaldata
Chapter 7: fpinjava-handlingerrors
Chapter 8: fpinjava-advancedlisthandling
Chapter 9: fpinjava-laziness
Chapter 10: fpinjava-trees
Chapter 11: fpinjava-advancedtrees
Chapter 12: fpinjava-state
Chapter 13: fpinjava-io
Chapter 14: fpinjava-actors
Chapter 15: fpinjava-applications
Most modules exist in two versions: exercises and solutions. However, chapters 1 (fpinjava-introduction), 14 (fpinjava-actors) and 15 (fpinjava-applications) have no exercises.
Most modules have unit tests that may be run to verify that your solutions to exercises are correct. However, chapter 13 has not unit tests. Instead, all packages in this chapter have executable programs that may be run to verify that the output corresponds to what is expected.