-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava8
More file actions
91 lines (73 loc) · 2.06 KB
/
java8
File metadata and controls
91 lines (73 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
- release March 14
Features:
1. forEach() method
- Iterable interface
2. default & static methods in interface
default method:
- allow interface to have methods with implementation without affecting the classes
that implement the interface
- Default methods are also known as Defender methods or virtual extension methods
- provide backward compatibility so existing interfaces can use without implementing the
default methods in the class
static method:
- can not be overridden
3. Functional Interface & Lambda Expressions
- an interface with exactly one abstract method
- it is not mandatory to use annotation but we can use functional interface to avoid
addition of extra abstract methods
- benefit of java 8 functional interfaces is that we can use lambda expressions
- used to refer method of functional interface
4. Method Reference
- prerequisites are functional interface & lambda exp
- we can replace lambda exp with method ref
- used to refer method of functional interface
Types of Method References
1. Reference to a static method
2. Reference to an instance method
3. Reference to a constructor
5. Optional
- it's a final class
- to deal with NullPointerException
- to avoid abnormal termination of application
- java.util package
6. Stream API
- from java.util.stream package
- it does not store elements
7. Java Time API
8. Collection API improvement
9. Concurrency API improvement
8. I/O improvement
Base64
- java.util
Interfaces:
1. Consumer
- represents a function which accepts in one arguments and returns no result
- functional interface
2. BiConsumer
- represents a function which accepts in two arguments and returns no result
3. Function
- Represents a function that accepts one argument and produces a result
- java.util.Objects
Homework:
1.
interface I1{
default void display(){
// lines of code
}
}
interface I2{
default void display(){
// lines of code
}
}
class TestInterface implements I1,I2{
main(){
//lines of code
}
}
Addition of two nos using java 8
class Employee{
name,
id,
salary
}