Questions and coding challenges
In this section, we cover 21 questions and coding challenges that are very popular in interviews. Let's begin!
Coding challenge 1 – Lambda parts
Problem: Describe the parts of a lambda expression in Java. In addition, what characterizes a lambda expression?
Solution: As the following diagram reveals, a lambda has three main parts:
The parts of a lambda expression are as follows:
- On the left of the arrow, there are the parameters of this lambda that are used in the lambda body. In this example, these are the parameters of the
FilenameFilter.accept(File folder, String fileName)
method. - On the right of the arrow, there is the lambda body. In this example, the lambda body checks whether the folder (
folder
) in which the file (fileName
) was found can be read and whether the name of this file is suffixed with the .pdf string. - The arrow that sits between the list...