At the end of November I saw a post on Reddit about Oracle having a MOOC (Massive Open Online Course) on lambdas and streams in December 2016. I signed up and was enrolled. It was divided into three lessons starting in December, one lesson a week. At the end of each lesson there was a test.
Instructor Simon Ritter was very good at covering the subjects. The first lesson introduces lambda expressions, why it was added to Java 8, what problems it intends to solve. Then the syntax is described and basic usage.
One example is a list converted to uppercase:
List<String> myList = ... myList.replaceAll(s -> s.toUppercase);
So instead of manually creating a loop to iterate over the list and convert each element it is now told what to do. This small example is of course a bit contrived but shows the essence of lambda expressions.
Lesson two introduces the streams api and functional programming concepts. It “allows functions to be treated as values” and is the reason “Lambda expressions were required in JDK 8” (page 9).
One or more stream operations can be chained together. The last operation is a terminal operation.
List<String> l = Arrays.asList("a", "b", "c"); List<String> r = l.stream().limit(1).collect(Collectors.toList());
Lesson three covers streams in more detail. Streams can be serial or parallel. If an element in the source input is computational intensive it can be beneficial to parallelize the stream but it also incurs some overhead. This lesson have some tips on how and when to convert a streams to either serial or parallel.
This course by Oracle is recommended when a person like me knows “something” about lambdas and streams and have begun to explore them but still would like to know more when and where it can be put to work in an efficient manner.