Showing posts from November, 2016

Streams and LambdaExpressions in Java 8

Introduction Typical processing patterns on collections were very hard up until Java 8 introduced a new abstraction called a Stream. Stream operations are chained together into pipelines. Other than that lambda expressions (JSR335) facilitate functional programming and simplifies the development a lot.
Workshop For an example consider the following real world use case. Suppose we have university system where an instructor can deliver questions (multiple choice) to students. Then students start responding the question with answers. The instructor needs to find following abstract information out of all the responses.
Percentage of correct responses. Assuming that the multiple choice question has four answer options, how many students have chosen each option.
If you implement this by following orthodox way, you may end up with many lines of code  blocks. That’s where Java8 comes to the rescue. By combining Java8 streams and lambda functions you can write each usecase in one single line of cod…