Tan115's picture
Add files using upload-large-folder tool
2e5dac7 verified
Raw
History Blame Contribute Delete
14.8 kB
1
00:00:06,000 --> 00:00:06,000
Hello.
2
00:00:06,000 --> 00:00:09,000
Students, in this lesson, we are going to learn what connections are.
3
00:00:10,000 --> 00:00:15,000
This is very important topic because connection interface is implemented by all connections implementations
4
00:00:15,000 --> 00:00:16,000
in Java.
5
00:00:16,000 --> 00:00:23,000
That's why understanding of collection interface is a key for understanding of all other collections
6
00:00:23,000 --> 00:00:23,000
in Java.
7
00:00:24,000 --> 00:00:28,000
So today our primary focus is learning of collection interface.
8
00:00:28,000 --> 00:00:35,000
I'm going to show you your middle class diagram, will understand what it is and how we can use it in
9
00:00:35,000 --> 00:00:36,000
the future.
10
00:00:36,000 --> 00:00:42,000
To understand a type structure during the lesson will understand what methods collection interface has
11
00:00:42,000 --> 00:00:43,000
and why do we need them.
12
00:00:44,000 --> 00:00:50,000
We will review abstract and default methods of collection interface and at the end of the lesson, we'll
13
00:00:50,000 --> 00:00:52,000
look at the collection source code.
14
00:00:52,000 --> 00:00:53,000
Let's start.
15
00:00:53,000 --> 00:00:59,000
I suggest that our lesson from this slide on this slide, you may see visualization of what the collection
16
00:00:59,000 --> 00:01:02,000
is to understand collection.
17
00:01:02,000 --> 00:01:07,000
Imagine the back, the big back where you may put all your stuff.
18
00:01:07,000 --> 00:01:15,000
You might put your product, user card and all other objects, and you can retrieve exactly user or
19
00:01:15,000 --> 00:01:19,000
product or cards by its index like you did in array.
20
00:01:20,000 --> 00:01:25,000
What you can do is to put all things from your back on the floor and go over them one by one.
21
00:01:26,000 --> 00:01:31,000
We're also going to learn in the separate lessons, the specific type that is developed to go over each
22
00:01:31,000 --> 00:01:32,000
element.
23
00:01:32,000 --> 00:01:34,000
What else we can do with these?
24
00:01:34,000 --> 00:01:40,000
Back to answer this question, let's take a look at collection interface and we'll learn what else we
25
00:01:40,000 --> 00:01:42,000
can do with our bag of elements.
26
00:01:43,000 --> 00:01:49,000
Here is a class diagram we are going to learn with your UML language that is unified model and language
27
00:01:49,000 --> 00:01:50,000
in detail a bit later.
28
00:01:51,000 --> 00:01:54,000
But this is what is used to call class diagram.
29
00:01:54,000 --> 00:01:59,000
And while being a software engineer, you are going to see such diagrams very often.
30
00:02:00,000 --> 00:02:01,000
What do we have here?
31
00:02:01,000 --> 00:02:06,000
We can see that collection interface extends a terrible interface, a terrible interface.
32
00:02:06,000 --> 00:02:10,000
We are going to learn in a separate lesson, the same as Iterator.
33
00:02:10,000 --> 00:02:17,000
But in short, this is an interface that stands on top of all collections interfaces to make sure that
34
00:02:17,000 --> 00:02:23,000
it will be possible to iterate over each element in each implementation of collection interface.
35
00:02:24,000 --> 00:02:29,000
Today we are going to focus on collection interface and we will start learning it from this class diagram.
36
00:02:30,000 --> 00:02:32,000
Let me give you a quick introduction regarding symbols here.
37
00:02:33,000 --> 00:02:40,000
You can find indication whether this type interface or no, that is our interface text right above the
38
00:02:40,000 --> 00:02:41,000
interface name.
39
00:02:41,000 --> 00:02:46,000
We can see that it's Arabel and collections, both interfaces here.
40
00:02:46,000 --> 00:02:52,000
We can see list of methods that each specific type has, plus some means that this method is public.
41
00:02:53,000 --> 00:02:55,000
After that goes method signature.
42
00:02:55,000 --> 00:02:59,000
That is method, name and method parameters followed by colon.
43
00:02:59,000 --> 00:03:03,000
And we can find return type right after the column.
44
00:03:03,000 --> 00:03:09,000
For example, the first method in the list in collection interface is this method without parameters
45
00:03:09,000 --> 00:03:11,000
that returns in value.
46
00:03:11,000 --> 00:03:12,000
Does it make sense now?
47
00:03:13,000 --> 00:03:18,000
This knowledge will help you to understand class diagrams written down on human language.
48
00:03:19,000 --> 00:03:21,000
And let's answer our original question.
49
00:03:21,000 --> 00:03:23,000
What else we can do with this back?
50
00:03:24,000 --> 00:03:26,000
We can check a number of elements in it.
51
00:03:26,000 --> 00:03:28,000
That is what size method does.
52
00:03:28,000 --> 00:03:31,000
We can check if this bag is empty or no.
53
00:03:31,000 --> 00:03:34,000
We can check if this bag is empty or no.
54
00:03:34,000 --> 00:03:41,000
That's why when it is empty, we can ask our back elements, does it contain some specific element or
55
00:03:41,000 --> 00:03:45,000
no contains measures that will help us with this task.
56
00:03:45,000 --> 00:03:51,000
We have also matters that control collection of elements, interior objects and methods that can turn
57
00:03:51,000 --> 00:03:54,000
collection of elements into the array of specific types.
58
00:03:54,000 --> 00:04:00,000
For example, if your collection contains only elements of product type, we can convert our collection
59
00:04:00,000 --> 00:04:04,000
into of product elements, but not in the array of objects.
60
00:04:04,000 --> 00:04:07,000
If you don't want, can you feel the difference?
61
00:04:08,000 --> 00:04:08,000
After that?
62
00:04:08,000 --> 00:04:11,000
We can see methods that we already kind of discuss.
63
00:04:11,000 --> 00:04:12,000
Let us add methods.
64
00:04:13,000 --> 00:04:15,000
I can add elements to the collection.
65
00:04:15,000 --> 00:04:21,000
I can also remove elements from the collection and to remove elements from the collection, I have to
66
00:04:21,000 --> 00:04:23,000
pass this exact element.
67
00:04:24,000 --> 00:04:30,000
Another important behavior, we can check whether this collection contains all elements that other collection
68
00:04:30,000 --> 00:04:30,000
has.
69
00:04:30,000 --> 00:04:32,000
That is our contains all method.
70
00:04:33,000 --> 00:04:36,000
We can add all elements from one collection to another.
71
00:04:36,000 --> 00:04:43,000
To do this, we have to use at all method and we can remove all elements from the current collections
72
00:04:43,000 --> 00:04:50,000
and other collection has that is our remove all method and believe you can see on the slide that message
73
00:04:50,000 --> 00:04:51,000
that we have just discussed.
74
00:04:51,000 --> 00:04:54,000
Take out the collection as my argument.
75
00:04:54,000 --> 00:04:58,000
If you want, you can keep only elements that are present in both collections.
76
00:04:58,000 --> 00:05:04,000
To do this, we have to invoke retain all methods and positive reference to another collection into
77
00:05:04,000 --> 00:05:04,000
it.
78
00:05:05,000 --> 00:05:11,000
In other words, this message removes from the current collection all elements that are not present
79
00:05:11,000 --> 00:05:17,000
in the collection that we passed as a method augment the methods that are left here are also describing
80
00:05:18,000 --> 00:05:23,000
claims method will remove all elements from the collection and as you already know, equals and harsh
81
00:05:23,000 --> 00:05:26,000
methods that are the methods that each object should have.
82
00:05:27,000 --> 00:05:33,000
But the idea of specifying equals and Haskett methods in the collection interface is to put stress on
83
00:05:33,000 --> 00:05:39,000
the fact that these methods should be implemented in an implementation of collection interface and that
84
00:05:39,000 --> 00:05:43,000
these methods should override default behavior from object class.
85
00:05:43,000 --> 00:05:48,000
And the last but not the least, massive collection interface is an iterator.
86
00:05:48,000 --> 00:05:51,000
Pay attention to the iterable interface description now.
87
00:05:52,000 --> 00:05:57,000
It is also the collection interface because it implements a terrible interface.
88
00:05:57,000 --> 00:06:03,000
As you can see, Iterator method returns object of iterator type insert.
89
00:06:03,000 --> 00:06:07,000
This object will help you to iterate over each element in your collection.
90
00:06:07,000 --> 00:06:13,000
We are going to learn what Iterator is in the separate class and that is how our collection interface
91
00:06:13,000 --> 00:06:14,000
that is something.
92
00:06:14,000 --> 00:06:15,000
What do you have to remember?
93
00:06:16,000 --> 00:06:21,000
We just have such interface and what we can do is just to remember it just as an alphabet.
94
00:06:21,000 --> 00:06:26,000
We don't ask why a letter is written exactly in this way.
95
00:06:26,000 --> 00:06:30,000
We just learned that this is a letter and how it sounds.
96
00:06:30,000 --> 00:06:36,000
And when we know that we start building words with this letter, the same as here, we just have to
97
00:06:36,000 --> 00:06:38,000
learn collection, interface and learn how to use it.
98
00:06:39,000 --> 00:06:45,000
So here on the screen, you may see only abstract methods that should be implemented in each collection,
99
00:06:45,000 --> 00:06:49,000
but there are a few more other default methods in the collection interface.
100
00:06:49,000 --> 00:06:55,000
What are they to answer this question and to give you otherwise how constantly learn new things and
101
00:06:55,000 --> 00:07:00,000
check information that you get not only on this lesson but in any tutorial?
102
00:07:00,000 --> 00:07:03,000
Always investigate the source code of your conversion.
103
00:07:04,000 --> 00:07:09,000
I believe you remember how to add source code, your code editor and where you might find it.
104
00:07:09,000 --> 00:07:14,000
Let's open collection type to investigate the source code and find methods that we didn't learn yet.
105
00:07:15,000 --> 00:07:20,000
I press control shift and simultaneously I have to type collection.
106
00:07:21,000 --> 00:07:27,000
I need collection from Java with your package and here this and here on the right, we might see a list
107
00:07:27,000 --> 00:07:30,000
of all methods that are present in this interface.
108
00:07:30,000 --> 00:07:34,000
It looks like we went over all abstract methods.
109
00:07:34,000 --> 00:07:40,000
How I learned which method is abstract and it's is a small a letter that stands for abstract.
110
00:07:41,000 --> 00:07:45,000
But we didn't cover in our presentation methods that have Glitnir.
111
00:07:45,000 --> 00:07:46,000
What are they?
112
00:07:47,000 --> 00:07:50,000
Here's the overloaded method to array it.
113
00:07:50,000 --> 00:07:57,000
Just take specific functions that will describe how to convert collection to a right to be able to apply
114
00:07:57,000 --> 00:07:57,000
this method.
115
00:07:57,000 --> 00:08:03,000
We have to know how to write in the functional style in Java and understand what functional interface
116
00:08:03,000 --> 00:08:03,000
is.
117
00:08:04,000 --> 00:08:05,000
Don't worry.
118
00:08:05,000 --> 00:08:08,000
This topic also will be discussed in the separate lesson.
119
00:08:08,000 --> 00:08:13,000
I just want you to understand, at least on the high level, what these default methods are about.
120
00:08:13,000 --> 00:08:21,000
Remove method, this method takes predicate, predicate is a specific type that can return true or false
121
00:08:22,000 --> 00:08:26,000
based on the specific function that you will pass as a method argument to this method.
122
00:08:26,000 --> 00:08:29,000
It will identify which element should be removed.
123
00:08:29,000 --> 00:08:32,000
For example, you may describe functions that will return.
124
00:08:32,000 --> 00:08:38,000
True in a case product price is more than one hundred dollars, and in case this function will be applied
125
00:08:38,000 --> 00:08:44,000
to this specific product and collection, it will be removed and this function will be applied to each
126
00:08:44,000 --> 00:08:50,000
element in the collection you might find while loop here and see that Iterator is used to go over the
127
00:08:50,000 --> 00:08:56,000
collection as a condition for each element in the collection and remove it in case it satisfies the
128
00:08:56,000 --> 00:08:57,000
condition.
129
00:08:57,000 --> 00:09:01,000
Also, there is a default method that creates iterator.
130
00:09:01,000 --> 00:09:07,000
Split Iterator is a specific type that can traverse and make parts of elements of the source collection.
131
00:09:08,000 --> 00:09:11,000
And here is a method that exists in all implementations of collection.
132
00:09:11,000 --> 00:09:18,000
Interface Stream Method joins the collection into stream of elements or in other words, sequential
133
00:09:18,000 --> 00:09:19,000
stream of elements.
134
00:09:20,000 --> 00:09:26,000
String Mapei was introduced in Java version eight and it was a breakthrough in this course in separate
135
00:09:26,000 --> 00:09:31,000
lesson will be on stream API and we'll learn how to use it as a practical exercise.
136
00:09:31,000 --> 00:09:35,000
Will even rewrite our home tasks with the help of the Stream API.
137
00:09:36,000 --> 00:09:38,000
And here is a massive, transparent stream.
138
00:09:39,000 --> 00:09:44,000
According to documentation, it returns possible parallel stream with the current collection at its
139
00:09:44,000 --> 00:09:44,000
source.
140
00:09:46,000 --> 00:09:51,000
Now, let's recap what we have learned today, so they've learned what the connection is, we try to
141
00:09:51,000 --> 00:09:54,000
imagine collection is a back for our understanding.
142
00:09:55,000 --> 00:09:59,000
The day you saw your first UML diagram, class diagram.
143
00:09:59,000 --> 00:10:05,000
Now you know how to read class diagrams to understand the type of description we reviewed all abstract
144
00:10:05,000 --> 00:10:07,000
methods in collection interface.
145
00:10:07,000 --> 00:10:10,000
And after that, we reviewed the collection before methods.
146
00:10:10,000 --> 00:10:14,000
Also during the lesson we investigated source code of collection interface.
147
00:10:15,000 --> 00:10:17,000
That's all what I have for you for today.
148
00:10:17,000 --> 00:10:18,000
Thanks a lot for your attention.
149
00:10:18,000 --> 00:10:20,000
See you in the next lesson.