This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> collection = | |
Arrays.asList("enes", "emre", "mert", "burak"); | |
collection.stream() | |
.filter(s -> s.startsWith("e")) | |
.sorted() | |
.forEach(System.out::println); | |
// emre | |
// enes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Printable { | |
void printMessage(String message); | |
} | |
class Message { | |
public Message(String message) { | |
System.out.println(message); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Printable { | |
void printMessage(); | |
} | |
class Message { | |
public void getMessage(){ | |
System.out.println("Hello!"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// With anonymous inner class | |
Thread threadInner = new Thread(new Runnable() { | |
@Override | |
public void run() { | |
System.out.println("Printed inside anon inner class."); | |
} | |
}); | |
// With lambda expression | |
Thread threadLambda = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
greetingFunction = () -> System.out.println("Hello world!"); | |
doubleNumberFunction = a -> a * 2; | |
addNumberFunction = (a, b) -> { | |
return a + b; | |
}; | |
safeDivideFunction = (a, b) -> { | |
if (b == 0) return 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
greetingFunction = public void perform() { | |
System.out.println("Hello world!"); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Greeter greeter = new Greeter(); | |
greeter.greet(new Greeting() { | |
@Override | |
public void perform() { | |
System.out.println("Hello world!"); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Greeter { | |
public void greet(Greeting greeting) { | |
greeting.perform(); | |
} | |
public static void main(String[] args) { | |
Greeter greeter = new Greeter(); | |
HelloGreeting helloGreeting = new HelloGreeting(); | |
greeter.greet(helloGreeting); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Greeting { | |
void perform(); | |
} | |
public class HelloGreeting implements Greeting { | |
@Override | |
public void perform() { | |
System.out.println("Hello world!"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Greeter { | |
public void greet() { | |
System.out.println("Hello world!"); | |
} | |
public static void main(String[] args) { | |
Greeter greeter = new Greeter(); | |
greeter.greet(); | |
} |
NewerOlder