You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Welcome to the Lambda Programming Laboratory! The goal of thislab is for you to learn about the lambda expressions, default methods,and APIs (particularly the Streams library) introduced in Java 8, plusa few API additions in Java 9 and 10.
The lab is structured as a set of exercises in the form of JUnittests. To complete each exercise, write some code that uses alambda or new API that enables the test to pass.
Lab Instructions
Open the NetBeans development build (or your favorite IDE).
Open the LambdaLab project. If you don't have it, it can be clonedfrom github:
Each exercise is in the form of a single JUnit test method. Eachtest is marked with an @Ignore annotation so that JUnit will skip thattest initially.
To work on a test, delete the @Ignore annotation, fill in code atthe // TODO marker, trying to avoid modifying any setup code above theTODO marker and assertion code below the TODO marker.
Press Control-F6 to run the tests in this file.
Make all the tests pass and get a 100% green bar!
Detailed Test Description
At the top of each exercise is a comment that describes the goal ofthe exercise. Within the test method, there is a // TODO comment thatmarks the location where you need fill in some implementationcode. There may be some setup code above the // TODO comment, andthere will be some assertion-checking code below. You shouldn't haveto modify any of the setup code at the top of the test method or theassertions at the bottom of the test method.
There is sometimes a hint or two after a test method. If you're havingtrouble with an exercise, look for hints. The hint text is insidea editor fold that is closed by default, so click on the plus-signin the left margin to read it.
The intent of the exercises is to solve them using the Java 8 lambdaexpressions feature, the Java 8 default methods feature, the Java 8Streams API, and other APIs added in Java 8 or Java 9. Of course, itis possible to use conventional Java code, such as for-loops, but allof the exercises are amenable to being solved using new features injust a handful of lines. Most exercises will take less than half adozen lines. Some of the more difficult exercises may take up to eightlines, depending upon how aggressive you are about breakinglines. None of the exercises involve writing large amounts ofcode. Most of the streams-based exercises involve writing a singlestream pipeline.
Several of the exercises read data from a text file. The field named"reader" is a BufferedReader which will be opened for you on the textfile. In any exercise that refers to reading from the text file, youcan simply use the "reader" variable without worry about opening orclosing it. This is set up by JUnit using the @Before and @Aftermethods at the bottom of the file. The text file is "SonnetI.txt"(Shakespeare's first sonnet) which is located at the root of thisNetBeans project.
If you're really stuck, the solutions to the exercises are in the package
Test Packages > solutions
There is one solutions file corresponding to each exercise file. Manyexercises can be solved in several different ways. In some cases, thesolutions file will have several alternatives. Even if you've solvedan exercise, it can be useful to look at the solutions to compare yoursolutions with those of the lab authors.