This is the accompanying repository for the O'Reilly book A Functional Approach to Java.
The repository is structured like the book.
Each explicit example has its own directory containing code, usually Java and JShell files.
The actual implementation of the examples might differ from their counterparts in the book to make them easier to use.
Many examples are supposed to highlight how a specific code syntax is used and don't represent a full-fledged example with actual output. Especially JShell scripts don't have explicit output, but the results are printed anyway.
Nevertheless, the examples should be helpful as a starting point to experiment.
To not require a myriad of intermediate folders (src/main/java
etc.), the examples are plain files with an adapted classpath.
This way, you can start sill start examples with Gradle.
All examples are grouped by chapters, see:
./gradlew tasks
The task name for each example is unique and runs without requiring the subproject:
# Actually runs :02-functional-java:example-2-9
./gradlew example-2-9
Examples with lowercase-dash-separated names are JShell-compatible files.
They have the .jsh
extension, so they do not clash with the .java
files for Gradle.
The examples from the book can mostly be run directly in JShell:
jshell part-2/06-data-processing-with-streams/example-6-15/fruits-naive.jsh
# or
cd part-2/06-data-processing-with-streams/example-6-15/
jshell fruits-naive.jsh
Some code, however, demonstrates invalid code, throws Exceptions, or won't compile at all. Other examples won't compile due to parsing rules of new lines. I've tried to mark such examples with a comment in the header.
Besides using the O'Reilly Learning Platform, you can buy a paperback version of the book at your favorite store. Here are a few direct links to US stores:
ISBN-10: 1098109929
ISBN-13: 9781098109929
The book is also available in Polish and Korean: