Introduction to Java 8 Lambda expressions

This is NOT the official website
of Java.
Let's create and run some Runnable! With Java 8, instead of using anonymous classes, we can use lambda expressions.
The syntax (params) -> statement is used to create an instance of Runnable by implementing its run method.
This is possible only for interfaces that have only one abstract method, and such interfaces are called functional interfaces.
Wait, aren't all interface methods abstract? Not anymore. See Defender (Default) methods.
Runnable r = () -> System.out.println("Hello!");
r.run(); // prints "Hello!"
 
 
// Before Java 8, we had to write code like this:
Runnable r = new Runnable() {
  @Override
    public void run() {
        System.out.println("Hello!");
    }
};