On 18 March 2014, Oracle released Java 8 into the wild, introducing Java developers to many new features. Of particular interest are those features added that facilitate programming in the functional style. Being an imperative language, effective use of these new constructs can feel foreign, even to the most seasoned Java programmer.
The aim of this tutorial is to provide a hands-on introduction to these new features in a way that should feel familiar to to even the casual Java programmer.
The intended audience of this tutorial are Java developers, from casual to experienced, interested in learning about the features available in Java 8 that facilitate programming in the functional style. There is no expectation for the reader to be familiar with anything beyond basic Java syntax and standard Java APIs (the reader does not need to be familiar with any external libraries).
For readers that are new to Java and wonder if this tutorial is right for them, links to important API documentation are included throughout the tutorial.
- Java 8 SDK (tested with update 111 for macOS).
- Apache Maven (tested with version 3.2.5)
- git (tested with version 2.9.3)
- POSIX shell (e.g., bash) in a UNIX-like environment (e.g., Linux, macOS, BSD, etc.) or confidence in converting commands into your preferred environment.
- A text editor or Java IDE, such as Intellij CE (recommended) or Eclipse.
- (Optional) Markdown support for Intellij.
All of the exercises require writing very short snippets of Java that can easily be completed with an ordinary text editor. Although an IDE is probably overkill for this tutorial, the files are organized to be IDE-friendly. Being new to Java 8, you may benefit from the features of an IDE (such as auto-completion and inline-debugging), allowing you to focus on code structure.
If you prefer using an IDE but don't know which to choose, Consider trying the free Intellij IDEA Community Edition from Jetbrains.
The entire tutorial, including the code skeletons to be filled in, can all be found in this github repo.
To clone the repo, open up a terminal and navigate to the directory under which you would like to store the tutorial:
cd ~/tutorials
then clone the repo using git
command:
git clone https://github.com/mkralka/functional-java-tutorial
then navigate to the root of repo:
cd functional-java-tutorial
It's a good idea to verify your environment is set up for the exercises before getting started on the tutorial. This can be done by running the following command from the root of the repo:
mvn test -Dtest=SetupTest
If all goes well, the output from the above command will end with a tests section that will look similar to the following:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running functionaljava.SetupTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@759ebb3d
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.402 sec
Results :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.968 s
[INFO] Finished at: 2016-12-05T19:43:52-08:00
[INFO] Final Memory: 16M/259M
[INFO] ------------------------------------------------------------------------
The tutorial begins here.
If you would prefer reading the tutorial offline, you have several options:
- Use your favorite editor/text reader (e.g., vim, less, etc) and open
tutorial/start.md
. - Use your favorite web browser with support for markdown preview (e.g.,
Chrome with the
Markdown Preview Plus
extension) and open
tutorial/start.md
. - Use your IDE with support for markdown preview (e.g.,
Intellij IDEA with the
Markdown support plugin) and
open
tutorial/start.md
.
Although the entire tutorial is written in markdown (making it possible to following using your favorite plain-text reader) you may find it more satisfying to use a markdown previewer that supports hyperlinks.