Skip to content

Commit e88feaf

Browse files
author
b
committed
Added Examples
1 parent 8140410 commit e88feaf

File tree

3 files changed

+98
-20
lines changed

3 files changed

+98
-20
lines changed
+45-20
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,66 @@
11
package com.advancedjava;
22

33
import com.advancedjava.*;
4+
import java.util.ArrayList;
45
import java.util.HashMap;
56

6-
class Square {
7+
public class Exx10Streams {
8+
9+
public static void main(String[] args) {
10+
ArrayList<Book> books = populateLibrary();
11+
12+
books.stream()
13+
.filter(book-> book.getAuthor().startsWith("B"))
14+
.forEach(System.out::println);
715

8-
int sideLength;
916

10-
public Square(int sideLength) {
11-
this.sideLength = sideLength;
1217
}
1318

14-
public int calculateArea() {
15-
return sideLength * sideLength;
19+
private static ArrayList<Book> populateLibrary() {
20+
ArrayList<Book> list = new ArrayList();
21+
list.add(new Book("Bodrul", "Funcitonal programming"));
22+
list.add(new Book("Bodrul", "Funcitonal programming"));
23+
list.add(new Book("Khalil", "Hello programming"));
24+
list.add(new Book("Rakib", "Funcitonal programming"));
25+
list.add(new Book("Bodrul", "Funcitonal programming"));
26+
list.add(new Book("Bodrul", "Funcitonal programming"));
27+
28+
29+
return list;
1630
}
17-
}
1831

19-
@FunctionalInterface
20-
interface Shapes{
21-
public abstract int getArea(Square person);
2232
}
2333

34+
class Book {
2435

25-
public class Exx10Streams {
36+
private String author;
37+
private String title;
2638

27-
public static void main(String[] args) {
28-
Square s = new Square(4);
29-
Shapes shapes = ((square) -> {
30-
return square.calculateArea(); //To change body of generated lambdas, choose Tools | Templates.
31-
});
39+
public Book(String author, String title) {
40+
this.author = author;
41+
this.title = title;
42+
}
43+
44+
public String getTitle() {
45+
return title;
46+
}
3247

33-
Shapes altShapes = Square::calculateArea;
48+
public void setTitle(String title) {
49+
this.title = title;
50+
}
51+
52+
public String getAuthor() {
53+
return author;
54+
}
3455

35-
System.out.println(shapes.getArea(s));
36-
System.out.println(altShapes.getArea(s));
56+
public void setAuthor(String author) {
57+
this.author = author;
58+
}
3759

38-
60+
@Override
61+
public String toString() {
62+
return "Book{" + "author=" + author + ", title=" + title + '}';
3963
}
64+
4065

4166
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.advancedjava;
2+
3+
class ThreadEx extends Thread {
4+
5+
@Override
6+
public void run() {
7+
8+
int i = 1;
9+
while (i <= 100) {
10+
System.out.println(i + " " + this.getName());
11+
i++;
12+
}
13+
}
14+
15+
}
16+
17+
public class Exx11ThreadClass {
18+
19+
public static void main(String[] args) {
20+
21+
ThreadEx thread1 = new ThreadEx();
22+
thread1.setName("My first Thread");
23+
thread1.start();
24+
25+
ThreadEx thread2 = new ThreadEx();
26+
thread2.setName("My second Thread");
27+
thread2.start();
28+
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.advancedjava;
2+
3+
class RunnableEx implements Runnable {
4+
5+
@Override
6+
public void run() {
7+
8+
int i = 1;
9+
while (i <= 100) {
10+
System.out.println(i + " " + Thread.currentThread().getName());
11+
i++;
12+
}
13+
}
14+
15+
}
16+
17+
public class Exx12ThreadRunnable {
18+
19+
public static void main(String[] args) {
20+
21+
}
22+
}

0 commit comments

Comments
 (0)