Tan115 commited on
Commit
407b94e
·
verified ·
1 Parent(s): f99add3

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +5 -0
  2. 05 - Operators and Operations with primitive types/005 Compare primitive and reference types & Java Memory Model.mp4 +3 -0
  3. 05 - Operators and Operations with primitive types/010 Homework review Operators and Operations.mp4 +3 -0
  4. 06 - Strings in Java/001 String object creation and main methods overview.mp4 +3 -0
  5. 06 - Strings in Java/002 String comparison How to compare Strings and what is String Pool.mp4 +3 -0
  6. 06 - Strings in Java/003 Escape Sequences in Java.mp4 +3 -0
  7. 13 - Object-oriented programming/002 Classes & Objects_en.srt +856 -0
  8. 13 - Object-oriented programming/002 Source-code-Cart-class.url +2 -0
  9. 13 - Object-oriented programming/002 Source-code-Demo-class.url +2 -0
  10. 13 - Object-oriented programming/002 Source-code-Product-class.url +2 -0
  11. 13 - Object-oriented programming/003 Different types of Classes, Abstract keyword and Abstract classes_en.srt +584 -0
  12. 13 - Object-oriented programming/003 Source-code-Abstract-Product.url +2 -0
  13. 13 - Object-oriented programming/003 Source-code-Cart-with-Tax-and-Discount.url +2 -0
  14. 13 - Object-oriented programming/003 Source-code-Demo-class.url +2 -0
  15. 13 - Object-oriented programming/003 Source-code-Master-Product.url +2 -0
  16. 13 - Object-oriented programming/003 Source-code-POJO-Product.url +2 -0
  17. 13 - Object-oriented programming/003 Source-code-User-class.url +2 -0
  18. 13 - Object-oriented programming/003 Source-code-Variant-product.url +2 -0
  19. 13 - Object-oriented programming/004 Interfaces_en.srt +688 -0
  20. 13 - Object-oriented programming/004 Source-code-ChasePaymentProcessor.url +2 -0
  21. 13 - Object-oriented programming/004 Source-code-Client-class.url +2 -0
  22. 13 - Object-oriented programming/004 Source-code-PayPalPaymentProcessor.url +2 -0
  23. 13 - Object-oriented programming/004 Source-code-PaymentData.url +2 -0
  24. 13 - Object-oriented programming/004 Source-code-PaymentProcessor-interface.url +2 -0
  25. 13 - Object-oriented programming/004 Source-code-PaymentValidator.url +2 -0
  26. 13 - Object-oriented programming/005 Inheritance_en.srt +636 -0
  27. 13 - Object-oriented programming/005 Source-code-Demo.url +2 -0
  28. 13 - Object-oriented programming/005 Source-code-Object-initialization-order.url +2 -0
  29. 13 - Object-oriented programming/005 Source-code-Phone.url +2 -0
  30. 13 - Object-oriented programming/005 Source-code-Product.url +2 -0
  31. 13 - Object-oriented programming/006 Polymorphism and 'final' keyword_en.srt +556 -0
  32. 13 - Object-oriented programming/006 Source-code-Account-Information.url +2 -0
  33. 13 - Object-oriented programming/006 Source-code-Admin-User.url +2 -0
  34. 13 - Object-oriented programming/006 Source-code-Archiver.url +2 -0
  35. 13 - Object-oriented programming/006 Source-code-Content-Manager.url +2 -0
  36. 13 - Object-oriented programming/006 Source-code-Demo.url +2 -0
  37. 13 - Object-oriented programming/006 Source-code-Profile-Information-Data.url +2 -0
  38. 13 - Object-oriented programming/006 Source-code-Profile.url +2 -0
  39. 13 - Object-oriented programming/006 Source-code-Rar-Archiver.url +2 -0
  40. 13 - Object-oriented programming/006 Source-code-User-Profile.url +2 -0
  41. 13 - Object-oriented programming/006 Source-code-User.url +2 -0
  42. 13 - Object-oriented programming/006 Source-code-Zip-Archiver.url +2 -0
  43. 13 - Object-oriented programming/007 'static' keyword_en.srt +440 -0
  44. 13 - Object-oriented programming/007 Source-code-Demo.url +2 -0
  45. 13 - Object-oriented programming/007 Source-code-Employee.url +2 -0
  46. 13 - Object-oriented programming/007 Source-code-User.url +2 -0
  47. 13 - Object-oriented programming/008 Encapsulation_en.srt +384 -0
  48. 13 - Object-oriented programming/008 Source-code-All-examples-from-the-lecture.url +2 -0
  49. 13 - Object-oriented programming/009 Object, JNI and Object class overview_en.srt +532 -0
  50. 13 - Object-oriented programming/010 Quiz Object-oriented programming - Check yourself.html +69 -0
.gitattributes CHANGED
@@ -52,3 +52,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
52
  05[[:space:]]-[[:space:]]Operators[[:space:]]and[[:space:]]Operations[[:space:]]with[[:space:]]primitive[[:space:]]types/004[[:space:]]Type[[:space:]]of[[:space:]]the[[:space:]]expression[[:space:]]in[[:space:]]Java.mp4 filter=lfs diff=lfs merge=lfs -text
53
  05[[:space:]]-[[:space:]]Operators[[:space:]]and[[:space:]]Operations[[:space:]]with[[:space:]]primitive[[:space:]]types/001[[:space:]]Operators[[:space:]]in[[:space:]]Java.mp4 filter=lfs diff=lfs merge=lfs -text
54
  05[[:space:]]-[[:space:]]Operators[[:space:]]and[[:space:]]Operations[[:space:]]with[[:space:]]primitive[[:space:]]types/006[[:space:]]Read[[:space:]]user[[:space:]]input[[:space:]]from[[:space:]]console.mp4 filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
52
  05[[:space:]]-[[:space:]]Operators[[:space:]]and[[:space:]]Operations[[:space:]]with[[:space:]]primitive[[:space:]]types/004[[:space:]]Type[[:space:]]of[[:space:]]the[[:space:]]expression[[:space:]]in[[:space:]]Java.mp4 filter=lfs diff=lfs merge=lfs -text
53
  05[[:space:]]-[[:space:]]Operators[[:space:]]and[[:space:]]Operations[[:space:]]with[[:space:]]primitive[[:space:]]types/001[[:space:]]Operators[[:space:]]in[[:space:]]Java.mp4 filter=lfs diff=lfs merge=lfs -text
54
  05[[:space:]]-[[:space:]]Operators[[:space:]]and[[:space:]]Operations[[:space:]]with[[:space:]]primitive[[:space:]]types/006[[:space:]]Read[[:space:]]user[[:space:]]input[[:space:]]from[[:space:]]console.mp4 filter=lfs diff=lfs merge=lfs -text
55
+ 05[[:space:]]-[[:space:]]Operators[[:space:]]and[[:space:]]Operations[[:space:]]with[[:space:]]primitive[[:space:]]types/005[[:space:]]Compare[[:space:]]primitive[[:space:]]and[[:space:]]reference[[:space:]]types[[:space:]]&[[:space:]]Java[[:space:]]Memory[[:space:]]Model.mp4 filter=lfs diff=lfs merge=lfs -text
56
+ 05[[:space:]]-[[:space:]]Operators[[:space:]]and[[:space:]]Operations[[:space:]]with[[:space:]]primitive[[:space:]]types/010[[:space:]]Homework[[:space:]]review[[:space:]]Operators[[:space:]]and[[:space:]]Operations.mp4 filter=lfs diff=lfs merge=lfs -text
57
+ 06[[:space:]]-[[:space:]]Strings[[:space:]]in[[:space:]]Java/001[[:space:]]String[[:space:]]object[[:space:]]creation[[:space:]]and[[:space:]]main[[:space:]]methods[[:space:]]overview.mp4 filter=lfs diff=lfs merge=lfs -text
58
+ 06[[:space:]]-[[:space:]]Strings[[:space:]]in[[:space:]]Java/002[[:space:]]String[[:space:]]comparison[[:space:]][[:space:]]How[[:space:]]to[[:space:]]compare[[:space:]]Strings[[:space:]]and[[:space:]]what[[:space:]]is[[:space:]]String[[:space:]]Pool.mp4 filter=lfs diff=lfs merge=lfs -text
59
+ 06[[:space:]]-[[:space:]]Strings[[:space:]]in[[:space:]]Java/003[[:space:]]Escape[[:space:]]Sequences[[:space:]]in[[:space:]]Java.mp4 filter=lfs diff=lfs merge=lfs -text
05 - Operators and Operations with primitive types/005 Compare primitive and reference types & Java Memory Model.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fa65814a0105381b8efd2e0754d45865f0cba944d1c84f5f900c366f9fa4950a
3
+ size 182856283
05 - Operators and Operations with primitive types/010 Homework review Operators and Operations.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6113b981b8c9003eb4c3d4f46010c7bb6b48364f57b6afa30046ed2502f565f9
3
+ size 207450063
06 - Strings in Java/001 String object creation and main methods overview.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b15ae7711f85af21a92bc9f098a73bb122ec2c99181df74a9b929846944008a0
3
+ size 52079039
06 - Strings in Java/002 String comparison How to compare Strings and what is String Pool.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0382fc777a8b147d88218daf2590a8f1824d3feb332f77b80882436bff9b35e3
3
+ size 50592934
06 - Strings in Java/003 Escape Sequences in Java.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e03bf9b9c615acfa82054ac6fe95d1f244912ea5bc42dca16c10236cf7c2027c
3
+ size 15472125
13 - Object-oriented programming/002 Classes & Objects_en.srt ADDED
@@ -0,0 +1,856 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:05,000 --> 00:00:06,000
3
+ Hello, Jim.
4
+
5
+ 2
6
+ 00:00:06,000 --> 00:00:08,000
7
+ So they were going to run with you with the glasses.
8
+
9
+ 3
10
+ 00:00:09,000 --> 00:00:12,000
11
+ We'll talk about what glass can contain on good examples.
12
+
13
+ 4
14
+ 00:00:12,000 --> 00:00:17,000
15
+ We learn what our fields and utilization logs, constructors methods and nested classes.
16
+
17
+ 5
18
+ 00:00:17,000 --> 00:00:21,000
19
+ I'm going to explain to you what getters and setters are and how we can use them.
20
+
21
+ 6
22
+ 00:00:21,000 --> 00:00:26,000
23
+ We are going to create our own class and we'll create object of our custom class together.
24
+
25
+ 7
26
+ 00:00:26,000 --> 00:00:28,000
27
+ Let's start from the previous lesson.
28
+
29
+ 8
30
+ 00:00:28,000 --> 00:00:33,000
31
+ You already know that class is our template for objects, but what does it consist of?
32
+
33
+ 9
34
+ 00:00:33,000 --> 00:00:41,000
35
+ Glass can contain constructors, fields, methods and utilization blocks and nested classes to understand
36
+
37
+ 10
38
+ 00:00:41,000 --> 00:00:41,000
39
+ and better.
40
+
41
+ 11
42
+ 00:00:41,000 --> 00:00:43,000
43
+ Let's jump to example.
44
+
45
+ 12
46
+ 00:00:43,000 --> 00:00:48,000
47
+ Let's imagine we are implementing online store and we need to implement our virtual card for shopping.
48
+
49
+ 13
50
+ 00:00:49,000 --> 00:00:53,000
51
+ You already know OPIS and you know that everything is an object.
52
+
53
+ 14
54
+ 00:00:53,000 --> 00:00:56,000
55
+ Take into account we expect multiple users on our website.
56
+
57
+ 15
58
+ 00:00:56,000 --> 00:00:58,000
59
+ We are going to have a lot of cards.
60
+
61
+ 16
62
+ 00:00:58,000 --> 00:01:01,000
63
+ We need to have a template for card object.
64
+
65
+ 17
66
+ 00:01:01,000 --> 00:01:04,000
67
+ That's why we need to create card class.
68
+
69
+ 18
70
+ 00:01:04,000 --> 00:01:05,000
71
+ Here's card class.
72
+
73
+ 19
74
+ 00:01:05,000 --> 00:01:09,000
75
+ I created it beforehand to save time during this video lesson.
76
+
77
+ 20
78
+ 00:01:09,000 --> 00:01:11,000
79
+ I will walk you through it line by line.
80
+
81
+ 21
82
+ 00:01:12,000 --> 00:01:14,000
83
+ Our goal now to understand what class can contain.
84
+
85
+ 22
86
+ 00:01:15,000 --> 00:01:17,000
87
+ First of all, class can contain fields.
88
+
89
+ 23
90
+ 00:01:18,000 --> 00:01:19,000
91
+ Often fields are called properties.
92
+
93
+ 24
94
+ 00:01:20,000 --> 00:01:25,000
95
+ With the help of the fields we can express state of specific object fields can have different modifiers.
96
+
97
+ 25
98
+ 00:01:26,000 --> 00:01:30,000
99
+ For example, fields can be static and non static, final and non final.
100
+
101
+ 26
102
+ 00:01:30,000 --> 00:01:35,000
103
+ We are going to have separate lesson about static keyword and static elements in Java and we'll discuss
104
+
105
+ 27
106
+ 00:01:35,000 --> 00:01:36,000
107
+ final keywords.
108
+
109
+ 28
110
+ 00:01:36,000 --> 00:01:40,000
111
+ Also in separate lesson, this lesson only about classes.
112
+
113
+ 29
114
+ 00:01:40,000 --> 00:01:43,000
115
+ So this is all fields which we have in our class.
116
+
117
+ 30
118
+ 00:01:43,000 --> 00:01:45,000
119
+ Class also can contain initialization blocks.
120
+
121
+ 31
122
+ 00:01:46,000 --> 00:01:49,000
123
+ We may have static and on static initialization blocks.
124
+
125
+ 32
126
+ 00:01:49,000 --> 00:01:50,000
127
+ Why do we need them?
128
+
129
+ 33
130
+ 00:01:50,000 --> 00:01:55,000
131
+ For example, I have some fields which I want to be initialized with values by default.
132
+
133
+ 34
134
+ 00:01:56,000 --> 00:01:59,000
135
+ In this case, every timecards object will be created.
136
+
137
+ 35
138
+ 00:01:59,000 --> 00:02:05,000
139
+ Card counter will be incremented in case cards will be created without user i.e. I know that I need
140
+
141
+ 36
142
+ 00:02:05,000 --> 00:02:07,000
143
+ to sign this card to some user.
144
+
145
+ 37
146
+ 00:02:08,000 --> 00:02:13,000
147
+ Let it be special user with ID one and one of the properties has tax time.
148
+
149
+ 38
150
+ 00:02:13,000 --> 00:02:16,000
151
+ This is also custom type described by us.
152
+
153
+ 39
154
+ 00:02:16,000 --> 00:02:18,000
155
+ I will show it to you later in this lesson.
156
+
157
+ 40
158
+ 00:02:19,000 --> 00:02:24,000
159
+ But now imagine that you have this field and you don't want to leave it, not initialized.
160
+
161
+ 41
162
+ 00:02:24,000 --> 00:02:27,000
163
+ What default value has all reference types of data?
164
+
165
+ 42
166
+ 00:02:27,000 --> 00:02:28,000
167
+ No.
168
+
169
+ 43
170
+ 00:02:28,000 --> 00:02:34,000
171
+ And according to logic that I implemented, I know that tax should not be known to avoid no pointer
172
+
173
+ 44
174
+ 00:02:34,000 --> 00:02:40,000
175
+ exception because I use this variable in court below and b what stands for null pointer exception,
176
+
177
+ 45
178
+ 00:02:40,000 --> 00:02:44,000
179
+ one of the most widespread exception which happens when you call method or new value.
180
+
181
+ 46
182
+ 00:02:45,000 --> 00:02:47,000
183
+ That's why it's called no pointer exception.
184
+
185
+ 47
186
+ 00:02:48,000 --> 00:02:50,000
187
+ We'll learn more about exceptions in separate section.
188
+
189
+ 48
190
+ 00:02:50,000 --> 00:02:54,000
191
+ For now, I want at least some default value should be assigned to this variable.
192
+
193
+ 49
194
+ 00:02:55,000 --> 00:02:57,000
195
+ That is exactly what I'm doing here.
196
+
197
+ 50
198
+ 00:02:57,000 --> 00:03:02,000
199
+ I using this civilization look to initialize this field, the similar situation with our discount object.
200
+
201
+ 51
202
+ 00:03:02,000 --> 00:03:09,000
203
+ I initialize this field to make sure it won't be no talking about starting blocks, it is worth to mention
204
+
205
+ 52
206
+ 00:03:09,000 --> 00:03:13,000
207
+ that they are very narrow application domain Whiskas class example.
208
+
209
+ 53
210
+ 00:03:13,000 --> 00:03:16,000
211
+ It was hard for me to come up with the example of static initialization block.
212
+
213
+ 54
214
+ 00:03:17,000 --> 00:03:22,000
215
+ This block will be executed only once one class will be uploaded into GBM.
216
+
217
+ 55
218
+ 00:03:22,000 --> 00:03:25,000
219
+ In this case we just write text to console.
220
+
221
+ 56
222
+ 00:03:25,000 --> 00:03:29,000
223
+ Good example of static Blokland civilization usage is driver classis.
224
+
225
+ 57
226
+ 00:03:29,000 --> 00:03:35,000
227
+ You always need to register driver in the system so it would be comfortable to use static initialization
228
+
229
+ 58
230
+ 00:03:35,000 --> 00:03:36,000
231
+ work for this.
232
+
233
+ 59
234
+ 00:03:36,000 --> 00:03:41,000
235
+ For example, once driver class is uploaded into GBM, we can register it in some services.
236
+
237
+ 60
238
+ 00:03:42,000 --> 00:03:45,000
239
+ This is a real life example which we will see later in this course.
240
+
241
+ 61
242
+ 00:03:45,000 --> 00:03:50,000
243
+ But now you at least understand how potentially we can use static in civilization.
244
+
245
+ 62
246
+ 00:03:50,000 --> 00:03:52,000
247
+ Bloks problems it again.
248
+
249
+ 63
250
+ 00:03:52,000 --> 00:03:59,000
251
+ Universalization looks let's move on may contain constructor's constructor is a special method which
252
+
253
+ 64
254
+ 00:03:59,000 --> 00:04:01,000
255
+ should be called to instantiate object.
256
+
257
+ 65
258
+ 00:04:01,000 --> 00:04:06,000
259
+ Important things to mention about the constructor constructor name should always be the same as class
260
+
261
+ 66
262
+ 00:04:06,000 --> 00:04:07,000
263
+ name.
264
+
265
+ 67
266
+ 00:04:07,000 --> 00:04:12,000
267
+ If your class name is called, then constructor is also called rule about writing.
268
+
269
+ 68
270
+ 00:04:12,000 --> 00:04:15,000
271
+ Method starting from lowercase is not applied to constructors.
272
+
273
+ 69
274
+ 00:04:15,000 --> 00:04:17,000
275
+ It doesn't have return type.
276
+
277
+ 70
278
+ 00:04:17,000 --> 00:04:21,000
279
+ You remember that all method should have return type in constructor.
280
+
281
+ 71
282
+ 00:04:21,000 --> 00:04:27,000
283
+ You should not specify return time because constructors always by default return reference to the object
284
+
285
+ 72
286
+ 00:04:27,000 --> 00:04:27,000
287
+ and keep memory.
288
+
289
+ 73
290
+ 00:04:28,000 --> 00:04:30,000
291
+ You always have constructor by default.
292
+
293
+ 74
294
+ 00:04:30,000 --> 00:04:31,000
295
+ Let me show you this.
296
+
297
+ 75
298
+ 00:04:32,000 --> 00:04:36,000
299
+ Even if I wouldn't have this constructors, I would still have default one.
300
+
301
+ 76
302
+ 00:04:36,000 --> 00:04:41,000
303
+ Let me comment on this court and now let's jump to the demo file and create card object.
304
+
305
+ 77
306
+ 00:04:42,000 --> 00:04:45,000
307
+ Let me declare a variable of type card and assign cards.
308
+
309
+ 78
310
+ 00:04:45,000 --> 00:04:46,000
311
+ Object to it.
312
+
313
+ 79
314
+ 00:04:46,000 --> 00:04:48,000
315
+ The great object I write new keyword.
316
+
317
+ 80
318
+ 00:04:49,000 --> 00:04:55,000
319
+ This is a common to Java to allocate memory for object in here and after that I call constructor and
320
+
321
+ 81
322
+ 00:04:55,000 --> 00:04:56,000
323
+ print cards object to cancel.
324
+
325
+ 82
326
+ 00:04:57,000 --> 00:04:58,000
327
+ Let's run this program.
328
+
329
+ 83
330
+ 00:04:59,000 --> 00:05:05,000
331
+ And here we are, you see that quote from Start, a conservation blog executed first, and here's our
332
+
333
+ 84
334
+ 00:05:05,000 --> 00:05:06,000
335
+ character object printed to console.
336
+
337
+ 85
338
+ 00:05:07,000 --> 00:05:09,000
339
+ Now let me create custom constructor.
340
+
341
+ 86
342
+ 00:05:09,000 --> 00:05:13,000
343
+ Let's pretend I want to create card with specified cartridges and user aguy.
344
+
345
+ 87
346
+ 00:05:14,000 --> 00:05:18,000
347
+ And when I created custom constructor, there is no default constructor anymore.
348
+
349
+ 88
350
+ 00:05:18,000 --> 00:05:20,000
351
+ And here is see compilation error.
352
+
353
+ 89
354
+ 00:05:20,000 --> 00:05:22,000
355
+ The constructor card is undefined.
356
+
357
+ 90
358
+ 00:05:23,000 --> 00:05:27,000
359
+ That's why if you want to declare a custom constructor and keep constructor by default, you should
360
+
361
+ 91
362
+ 00:05:27,000 --> 00:05:32,000
363
+ specified explicitly when I am Corman's, this constructor compilation error is gone.
364
+
365
+ 92
366
+ 00:05:33,000 --> 00:05:36,000
367
+ Let's take a look how we can use custom constructor.
368
+
369
+ 93
370
+ 00:05:36,000 --> 00:05:42,000
371
+ We know that our constructor can take two integers as arguments and you see that the first parameter
372
+
373
+ 94
374
+ 00:05:42,000 --> 00:05:48,000
375
+ will be assigned to a property of this object in the second parameter will be assigned to user the property
376
+
377
+ 95
378
+ 00:05:48,000 --> 00:05:49,000
379
+ of the current object.
380
+
381
+ 96
382
+ 00:05:50,000 --> 00:05:56,000
383
+ You can see that I use this keyword to reference current object because this idea, if this property
384
+
385
+ 97
386
+ 00:05:56,000 --> 00:06:03,000
387
+ in card object and ID is just a local variable of the constructor, that that makes sense.
388
+
389
+ 98
390
+ 00:06:03,000 --> 00:06:09,000
391
+ So inside the class you have keywords which always reference to the specific object.
392
+
393
+ 99
394
+ 00:06:10,000 --> 00:06:16,000
395
+ Now you can call your custom constructor like this new card and parse constructor arguments when we
396
+
397
+ 100
398
+ 00:06:16,000 --> 00:06:17,000
399
+ bring second car token.
400
+
401
+ 101
402
+ 00:06:17,000 --> 00:06:22,000
403
+ So you can see that IJI and user idea of this class is different from the first class object.
404
+
405
+ 102
406
+ 00:06:23,000 --> 00:06:28,000
407
+ Now, when you know what the constructor's, you might be wondering why do we need initialization blocks
408
+
409
+ 103
410
+ 00:06:28,000 --> 00:06:33,000
411
+ if they have constructor's on this example, you can see that no matter which constructor will be called
412
+
413
+ 104
414
+ 00:06:33,000 --> 00:06:35,000
415
+ utilisation, LOC will be executed.
416
+
417
+ 105
418
+ 00:06:35,000 --> 00:06:36,000
419
+ In both cases.
420
+
421
+ 106
422
+ 00:06:36,000 --> 00:06:42,000
423
+ Knowing this, you can use initialization blocks to put their code, which you want to execute no matter
424
+
425
+ 107
426
+ 00:06:42,000 --> 00:06:43,000
427
+ what constructor will be called.
428
+
429
+ 108
430
+ 00:06:43,000 --> 00:06:47,000
431
+ Is it clear now what else our class can have?
432
+
433
+ 109
434
+ 00:06:47,000 --> 00:06:49,000
435
+ Our class can have methods.
436
+
437
+ 110
438
+ 00:06:49,000 --> 00:06:51,000
439
+ That is behavior of our object.
440
+
441
+ 111
442
+ 00:06:51,000 --> 00:06:54,000
443
+ For example, our cars can add new product to the cart.
444
+
445
+ 112
446
+ 00:06:55,000 --> 00:06:57,000
447
+ Let's not get deep dive into the logic here.
448
+
449
+ 113
450
+ 00:06:57,000 --> 00:07:03,000
451
+ I will share with you source code of this lesson and you will be able to take a look miserably at implementation.
452
+
453
+ 114
454
+ 00:07:03,000 --> 00:07:09,000
455
+ But now let's understand that methods are behavior of our object and can change state of our object.
456
+
457
+ 115
458
+ 00:07:10,000 --> 00:07:13,000
459
+ And now you can understand the difference between method and function.
460
+
461
+ 116
462
+ 00:07:14,000 --> 00:07:17,000
463
+ Function can exist without object independently.
464
+
465
+ 117
466
+ 00:07:17,000 --> 00:07:19,000
467
+ Method is the behavior of the object.
468
+
469
+ 118
470
+ 00:07:20,000 --> 00:07:26,000
471
+ That's why in Olby we call specific box of code, which can be invoked by their names methods but not
472
+
473
+ 119
474
+ 00:07:26,000 --> 00:07:28,000
475
+ functions methods.
476
+
477
+ 120
478
+ 00:07:28,000 --> 00:07:31,000
479
+ This is something that is always associated with an object.
480
+
481
+ 121
482
+ 00:07:31,000 --> 00:07:37,000
483
+ In this particular example, our card contains an array of products and we can add product to this card,
484
+
485
+ 122
486
+ 00:07:37,000 --> 00:07:39,000
487
+ namely to this array of products.
488
+
489
+ 123
490
+ 00:07:40,000 --> 00:07:42,000
491
+ That is exactly what this method does.
492
+
493
+ 124
494
+ 00:07:42,000 --> 00:07:46,000
495
+ It adds new product and change the state of our cart.
496
+
497
+ 125
498
+ 00:07:46,000 --> 00:07:51,000
499
+ Notice that each time new product is added to the cart, other methods are called to calculate total
500
+
501
+ 126
502
+ 00:07:51,000 --> 00:07:53,000
503
+ net price and total gross price.
504
+
505
+ 127
506
+ 00:07:54,000 --> 00:07:55,000
507
+ These are two private methods.
508
+
509
+ 128
510
+ 00:07:56,000 --> 00:08:00,000
511
+ That means nobody outside this class can call these methods.
512
+
513
+ 129
514
+ 00:08:00,000 --> 00:08:02,000
515
+ I can call these methods from this class.
516
+
517
+ 130
518
+ 00:08:02,000 --> 00:08:07,000
519
+ Only X modifiers will be covered in detail in encapsulation.
520
+
521
+ 131
522
+ 00:08:07,000 --> 00:08:10,000
523
+ Lesson in your code method and location might look like this.
524
+
525
+ 132
526
+ 00:08:11,000 --> 00:08:16,000
527
+ You created car to object and after that use its behavior to add product to the cart products is also
528
+
529
+ 133
530
+ 00:08:16,000 --> 00:08:17,000
531
+ our custom class.
532
+
533
+ 134
534
+ 00:08:17,000 --> 00:08:22,000
535
+ By the way, here it is, just two properties for the sake of our example.
536
+
537
+ 135
538
+ 00:08:23,000 --> 00:08:29,000
539
+ And he seemed concerned that after we added two products, total net price, total gross price and total
540
+
541
+ 136
542
+ 00:08:29,000 --> 00:08:30,000
543
+ tax have been changed.
544
+
545
+ 137
546
+ 00:08:31,000 --> 00:08:37,000
547
+ After these methods, I have other methods that are called getters and setters, why do we need them?
548
+
549
+ 138
550
+ 00:08:38,000 --> 00:08:40,000
551
+ You see that all properties of cart objects are private.
552
+
553
+ 139
554
+ 00:08:41,000 --> 00:08:46,000
555
+ That is because I want to have full control over how people can interact with my object and how they
556
+
557
+ 140
558
+ 00:08:46,000 --> 00:08:47,000
559
+ can change.
560
+
561
+ 141
562
+ 00:08:47,000 --> 00:08:51,000
563
+ State of object was usually used to rid properties of objects.
564
+
565
+ 142
566
+ 00:08:51,000 --> 00:08:57,000
567
+ You can be 100 if we are making our properties private so nobody could access them and change them,
568
+
569
+ 143
570
+ 00:08:57,000 --> 00:08:59,000
571
+ then why do we need to create better sensors?
572
+
573
+ 144
574
+ 00:09:00,000 --> 00:09:02,000
575
+ Let me explain you on this example.
576
+
577
+ 145
578
+ 00:09:02,000 --> 00:09:08,000
579
+ You can create together and return your products array, but this means that everybody who has links
580
+
581
+ 146
582
+ 00:09:08,000 --> 00:09:10,000
583
+ to your products array can change state of disarray.
584
+
585
+ 147
586
+ 00:09:10,000 --> 00:09:16,000
587
+ Just using this reference, for example, having reference to products, every object I can add to more
588
+
589
+ 148
590
+ 00:09:16,000 --> 00:09:20,000
591
+ products in it and state of the card will be different.
592
+
593
+ 149
594
+ 00:09:20,000 --> 00:09:26,000
595
+ In this case, there would be two more products in CART, but now when you can write code of your car,
596
+
597
+ 150
598
+ 00:09:26,000 --> 00:09:29,000
599
+ you can say that you want to give reference to this array.
600
+
601
+ 151
602
+ 00:09:30,000 --> 00:09:35,000
603
+ Everyone who wants to investigate state of products are we can do this and you can return a copy of
604
+
605
+ 152
606
+ 00:09:35,000 --> 00:09:37,000
607
+ the script by doing this.
608
+
609
+ 153
610
+ 00:09:37,000 --> 00:09:42,000
611
+ You can be sure that even if in some other places reference to products that will be obtained, they
612
+
613
+ 154
614
+ 00:09:42,000 --> 00:09:48,000
615
+ will get reference to the copy of your and won't be able to change state of our regional products away
616
+
617
+ 155
618
+ 00:09:48,000 --> 00:09:49,000
619
+ from your car.
620
+
621
+ 156
622
+ 00:09:49,000 --> 00:09:54,000
623
+ This is critical for us because based on the products from this array, we calculate total net and total
624
+
625
+ 157
626
+ 00:09:54,000 --> 00:09:55,000
627
+ gross price.
628
+
629
+ 158
630
+ 00:09:56,000 --> 00:10:01,000
631
+ Imagine that somebody would take the reference to products are a few more products to it without recalculate
632
+
633
+ 159
634
+ 00:10:01,000 --> 00:10:05,000
635
+ total net and gross price and would just proceed to checkout with this car.
636
+
637
+ 160
638
+ 00:10:06,000 --> 00:10:12,000
639
+ Customers would be happy that they got more items for free, but our management definitely won't be
640
+
641
+ 161
642
+ 00:10:12,000 --> 00:10:12,000
643
+ happy.
644
+
645
+ 162
646
+ 00:10:13,000 --> 00:10:18,000
647
+ And if I don't want that somebody said a completely new array of products in my car, I just don't create
648
+
649
+ 163
650
+ 00:10:18,000 --> 00:10:19,000
651
+ Setar.
652
+
653
+ 164
654
+ 00:10:19,000 --> 00:10:19,000
655
+ That's it.
656
+
657
+ 165
658
+ 00:10:20,000 --> 00:10:24,000
659
+ But if you have Setar, you can verify arguments to make sure that they are valid.
660
+
661
+ 166
662
+ 00:10:24,000 --> 00:10:30,000
663
+ According to our business logic, for example, everyone can, said Cartledge here, but nobody can
664
+
665
+ 167
666
+ 00:10:30,000 --> 00:10:37,000
667
+ set a value less than zero because I wrote the code to verify this in case I'd is less than zero.
668
+
669
+ 168
670
+ 00:10:37,000 --> 00:10:43,000
671
+ Just exit from this method and you can see that Rejon keyword is also used to exit method in both methods.
672
+
673
+ 169
674
+ 00:10:44,000 --> 00:10:50,000
675
+ Even when you don't have intention to return some value from method or like here, for example, anybody
676
+
677
+ 170
678
+ 00:10:50,000 --> 00:10:51,000
679
+ can add product to the cart.
680
+
681
+ 171
682
+ 00:10:51,000 --> 00:10:57,000
683
+ But in case somebody is trying to add no into my array, I don't allow to do this and exit from method.
684
+
685
+ 172
686
+ 00:10:57,000 --> 00:11:03,000
687
+ Remember that validation of all arguments which were passed to the method if the rule which you always
688
+
689
+ 173
690
+ 00:11:03,000 --> 00:11:04,000
691
+ must follow.
692
+
693
+ 174
694
+ 00:11:04,000 --> 00:11:12,000
695
+ By the way, if you want easily generated getters and setters, use next hotkey old shift s and select
696
+
697
+ 175
698
+ 00:11:12,000 --> 00:11:13,000
699
+ generate getters and setters.
700
+
701
+ 176
702
+ 00:11:14,000 --> 00:11:17,000
703
+ You can select fields for which you need getters and setters or only getters.
704
+
705
+ 177
706
+ 00:11:17,000 --> 00:11:23,000
707
+ For example, if you don't want the grade setters and vice versa, press generate to generate code.
708
+
709
+ 178
710
+ 00:11:23,000 --> 00:11:25,000
711
+ I already have all necessary getters and setters.
712
+
713
+ 179
714
+ 00:11:25,000 --> 00:11:27,000
715
+ That is why I wouldn't press this button.
716
+
717
+ 180
718
+ 00:11:27,000 --> 00:11:30,000
719
+ Now, in case you forgot hotkeys press mouse right.
720
+
721
+ 181
722
+ 00:11:30,000 --> 00:11:33,000
723
+ Click select source and then generate getters and setters.
724
+
725
+ 182
726
+ 00:11:34,000 --> 00:11:40,000
727
+ We have to string method here, we are going to talk about this method in details in the lesson about
728
+
729
+ 183
730
+ 00:11:40,000 --> 00:11:40,000
731
+ object class.
732
+
733
+ 184
734
+ 00:11:41,000 --> 00:11:46,000
735
+ But in the meantime, let me explain you what this method is about in a few words in Arkansas here we
736
+
737
+ 185
738
+ 00:11:46,000 --> 00:11:49,000
739
+ see text representation of our the object.
740
+
741
+ 186
742
+ 00:11:49,000 --> 00:11:52,000
743
+ That is because to string method is overridden here.
744
+
745
+ 187
746
+ 00:11:52,000 --> 00:11:59,000
747
+ And you can see how the string is created from combination of fields from our car object when we pass
748
+
749
+ 188
750
+ 00:11:59,000 --> 00:12:04,000
751
+ reference type to Winterland, method to string method call is invisible for us and when to string method
752
+
753
+ 189
754
+ 00:12:04,000 --> 00:12:08,000
755
+ is called this code is executed and this string is returned.
756
+
757
+ 190
758
+ 00:12:09,000 --> 00:12:15,000
759
+ That's why we see rideable representation of our card object to generate to string method use the same
760
+
761
+ 191
762
+ 00:12:15,000 --> 00:12:19,000
763
+ hotkey as we discussed earlier, all shifts and select generate to string.
764
+
765
+ 192
766
+ 00:12:20,000 --> 00:12:26,000
767
+ It says that I already have two string but still I want to show you details you can select which fields
768
+
769
+ 193
770
+ 00:12:26,000 --> 00:12:30,000
771
+ methods you would like to use to create string which will be returned after the string method call.
772
+
773
+ 194
774
+ 00:12:32,000 --> 00:12:37,000
775
+ Besides what we have already discussed, glasses can also contain nested glasses, nested glasses can
776
+
777
+ 195
778
+ 00:12:37,000 --> 00:12:44,000
779
+ be static and non static, static nested glasses, usually called just nested static glasses and nested,
780
+
781
+ 196
782
+ 00:12:44,000 --> 00:12:47,000
783
+ not static glasses, usually called inner glasses.
784
+
785
+ 197
786
+ 00:12:48,000 --> 00:12:53,000
787
+ And here you see discount untax glasses we use for both of these types in our cars glass.
788
+
789
+ 198
790
+ 00:12:54,000 --> 00:12:59,000
791
+ And I believe you remember the beginning reinitialize variables of these types with default values in
792
+
793
+ 199
794
+ 00:12:59,000 --> 00:13:03,000
795
+ our initialization lock to not overwhelm you with information.
796
+
797
+ 200
798
+ 00:13:03,000 --> 00:13:07,000
799
+ In this lesson, let's agree to learn types of classes in the separate lesson.
800
+
801
+ 201
802
+ 00:13:07,000 --> 00:13:09,000
803
+ For now, let's repeat one more time.
804
+
805
+ 202
806
+ 00:13:09,000 --> 00:13:16,000
807
+ One glass can contain glass, can contain fildes, initialization blocks, constructors methods, nested
808
+
809
+ 203
810
+ 00:13:16,000 --> 00:13:17,000
811
+ classes.
812
+
813
+ 204
814
+ 00:13:17,000 --> 00:13:22,000
815
+ And we know that nested classes could be nested static classes and in their classes.
816
+
817
+ 205
818
+ 00:13:22,000 --> 00:13:27,000
819
+ I will share with you links to the source code in attachments to this lesson so you can review it one
820
+
821
+ 206
822
+ 00:13:27,000 --> 00:13:27,000
823
+ more time.
824
+
825
+ 207
826
+ 00:13:28,000 --> 00:13:30,000
827
+ Method classes will be discussed in the separate lesson.
828
+
829
+ 208
830
+ 00:13:31,000 --> 00:13:33,000
831
+ And now let's review what we have learned today.
832
+
833
+ 209
834
+ 00:13:34,000 --> 00:13:38,000
835
+ Today we learned what class can contain and how to create our custom objects.
836
+
837
+ 210
838
+ 00:13:38,000 --> 00:13:43,000
839
+ Now you know the difference between a method and a function, really, of the concept of getters and
840
+
841
+ 211
842
+ 00:13:43,000 --> 00:13:46,000
843
+ setters and how to generate them easily in eclipse.
844
+
845
+ 212
846
+ 00:13:47,000 --> 00:13:51,000
847
+ Take a look one more time in the source code of examples which we reviewed during the lesson and be
848
+
849
+ 213
850
+ 00:13:51,000 --> 00:13:53,000
851
+ prepared for the next lesson.
852
+
853
+ 214
854
+ 00:13:53,000 --> 00:13:56,000
855
+ Thank you for your attention and see you in the next lesson.
856
+
13 - Object-oriented programming/002 Source-code-Cart-class.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/classes/Cart.java
13 - Object-oriented programming/002 Source-code-Demo-class.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/classes/Demo.java
13 - Object-oriented programming/002 Source-code-Product-class.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/classes/Product.java
13 - Object-oriented programming/003 Different types of Classes, Abstract keyword and Abstract classes_en.srt ADDED
@@ -0,0 +1,584 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:05,000 --> 00:00:07,000
3
+ Hello, yes, students today.
4
+
5
+ 2
6
+ 00:00:07,000 --> 00:00:08,000
7
+ We'll talk more about.
8
+
9
+ 3
10
+ 00:00:08,000 --> 00:00:11,000
11
+ I'm going to tell you what types of classes we have in Java.
12
+
13
+ 4
14
+ 00:00:12,000 --> 00:00:18,000
15
+ We'll talk about all types of classes can create inner nested final classes, Bodger classes, Absaroka
16
+
17
+ 5
18
+ 00:00:18,000 --> 00:00:19,000
19
+ and Anonymous.
20
+
21
+ 6
22
+ 00:00:20,000 --> 00:00:24,000
23
+ During the lesson, you are going to learn what is APSA key word and how you can use it with classes
24
+
25
+ 7
26
+ 00:00:24,000 --> 00:00:28,000
27
+ and methods to learn this topic, it is better to start from examples.
28
+
29
+ 8
30
+ 00:00:29,000 --> 00:00:34,000
31
+ Before this lesson, I created a concrete class to show you why it's called concrete because this class
32
+
33
+ 9
34
+ 00:00:34,000 --> 00:00:37,000
35
+ has an implementation for all of its methods.
36
+
37
+ 10
38
+ 00:00:37,000 --> 00:00:40,000
39
+ Concrete classes can have any and implemented methods.
40
+
41
+ 11
42
+ 00:00:41,000 --> 00:00:45,000
43
+ Let's imagine we're implementing the e-commerce platform and we have user in it.
44
+
45
+ 12
46
+ 00:00:45,000 --> 00:00:52,000
47
+ User has its own properties like Unique ID, first name, last name, email, and an array of products
48
+
49
+ 13
50
+ 00:00:52,000 --> 00:00:58,000
51
+ which user bought in our online shop user can calculate personal discount based on the total amount
52
+
53
+ 14
54
+ 00:00:58,000 --> 00:01:03,000
55
+ of money he or she spent in our shop in case he spent more than one thousand dollars.
56
+
57
+ 15
58
+ 00:01:04,000 --> 00:01:06,000
59
+ User gets five percent discount.
60
+
61
+ 16
62
+ 00:01:06,000 --> 00:01:11,000
63
+ The rest of the methods are getters and setters and you can see that all methods have implementation.
64
+
65
+ 17
66
+ 00:01:12,000 --> 00:01:14,000
67
+ To create an object of a concrete class.
68
+
69
+ 18
70
+ 00:01:14,000 --> 00:01:16,000
71
+ You just need to call the constructor of this type.
72
+
73
+ 19
74
+ 00:01:20,000 --> 00:01:26,000
75
+ Now, let's take a look what nested classes are you already know that we can have nested static classes
76
+
77
+ 20
78
+ 00:01:26,000 --> 00:01:29,000
79
+ and inner classes to explain what the nested class is?
80
+
81
+ 21
82
+ 00:01:29,000 --> 00:01:31,000
83
+ Let's consider the next case.
84
+
85
+ 22
86
+ 00:01:31,000 --> 00:01:37,000
87
+ Imagine we have Kaat object and we need to declare a specific class which will represent the tax.
88
+
89
+ 23
90
+ 00:01:37,000 --> 00:01:42,000
91
+ But logically, we understand that tax can exist without Kaat.
92
+
93
+ 24
94
+ 00:01:42,000 --> 00:01:48,000
95
+ But there is no sense to have tax without cards because if the cart is empty, then the tax for this
96
+
97
+ 25
98
+ 00:01:48,000 --> 00:01:50,000
99
+ order also will be absent.
100
+
101
+ 26
102
+ 00:01:51,000 --> 00:01:56,000
103
+ Then there is no reason to have this tax, but still it can exist.
104
+
105
+ 27
106
+ 00:01:56,000 --> 00:02:02,000
107
+ Agree, taking into account the fact that tax is tightly coupled with the cart object, we declare a
108
+
109
+ 28
110
+ 00:02:02,000 --> 00:02:07,000
111
+ new class inside cart here you see that I add Statik static modifier before class.
112
+
113
+ 29
114
+ 00:02:07,000 --> 00:02:10,000
115
+ But beside that this class can contain everything.
116
+
117
+ 30
118
+ 00:02:10,000 --> 00:02:12,000
119
+ What a concrete class can contain.
120
+
121
+ 31
122
+ 00:02:13,000 --> 00:02:17,000
123
+ To create an instance of a tax object, you need to call constructor of tax type.
124
+
125
+ 32
126
+ 00:02:17,000 --> 00:02:25,000
127
+ But with the help of car type, you have to write new laws and specify the class dot name of the nested
128
+
129
+ 33
130
+ 00:02:25,000 --> 00:02:27,000
131
+ class and call a constructor.
132
+
133
+ 34
134
+ 00:02:27,000 --> 00:02:32,000
135
+ You might be wondering what is the sense and declare an asset class if we can create object of nested
136
+
137
+ 35
138
+ 00:02:32,000 --> 00:02:35,000
139
+ class when we need without object of court class.
140
+
141
+ 36
142
+ 00:02:36,000 --> 00:02:37,000
143
+ And you will be right.
144
+
145
+ 37
146
+ 00:02:37,000 --> 00:02:42,000
147
+ As we keep learning object oriented programming, you will see different examples from JDK and you will
148
+
149
+ 38
150
+ 00:02:42,000 --> 00:02:49,000
151
+ feel when you need to create nested classes and very often nested classes have private modifier so that
152
+
153
+ 39
154
+ 00:02:49,000 --> 00:02:54,000
155
+ you wouldn't be able to create an instance of nested class outside of the order class because of their
156
+
157
+ 40
158
+ 00:02:54,000 --> 00:03:00,000
159
+ close relation in this particular case with that client of our code to create an object without cards.
160
+
161
+ 41
162
+ 00:03:00,000 --> 00:03:03,000
163
+ But we are seen with our architecture here.
164
+
165
+ 42
166
+ 00:03:03,000 --> 00:03:05,000
167
+ That tax is closely connected with class object.
168
+
169
+ 43
170
+ 00:03:06,000 --> 00:03:08,000
171
+ On the other hand, you have inner classes.
172
+
173
+ 44
174
+ 00:03:08,000 --> 00:03:13,000
175
+ They are also declared inside of classes, but they do not have static modifier.
176
+
177
+ 45
178
+ 00:03:13,000 --> 00:03:19,000
179
+ Imagine that we have card and you need to describe discounts that can be applied to the card and in
180
+
181
+ 46
182
+ 00:03:19,000 --> 00:03:22,000
183
+ your program, discount can't exist without a card.
184
+
185
+ 47
186
+ 00:03:22,000 --> 00:03:25,000
187
+ In this case, we need to create an inner class and here it is.
188
+
189
+ 48
190
+ 00:03:26,000 --> 00:03:30,000
191
+ You can create methods and fields and everything else inside the inner class.
192
+
193
+ 49
194
+ 00:03:31,000 --> 00:03:37,000
195
+ Now let's take a look how we can create objects of inner class to instantiate objects of inner class.
196
+
197
+ 50
198
+ 00:03:37,000 --> 00:03:40,000
199
+ You need to have a reference to the object of auto class.
200
+
201
+ 51
202
+ 00:03:40,000 --> 00:03:45,000
203
+ Does that mean you can't create object of inner class without having an object of auto class?
204
+
205
+ 52
206
+ 00:03:46,000 --> 00:03:49,000
207
+ That's why here a great object of the car type first.
208
+
209
+ 53
210
+ 00:03:49,000 --> 00:03:54,000
211
+ And after that I create the object of the discount type and call the constructor.
212
+
213
+ 54
214
+ 00:03:54,000 --> 00:04:00,000
215
+ Now I can assign reference to this object to this variable, the feel, the difference between inner
216
+
217
+ 55
218
+ 00:04:00,000 --> 00:04:01,000
219
+ and nested classes.
220
+
221
+ 56
222
+ 00:04:02,000 --> 00:04:06,000
223
+ Hobbs's specific examples help you to understand the difference better.
224
+
225
+ 57
226
+ 00:04:06,000 --> 00:04:09,000
227
+ As always, you have the opportunity to look at the source code.
228
+
229
+ 58
230
+ 00:04:09,000 --> 00:04:12,000
231
+ I will leave links to these files in the attachments to this lesson.
232
+
233
+ 59
234
+ 00:04:13,000 --> 00:04:16,000
235
+ Now let's talk about what the final classes are.
236
+
237
+ 60
238
+ 00:04:16,000 --> 00:04:19,000
239
+ We can make our user class final just like this.
240
+
241
+ 61
242
+ 00:04:19,000 --> 00:04:22,000
243
+ Just add final keyword before class.
244
+
245
+ 62
246
+ 00:04:22,000 --> 00:04:23,000
247
+ What does it mean?
248
+
249
+ 63
250
+ 00:04:23,000 --> 00:04:30,000
251
+ You remember I told you about inheritance as a basic or principle when you wrote final keyword here.
252
+
253
+ 64
254
+ 00:04:30,000 --> 00:04:33,000
255
+ That means you are not able to describe new classes.
256
+
257
+ 65
258
+ 00:04:33,000 --> 00:04:39,000
259
+ And based on this one, that means you are not able to extend this class and add new behavior to this
260
+
261
+ 66
262
+ 00:04:39,000 --> 00:04:39,000
263
+ type.
264
+
265
+ 67
266
+ 00:04:40,000 --> 00:04:42,000
267
+ For example, string is also final class.
268
+
269
+ 68
270
+ 00:04:43,000 --> 00:04:47,000
271
+ And let's imagine I want to extend user from Streambed for some reasons.
272
+
273
+ 69
274
+ 00:04:50,000 --> 00:04:57,000
275
+ I can write extends here and string the type user cannot be a subclass of the final clustering.
276
+
277
+ 70
278
+ 00:04:58,000 --> 00:05:00,000
279
+ We'll talk more about inheritance in a separate lesson.
280
+
281
+ 71
282
+ 00:05:01,000 --> 00:05:06,000
283
+ But right now, I want you to understand that when we are talking about final classes, first of all,
284
+
285
+ 72
286
+ 00:05:06,000 --> 00:05:08,000
287
+ women classes that we can't extend.
288
+
289
+ 73
290
+ 00:05:09,000 --> 00:05:15,000
291
+ Project classes will be easy for you to understand, Bodger stands for plain old Jawa Object.
292
+
293
+ 74
294
+ 00:05:16,000 --> 00:05:18,000
295
+ These are just simple Java classes.
296
+
297
+ 75
298
+ 00:05:19,000 --> 00:05:24,000
299
+ For example, project classes shouldn't, first of all, extend to any other classes.
300
+
301
+ 76
302
+ 00:05:24,000 --> 00:05:32,000
303
+ Secondly, implement interfaces and contain prespecified annotations like antiquing or Odos.
304
+
305
+ 77
306
+ 00:05:32,000 --> 00:05:38,000
307
+ Usually people call simple classes with just getters and setters and default constructor your classes.
308
+
309
+ 78
310
+ 00:05:38,000 --> 00:05:42,000
311
+ For example, this product class can be called project class.
312
+
313
+ 79
314
+ 00:05:42,000 --> 00:05:44,000
315
+ So now you know the terminology.
316
+
317
+ 80
318
+ 00:05:44,000 --> 00:05:46,000
319
+ As you can see, that was easy.
320
+
321
+ 81
322
+ 00:05:47,000 --> 00:05:53,000
323
+ APSA classes, APSA classes exist to put their common code for the specific Iraqi.
324
+
325
+ 82
326
+ 00:05:53,000 --> 00:05:58,000
327
+ For example, let's pretend that in our e-commerce solution we have product class.
328
+
329
+ 83
330
+ 00:05:58,000 --> 00:06:05,000
331
+ It will be abstract, it will have such fields as an idea, name, minimum amount of order quantity
332
+
333
+ 84
334
+ 00:06:05,000 --> 00:06:10,000
335
+ will also have here Flaxton in the five, whether the product is available for delivery.
336
+
337
+ 85
338
+ 00:06:10,000 --> 00:06:13,000
339
+ We don't want to make product class concrete.
340
+
341
+ 86
342
+ 00:06:13,000 --> 00:06:18,000
343
+ We want to keep it abstract y because in our program we don't need to instantiate product types.
344
+
345
+ 87
346
+ 00:06:19,000 --> 00:06:20,000
347
+ What do we need?
348
+
349
+ 88
350
+ 00:06:20,000 --> 00:06:24,000
351
+ Instead, we need to instantiate master product and waron product.
352
+
353
+ 89
354
+ 00:06:24,000 --> 00:06:28,000
355
+ These are specific types of products which will be used in our online shop.
356
+
357
+ 90
358
+ 00:06:29,000 --> 00:06:35,000
359
+ Kivi can be master product, Boutte's will be Verant product because we can have different sizes of
360
+
361
+ 91
362
+ 00:06:35,000 --> 00:06:39,000
363
+ the same goods and different sizes of boots as in most master products.
364
+
365
+ 92
366
+ 00:06:40,000 --> 00:06:46,000
367
+ Master and Vuuren products will extend abasic product type and just few properties will be added to
368
+
369
+ 93
370
+ 00:06:46,000 --> 00:06:47,000
371
+ these types.
372
+
373
+ 94
374
+ 00:06:47,000 --> 00:06:53,000
375
+ For example, array of master products will be added to via product because let's pretend we want to
376
+
377
+ 95
378
+ 00:06:53,000 --> 00:06:55,000
379
+ sell goods, goods, a variant.
380
+
381
+ 96
382
+ 00:06:55,000 --> 00:06:57,000
383
+ You can have boots of different sizes.
384
+
385
+ 97
386
+ 00:06:58,000 --> 00:07:03,000
387
+ Master Product also has another property which is different from abstract product type will have boolean
388
+
389
+ 98
390
+ 00:07:03,000 --> 00:07:08,000
391
+ property is available for lease to identify whether this product is available for lease.
392
+
393
+ 99
394
+ 00:07:09,000 --> 00:07:11,000
395
+ Now let's try to create objects.
396
+
397
+ 100
398
+ 00:07:11,000 --> 00:07:17,000
399
+ We can't create an object from an abstract class, but we can create objects of concrete glass that
400
+
401
+ 101
402
+ 00:07:17,000 --> 00:07:19,000
403
+ extends our abstract class.
404
+
405
+ 102
406
+ 00:07:19,000 --> 00:07:21,000
407
+ And I want to pay your attention here.
408
+
409
+ 103
410
+ 00:07:21,000 --> 00:07:24,000
411
+ Take into account master product and and product.
412
+
413
+ 104
414
+ 00:07:24,000 --> 00:07:26,000
415
+ Class extends product.
416
+
417
+ 105
418
+ 00:07:26,000 --> 00:07:30,000
419
+ We have the same methods which we have in product class.
420
+
421
+ 106
422
+ 00:07:31,000 --> 00:07:38,000
423
+ So you can understand that code which is placed here in product class is common for all child classes.
424
+
425
+ 107
426
+ 00:07:39,000 --> 00:07:40,000
427
+ Does it make sense?
428
+
429
+ 108
430
+ 00:07:40,000 --> 00:07:43,000
431
+ Can you see why do you need to have abstract classes?
432
+
433
+ 109
434
+ 00:07:43,000 --> 00:07:49,000
435
+ For example, we'll talk more in details regarding inheritance and extends keyword in separate lesson.
436
+
437
+ 110
438
+ 00:07:49,000 --> 00:07:55,000
439
+ But I decided to show you this example because it will be hard to explain the necessity of having abstract
440
+
441
+ 111
442
+ 00:07:55,000 --> 00:07:56,000
443
+ classes in your program.
444
+
445
+ 112
446
+ 00:07:57,000 --> 00:08:01,000
447
+ And that's a reason to have an abstract class is in case you know that your object should have some
448
+
449
+ 113
450
+ 00:08:01,000 --> 00:08:07,000
451
+ specific behavior, but you don't know the exact implementation of this behavior for all child classes.
452
+
453
+ 114
454
+ 00:08:07,000 --> 00:08:12,000
455
+ Let me show you this on the example, your products will be able to check whether it's available in
456
+
457
+ 115
458
+ 00:08:12,000 --> 00:08:18,000
459
+ stock, but you have different implementations for this behavior in master environ product classes.
460
+
461
+ 116
462
+ 00:08:19,000 --> 00:08:22,000
463
+ That's why I graded abstract methods in product class.
464
+
465
+ 117
466
+ 00:08:22,000 --> 00:08:25,000
467
+ Abstract method is a method without body.
468
+
469
+ 118
470
+ 00:08:25,000 --> 00:08:30,000
471
+ You see that I added abstract keyword and there is no body in this method.
472
+
473
+ 119
474
+ 00:08:30,000 --> 00:08:32,000
475
+ It is just the method declaration.
476
+
477
+ 120
478
+ 00:08:33,000 --> 00:08:36,000
479
+ And this method should be implemented in child classes.
480
+
481
+ 121
482
+ 00:08:36,000 --> 00:08:39,000
483
+ For example, in multiproduct you will just check remaining amount.
484
+
485
+ 122
486
+ 00:08:40,000 --> 00:08:43,000
487
+ If it's not zero, then you have this product in stock.
488
+
489
+ 123
490
+ 00:08:43,000 --> 00:08:48,000
491
+ Yet the remaining amount and stock method is the method which will check the amount of this product
492
+
493
+ 124
494
+ 00:08:48,000 --> 00:08:49,000
495
+ in stock, in database.
496
+
497
+ 125
498
+ 00:08:50,000 --> 00:08:56,000
499
+ For the sake of example, I made a stop here to focus your attention on the other concept invariant
500
+
501
+ 126
502
+ 00:08:56,000 --> 00:08:56,000
503
+ product.
504
+
505
+ 127
506
+ 00:08:56,000 --> 00:08:59,000
507
+ You have to iterate over each variant and encase case.
508
+
509
+ 128
510
+ 00:08:59,000 --> 00:09:02,000
511
+ At least one variant of the product is in stock.
512
+
513
+ 129
514
+ 00:09:02,000 --> 00:09:06,000
515
+ Let's indicate to our user that this product is in stock and let's return.
516
+
517
+ 130
518
+ 00:09:06,000 --> 00:09:10,000
519
+ True, and only if NIESR variance is in stock.
520
+
521
+ 131
522
+ 00:09:10,000 --> 00:09:11,000
523
+ Let's return false.
524
+
525
+ 132
526
+ 00:09:12,000 --> 00:09:15,000
527
+ I hope now you get clarity on what abstract classes are.
528
+
529
+ 133
530
+ 00:09:16,000 --> 00:09:19,000
531
+ And last but not least for today, is anonymous class.
532
+
533
+ 134
534
+ 00:09:19,000 --> 00:09:24,000
535
+ You already know that I can't create an instant of the abstract class product, but I can create an
536
+
537
+ 135
538
+ 00:09:24,000 --> 00:09:27,000
539
+ instance of anonymous class that extends class product.
540
+
541
+ 136
542
+ 00:09:28,000 --> 00:09:34,000
543
+ For example, here are wrote new product, curly bracket and now I can implement abstract method.
544
+
545
+ 137
546
+ 00:09:35,000 --> 00:09:41,000
547
+ This definition is called abstract class because this is a definition of a new class that has no name.
548
+
549
+ 138
550
+ 00:09:42,000 --> 00:09:47,000
551
+ Usually you declare anonymous class and instantiate object at the same moment of time.
552
+
553
+ 139
554
+ 00:09:47,000 --> 00:09:48,000
555
+ That's it.
556
+
557
+ 140
558
+ 00:09:48,000 --> 00:09:51,000
559
+ Now you know all types of classes that can exist in Java.
560
+
561
+ 141
562
+ 00:09:52,000 --> 00:09:54,000
563
+ Now let's recap what we have learned today.
564
+
565
+ 142
566
+ 00:09:55,000 --> 00:09:59,000
567
+ We learned what can create static nested in our final bodger.
568
+
569
+ 143
570
+ 00:09:59,000 --> 00:10:03,000
571
+ Abstract and anonymous classes are after today's lesson.
572
+
573
+ 144
574
+ 00:10:03,000 --> 00:10:08,000
575
+ You also know what abstract methods are and how you can use abstract modifier with classes and methods.
576
+
577
+ 145
578
+ 00:10:10,000 --> 00:10:11,000
579
+ That's all what I have for you for today.
580
+
581
+ 146
582
+ 00:10:12,000 --> 00:10:15,000
583
+ Thanks a lot for your attention and see you in the next lesson.
584
+
13 - Object-oriented programming/003 Source-code-Abstract-Product.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/classes/typesofclasses/Product.java
13 - Object-oriented programming/003 Source-code-Cart-with-Tax-and-Discount.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/classes/Cart.java
13 - Object-oriented programming/003 Source-code-Demo-class.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/classes/typesofclasses/Demo.java
13 - Object-oriented programming/003 Source-code-Master-Product.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/classes/typesofclasses/MasterProduct.java
13 - Object-oriented programming/003 Source-code-POJO-Product.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/classes/Product.java
13 - Object-oriented programming/003 Source-code-User-class.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/classes/typesofclasses/User.java
13 - Object-oriented programming/003 Source-code-Variant-product.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/classes/typesofclasses/VariantProduct.java
13 - Object-oriented programming/004 Interfaces_en.srt ADDED
@@ -0,0 +1,688 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:05,000 --> 00:00:10,000
3
+ Hello, dear students, in this lesson, we are going to talk with you about interfaces from this lesson,
4
+
5
+ 2
6
+ 00:00:10,000 --> 00:00:13,000
7
+ you learn what interfaces are and what do they consist of.
8
+
9
+ 3
10
+ 00:00:13,000 --> 00:00:18,000
11
+ Also, we'll discuss what is the difference between abstract class and interface.
12
+
13
+ 4
14
+ 00:00:18,000 --> 00:00:23,000
15
+ And at the end of the lesson, I will tell you what is the difference between such terms as interface,
16
+
17
+ 5
18
+ 00:00:23,000 --> 00:00:24,000
19
+ class and time.
20
+
21
+ 6
22
+ 00:00:25,000 --> 00:00:30,000
23
+ Let's go as I just start and look at examples to understand what interfaces are.
24
+
25
+ 7
26
+ 00:00:30,000 --> 00:00:36,000
27
+ First of all, let's come up with a definition of an interface interfaces, an abstraction which defines
28
+
29
+ 8
30
+ 00:00:36,000 --> 00:00:41,000
31
+ a behavioral contract that must be followed by every class that implements this interface.
32
+
33
+ 9
34
+ 00:00:42,000 --> 00:00:48,000
35
+ In other words, you specify a set of expected behavior which should be present in each class that implements
36
+
37
+ 10
38
+ 00:00:48,000 --> 00:00:49,000
39
+ this interface.
40
+
41
+ 11
42
+ 00:00:49,000 --> 00:00:53,000
43
+ But it don't specify how exactly this behavior will be implemented.
44
+
45
+ 12
46
+ 00:00:53,000 --> 00:00:56,000
47
+ For example, have interface here for payment processor.
48
+
49
+ 13
50
+ 00:00:57,000 --> 00:01:03,000
51
+ I need to have some type in my program that will be able to process payment and send information about
52
+
53
+ 14
54
+ 00:01:03,000 --> 00:01:04,000
55
+ our payment to Payment Gateway.
56
+
57
+ 15
58
+ 00:01:05,000 --> 00:01:12,000
59
+ That's why I want to declare what method with the name process payment, the text payment data object
60
+
61
+ 16
62
+ 00:01:12,000 --> 00:01:13,000
63
+ as an argument.
64
+
65
+ 17
66
+ 00:01:13,000 --> 00:01:20,000
67
+ Payment data is simple project loss that has the payment amount tax amount idea of a user who wants
68
+
69
+ 18
70
+ 00:01:20,000 --> 00:01:22,000
71
+ to make a payment and currency.
72
+
73
+ 19
74
+ 00:01:23,000 --> 00:01:25,000
75
+ The rest of the message here I just getters and setters.
76
+
77
+ 20
78
+ 00:01:26,000 --> 00:01:27,000
79
+ Now let's get back to our interface.
80
+
81
+ 21
82
+ 00:01:28,000 --> 00:01:32,000
83
+ You see that I declared method without body and without any other modifiers.
84
+
85
+ 22
86
+ 00:01:33,000 --> 00:01:33,000
87
+ Why?
88
+
89
+ 23
90
+ 00:01:34,000 --> 00:01:39,000
91
+ Because invisibly, all matters in interface have modifiers, public and abstract.
92
+
93
+ 24
94
+ 00:01:39,000 --> 00:01:44,000
95
+ So in case I will add here public and abstract modifier, nothing will change.
96
+
97
+ 25
98
+ 00:01:45,000 --> 00:01:50,000
99
+ But there is no sense in any public abstract modifiers because all methods and interfaces by default
100
+
101
+ 26
102
+ 00:01:50,000 --> 00:01:52,000
103
+ are public and abstract.
104
+
105
+ 27
106
+ 00:01:52,000 --> 00:01:58,000
107
+ I can say that this interface said the contract on the process payment behavior by same contract.
108
+
109
+ 28
110
+ 00:01:58,000 --> 00:02:04,000
111
+ I mean, this interface clearly defines what a return type will be, how method will be called and what
112
+
113
+ 29
114
+ 00:02:04,000 --> 00:02:06,000
115
+ parameters will be in it, period.
116
+
117
+ 30
118
+ 00:02:07,000 --> 00:02:11,000
119
+ But this interface doesn't bother about what exact code will be written.
120
+
121
+ 31
122
+ 00:02:12,000 --> 00:02:17,000
123
+ And now when I have such interface in my program, I can create time that will implement this contract.
124
+
125
+ 32
126
+ 00:02:17,000 --> 00:02:23,000
127
+ I have changed payment processor and PayPal payment processor both implements payment processor interface.
128
+
129
+ 33
130
+ 00:02:24,000 --> 00:02:28,000
131
+ That means these classes are obligated to implement process payment methods.
132
+
133
+ 34
134
+ 00:02:29,000 --> 00:02:35,000
135
+ Since this method is abstract in the interface in our concrete class, we must implement this method.
136
+
137
+ 35
138
+ 00:02:35,000 --> 00:02:37,000
139
+ If only our class will be abstract.
140
+
141
+ 36
142
+ 00:02:38,000 --> 00:02:40,000
143
+ There is no need to implement this method.
144
+
145
+ 37
146
+ 00:02:40,000 --> 00:02:44,000
147
+ Let me call on this method and at absolute keyword before class.
148
+
149
+ 38
150
+ 00:02:44,000 --> 00:02:47,000
151
+ You see, there is no compilation error.
152
+
153
+ 39
154
+ 00:02:47,000 --> 00:02:52,000
155
+ But since this class is not abstract, there will be compilation error.
156
+
157
+ 40
158
+ 00:02:52,000 --> 00:02:58,000
159
+ In case we won't implement this method, you can press control plus one and select and implemented methods
160
+
161
+ 41
162
+ 00:02:58,000 --> 00:02:59,000
163
+ to generate stop method.
164
+
165
+ 42
166
+ 00:03:00,000 --> 00:03:02,000
167
+ I will just on existing one.
168
+
169
+ 43
170
+ 00:03:02,000 --> 00:03:04,000
171
+ This method will work differently.
172
+
173
+ 44
174
+ 00:03:04,000 --> 00:03:07,000
175
+ For example, chase payment processor.
176
+
177
+ 45
178
+ 00:03:07,000 --> 00:03:13,000
179
+ Because of the specifics of Payment Gateway, it should obtain security token first for authorization
180
+
181
+ 46
182
+ 00:03:14,000 --> 00:03:19,000
183
+ and only after that we can initialize payment page with secure token and the amount of money to pay.
184
+
185
+ 47
186
+ 00:03:20,000 --> 00:03:26,000
187
+ On the other hand, let's pretend that PayPal payment processor needs to request payment for by using
188
+
189
+ 48
190
+ 00:03:26,000 --> 00:03:27,000
191
+ a specific application key.
192
+
193
+ 49
194
+ 00:03:27,000 --> 00:03:32,000
195
+ And after that we have to fill out this form of payment details and submit it.
196
+
197
+ 50
198
+ 00:03:32,000 --> 00:03:36,000
199
+ You can notice that in both cases we have override annotation here.
200
+
201
+ 51
202
+ 00:03:36,000 --> 00:03:40,000
203
+ This notation exists for the sake of a successful compilation.
204
+
205
+ 52
206
+ 00:03:40,000 --> 00:03:41,000
207
+ Do not switch the topic.
208
+
209
+ 53
210
+ 00:03:41,000 --> 00:03:43,000
211
+ Let's keep focus on our interfaces.
212
+
213
+ 54
214
+ 00:03:43,000 --> 00:03:48,000
215
+ I will tell you more about overwrite annotation in our detailed lesson about polymorphism.
216
+
217
+ 55
218
+ 00:03:48,000 --> 00:03:50,000
219
+ Do we see these two examples?
220
+
221
+ 56
222
+ 00:03:51,000 --> 00:03:55,000
223
+ The behavior is the same both classes, protests, payment data.
224
+
225
+ 57
226
+ 00:03:55,000 --> 00:03:57,000
227
+ But they do this in different ways.
228
+
229
+ 58
230
+ 00:03:57,000 --> 00:04:00,000
231
+ What do all this look like exactly?
232
+
233
+ 59
234
+ 00:04:00,000 --> 00:04:06,000
235
+ This look like implementation of polymorphism principle, one of the main or P principle?
236
+
237
+ 60
238
+ 00:04:06,000 --> 00:04:07,000
239
+ Why else?
240
+
241
+ 61
242
+ 00:04:07,000 --> 00:04:12,000
243
+ We need interfaces to build our application was dependency on the obstruction types, but not on the
244
+
245
+ 62
246
+ 00:04:12,000 --> 00:04:13,000
247
+ concrete classes.
248
+
249
+ 63
250
+ 00:04:14,000 --> 00:04:15,000
251
+ Let me show you this example.
252
+
253
+ 64
254
+ 00:04:16,000 --> 00:04:18,000
255
+ You mentioned we have some client of our code.
256
+
257
+ 65
258
+ 00:04:18,000 --> 00:04:22,000
259
+ It could be some other class so-called facade class or controller class.
260
+
261
+ 66
262
+ 00:04:22,000 --> 00:04:23,000
263
+ That doesn't matter.
264
+
265
+ 67
266
+ 00:04:24,000 --> 00:04:28,000
267
+ And this class can simply rely on the interface of payment processor type.
268
+
269
+ 68
270
+ 00:04:29,000 --> 00:04:33,000
271
+ We can say that by default, variable of payment processor reference to PayPal payment processor.
272
+
273
+ 69
274
+ 00:04:34,000 --> 00:04:38,000
275
+ But in fact, this client doesn't bother with implementation of payment processor.
276
+
277
+ 70
278
+ 00:04:38,000 --> 00:04:42,000
279
+ We will use PayPal payment processor or chase payment processor.
280
+
281
+ 71
282
+ 00:04:42,000 --> 00:04:48,000
283
+ Moreover, somebody can use Setar and that is a chase or PayPal payment process during the runtime.
284
+
285
+ 72
286
+ 00:04:49,000 --> 00:04:55,000
287
+ The good thing about interfaces and they define level of abstraction and we can build our program relying
288
+
289
+ 73
290
+ 00:04:55,000 --> 00:04:56,000
291
+ on this abstraction.
292
+
293
+ 74
294
+ 00:04:56,000 --> 00:05:01,000
295
+ They see this method and location and checkout method no matter what implementation of payment.
296
+
297
+ 75
298
+ 00:05:01,000 --> 00:05:08,000
299
+ Sir, I will have here during Zeron time, I don't need to change this code and also pay attention to
300
+
301
+ 76
302
+ 00:05:08,000 --> 00:05:09,000
303
+ one more thing here.
304
+
305
+ 77
306
+ 00:05:09,000 --> 00:05:16,000
307
+ I can initialize variable of interface type with a reference to an object of any other class which implements
308
+
309
+ 78
310
+ 00:05:16,000 --> 00:05:17,000
311
+ this interface.
312
+
313
+ 79
314
+ 00:05:18,000 --> 00:05:20,000
315
+ OK, Holmes, this is clear.
316
+
317
+ 80
318
+ 00:05:20,000 --> 00:05:23,000
319
+ Now, let's take a look what our interface can contain.
320
+
321
+ 81
322
+ 00:05:23,000 --> 00:05:27,000
323
+ As you already understand, our interface can contain abstract methods.
324
+
325
+ 82
326
+ 00:05:27,000 --> 00:05:29,000
327
+ It can have as many methods as you wish.
328
+
329
+ 83
330
+ 00:05:30,000 --> 00:05:34,000
331
+ But later we will learn other object oriented principles and you will understand that it is better to
332
+
333
+ 84
334
+ 00:05:34,000 --> 00:05:37,000
335
+ have a lot of small interfaces rather than one.
336
+
337
+ 85
338
+ 00:05:37,000 --> 00:05:42,000
339
+ And besides abstract methods, our interface can contain default methods.
340
+
341
+ 86
342
+ 00:05:42,000 --> 00:05:48,000
343
+ Default methods are methods that have body so you can treat them like regular methods in concrete glass.
344
+
345
+ 87
346
+ 00:05:49,000 --> 00:05:54,000
347
+ But the Java syntax wouldn't allow you to declare a method with body and interface without default.
348
+
349
+ 88
350
+ 00:05:54,000 --> 00:06:02,000
351
+ Keyword in case iRace the default keyword compiler tells me that abstract methods don't have money because
352
+
353
+ 89
354
+ 00:06:02,000 --> 00:06:04,000
355
+ compiler treats this method as abstract.
356
+
357
+ 90
358
+ 00:06:05,000 --> 00:06:07,000
359
+ Also, our interface may contain static methods.
360
+
361
+ 91
362
+ 00:06:07,000 --> 00:06:12,000
363
+ We are going to have a separate lesson about static keywords, but right now you can remember the static
364
+
365
+ 92
366
+ 00:06:12,000 --> 00:06:15,000
367
+ methods can be called without any object.
368
+
369
+ 93
370
+ 00:06:15,000 --> 00:06:19,000
371
+ So you don't need to write newcomer's and create objects.
372
+
373
+ 94
374
+ 00:06:19,000 --> 00:06:23,000
375
+ You can just write type name and column method like I did here.
376
+
377
+ 95
378
+ 00:06:23,000 --> 00:06:28,000
379
+ For example, I wrote the name of the interface and invoke static method on this interface.
380
+
381
+ 96
382
+ 00:06:29,000 --> 00:06:32,000
383
+ Notice I didn't use variable of payment processor type.
384
+
385
+ 97
386
+ 00:06:32,000 --> 00:06:33,000
387
+ I use interface.
388
+
389
+ 98
390
+ 00:06:34,000 --> 00:06:36,000
391
+ It is not very object oriented approach.
392
+
393
+ 99
394
+ 00:06:36,000 --> 00:06:40,000
395
+ Why wait for the in the most cited keywords and I will tell you more about it.
396
+
397
+ 100
398
+ 00:06:41,000 --> 00:06:45,000
399
+ So far, you know that interface can contain abstract default and static methods.
400
+
401
+ 101
402
+ 00:06:45,000 --> 00:06:48,000
403
+ What else interface can have constants.
404
+
405
+ 102
406
+ 00:06:49,000 --> 00:06:53,000
407
+ For example, imagine the real life scenario in case our payment failed.
408
+
409
+ 103
410
+ 00:06:53,000 --> 00:06:55,000
411
+ We need to retrieve a few more times.
412
+
413
+ 104
414
+ 00:06:55,000 --> 00:07:02,000
415
+ I create variable of type retry attempts and you probably noticed that the clips for months, this variable
416
+
417
+ 105
418
+ 00:07:02,000 --> 00:07:06,000
419
+ name like a constant I'm in cursive and another color.
420
+
421
+ 106
422
+ 00:07:06,000 --> 00:07:10,000
423
+ That is because by default, all fields and interfaces have public static.
424
+
425
+ 107
426
+ 00:07:10,000 --> 00:07:17,000
427
+ Final modifiers like all constants have public so that everyone could access it static because constant
428
+
429
+ 108
430
+ 00:07:17,000 --> 00:07:22,000
431
+ should exist in a single copy and final so that nobody could override it.
432
+
433
+ 109
434
+ 00:07:22,000 --> 00:07:25,000
435
+ We will talk more about constants in the lesson about static keywords.
436
+
437
+ 110
438
+ 00:07:26,000 --> 00:07:30,000
439
+ And even if I would add these modifiers here, nothing will change.
440
+
441
+ 111
442
+ 00:07:30,000 --> 00:07:33,000
443
+ But usually developers give this modifiers in interfaces.
444
+
445
+ 112
446
+ 00:07:34,000 --> 00:07:37,000
447
+ Let me also removed important things that we didn't discuss yet.
448
+
449
+ 113
450
+ 00:07:37,000 --> 00:07:43,000
451
+ If the fact that class can implement multiple interfaces at once, I'm not sure whether you notice that
452
+
453
+ 114
454
+ 00:07:43,000 --> 00:07:49,000
455
+ our chase payment processor implements two interfaces, the one we discussed already, and another one
456
+
457
+ 115
458
+ 00:07:49,000 --> 00:07:51,000
459
+ is payment for the data.
460
+
461
+ 116
462
+ 00:07:51,000 --> 00:07:56,000
463
+ If this class implements payment for the data interface, that means this class should implement validate
464
+
465
+ 117
466
+ 00:07:56,000 --> 00:08:02,000
467
+ payment methods which will validate payment to be sure that it has all necessary information for payment
468
+
469
+ 118
470
+ 00:08:02,000 --> 00:08:03,000
471
+ processing.
472
+
473
+ 119
474
+ 00:08:03,000 --> 00:08:07,000
475
+ In this payment gateway in Java, it is allowed to implement multiple interfaces.
476
+
477
+ 120
478
+ 00:08:08,000 --> 00:08:11,000
479
+ But in one specific case, this can lead to compilation error.
480
+
481
+ 121
482
+ 00:08:11,000 --> 00:08:13,000
483
+ And I want you to know this case.
484
+
485
+ 122
486
+ 00:08:14,000 --> 00:08:15,000
487
+ Let's discuss it.
488
+
489
+ 123
490
+ 00:08:15,000 --> 00:08:21,000
491
+ For example, in payment processor interface, you have some default method and in payment for the data,
492
+
493
+ 124
494
+ 00:08:21,000 --> 00:08:24,000
495
+ you also have default method with the same signature.
496
+
497
+ 125
498
+ 00:08:24,000 --> 00:08:30,000
499
+ Here it this this can lead to compilation error in chase payment processor class, because during the
500
+
501
+ 126
502
+ 00:08:30,000 --> 00:08:33,000
503
+ runtime it will be unclear which default method should be used.
504
+
505
+ 127
506
+ 00:08:34,000 --> 00:08:37,000
507
+ The one from payment for the data was the one from payment processor.
508
+
509
+ 128
510
+ 00:08:38,000 --> 00:08:44,000
511
+ That's why it doesn't allow us to compile this code until we resolve issue was duplicated default methods.
512
+
513
+ 129
514
+ 00:08:44,000 --> 00:08:47,000
515
+ So now you know really a lot about interfaces.
516
+
517
+ 130
518
+ 00:08:48,000 --> 00:08:53,000
519
+ It is time to understand how good you learned interfaces and ask you what is the difference between
520
+
521
+ 131
522
+ 00:08:53,000 --> 00:08:55,000
523
+ abstract classes and interfaces.
524
+
525
+ 132
526
+ 00:08:55,000 --> 00:08:59,000
527
+ Absolute class we can extend with extensive keyboard interface.
528
+
529
+ 133
530
+ 00:08:59,000 --> 00:09:02,000
531
+ We can implement using implements, keyboard apps.
532
+
533
+ 134
534
+ 00:09:03,000 --> 00:09:06,000
535
+ A class can have properties with all possible modifiers.
536
+
537
+ 135
538
+ 00:09:06,000 --> 00:09:11,000
539
+ On the other hand, all properties interfaces have public static final modifiers.
540
+
541
+ 136
542
+ 00:09:12,000 --> 00:09:17,000
543
+ You can extend only one class in Java, but you can implement multiple interfaces.
544
+
545
+ 137
546
+ 00:09:17,000 --> 00:09:23,000
547
+ You remember that example when our PayPal payment processor implemented two interfaces at a time?
548
+
549
+ 138
550
+ 00:09:23,000 --> 00:09:27,000
551
+ Basically that the most significant difference between abstract classes and interfaces.
552
+
553
+ 139
554
+ 00:09:28,000 --> 00:09:33,000
555
+ It is also worth to mention that the introduction of default and static methods and interfaces made
556
+
557
+ 140
558
+ 00:09:33,000 --> 00:09:36,000
559
+ it harder to distinguish interfaces from abstract classes.
560
+
561
+ 141
562
+ 00:09:37,000 --> 00:09:42,000
563
+ Based on the difference which we discussed, you can select whether you need to use abstract class or
564
+
565
+ 142
566
+ 00:09:42,000 --> 00:09:43,000
567
+ interface.
568
+
569
+ 143
570
+ 00:09:43,000 --> 00:09:48,000
571
+ For example, if you know that you need to list properties with private or protected access modifiers
572
+
573
+ 144
574
+ 00:09:48,000 --> 00:09:53,000
575
+ that are not static, you already know that you need to use abstract class instead of interface.
576
+
577
+ 145
578
+ 00:09:53,000 --> 00:09:59,000
579
+ And if you need to be able to implement specific interface together with other ones, you know that
580
+
581
+ 146
582
+ 00:09:59,000 --> 00:10:00,000
583
+ you need to use interfaces.
584
+
585
+ 147
586
+ 00:10:01,000 --> 00:10:06,000
587
+ Last but not the least question for today and our agenda is to define the difference between such terms
588
+
589
+ 148
590
+ 00:10:06,000 --> 00:10:11,000
591
+ as class type and interface, you already know what a class is.
592
+
593
+ 149
594
+ 00:10:11,000 --> 00:10:13,000
595
+ Ensure that class is a template for your future.
596
+
597
+ 150
598
+ 00:10:13,000 --> 00:10:19,000
599
+ Object's interface is an abstraction which defines application programming interface and contract for
600
+
601
+ 151
602
+ 00:10:19,000 --> 00:10:20,000
603
+ behavior.
604
+
605
+ 152
606
+ 00:10:20,000 --> 00:10:27,000
607
+ But what is a type probably you heard during the lessons that I use type word as a synonym when I reference
608
+
609
+ 153
610
+ 00:10:27,000 --> 00:10:33,000
611
+ to class interface because class is a type interface is also a type.
612
+
613
+ 154
614
+ 00:10:33,000 --> 00:10:39,000
615
+ That means every type is also is a class and interface and enumeration or an array.
616
+
617
+ 155
618
+ 00:10:39,000 --> 00:10:43,000
619
+ Also, each object has a time and every expression has a type.
620
+
621
+ 156
622
+ 00:10:43,000 --> 00:10:50,000
623
+ If during that interview you will be asked what a typist you can answer something like this type summarizes
624
+
625
+ 157
626
+ 00:10:50,000 --> 00:10:53,000
627
+ the common features of a set of objects with the same characteristics.
628
+
629
+ 158
630
+ 00:10:54,000 --> 00:11:00,000
631
+ Class is a concrete data structure and group of methods that represents an implementation of the type.
632
+
633
+ 159
634
+ 00:11:01,000 --> 00:11:04,000
635
+ Let's look at this example one more time attentively.
636
+
637
+ 160
638
+ 00:11:04,000 --> 00:11:10,000
639
+ Payment processor variable has payment processor type, but this variable reference to the PayPal payment
640
+
641
+ 161
642
+ 00:11:10,000 --> 00:11:12,000
643
+ processor object.
644
+
645
+ 162
646
+ 00:11:12,000 --> 00:11:15,000
647
+ So we can say that the object has a payment processor type.
648
+
649
+ 163
650
+ 00:11:15,000 --> 00:11:22,000
651
+ And you see here in the method parameters, this sector can accept any object of type payment processor.
652
+
653
+ 164
654
+ 00:11:22,000 --> 00:11:29,000
655
+ That means this method can work with any object that implements this interface doesn't make sense.
656
+
657
+ 165
658
+ 00:11:29,000 --> 00:11:32,000
659
+ Hope with this examples, things become clearer.
660
+
661
+ 166
662
+ 00:11:33,000 --> 00:11:35,000
663
+ Let's recap what we have learned today.
664
+
665
+ 167
666
+ 00:11:35,000 --> 00:11:42,000
667
+ In this lesson, we learned what interfaces are, what interfaces can contain inside, how to implement
668
+
669
+ 168
670
+ 00:11:42,000 --> 00:11:48,000
671
+ interface, what default methods and interfaces are, what static methods interfaces are.
672
+
673
+ 169
674
+ 00:11:48,000 --> 00:11:52,000
675
+ Now, you know what the difference between abstract class and interface is.
676
+
677
+ 170
678
+ 00:11:53,000 --> 00:11:56,000
679
+ And you also learn the difference between type and object.
680
+
681
+ 171
682
+ 00:11:57,000 --> 00:11:58,000
683
+ That's all what we have for today.
684
+
685
+ 172
686
+ 00:11:59,000 --> 00:12:02,000
687
+ Thanks a lot for your attention and see you in the next lesson.
688
+
13 - Object-oriented programming/004 Source-code-ChasePaymentProcessor.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/interfaces/ChasePaymentProcessor.java
13 - Object-oriented programming/004 Source-code-Client-class.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/interfaces/Client.java
13 - Object-oriented programming/004 Source-code-PayPalPaymentProcessor.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/interfaces/PayPalPaymentProcessor.java
13 - Object-oriented programming/004 Source-code-PaymentData.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/interfaces/PaymentData.java
13 - Object-oriented programming/004 Source-code-PaymentProcessor-interface.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/interfaces/PaymentProcessor.java
13 - Object-oriented programming/004 Source-code-PaymentValidator.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/interfaces/PaymentValidator.java
13 - Object-oriented programming/005 Inheritance_en.srt ADDED
@@ -0,0 +1,636 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:05,000 --> 00:00:06,000
3
+ Hello, Jim.
4
+
5
+ 2
6
+ 00:00:06,000 --> 00:00:11,000
7
+ In this lesson, we are going to learn more about one of the key principles of the object oriented programming
8
+
9
+ 3
10
+ 00:00:11,000 --> 00:00:12,000
11
+ approach.
12
+
13
+ 4
14
+ 00:00:12,000 --> 00:00:13,000
15
+ I'm talking about inheritance.
16
+
17
+ 5
18
+ 00:00:14,000 --> 00:00:16,000
19
+ And they will talk not only about inheritance.
20
+
21
+ 6
22
+ 00:00:16,000 --> 00:00:23,000
23
+ Well, on super keyword and you operator instance of I will show you how we can extend classes and what
24
+
25
+ 7
26
+ 00:00:23,000 --> 00:00:25,000
27
+ rules should be followed during inheritance.
28
+
29
+ 8
30
+ 00:00:25,000 --> 00:00:27,000
31
+ So let's start.
32
+
33
+ 9
34
+ 00:00:27,000 --> 00:00:32,000
35
+ I believe you remember theoretical part which we discussed in lesson about inheritance.
36
+
37
+ 10
38
+ 00:00:32,000 --> 00:00:37,000
39
+ So now it is time for practical code examples demo to understand this topic better.
40
+
41
+ 11
42
+ 00:00:38,000 --> 00:00:42,000
43
+ I always try to create real life example for you so that you could understand how this works for real
44
+
45
+ 12
46
+ 00:00:43,000 --> 00:00:44,000
47
+ in this lesson.
48
+
49
+ 13
50
+ 00:00:44,000 --> 00:00:46,000
51
+ Imagine that you have product type in your program.
52
+
53
+ 14
54
+ 00:00:46,000 --> 00:00:50,000
55
+ I didn't create too many fields to not distract attention from inheritance topic.
56
+
57
+ 15
58
+ 00:00:51,000 --> 00:00:54,000
59
+ Just imagine that product can have multiple fields and methods.
60
+
61
+ 16
62
+ 00:00:55,000 --> 00:00:56,000
63
+ And we also have the phone type.
64
+
65
+ 17
66
+ 00:00:57,000 --> 00:00:59,000
67
+ Phone is also a product in our online shop.
68
+
69
+ 18
70
+ 00:01:00,000 --> 00:01:03,000
71
+ It will have similar fields and behavior as product has.
72
+
73
+ 19
74
+ 00:01:03,000 --> 00:01:09,000
75
+ But besides that, it has also some phone specific behavior like ring method, for example.
76
+
77
+ 20
78
+ 00:01:10,000 --> 00:01:15,000
79
+ Now let's create phone object I a product variable and initialize it with foreign object.
80
+
81
+ 21
82
+ 00:01:15,000 --> 00:01:22,000
83
+ Take into account for an object is also a type product and you can see that our product variable has
84
+
85
+ 22
86
+ 00:01:22,000 --> 00:01:24,000
87
+ own methods that are declared in product type.
88
+
89
+ 23
90
+ 00:01:25,000 --> 00:01:31,000
91
+ I have said gather and calculate remaining amount method which is not declared in phone but declared
92
+
93
+ 24
94
+ 00:01:31,000 --> 00:01:32,000
95
+ in product.
96
+
97
+ 25
98
+ 00:01:32,000 --> 00:01:39,000
99
+ So the idea of inheritance is to describe new types based on existing one from technical side.
100
+
101
+ 26
102
+ 00:01:39,000 --> 00:01:46,000
103
+ This allows us to reuse already written code, which is also pretty cool because let's imagine you need
104
+
105
+ 27
106
+ 00:01:46,000 --> 00:01:49,000
107
+ to change the logic how remaining amount in stock is calculated.
108
+
109
+ 28
110
+ 00:01:50,000 --> 00:01:56,000
111
+ Instead of changing this method in all classes where this method is used, I can just do change in one
112
+
113
+ 29
114
+ 00:01:56,000 --> 00:02:01,000
115
+ place in product class and behaviour will become different in old child classes.
116
+
117
+ 30
118
+ 00:02:01,000 --> 00:02:07,000
119
+ And you also see that foreign object doesn't have name field, but somehow I can set the value for name
120
+
121
+ 31
122
+ 00:02:07,000 --> 00:02:09,000
123
+ property of the form.
124
+
125
+ 32
126
+ 00:02:09,000 --> 00:02:12,000
127
+ That is because inheritance of this field from product object.
128
+
129
+ 33
130
+ 00:02:13,000 --> 00:02:15,000
131
+ OK, but let's try to ring right now.
132
+
133
+ 34
134
+ 00:02:16,000 --> 00:02:21,000
135
+ Unfortunately, we have compilation error because Renk method is not defined for the type product,
136
+
137
+ 35
138
+ 00:02:21,000 --> 00:02:26,000
139
+ but we see here that we created for an object and we still don't have that Renk method available.
140
+
141
+ 36
142
+ 00:02:27,000 --> 00:02:27,000
143
+ Why?
144
+
145
+ 37
146
+ 00:02:28,000 --> 00:02:30,000
147
+ Because Java is not mahzarin.
148
+
149
+ 38
150
+ 00:02:30,000 --> 00:02:33,000
151
+ What object will be here in this line during the runtime?
152
+
153
+ 39
154
+ 00:02:34,000 --> 00:02:40,000
155
+ You can initialize the variable with any object of this type and Java doesn't want to guess what object
156
+
157
+ 40
158
+ 00:02:40,000 --> 00:02:41,000
159
+ is there for real.
160
+
161
+ 41
162
+ 00:02:41,000 --> 00:02:47,000
163
+ What Java knows that in case code is compiler, that means object which was assigned to this variable
164
+
165
+ 42
166
+ 00:02:47,000 --> 00:02:50,000
167
+ has the same interface as this type for sure.
168
+
169
+ 43
170
+ 00:02:50,000 --> 00:02:56,000
171
+ That's why we don't see any matters from form type here, because we have variable of type product.
172
+
173
+ 44
174
+ 00:02:57,000 --> 00:03:03,000
175
+ When I create variable or form that I can invoke Renk method without compilation error.
176
+
177
+ 45
178
+ 00:03:03,000 --> 00:03:08,000
179
+ But what if my class or method works with product type and I want to call Remarque method?
180
+
181
+ 46
182
+ 00:03:09,000 --> 00:03:12,000
183
+ I will be able to do that only in case during the runtime.
184
+
185
+ 47
186
+ 00:03:12,000 --> 00:03:14,000
187
+ I have phone object here.
188
+
189
+ 48
190
+ 00:03:15,000 --> 00:03:21,000
191
+ But how I can understand this now I will show you a new keyword and operator which you will be able
192
+
193
+ 49
194
+ 00:03:21,000 --> 00:03:23,000
195
+ to use in your programs.
196
+
197
+ 50
198
+ 00:03:23,000 --> 00:03:25,000
199
+ Here is an instance of operator.
200
+
201
+ 51
202
+ 00:03:26,000 --> 00:03:29,000
203
+ It allows you to check the type consistency with the object.
204
+
205
+ 52
206
+ 00:03:30,000 --> 00:03:33,000
207
+ It is a binary operator which works with two operands.
208
+
209
+ 53
210
+ 00:03:34,000 --> 00:03:38,000
211
+ Let me show you how you can use it if object behind the product variable.
212
+
213
+ 54
214
+ 00:03:38,000 --> 00:03:41,000
215
+ This one is instance of phone type.
216
+
217
+ 55
218
+ 00:03:41,000 --> 00:03:44,000
219
+ The result will be true in terms of returns.
220
+
221
+ 56
222
+ 00:03:44,000 --> 00:03:51,000
223
+ Is a true or false and if instance of returns true, I can cast this variable to type the remember how
224
+
225
+ 57
226
+ 00:03:51,000 --> 00:03:53,000
227
+ Wikus primitive types.
228
+
229
+ 58
230
+ 00:03:53,000 --> 00:03:56,000
231
+ We can just reference types in a similar way.
232
+
233
+ 59
234
+ 00:03:56,000 --> 00:03:57,000
235
+ Right.
236
+
237
+ 60
238
+ 00:03:57,000 --> 00:03:59,000
239
+ Phone and variable name.
240
+
241
+ 61
242
+ 00:03:59,000 --> 00:04:04,000
243
+ Now put the type name in parentheses and name of the variable you want to cast.
244
+
245
+ 62
246
+ 00:04:05,000 --> 00:04:11,000
247
+ Now you can invoke Renk method instance of the return false in case variable reference to object is
248
+
249
+ 63
250
+ 00:04:11,000 --> 00:04:15,000
251
+ incompatible with the type you specified as a second operand.
252
+
253
+ 64
254
+ 00:04:16,000 --> 00:04:20,000
255
+ OK, you know what is instance of and when you can use it.
256
+
257
+ 65
258
+ 00:04:20,000 --> 00:04:24,000
259
+ Let's proceed with inheritance topic in your child class.
260
+
261
+ 66
262
+ 00:04:24,000 --> 00:04:26,000
263
+ You always have a reference to a parent class.
264
+
265
+ 67
266
+ 00:04:27,000 --> 00:04:32,000
267
+ You might want to have the reference to the parent class, for example, to call some parent methods.
268
+
269
+ 68
270
+ 00:04:32,000 --> 00:04:33,000
271
+ Let's take a look here.
272
+
273
+ 69
274
+ 00:04:34,000 --> 00:04:40,000
275
+ Product Class has a message that returns the least of all variant products associated with the current
276
+
277
+ 70
278
+ 00:04:40,000 --> 00:04:40,000
279
+ product.
280
+
281
+ 71
282
+ 00:04:40,000 --> 00:04:46,000
283
+ And our phone object overrides this behavior and throws and supports the separation exception.
284
+
285
+ 72
286
+ 00:04:46,000 --> 00:04:51,000
287
+ This exception indicates that this behavior is not supported in this class.
288
+
289
+ 73
290
+ 00:04:52,000 --> 00:04:57,000
291
+ Later in this course, we will learn that this implementation violates one of the design principles
292
+
293
+ 74
294
+ 00:04:57,000 --> 00:04:59,000
295
+ in the object oriented programming.
296
+
297
+ 75
298
+ 00:04:59,000 --> 00:05:02,000
299
+ But you would face with similar cases many in.
300
+
301
+ 76
302
+ 00:05:02,000 --> 00:05:09,000
303
+ Times, believe me, and now what will happen if in another method calculate the amount of variance
304
+
305
+ 77
306
+ 00:05:09,000 --> 00:05:17,000
307
+ I will call least variance method of this object will be called and program will stop execution because
308
+
309
+ 78
310
+ 00:05:17,000 --> 00:05:18,000
311
+ of the exception?
312
+
313
+ 79
314
+ 00:05:18,000 --> 00:05:20,000
315
+ Let me run this program to show you this.
316
+
317
+ 80
318
+ 00:05:21,000 --> 00:05:22,000
319
+ What do you have to do right now?
320
+
321
+ 81
322
+ 00:05:22,000 --> 00:05:27,000
323
+ You already know that in each class you have reference to a parent class who is super keyword.
324
+
325
+ 82
326
+ 00:05:28,000 --> 00:05:34,000
327
+ So let's call math at least reference not from this class, but let's call method list variants of the
328
+
329
+ 83
330
+ 00:05:34,000 --> 00:05:34,000
331
+ parent class.
332
+
333
+ 84
334
+ 00:05:35,000 --> 00:05:38,000
335
+ This one just right super.
336
+
337
+ 85
338
+ 00:05:38,000 --> 00:05:43,000
339
+ This is a reference to the parent type Dorte and invoke the same method.
340
+
341
+ 86
342
+ 00:05:43,000 --> 00:05:47,000
343
+ What we have now left me around this program one more time.
344
+
345
+ 87
346
+ 00:05:47,000 --> 00:05:54,000
347
+ We won't have any error because this method was called you can always use super keyword to reference
348
+
349
+ 88
350
+ 00:05:54,000 --> 00:05:56,000
351
+ methods or properties of a parent class.
352
+
353
+ 89
354
+ 00:05:57,000 --> 00:05:59,000
355
+ Now imagine the next scenario.
356
+
357
+ 90
358
+ 00:05:59,000 --> 00:06:04,000
359
+ Imagine you don't have the full constructor in your parent object because you can create products only
360
+
361
+ 91
362
+ 00:06:04,000 --> 00:06:05,000
363
+ with names.
364
+
365
+ 92
366
+ 00:06:06,000 --> 00:06:10,000
367
+ How this will impact your phone that you're going to have compilation error.
368
+
369
+ 93
370
+ 00:06:10,000 --> 00:06:11,000
371
+ Why?
372
+
373
+ 94
374
+ 00:06:11,000 --> 00:06:20,000
375
+ Because the grade child object GBM invokes constructor of all parent classes and now you can call constructor
376
+
377
+ 95
378
+ 00:06:20,000 --> 00:06:23,000
379
+ of parent classes because it doesn't know what should be passed.
380
+
381
+ 96
382
+ 00:06:23,000 --> 00:06:28,000
383
+ As a constructor argument, the full constructor often looks like this.
384
+
385
+ 97
386
+ 00:06:29,000 --> 00:06:35,000
387
+ So what we need to do to remove this compilation error, we need to explicitly call constructor of parent
388
+
389
+ 98
390
+ 00:06:35,000 --> 00:06:42,000
391
+ class and pass a string parameter to it that's type super parentheses and pass some string argument
392
+
393
+ 99
394
+ 00:06:42,000 --> 00:06:43,000
395
+ to it.
396
+
397
+ 100
398
+ 00:06:43,000 --> 00:06:48,000
399
+ Here we call parent constructor and you see that now compilation error is gone.
400
+
401
+ 101
402
+ 00:06:49,000 --> 00:06:56,000
403
+ Now Joram will be able to create an object of the form type one more important common here call of the
404
+
405
+ 102
406
+ 00:06:56,000 --> 00:06:59,000
407
+ parent constructor always should go first in child constructor.
408
+
409
+ 103
410
+ 00:07:00,000 --> 00:07:03,000
411
+ I mean you can't call any other methods before super.
412
+
413
+ 104
414
+ 00:07:03,000 --> 00:07:05,000
415
+ Here, let me show you.
416
+
417
+ 105
418
+ 00:07:06,000 --> 00:07:10,000
419
+ If I write here some code, it doesn't matter what exactly are right here.
420
+
421
+ 106
422
+ 00:07:11,000 --> 00:07:11,000
423
+ Let me cancel.
424
+
425
+ 107
426
+ 00:07:11,000 --> 00:07:14,000
427
+ Output will have again compilation error.
428
+
429
+ 108
430
+ 00:07:14,000 --> 00:07:20,000
431
+ You need to remember that invocation of Ben constructor and using of super keyword should always go
432
+
433
+ 109
434
+ 00:07:20,000 --> 00:07:22,000
435
+ first in shall constructor.
436
+
437
+ 110
438
+ 00:07:22,000 --> 00:07:23,000
439
+ I will make a post now.
440
+
441
+ 111
442
+ 00:07:24,000 --> 00:07:27,000
443
+ Is it clear if this is clear, let's move on.
444
+
445
+ 112
446
+ 00:07:28,000 --> 00:07:30,000
447
+ I told you that OP is fun.
448
+
449
+ 113
450
+ 00:07:31,000 --> 00:07:37,000
451
+ Now you know that to create a child's object constructor of a parent type is called what else happens
452
+
453
+ 114
454
+ 00:07:37,000 --> 00:07:39,000
455
+ during child object initialization.
456
+
457
+ 115
458
+ 00:07:39,000 --> 00:07:44,000
459
+ Here is a quick exercise for you that will help you to remember for the rest of your lives what happens
460
+
461
+ 116
462
+ 00:07:44,000 --> 00:07:46,000
463
+ during child object construction.
464
+
465
+ 117
466
+ 00:07:47,000 --> 00:07:49,000
467
+ Here is the code of our exercise.
468
+
469
+ 118
470
+ 00:07:49,000 --> 00:07:50,000
471
+ So let's start.
472
+
473
+ 119
474
+ 00:07:51,000 --> 00:07:53,000
475
+ We have parent type here.
476
+
477
+ 120
478
+ 00:07:53,000 --> 00:07:57,000
479
+ You can see static initialization lock installation, lock constructor.
480
+
481
+ 121
482
+ 00:07:58,000 --> 00:08:03,000
483
+ We have console output everywhere here and it's clearly specified that this output belongs to the parent
484
+
485
+ 122
486
+ 00:08:03,000 --> 00:08:07,000
487
+ type and we have child types that extends parent class.
488
+
489
+ 123
490
+ 00:08:08,000 --> 00:08:14,000
491
+ The child class has the same things that parent has static, initialization block, initialization lock
492
+
493
+ 124
494
+ 00:08:14,000 --> 00:08:15,000
495
+ and constructor.
496
+
497
+ 125
498
+ 00:08:16,000 --> 00:08:19,000
499
+ And you see the text and console output is different.
500
+
501
+ 126
502
+ 00:08:19,000 --> 00:08:24,000
503
+ The question is what will be printed to console when I will create child object?
504
+
505
+ 127
506
+ 00:08:25,000 --> 00:08:30,000
507
+ And another question, what will be printed to console when I will create child object the second time?
508
+
509
+ 128
510
+ 00:08:31,000 --> 00:08:34,000
511
+ Press pause and try to answer this question.
512
+
513
+ 129
514
+ 00:08:35,000 --> 00:08:36,000
515
+ OK, let me answer this.
516
+
517
+ 130
518
+ 00:08:37,000 --> 00:08:42,000
519
+ I will run the program and we will investigate console output and let's see what we have here.
520
+
521
+ 131
522
+ 00:08:43,000 --> 00:08:49,000
523
+ Static initialization block of the parent is executed and after that static installation lock of the
524
+
525
+ 132
526
+ 00:08:49,000 --> 00:08:51,000
527
+ child type is executed.
528
+
529
+ 133
530
+ 00:08:51,000 --> 00:08:59,000
531
+ Why static blocks are executed when classes uploaded into GBM parent class was uploaded first and after
532
+
533
+ 134
534
+ 00:08:59,000 --> 00:09:05,000
535
+ that child class was uploaded after the JVM wants to initialize parent fields first.
536
+
537
+ 135
538
+ 00:09:05,000 --> 00:09:08,000
539
+ That's why it executes parent installation block.
540
+
541
+ 136
542
+ 00:09:08,000 --> 00:09:15,000
543
+ And after that parent constructor and only after that JVM starts to create child object and executes
544
+
545
+ 137
546
+ 00:09:15,000 --> 00:09:19,000
547
+ child and installation work and child constructor home.
548
+
549
+ 138
550
+ 00:09:19,000 --> 00:09:20,000
551
+ This example is clear.
552
+
553
+ 139
554
+ 00:09:20,000 --> 00:09:24,000
555
+ What happens when I try to create child objects a second time?
556
+
557
+ 140
558
+ 00:09:24,000 --> 00:09:28,000
559
+ Everything the same beside the execution of static initialization locks.
560
+
561
+ 141
562
+ 00:09:29,000 --> 00:09:29,000
563
+ Why?
564
+
565
+ 142
566
+ 00:09:30,000 --> 00:09:35,000
567
+ Because everything what is followed by static keyword, including initialization blocks, is associated
568
+
569
+ 143
570
+ 00:09:35,000 --> 00:09:39,000
571
+ not with the object of this class, but with the class itself.
572
+
573
+ 144
574
+ 00:09:39,000 --> 00:09:44,000
575
+ So when classes are uploaded into GBM, these blocks are executed.
576
+
577
+ 145
578
+ 00:09:44,000 --> 00:09:48,000
579
+ They won't be executed two times in a row home.
580
+
581
+ 146
582
+ 00:09:48,000 --> 00:09:54,000
583
+ Now with this example, it has become clearer what is initialization order during the construction of
584
+
585
+ 147
586
+ 00:09:54,000 --> 00:09:55,000
587
+ a giant object.
588
+
589
+ 148
590
+ 00:09:55,000 --> 00:10:01,000
591
+ The last thing you need to know about inheritance is that in Java, multiple inheritance is not supported
592
+
593
+ 149
594
+ 00:10:01,000 --> 00:10:02,000
595
+ that.
596
+
597
+ 150
598
+ 00:10:02,000 --> 00:10:08,000
599
+ Means you can't define new type on the basis of two or more opposite types after extensive keyword.
600
+
601
+ 151
602
+ 00:10:08,000 --> 00:10:14,000
603
+ You can specify only one class, but in some other languages, multiple inheritance is supported.
604
+
605
+ 152
606
+ 00:10:15,000 --> 00:10:17,000
607
+ That's all what we have in our agenda for today.
608
+
609
+ 153
610
+ 00:10:18,000 --> 00:10:20,000
611
+ Let's recap what we have learned today.
612
+
613
+ 154
614
+ 00:10:20,000 --> 00:10:24,000
615
+ We learned what inheritance is and how we can extend the time.
616
+
617
+ 155
618
+ 00:10:24,000 --> 00:10:31,000
619
+ Now, you know, two more key words, super and instance of you learn some specific constraints while
620
+
621
+ 156
622
+ 00:10:31,000 --> 00:10:32,000
623
+ extending classes.
624
+
625
+ 157
626
+ 00:10:33,000 --> 00:10:39,000
627
+ And today you learned what initialization order is of new objects that is extended from another class.
628
+
629
+ 158
630
+ 00:10:39,000 --> 00:10:40,000
631
+ That's all.
632
+
633
+ 159
634
+ 00:10:41,000 --> 00:10:44,000
635
+ Thank you for your attention and see you in the next lesson.
636
+
13 - Object-oriented programming/005 Source-code-Demo.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/inheritance/Demo.java
13 - Object-oriented programming/005 Source-code-Object-initialization-order.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/inheritance/ObjectInitializationOrder.java
13 - Object-oriented programming/005 Source-code-Phone.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/inheritance/Phone.java
13 - Object-oriented programming/005 Source-code-Product.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/inheritance/Product.java
13 - Object-oriented programming/006 Polymorphism and 'final' keyword_en.srt ADDED
@@ -0,0 +1,556 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:05,000 --> 00:00:06,000
3
+ Hello, Jim.
4
+
5
+ 2
6
+ 00:00:06,000 --> 00:00:11,000
7
+ In this lesson, we'll discuss principle of the object oriented programming approach polymorphism,
8
+
9
+ 3
10
+ 00:00:11,000 --> 00:00:14,000
11
+ they will talk about what polymorphism is.
12
+
13
+ 4
14
+ 00:00:14,000 --> 00:00:16,000
15
+ I will tell you what method of writing this.
16
+
17
+ 5
18
+ 00:00:17,000 --> 00:00:21,000
19
+ You will learn what is the difference between method of writing and method of reloading hope.
20
+
21
+ 6
22
+ 00:00:21,000 --> 00:00:25,000
23
+ After this lesson, you will understand what dynamic Bindon is.
24
+
25
+ 7
26
+ 00:00:25,000 --> 00:00:31,000
27
+ Also on different examples, I will show you how final key words works and what does it mean.
28
+
29
+ 8
30
+ 00:00:31,000 --> 00:00:32,000
31
+ So let's start.
32
+
33
+ 9
34
+ 00:00:33,000 --> 00:00:35,000
35
+ We have a lot of things to learn today.
36
+
37
+ 10
38
+ 00:00:35,000 --> 00:00:38,000
39
+ Polymorphism literally means many forms.
40
+
41
+ 11
42
+ 00:00:38,000 --> 00:00:39,000
43
+ Many forms of what?
44
+
45
+ 12
46
+ 00:00:40,000 --> 00:00:41,000
47
+ Many forms of behavior.
48
+
49
+ 13
50
+ 00:00:42,000 --> 00:00:47,000
51
+ Often we can see how polymorphism works when we extend any class or implement any interface.
52
+
53
+ 14
54
+ 00:00:47,000 --> 00:00:48,000
55
+ Let me show you one example.
56
+
57
+ 15
58
+ 00:00:49,000 --> 00:00:54,000
59
+ Imagine that we have abstract class user and we have content manager and admin user classes.
60
+
61
+ 16
62
+ 00:00:54,000 --> 00:00:59,000
63
+ Both extensive user user has methods named validate access rights.
64
+
65
+ 17
66
+ 00:01:00,000 --> 00:01:04,000
67
+ This method should check permissions of the user to perform some actions in our system.
68
+
69
+ 18
70
+ 00:01:04,000 --> 00:01:10,000
71
+ You can see that in user class we have default console output where it is set that there are no specific
72
+
73
+ 19
74
+ 00:01:10,000 --> 00:01:12,000
75
+ permissions in content.
76
+
77
+ 20
78
+ 00:01:12,000 --> 00:01:15,000
79
+ Manager with the console output was indication of the permissions.
80
+
81
+ 21
82
+ 00:01:15,000 --> 00:01:21,000
83
+ Content manager can't withdraw money and for admin user we see a completely different message.
84
+
85
+ 22
86
+ 00:01:22,000 --> 00:01:26,000
87
+ Now let me declare two variables of type user and create two objects.
88
+
89
+ 23
90
+ 00:01:26,000 --> 00:01:30,000
91
+ Object of content manager type an object of admin user type.
92
+
93
+ 24
94
+ 00:01:30,000 --> 00:01:35,000
95
+ After that I want to invoke validate access rights methods on these objects.
96
+
97
+ 25
98
+ 00:01:35,000 --> 00:01:42,000
99
+ What will be printed to cancel text from user class, from content manager class or from admin user
100
+
101
+ 26
102
+ 00:01:42,000 --> 00:01:42,000
103
+ class.
104
+
105
+ 27
106
+ 00:01:43,000 --> 00:01:45,000
107
+ Take a few seconds to think about this.
108
+
109
+ 28
110
+ 00:01:45,000 --> 00:01:51,000
111
+ Let me run this program and we use it for content manager object method from content manager class was
112
+
113
+ 29
114
+ 00:01:51,000 --> 00:01:55,000
115
+ invoked and for admin user method from admin user class was invoked.
116
+
117
+ 30
118
+ 00:01:56,000 --> 00:02:02,000
119
+ This is polymorphism user type has the one behavior, the data user access rights.
120
+
121
+ 31
122
+ 00:02:02,000 --> 00:02:05,000
123
+ But there are different forms of this behavior.
124
+
125
+ 32
126
+ 00:02:06,000 --> 00:02:08,000
127
+ Type of the reference can't be changed.
128
+
129
+ 33
130
+ 00:02:08,000 --> 00:02:15,000
131
+ The object of the reference can be of different type, but object type should be compatible with type
132
+
133
+ 34
134
+ 00:02:15,000 --> 00:02:16,000
135
+ of the reference.
136
+
137
+ 35
138
+ 00:02:16,000 --> 00:02:22,000
139
+ And in the runtime, Java identifies what methods should be called based on the object here during the
140
+
141
+ 36
142
+ 00:02:22,000 --> 00:02:23,000
143
+ runtime.
144
+
145
+ 37
146
+ 00:02:23,000 --> 00:02:27,000
147
+ That's why we see that methods of specific objects are called.
148
+
149
+ 38
150
+ 00:02:28,000 --> 00:02:35,000
151
+ This is called dynamic binding method that should be invoked is identified during the runtime and as
152
+
153
+ 39
154
+ 00:02:35,000 --> 00:02:36,000
155
+ a real life example.
156
+
157
+ 40
158
+ 00:02:36,000 --> 00:02:40,000
159
+ Imagine we have interface to describe type that can archive files.
160
+
161
+ 41
162
+ 00:02:40,000 --> 00:02:47,000
163
+ We can name it archive and says a contract for one method archive files which takes variable argument
164
+
165
+ 42
166
+ 00:02:47,000 --> 00:02:52,000
167
+ parameter of type file, will run this type a little bit later in our course.
168
+
169
+ 43
170
+ 00:02:52,000 --> 00:02:55,000
171
+ And we have different implementations of this interface.
172
+
173
+ 44
174
+ 00:02:55,000 --> 00:03:02,000
175
+ Zakharova and RA archive and again during the runtime, Java will identify the object which stands behind
176
+
177
+ 45
178
+ 00:03:02,000 --> 00:03:05,000
179
+ the reference and we'll call method of this exact object.
180
+
181
+ 46
182
+ 00:03:10,000 --> 00:03:17,000
183
+ You can notice this override annotation, this is just the information for a compiler, your code will
184
+
185
+ 47
186
+ 00:03:17,000 --> 00:03:19,000
187
+ work just awesome without this annotation.
188
+
189
+ 48
190
+ 00:03:19,000 --> 00:03:22,000
191
+ Let's remove it and run program one more time.
192
+
193
+ 49
194
+ 00:03:22,000 --> 00:03:23,000
195
+ There you see this.
196
+
197
+ 50
198
+ 00:03:24,000 --> 00:03:25,000
199
+ Everything is the same.
200
+
201
+ 51
202
+ 00:03:25,000 --> 00:03:27,000
203
+ Then why do we need it at all?
204
+
205
+ 52
206
+ 00:03:27,000 --> 00:03:32,000
207
+ Imagine that either by mistake or your colleague just added the method parameter here.
208
+
209
+ 53
210
+ 00:03:32,000 --> 00:03:36,000
211
+ You want to have compilation error, but what would you see in console?
212
+
213
+ 54
214
+ 00:03:37,000 --> 00:03:40,000
215
+ You're going to see a console output from the parent class.
216
+
217
+ 55
218
+ 00:03:41,000 --> 00:03:41,000
219
+ Why?
220
+
221
+ 56
222
+ 00:03:42,000 --> 00:03:48,000
223
+ Because you are calling validate access rights method but not validate access rights within the parameter.
224
+
225
+ 57
226
+ 00:03:49,000 --> 00:03:51,000
227
+ Do you remember topic about methods?
228
+
229
+ 58
230
+ 00:03:51,000 --> 00:03:54,000
231
+ These two methods have different signature.
232
+
233
+ 59
234
+ 00:03:54,000 --> 00:03:58,000
235
+ Jeff, I didn't know that you want to override behavior of this method.
236
+
237
+ 60
238
+ 00:03:59,000 --> 00:04:03,000
239
+ To tell the compiler that you want to override method just adds the sanitation.
240
+
241
+ 61
242
+ 00:04:04,000 --> 00:04:08,000
243
+ We'll talk about annotations and how to create them in the separate lesson about annotations.
244
+
245
+ 62
246
+ 00:04:09,000 --> 00:04:15,000
247
+ So now you can see that I have the compilation error because now I told the compiler that I want to
248
+
249
+ 63
250
+ 00:04:15,000 --> 00:04:17,000
251
+ override this method.
252
+
253
+ 64
254
+ 00:04:17,000 --> 00:04:22,000
255
+ And that tells me that if I want to override this method with new behavior, I need to have the same
256
+
257
+ 65
258
+ 00:04:22,000 --> 00:04:25,000
259
+ signature of the method as parent class has.
260
+
261
+ 66
262
+ 00:04:25,000 --> 00:04:28,000
263
+ And also my return type has to be compatible.
264
+
265
+ 67
266
+ 00:04:29,000 --> 00:04:30,000
267
+ Let's take a look at another example.
268
+
269
+ 68
270
+ 00:04:30,000 --> 00:04:35,000
271
+ Imagine we have abstract method in our user class to retrieve profile information.
272
+
273
+ 69
274
+ 00:04:35,000 --> 00:04:39,000
275
+ And when I will override this method in admin user class, I will return the instance of an account
276
+
277
+ 70
278
+ 00:04:39,000 --> 00:04:40,000
279
+ information.
280
+
281
+ 71
282
+ 00:04:41,000 --> 00:04:42,000
283
+ Will I have compilation error?
284
+
285
+ 72
286
+ 00:04:43,000 --> 00:04:48,000
287
+ No, because I build my application relying on abstractions, profile information.
288
+
289
+ 73
290
+ 00:04:48,000 --> 00:04:55,000
291
+ It is an interface, my abstraction, and I can return any object which is compatible with profile information
292
+
293
+ 74
294
+ 00:04:55,000 --> 00:04:58,000
295
+ that that will not violate any Java rules.
296
+
297
+ 75
298
+ 00:04:58,000 --> 00:04:59,000
299
+ One more thing.
300
+
301
+ 76
302
+ 00:04:59,000 --> 00:05:06,000
303
+ Imagine that according to interface get profile information accepts parameter of profile type during
304
+
305
+ 77
306
+ 00:05:06,000 --> 00:05:08,000
307
+ the method and location you can pass in the method.
308
+
309
+ 78
310
+ 00:05:08,000 --> 00:05:15,000
311
+ Any object of type profile, for example, user profile type is compatible with profile type because
312
+
313
+ 79
314
+ 00:05:15,000 --> 00:05:21,000
315
+ profile is an interface and user profile is a concrete class that implements this interface.
316
+
317
+ 80
318
+ 00:05:21,000 --> 00:05:27,000
319
+ Here you can see that I can call the method was instance of user profile class and there are no errors.
320
+
321
+ 81
322
+ 00:05:27,000 --> 00:05:33,000
323
+ So what you need to remember is that when you overwrite method, behavior, return type and method arguments
324
+
325
+ 82
326
+ 00:05:33,000 --> 00:05:38,000
327
+ that you pass to the method during invocation should be compatible with Stipe's declared in parent class
328
+
329
+ 83
330
+ 00:05:39,000 --> 00:05:39,000
331
+ hope.
332
+
333
+ 84
334
+ 00:05:39,000 --> 00:05:42,000
335
+ Now you understand how you can override methods.
336
+
337
+ 85
338
+ 00:05:42,000 --> 00:05:45,000
339
+ One more item which I wanted to discuss with you.
340
+
341
+ 86
342
+ 00:05:45,000 --> 00:05:49,000
343
+ General developers often mix up to germ's override and overload.
344
+
345
+ 87
346
+ 00:05:50,000 --> 00:05:52,000
347
+ We already know what this method override means.
348
+
349
+ 88
350
+ 00:05:53,000 --> 00:05:57,000
351
+ Overload it is when you have masses with the same name, but with different signature.
352
+
353
+ 89
354
+ 00:05:58,000 --> 00:06:03,000
355
+ For example, in Zipper Kiva archive files, Masset is overridden and overloaded.
356
+
357
+ 90
358
+ 00:06:03,000 --> 00:06:06,000
359
+ Shit is overridden and here it is overloaded.
360
+
361
+ 91
362
+ 00:06:06,000 --> 00:06:08,000
363
+ As you can see, overloaded.
364
+
365
+ 92
366
+ 00:06:08,000 --> 00:06:12,000
367
+ Macit has the same name but the different method signature.
368
+
369
+ 93
370
+ 00:06:12,000 --> 00:06:16,000
371
+ Now you know the difference between Macit override and overloading.
372
+
373
+ 94
374
+ 00:06:16,000 --> 00:06:17,000
375
+ Let's move on.
376
+
377
+ 95
378
+ 00:06:17,000 --> 00:06:21,000
379
+ And last but not the least topic for today is a final keyword final.
380
+
381
+ 96
382
+ 00:06:21,000 --> 00:06:24,000
383
+ Kimura's can have different meaning based on the context.
384
+
385
+ 97
386
+ 00:06:25,000 --> 00:06:29,000
387
+ It can be used with classes, methods, variables and parameters.
388
+
389
+ 98
390
+ 00:06:29,000 --> 00:06:31,000
391
+ Let's look at final class first.
392
+
393
+ 99
394
+ 00:06:32,000 --> 00:06:37,000
395
+ If the class is final like string class, for example, you can't extend new types from it.
396
+
397
+ 100
398
+ 00:06:38,000 --> 00:06:40,000
399
+ Let me try to extend my user class from string.
400
+
401
+ 101
402
+ 00:06:45,000 --> 00:06:51,000
403
+ And you see, I have the compilation error, so if you want to close your tab for extension, just add
404
+
405
+ 102
406
+ 00:06:51,000 --> 00:06:57,000
407
+ final keywords and you already understand that in case, I forbid, client of my code to extend my type
408
+
409
+ 103
410
+ 00:06:57,000 --> 00:07:00,000
411
+ in some degree, this violates polymorphism principle.
412
+
413
+ 104
414
+ 00:07:01,000 --> 00:07:08,000
415
+ Final verbals can't be initialized with any value after they were declared here in admin user class,
416
+
417
+ 105
418
+ 00:07:08,000 --> 00:07:11,000
419
+ a final variable user group of type string.
420
+
421
+ 106
422
+ 00:07:11,000 --> 00:07:17,000
423
+ If I have final variable, I can't assign any other value to it after its declaration.
424
+
425
+ 107
426
+ 00:07:17,000 --> 00:07:22,000
427
+ For example, if I would try to change value of this variable in the scope of this method, I will get
428
+
429
+ 108
430
+ 00:07:22,000 --> 00:07:23,000
431
+ compilation error.
432
+
433
+ 109
434
+ 00:07:23,000 --> 00:07:27,000
435
+ And we see here that the clips tells us about compilation error.
436
+
437
+ 110
438
+ 00:07:28,000 --> 00:07:34,000
439
+ Final feels should be initialised is instantly after declaration like I have here or in constructor
440
+
441
+ 111
442
+ 00:07:34,000 --> 00:07:35,000
443
+ or in installation.
444
+
445
+ 112
446
+ 00:07:35,000 --> 00:07:43,000
447
+ Look, if you want initialize final variable with any value, there will be compilation error like this.
448
+
449
+ 113
450
+ 00:07:44,000 --> 00:07:46,000
451
+ Similar behavior was final parameters.
452
+
453
+ 114
454
+ 00:07:47,000 --> 00:07:50,000
455
+ Usually it is a rule of thumb to make parameters final.
456
+
457
+ 115
458
+ 00:07:50,000 --> 00:07:53,000
459
+ That means you can't reassign this argument.
460
+
461
+ 116
462
+ 00:07:53,000 --> 00:07:56,000
463
+ What is helpful, in my opinion, you want to use that.
464
+
465
+ 117
466
+ 00:07:56,000 --> 00:08:01,000
467
+ People very often declare local variables of methods with final modifier.
468
+
469
+ 118
470
+ 00:08:01,000 --> 00:08:03,000
471
+ But this is considered to be a good practice.
472
+
473
+ 119
474
+ 00:08:04,000 --> 00:08:07,000
475
+ Final key word can be used with a method in a case.
476
+
477
+ 120
478
+ 00:08:07,000 --> 00:08:08,000
479
+ Method is final.
480
+
481
+ 121
482
+ 00:08:08,000 --> 00:08:10,000
483
+ It is can't be overridden.
484
+
485
+ 122
486
+ 00:08:10,000 --> 00:08:16,000
487
+ For example, in case I will add final modifier to validate access rights method in user class, I will
488
+
489
+ 123
490
+ 00:08:16,000 --> 00:08:19,000
491
+ receive compilation error in my admin user class.
492
+
493
+ 124
494
+ 00:08:19,000 --> 00:08:20,000
495
+ Let's check.
496
+
497
+ 125
498
+ 00:08:21,000 --> 00:08:27,000
499
+ Here's our compilation error, so if you don't want to give opportunity for anyone to override behavior
500
+
501
+ 126
502
+ 00:08:27,000 --> 00:08:29,000
503
+ of your method, you can make it final.
504
+
505
+ 127
506
+ 00:08:30,000 --> 00:08:35,000
507
+ But again, it doesn't look like object oriented approach because this violates polymorphism principle.
508
+
509
+ 128
510
+ 00:08:36,000 --> 00:08:41,000
511
+ And probably you already understand that you can't use final and observe keywords together because they
512
+
513
+ 129
514
+ 00:08:41,000 --> 00:08:43,000
515
+ can't exist simultaneously.
516
+
517
+ 130
518
+ 00:08:44,000 --> 00:08:47,000
519
+ It looks like that's all what we have in our agenda for today.
520
+
521
+ 131
522
+ 00:08:47,000 --> 00:08:50,000
523
+ Let's recap one more time what we have learned today.
524
+
525
+ 132
526
+ 00:08:50,000 --> 00:08:56,000
527
+ Today, we have learned with you what polymorphism is now you know, how you can override behavior and
528
+
529
+ 133
530
+ 00:08:56,000 --> 00:08:59,000
531
+ what rules we have to follow when we overwrite methods.
532
+
533
+ 134
534
+ 00:08:59,000 --> 00:09:02,000
535
+ Also, you learned what dynamic Bindon is.
536
+
537
+ 135
538
+ 00:09:02,000 --> 00:09:06,000
539
+ We discussed what is the difference between method overload and mycetoma.
540
+
541
+ 136
542
+ 00:09:06,000 --> 00:09:06,000
543
+ Right.
544
+
545
+ 137
546
+ 00:09:06,000 --> 00:09:12,000
547
+ And now you know how to use final keywords, which properties, classes, methods and method arguments.
548
+
549
+ 138
550
+ 00:09:12,000 --> 00:09:13,000
551
+ That's it.
552
+
553
+ 139
554
+ 00:09:14,000 --> 00:09:16,000
555
+ Thank you for your attention and see you in the next lesson.
556
+
13 - Object-oriented programming/006 Source-code-Account-Information.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/polymorphism/AccountInformation.java
13 - Object-oriented programming/006 Source-code-Admin-User.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/polymorphism/AdminUser.java
13 - Object-oriented programming/006 Source-code-Archiver.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/polymorphism/Archiver.java
13 - Object-oriented programming/006 Source-code-Content-Manager.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/polymorphism/ContentManager.java
13 - Object-oriented programming/006 Source-code-Demo.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/polymorphism/Demo.java
13 - Object-oriented programming/006 Source-code-Profile-Information-Data.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/polymorphism/ProfileInformationData.java
13 - Object-oriented programming/006 Source-code-Profile.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/polymorphism/Profile.java
13 - Object-oriented programming/006 Source-code-Rar-Archiver.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/polymorphism/RarArchiver.java
13 - Object-oriented programming/006 Source-code-User-Profile.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/polymorphism/UserProfile.java
13 - Object-oriented programming/006 Source-code-User.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/polymorphism/User.java
13 - Object-oriented programming/006 Source-code-Zip-Archiver.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/polymorphism/ZipArchiver.java
13 - Object-oriented programming/007 'static' keyword_en.srt ADDED
@@ -0,0 +1,440 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:05,000 --> 00:00:06,000
3
+ Hello.
4
+
5
+ 2
6
+ 00:00:06,000 --> 00:00:09,000
7
+ Students, in this lesson, we'll learn what is a static key word.
8
+
9
+ 3
10
+ 00:00:09,000 --> 00:00:12,000
11
+ We'll talk about where we can you start a keyboard.
12
+
13
+ 4
14
+ 00:00:12,000 --> 00:00:15,000
15
+ I will explain how we can use static methods, static fields.
16
+
17
+ 5
18
+ 00:00:15,000 --> 00:00:20,000
19
+ In this lesson, you are going to learn what a static impulse and what is the difference between static
20
+
21
+ 6
22
+ 00:00:20,000 --> 00:00:22,000
23
+ and dynamic binding.
24
+
25
+ 7
26
+ 00:00:22,000 --> 00:00:23,000
27
+ Let's start.
28
+
29
+ 8
30
+ 00:00:23,000 --> 00:00:25,000
31
+ I truly believe that this topic matter.
32
+
33
+ 9
34
+ 00:00:25,000 --> 00:00:27,000
35
+ We can jump to the examples.
36
+
37
+ 10
38
+ 00:00:27,000 --> 00:00:32,000
39
+ So first of all, where you can use static keyboard, you already saw in previous lessons that you can
40
+
41
+ 11
42
+ 00:00:32,000 --> 00:00:38,000
43
+ use static a keyboard during class declaration with initialization locks, with methods and with properties.
44
+
45
+ 12
46
+ 00:00:38,000 --> 00:00:41,000
47
+ Static keyword controls, variable lifetime.
48
+
49
+ 13
50
+ 00:00:41,000 --> 00:00:46,000
51
+ I believe you remember static nested classes and we even discussed how to create object of static nested
52
+
53
+ 14
54
+ 00:00:46,000 --> 00:00:47,000
55
+ classes.
56
+
57
+ 15
58
+ 00:00:47,000 --> 00:00:50,000
59
+ Let's understand what static is on this simple example.
60
+
61
+ 16
62
+ 00:00:50,000 --> 00:00:52,000
63
+ You have the user class.
64
+
65
+ 17
66
+ 00:00:52,000 --> 00:01:00,000
67
+ It has such properties as and name and one property has static modifier counter field is static during
68
+
69
+ 18
70
+ 00:01:00,000 --> 00:01:03,000
71
+ the utilization of each new object and command counter.
72
+
73
+ 19
74
+ 00:01:04,000 --> 00:01:09,000
75
+ Now let's try to create two objects of user type and investigate what will be the value of counter energy
76
+
77
+ 20
78
+ 00:01:09,000 --> 00:01:10,000
79
+ fields.
80
+
81
+ 21
82
+ 00:01:10,000 --> 00:01:16,000
83
+ Here you see a created user number one and user number two and get user aguy and counter value from
84
+
85
+ 22
86
+ 00:01:16,000 --> 00:01:18,000
87
+ the first and the second user.
88
+
89
+ 23
90
+ 00:01:18,000 --> 00:01:21,000
91
+ Let me run this program and we will investigate with you.
92
+
93
+ 24
94
+ 00:01:21,000 --> 00:01:21,000
95
+ Console output.
96
+
97
+ 25
98
+ 00:01:22,000 --> 00:01:29,000
99
+ You see that most users have IJI with zero value because zero is the default value for int variable.
100
+
101
+ 26
102
+ 00:01:29,000 --> 00:01:32,000
103
+ But counter is not the same as the beginning.
104
+
105
+ 27
106
+ 00:01:32,000 --> 00:01:33,000
107
+ Counter is equal to one.
108
+
109
+ 28
110
+ 00:01:34,000 --> 00:01:36,000
111
+ And after we see that counter is equal to two.
112
+
113
+ 29
114
+ 00:01:37,000 --> 00:01:43,000
115
+ And even more interesting things, if I would call get counter message on the user one object I will
116
+
117
+ 30
118
+ 00:01:43,000 --> 00:01:51,000
119
+ get two Y because static variable exists in the single copy and it belongs not to the object but to
120
+
121
+ 31
122
+ 00:01:51,000 --> 00:01:52,000
123
+ the whole class.
124
+
125
+ 32
126
+ 00:01:52,000 --> 00:01:59,000
127
+ Each time new object is created, this counter variable is incremented and take into account that it
128
+
129
+ 33
130
+ 00:01:59,000 --> 00:02:00,000
131
+ exists in single copy.
132
+
133
+ 34
134
+ 00:02:00,000 --> 00:02:04,000
135
+ Each time the object is created, the value become more and more.
136
+
137
+ 35
138
+ 00:02:04,000 --> 00:02:10,000
139
+ You know that class is a template for future object and each new object will have a new ID property.
140
+
141
+ 36
142
+ 00:02:10,000 --> 00:02:13,000
143
+ But static fields are not connected with objects.
144
+
145
+ 37
146
+ 00:02:14,000 --> 00:02:15,000
147
+ They are connected with the class.
148
+
149
+ 38
150
+ 00:02:16,000 --> 00:02:21,000
151
+ That's why each object knows about class properties and when I call, get the counter method for the
152
+
153
+ 39
154
+ 00:02:21,000 --> 00:02:24,000
155
+ second user and get counter message for the first user.
156
+
157
+ 40
158
+ 00:02:24,000 --> 00:02:26,000
159
+ I receive the value of the same variable.
160
+
161
+ 41
162
+ 00:02:27,000 --> 00:02:27,000
163
+ That's more.
164
+
165
+ 42
166
+ 00:02:28,000 --> 00:02:34,000
167
+ Imagine that our user has a child class employee, both user and employee have static method with the
168
+
169
+ 43
170
+ 00:02:34,000 --> 00:02:37,000
171
+ same name do any static action.
172
+
173
+ 44
174
+ 00:02:37,000 --> 00:02:41,000
175
+ The only difference is that console output is different here.
176
+
177
+ 45
178
+ 00:02:41,000 --> 00:02:45,000
179
+ Print the user class name to console and here print the employee.
180
+
181
+ 46
182
+ 00:02:45,000 --> 00:02:52,000
183
+ Now let's create object of employee type and let's call the static method what will be printed to console.
184
+
185
+ 47
186
+ 00:02:52,000 --> 00:02:58,000
187
+ If you answer in that user class name will be printed to console then you are right why it works this
188
+
189
+ 48
190
+ 00:02:58,000 --> 00:02:58,000
191
+ way.
192
+
193
+ 49
194
+ 00:02:58,000 --> 00:03:00,000
195
+ This is called static binding.
196
+
197
+ 50
198
+ 00:03:00,000 --> 00:03:04,000
199
+ The method which will be called is already known during the compilation time.
200
+
201
+ 51
202
+ 00:03:05,000 --> 00:03:11,000
203
+ It is known because I call static method something what belongs to the class but not to the object.
204
+
205
+ 52
206
+ 00:03:11,000 --> 00:03:18,000
207
+ That's why if I have a variable of type user here, static method of the type user will be invoked and
208
+
209
+ 53
210
+ 00:03:18,000 --> 00:03:23,000
211
+ you see that the clips highlights for us, this method quote, it tells me that static methods shouldn't
212
+
213
+ 54
214
+ 00:03:23,000 --> 00:03:30,000
215
+ be accessed in a different way in which we in different usually to access any static entities you use
216
+
217
+ 55
218
+ 00:03:30,000 --> 00:03:31,000
219
+ class name.
220
+
221
+ 56
222
+ 00:03:31,000 --> 00:03:36,000
223
+ I like this user class and after that you call any static method you wish.
224
+
225
+ 57
226
+ 00:03:36,000 --> 00:03:40,000
227
+ Let's call static method of user type and employee type.
228
+
229
+ 58
230
+ 00:03:40,000 --> 00:03:46,000
231
+ The example which we discussed in polymorphism when we have tried some method called Dynamic Bindon,
232
+
233
+ 59
234
+ 00:03:46,000 --> 00:03:52,000
235
+ because the method which should be executed will be identified during the runtime based on the object
236
+
237
+ 60
238
+ 00:03:52,000 --> 00:03:54,000
239
+ that will be behind the reference.
240
+
241
+ 61
242
+ 00:03:54,000 --> 00:03:59,000
243
+ And I believe now you understood the dynamic binding is not possible with static methods.
244
+
245
+ 62
246
+ 00:03:59,000 --> 00:04:06,000
247
+ You can't override static methods, static, often considered as a bad thing and object oriented programming
248
+
249
+ 63
250
+ 00:04:06,000 --> 00:04:13,000
251
+ y because it violates such basic or p principle as polymorphism, it doesn't allow to override behavior,
252
+
253
+ 64
254
+ 00:04:13,000 --> 00:04:15,000
255
+ which is the key for orby.
256
+
257
+ 65
258
+ 00:04:15,000 --> 00:04:21,000
259
+ Also, during building of a class Iraqi, it is not recommended to have static methods and fields do
260
+
261
+ 66
262
+ 00:04:21,000 --> 00:04:28,000
263
+ not get confused that multiple objects share in similar properties, also sometimes static behaviour
264
+
265
+ 67
266
+ 00:04:28,000 --> 00:04:30,000
267
+ and static state harder to test.
268
+
269
+ 68
270
+ 00:04:30,000 --> 00:04:35,000
271
+ But you will understand this later when we will learn how to write integration and unit tests.
272
+
273
+ 69
274
+ 00:04:35,000 --> 00:04:41,000
275
+ Obviously you can use static methods in your code and you can find in the case that static methods are
276
+
277
+ 70
278
+ 00:04:41,000 --> 00:04:42,000
279
+ pretty widespread thing.
280
+
281
+ 71
282
+ 00:04:43,000 --> 00:04:49,000
283
+ But be prepared that when you will be on your workplace, your team won't be happy to see all static
284
+
285
+ 72
286
+ 00:04:49,000 --> 00:04:50,000
287
+ methods in your code.
288
+
289
+ 73
290
+ 00:04:50,000 --> 00:04:56,000
291
+ During this course, I will share with you architecture and design approach, which relies on the or
292
+
293
+ 74
294
+ 00:04:56,000 --> 00:04:59,000
295
+ principles where static entities are not used.
296
+
297
+ 75
298
+ 00:05:00,000 --> 00:05:01,000
299
+ But now you know what?
300
+
301
+ 76
302
+ 00:05:01,000 --> 00:05:02,000
303
+ Static keywords.
304
+
305
+ 77
306
+ 00:05:02,000 --> 00:05:08,000
307
+ Means knowing this, you can understand why constants have modified static and final, that is because
308
+
309
+ 78
310
+ 00:05:08,000 --> 00:05:14,000
311
+ static means that this field exists in a single copy and final means that nobody can change the value
312
+
313
+ 79
314
+ 00:05:14,000 --> 00:05:17,000
315
+ of this variable after this variable was declared.
316
+
317
+ 80
318
+ 00:05:17,000 --> 00:05:23,000
319
+ So here you can see that I have the compilation error when I try to assign new value to the final variable.
320
+
321
+ 81
322
+ 00:05:24,000 --> 00:05:28,000
323
+ I believe you remember a lot about final keywords from the lesson about polymorphism.
324
+
325
+ 82
326
+ 00:05:29,000 --> 00:05:32,000
327
+ For now, you already understand why constants have static.
328
+
329
+ 83
330
+ 00:05:32,000 --> 00:05:38,000
331
+ Final modifier will not discuss static initialization blocks in this lesson because we discussing the
332
+
333
+ 84
334
+ 00:05:38,000 --> 00:05:39,000
335
+ inheritance topic.
336
+
337
+ 85
338
+ 00:05:39,000 --> 00:05:43,000
339
+ When I showed you example of all the initialization of an object.
340
+
341
+ 86
342
+ 00:05:43,000 --> 00:05:44,000
343
+ Feel free to check that lesson.
344
+
345
+ 87
346
+ 00:05:44,000 --> 00:05:50,000
347
+ If you want to recall information about static initialization, luks the last but not the least thing
348
+
349
+ 88
350
+ 00:05:50,000 --> 00:05:50,000
351
+ for today.
352
+
353
+ 89
354
+ 00:05:50,000 --> 00:05:53,000
355
+ What I wanted to discuss with you is a static Kimber's.
356
+
357
+ 90
358
+ 00:05:53,000 --> 00:05:55,000
359
+ It is pretty simple.
360
+
361
+ 91
362
+ 00:05:55,000 --> 00:05:57,000
363
+ For example, do you remember our class?
364
+
365
+ 92
366
+ 00:05:57,000 --> 00:06:03,000
367
+ It contains only static methods and to call any static method you need to write our race class name
368
+
369
+ 93
370
+ 00:06:03,000 --> 00:06:05,000
371
+ and then call any method you would like.
372
+
373
+ 94
374
+ 00:06:06,000 --> 00:06:12,000
375
+ But what if you don't want to write arrays every time you can import all static entities from a race
376
+
377
+ 95
378
+ 00:06:12,000 --> 00:06:12,000
379
+ class?
380
+
381
+ 96
382
+ 00:06:13,000 --> 00:06:15,000
383
+ How to do that on the top of your file?
384
+
385
+ 97
386
+ 00:06:15,000 --> 00:06:15,000
387
+ Right.
388
+
389
+ 98
390
+ 00:06:15,000 --> 00:06:22,000
391
+ This inpart, static java, which you are, is not an asterisk.
392
+
393
+ 99
394
+ 00:06:22,000 --> 00:06:29,000
395
+ This symbol means that you want to import all static entities that exist in this class by saying all
396
+
397
+ 100
398
+ 00:06:29,000 --> 00:06:30,000
399
+ I mean methods, fields.
400
+
401
+ 101
402
+ 00:06:30,000 --> 00:06:32,000
403
+ That is what you will use.
404
+
405
+ 102
406
+ 00:06:32,000 --> 00:06:37,000
407
+ And now you can call, for example, source method without writing our class name.
408
+
409
+ 103
410
+ 00:06:38,000 --> 00:06:40,000
411
+ It looks like that it according to our agenda.
412
+
413
+ 104
414
+ 00:06:40,000 --> 00:06:42,000
415
+ Let's recap what we have learned today.
416
+
417
+ 105
418
+ 00:06:43,000 --> 00:06:47,000
419
+ Today we learned how static keyboard works with fields and methods.
420
+
421
+ 106
422
+ 00:06:47,000 --> 00:06:50,000
423
+ We discuss what is static and dynamic binding.
424
+
425
+ 107
426
+ 00:06:50,000 --> 00:06:56,000
427
+ And now you know why static considered to be a bad thing in or B hope you understood how to declare
428
+
429
+ 108
430
+ 00:06:56,000 --> 00:06:57,000
431
+ your own constants variables.
432
+
433
+ 109
434
+ 00:06:58,000 --> 00:07:01,000
435
+ Also, you learned how to improve static in your Java file.
436
+
437
+ 110
438
+ 00:07:02,000 --> 00:07:06,000
439
+ That's said thank you for your attention and see you in the next lesson.
440
+
13 - Object-oriented programming/007 Source-code-Demo.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/staticdemo/Demo.java
13 - Object-oriented programming/007 Source-code-Employee.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/staticdemo/Employee.java
13 - Object-oriented programming/007 Source-code-User.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/oop/staticdemo/User.java
13 - Object-oriented programming/008 Encapsulation_en.srt ADDED
@@ -0,0 +1,384 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:05,000 --> 00:00:11,000
3
+ Hello, dear students, in this lesson, we'll talk about encapsulation and we'll learn what is the
4
+
5
+ 2
6
+ 00:00:11,000 --> 00:00:15,000
7
+ role of encapsulation principle in the object oriented programming.
8
+
9
+ 3
10
+ 00:00:15,000 --> 00:00:17,000
11
+ In this lesson, we'll talk with you.
12
+
13
+ 4
14
+ 00:00:17,000 --> 00:00:22,000
15
+ Why do we need encapsulation and how we can implement encapsulation in our programs?
16
+
17
+ 5
18
+ 00:00:22,000 --> 00:00:28,000
19
+ We'll learn with your access modifiers and on real court examples, I will show you how you can use
20
+
21
+ 6
22
+ 00:00:28,000 --> 00:00:28,000
23
+ them.
24
+
25
+ 7
26
+ 00:00:28,000 --> 00:00:34,000
27
+ I will share with you my practical experience when to use which modifier and will learn the rules which
28
+
29
+ 8
30
+ 00:00:34,000 --> 00:00:36,000
31
+ we need to follow during overwriting.
32
+
33
+ 9
34
+ 00:00:36,000 --> 00:00:40,000
35
+ So let's jump to examples to understand this topic better.
36
+
37
+ 10
38
+ 00:00:41,000 --> 00:00:42,000
39
+ What is an observation?
40
+
41
+ 11
42
+ 00:00:43,000 --> 00:00:48,000
43
+ Encapsulation is a principle that teaches us to group data and behavior those our fields and methods
44
+
45
+ 12
46
+ 00:00:49,000 --> 00:00:49,000
47
+ together.
48
+
49
+ 13
50
+ 00:00:49,000 --> 00:00:56,000
51
+ As a single unit, we can control access to interfaces, classes, fields, methods to control access.
52
+
53
+ 14
54
+ 00:00:56,000 --> 00:00:58,000
55
+ We have four main access modifiers.
56
+
57
+ 15
58
+ 00:00:59,000 --> 00:01:04,000
59
+ They are public protected package, private or default private.
60
+
61
+ 16
62
+ 00:01:05,000 --> 00:01:10,000
63
+ Let's start one by one to understand the difference on the specific examples, to not show you how access
64
+
65
+ 17
66
+ 00:01:10,000 --> 00:01:13,000
67
+ modifiers work with classes, fields and methods.
68
+
69
+ 18
70
+ 00:01:13,000 --> 00:01:19,000
71
+ Separately, I will show you how Access Modifier works with methods, because these modifiers control
72
+
73
+ 19
74
+ 00:01:19,000 --> 00:01:25,000
75
+ access to elements and the way how they work are similar, no matter whether you're trying to get access
76
+
77
+ 20
78
+ 00:01:25,000 --> 00:01:26,000
79
+ for field or method.
80
+
81
+ 21
82
+ 00:01:27,000 --> 00:01:34,000
83
+ OK, so imagine we have some class, let's call it Class A. And inside this class we have the method
84
+
85
+ 22
86
+ 00:01:34,000 --> 00:01:35,000
87
+ with public access modifier.
88
+
89
+ 23
90
+ 00:01:36,000 --> 00:01:39,000
91
+ That means you can access it from any point of your program.
92
+
93
+ 24
94
+ 00:01:39,000 --> 00:01:44,000
95
+ For example, here you can see them a class which is outside of our package.
96
+
97
+ 25
98
+ 00:01:44,000 --> 00:01:44,000
99
+ No.
100
+
101
+ 26
102
+ 00:01:44,000 --> 00:01:49,000
103
+ One, I can create the instance of Class A and call the public method on it.
104
+
105
+ 27
106
+ 00:01:50,000 --> 00:01:53,000
107
+ Now imagine I have protected MassArt.
108
+
109
+ 28
110
+ 00:01:53,000 --> 00:01:57,000
111
+ Do something to will I be able to call it from them a class?
112
+
113
+ 29
114
+ 00:01:57,000 --> 00:02:04,000
115
+ Unfortunately, no way, because I can get access to protected entities only inside the same package
116
+
117
+ 30
118
+ 00:02:04,000 --> 00:02:06,000
119
+ or in a child class.
120
+
121
+ 31
122
+ 00:02:06,000 --> 00:02:12,000
123
+ If only I had them a class inside the package, no one I would be able to call method to do something
124
+
125
+ 32
126
+ 00:02:12,000 --> 00:02:14,000
127
+ to see here.
128
+
129
+ 33
130
+ 00:02:15,000 --> 00:02:19,000
131
+ I can call this method when demo class is in the same package with class A.
132
+
133
+ 34
134
+ 00:02:20,000 --> 00:02:28,000
135
+ Also here I have a class of the class A, package number two and inside the do something class B I can
136
+
137
+ 35
138
+ 00:02:28,000 --> 00:02:29,000
139
+ call protective measures.
140
+
141
+ 36
142
+ 00:02:29,000 --> 00:02:30,000
143
+ Do something too.
144
+
145
+ 37
146
+ 00:02:30,000 --> 00:02:37,000
147
+ So now you understand that I can access protected entities in case they're in the same package or in
148
+
149
+ 38
150
+ 00:02:37,000 --> 00:02:38,000
151
+ child classes.
152
+
153
+ 39
154
+ 00:02:39,000 --> 00:02:41,000
155
+ Our next modifier is package private.
156
+
157
+ 40
158
+ 00:02:42,000 --> 00:02:43,000
159
+ You can see that do something.
160
+
161
+ 41
162
+ 00:02:43,000 --> 00:02:47,000
163
+ Class B doesn't have any access modifier specified.
164
+
165
+ 42
166
+ 00:02:47,000 --> 00:02:48,000
167
+ That is not true.
168
+
169
+ 43
170
+ 00:02:49,000 --> 00:02:54,000
171
+ When we don't specify access modifiers, that means that access to this entity is a default.
172
+
173
+ 44
174
+ 00:02:55,000 --> 00:02:58,000
175
+ So usually absence of any keywords are associated with access.
176
+
177
+ 45
178
+ 00:02:58,000 --> 00:03:02,000
179
+ Modifier is called package primary or just default access.
180
+
181
+ 46
182
+ 00:03:02,000 --> 00:03:04,000
183
+ So let me get back to them.
184
+
185
+ 47
186
+ 00:03:04,000 --> 00:03:10,000
187
+ A class and package number one in scope of this package, I will create the object of the Class B type.
188
+
189
+ 48
190
+ 00:03:10,000 --> 00:03:17,000
191
+ And on this object I call do something Class B method and you see that I have a compilation error.
192
+
193
+ 49
194
+ 00:03:17,000 --> 00:03:24,000
195
+ But if I create object of Class B type inside the package number two and call the same method, it is
196
+
197
+ 50
198
+ 00:03:24,000 --> 00:03:28,000
199
+ possible because default access is only within the same package.
200
+
201
+ 51
202
+ 00:03:29,000 --> 00:03:33,000
203
+ Take into account this demo class and Class B in the same package.
204
+
205
+ 52
206
+ 00:03:33,000 --> 00:03:39,000
207
+ We don't have compilation error and last but not least, modifier is private modifier.
208
+
209
+ 53
210
+ 00:03:39,000 --> 00:03:41,000
211
+ Everything is easy here.
212
+
213
+ 54
214
+ 00:03:41,000 --> 00:03:44,000
215
+ You can access private entities only in scope.
216
+
217
+ 55
218
+ 00:03:44,000 --> 00:03:49,000
219
+ When it was declared, for example, I have private method declared in this class and I can call this
220
+
221
+ 56
222
+ 00:03:49,000 --> 00:03:56,000
223
+ private method wherever I want in this class, but I can't call this method outside of the class, even
224
+
225
+ 57
226
+ 00:03:56,000 --> 00:03:58,000
227
+ in the same package.
228
+
229
+ 58
230
+ 00:03:58,000 --> 00:04:01,000
231
+ If I will try to do so, I see compilation error.
232
+
233
+ 59
234
+ 00:04:02,000 --> 00:04:05,000
235
+ So now you understand the difference between modifiers.
236
+
237
+ 60
238
+ 00:04:05,000 --> 00:04:11,000
239
+ I believe you understood that encapsulation in all AP language can be implemented with the help of access
240
+
241
+ 61
242
+ 00:04:11,000 --> 00:04:14,000
243
+ modifiers and you know how they work.
244
+
245
+ 62
246
+ 00:04:15,000 --> 00:04:19,000
247
+ Knowing this during the planning of architecture, you can choose access modifier, which works the
248
+
249
+ 63
250
+ 00:04:19,000 --> 00:04:20,000
251
+ best for you.
252
+
253
+ 64
254
+ 00:04:21,000 --> 00:04:27,000
255
+ I want to share with you, which modifies you will use most of the times in 99 percent of cases you
256
+
257
+ 65
258
+ 00:04:27,000 --> 00:04:29,000
259
+ will use is a private or public.
260
+
261
+ 66
262
+ 00:04:29,000 --> 00:04:35,000
263
+ This is because you may have very few business cases when you want to keep something visible only in
264
+
265
+ 67
266
+ 00:04:35,000 --> 00:04:39,000
267
+ scope of the package or only in scope of the package and child class.
268
+
269
+ 68
270
+ 00:04:40,000 --> 00:04:44,000
271
+ Most likely you will implement interfaces and would like to keep the behavior public.
272
+
273
+ 69
274
+ 00:04:45,000 --> 00:04:50,000
275
+ Sometimes you will have methods which are needed only for this class and you will keep them private.
276
+
277
+ 70
278
+ 00:04:50,000 --> 00:04:56,000
279
+ Usually all fields have the private access modifier because you want to control interaction with your
280
+
281
+ 71
282
+ 00:04:56,000 --> 00:04:57,000
283
+ object.
284
+
285
+ 72
286
+ 00:04:57,000 --> 00:05:03,000
287
+ So now you understand that default and protected modifiers are not used very often.
288
+
289
+ 73
290
+ 00:05:04,000 --> 00:05:09,000
291
+ And last thing for the day, which I wanted to discuss with you, is the rules for access modifiers
292
+
293
+ 74
294
+ 00:05:09,000 --> 00:05:09,000
295
+ during that method.
296
+
297
+ 75
298
+ 00:05:09,000 --> 00:05:12,000
299
+ Overriding the rule is simple.
300
+
301
+ 76
302
+ 00:05:12,000 --> 00:05:17,000
303
+ When you override the method, you can't reduce the visibility of the inherited method.
304
+
305
+ 77
306
+ 00:05:17,000 --> 00:05:21,000
307
+ For example, in class a way of do something method.
308
+
309
+ 78
310
+ 00:05:21,000 --> 00:05:27,000
311
+ Class B extends class A and class C extends class B, is that clear?
312
+
313
+ 79
314
+ 00:05:27,000 --> 00:05:35,000
315
+ And now I want to do something method and I override it was protected to modify it just to recall it
316
+
317
+ 80
318
+ 00:05:35,000 --> 00:05:37,000
319
+ was public and parent class.
320
+
321
+ 81
322
+ 00:05:37,000 --> 00:05:43,000
323
+ And I have a compilation error here because we can't narrow access.
324
+
325
+ 82
326
+ 00:05:43,000 --> 00:05:46,000
327
+ On the other hand, in Class B, do something.
328
+
329
+ 83
330
+ 00:05:46,000 --> 00:05:49,000
331
+ Class B method has default access modifier.
332
+
333
+ 84
334
+ 00:05:49,000 --> 00:05:50,000
335
+ I can increase access level.
336
+
337
+ 85
338
+ 00:05:53,000 --> 00:05:59,000
339
+ And you can see here that I overwrite my head with public modifier and there is no compilation error
340
+
341
+ 86
342
+ 00:05:59,000 --> 00:06:03,000
343
+ because you can extend access now, that's it.
344
+
345
+ 87
346
+ 00:06:04,000 --> 00:06:06,000
347
+ Now, let's recall what we have learned today.
348
+
349
+ 88
350
+ 00:06:07,000 --> 00:06:09,000
351
+ Today, we learned what an encapsulation is.
352
+
353
+ 89
354
+ 00:06:09,000 --> 00:06:13,000
355
+ We know that access modifiers can help us to implement encapsulation.
356
+
357
+ 90
358
+ 00:06:13,000 --> 00:06:20,000
359
+ Principle in our code also will learn the difference between public protected default and private access
360
+
361
+ 91
362
+ 00:06:20,000 --> 00:06:21,000
363
+ modifiers.
364
+
365
+ 92
366
+ 00:06:21,000 --> 00:06:27,000
367
+ We discussed which modifiers developers use more often, and we saw specific rules which we need to
368
+
369
+ 93
370
+ 00:06:27,000 --> 00:06:29,000
371
+ follow during override.
372
+
373
+ 94
374
+ 00:06:29,000 --> 00:06:32,000
375
+ And that's all what I had in my agenda for today.
376
+
377
+ 95
378
+ 00:06:32,000 --> 00:06:34,000
379
+ Thanks a lot for your attention.
380
+
381
+ 96
382
+ 00:06:34,000 --> 00:06:35,000
383
+ And see you in the next lesson.
384
+
13 - Object-oriented programming/008 Source-code-All-examples-from-the-lecture.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/oop/encapsulation
13 - Object-oriented programming/009 Object, JNI and Object class overview_en.srt ADDED
@@ -0,0 +1,532 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:06,000 --> 00:00:11,000
3
+ Hello, dissidents, today we have a very important topic that they will discuss with you what object
4
+
5
+ 2
6
+ 00:00:11,000 --> 00:00:13,000
7
+ this will review object class.
8
+
9
+ 3
10
+ 00:00:13,000 --> 00:00:19,000
11
+ We are going to discuss what methods object class has this really important for us because each class
12
+
13
+ 4
14
+ 00:00:19,000 --> 00:00:21,000
15
+ in Java implicitly extends object.
16
+
17
+ 5
18
+ 00:00:21,000 --> 00:00:23,000
19
+ Class will join with you today.
20
+
21
+ 6
22
+ 00:00:23,000 --> 00:00:26,000
23
+ What is Jeani and Nucleate Native?
24
+
25
+ 7
26
+ 00:00:26,000 --> 00:00:28,000
27
+ So let's us look at the source code.
28
+
29
+ 8
30
+ 00:00:28,000 --> 00:00:32,000
31
+ Learn the source code is the best way to learn any programming language.
32
+
33
+ 9
34
+ 00:00:33,000 --> 00:00:36,000
35
+ So you already know that everything in Java is an object.
36
+
37
+ 10
38
+ 00:00:36,000 --> 00:00:43,000
39
+ Object is a virtual entity that has its own behavior and state which can distinguish it from other objects.
40
+
41
+ 11
42
+ 00:00:43,000 --> 00:00:47,000
43
+ That means each object will inherit methods of object class.
44
+
45
+ 12
46
+ 00:00:47,000 --> 00:00:54,000
47
+ Our goal in this lesson to review these methods and to understand what therefore you can press control
48
+
49
+ 13
50
+ 00:00:54,000 --> 00:01:00,000
51
+ plus shift pastie to search for any specific type, I'd like to open source code of the object class.
52
+
53
+ 14
54
+ 00:01:00,000 --> 00:01:06,000
55
+ Now this class is from Java Lank package and you remember the Java land packages interested in each
56
+
57
+ 15
58
+ 00:01:06,000 --> 00:01:08,000
59
+ Java file by default.
60
+
61
+ 16
62
+ 00:01:08,000 --> 00:01:13,000
63
+ So you never have to import object class into Java files.
64
+
65
+ 17
66
+ 00:01:13,000 --> 00:01:18,000
67
+ First of all, you can find a new keyword native to understand what is it?
68
+
69
+ 18
70
+ 00:01:18,000 --> 00:01:21,000
71
+ Let's discuss with you what Jeani stands for.
72
+
73
+ 19
74
+ 00:01:21,000 --> 00:01:28,000
75
+ Java Native Interface is a foreign function interface programming framework that enables Java code running
76
+
77
+ 20
78
+ 00:01:28,000 --> 00:01:34,000
79
+ in Java Virtual Machine to call and be called by native applications and libraries written in other
80
+
81
+ 21
82
+ 00:01:34,000 --> 00:01:37,000
83
+ languages such as C or C++.
84
+
85
+ 22
86
+ 00:01:38,000 --> 00:01:45,000
87
+ To simplify this, you can see native keyword with the methods that are written on C or C++ language.
88
+
89
+ 23
90
+ 00:01:45,000 --> 00:01:48,000
91
+ Native keyword can be used only with methods.
92
+
93
+ 24
94
+ 00:01:48,000 --> 00:01:51,000
95
+ Sure, you see native method registered natives.
96
+
97
+ 25
98
+ 00:01:52,000 --> 00:01:55,000
99
+ You need to register all native functions.
100
+
101
+ 26
102
+ 00:01:55,000 --> 00:02:01,000
103
+ You see that you have static in your blog, which executes only once during your program execution.
104
+
105
+ 27
106
+ 00:02:01,000 --> 00:02:05,000
107
+ This static unit block calls register native method.
108
+
109
+ 28
110
+ 00:02:05,000 --> 00:02:09,000
111
+ This method has a private modifier so you will never use it.
112
+
113
+ 29
114
+ 00:02:09,000 --> 00:02:13,000
115
+ Let's focus our attention on the public interface of that class object.
116
+
117
+ 30
118
+ 00:02:14,000 --> 00:02:16,000
119
+ Here is the default constructor.
120
+
121
+ 31
122
+ 00:02:16,000 --> 00:02:17,000
123
+ Nothing special.
124
+
125
+ 32
126
+ 00:02:17,000 --> 00:02:25,000
127
+ Here's a good class method and you can notice that it also native so each object can return us its class.
128
+
129
+ 33
130
+ 00:02:26,000 --> 00:02:30,000
131
+ Class is a separate type which will learn in detail during the lesson about reflection.
132
+
133
+ 34
134
+ 00:02:31,000 --> 00:02:38,000
135
+ In short, this is Stack which describes objects of a class type, so each class during the runtime
136
+
137
+ 35
138
+ 00:02:38,000 --> 00:02:45,000
139
+ has an object associated with it and the class object knows all about fields, methods, annotations,
140
+
141
+ 36
142
+ 00:02:45,000 --> 00:02:47,000
143
+ constructors, everything.
144
+
145
+ 37
146
+ 00:02:47,000 --> 00:02:51,000
147
+ You can invoke methods on objects using getters.
148
+
149
+ 38
150
+ 00:02:51,000 --> 00:02:53,000
151
+ You can get whatever you need.
152
+
153
+ 39
154
+ 00:02:53,000 --> 00:02:58,000
155
+ For example, here's a getter that returns array of fields declared in the class.
156
+
157
+ 40
158
+ 00:02:58,000 --> 00:02:59,000
159
+ But let's not switch.
160
+
161
+ 41
162
+ 00:02:59,000 --> 00:03:04,000
163
+ The topic will return this class in detail later in our course.
164
+
165
+ 42
166
+ 00:03:04,000 --> 00:03:08,000
167
+ What else do we have in our object class Hedgcock method?
168
+
169
+ 43
170
+ 00:03:09,000 --> 00:03:14,000
171
+ A hash code is an integer value that is associated with each object in Java.
172
+
173
+ 44
174
+ 00:03:14,000 --> 00:03:20,000
175
+ Its main purpose is to facilitate hash in hash tables, which are used by data structures like hash
176
+
177
+ 45
178
+ 00:03:20,000 --> 00:03:26,000
179
+ map really learn how to override this method and how to use it when done with your Java collections
180
+
181
+ 46
182
+ 00:03:26,000 --> 00:03:27,000
183
+ framework.
184
+
185
+ 47
186
+ 00:03:27,000 --> 00:03:34,000
187
+ Because as I already mentioned, we can benefit from this method when we use collections equals method
188
+
189
+ 48
190
+ 00:03:34,000 --> 00:03:40,000
191
+ will tell you if the current object is equal to another object or no, it returns only true or false.
192
+
193
+ 49
194
+ 00:03:41,000 --> 00:03:43,000
195
+ And you see that by the fall, this matter.
196
+
197
+ 50
198
+ 00:03:43,000 --> 00:03:44,000
199
+ Check the references.
200
+
201
+ 51
202
+ 00:03:45,000 --> 00:03:52,000
203
+ So in case we need to be able to check equality of our objects in our classes, we have to override
204
+
205
+ 52
206
+ 00:03:52,000 --> 00:03:52,000
207
+ this method.
208
+
209
+ 53
210
+ 00:03:53,000 --> 00:03:58,000
211
+ When we will override this method, will check the state of each field to make sure that this is not
212
+
213
+ 54
214
+ 00:03:58,000 --> 00:04:01,000
215
+ the same object like we do when we compare references.
216
+
217
+ 55
218
+ 00:04:02,000 --> 00:04:06,000
219
+ But to say that this object is logically equal to the one in method argument.
220
+
221
+ 56
222
+ 00:04:07,000 --> 00:04:14,000
223
+ For example, you have Mercedes s class and your friend has Mercedes has class, most of them have the
224
+
225
+ 57
226
+ 00:04:14,000 --> 00:04:19,000
227
+ same color, the same engine displacement, the same color of laser.
228
+
229
+ 58
230
+ 00:04:19,000 --> 00:04:20,000
231
+ Inside the car.
232
+
233
+ 59
234
+ 00:04:20,000 --> 00:04:28,000
235
+ You have two cars, but do they equal they're still two separate cars, but they are logically equal
236
+
237
+ 60
238
+ 00:04:28,000 --> 00:04:29,000
239
+ to each other.
240
+
241
+ 61
242
+ 00:04:29,000 --> 00:04:34,000
243
+ That's why sometimes we need to override the equals method in our court.
244
+
245
+ 62
246
+ 00:04:35,000 --> 00:04:38,000
247
+ How to override the equals method will be covered in the separate lesson.
248
+
249
+ 63
250
+ 00:04:39,000 --> 00:04:42,000
251
+ Now let's briefly discuss Klown method.
252
+
253
+ 64
254
+ 00:04:42,000 --> 00:04:47,000
255
+ The goal of this method is to create new object on the basis of already existed one.
256
+
257
+ 65
258
+ 00:04:47,000 --> 00:04:54,000
259
+ But what you need to remember is that there is a deep and shallow cloning clone method by default,
260
+
261
+ 66
262
+ 00:04:54,000 --> 00:04:55,000
263
+ thus shallow cloning.
264
+
265
+ 67
266
+ 00:04:55,000 --> 00:04:56,000
267
+ What does that mean?
268
+
269
+ 68
270
+ 00:04:57,000 --> 00:05:00,000
271
+ That means that all references are copied.
272
+
273
+ 69
274
+ 00:05:00,000 --> 00:05:04,000
275
+ It doesn't cause a problem when we clone fields of primitive types.
276
+
277
+ 70
278
+ 00:05:04,000 --> 00:05:11,000
279
+ But this does cause problems when we are cloning reference types because only references are cloned
280
+
281
+ 71
282
+ 00:05:11,000 --> 00:05:18,000
283
+ by the true objects behind those references are not cloned to clones at all fields of the objects we
284
+
285
+ 72
286
+ 00:05:18,000 --> 00:05:22,000
287
+ need to override clone method and to implement deep cloning.
288
+
289
+ 73
290
+ 00:05:22,000 --> 00:05:28,000
291
+ What I would recommend us to do right now is to keep overview of the object methods and we'll have separate
292
+
293
+ 74
294
+ 00:05:28,000 --> 00:05:32,000
295
+ lessons to learn how to overwrite clone method to support the cloning.
296
+
297
+ 75
298
+ 00:05:33,000 --> 00:05:37,000
299
+ Also, pay attention to this method has protected access modifier.
300
+
301
+ 76
302
+ 00:05:37,000 --> 00:05:40,000
303
+ I believe you are already aware how the string method works.
304
+
305
+ 77
306
+ 00:05:40,000 --> 00:05:43,000
307
+ This method returns string representation of the object.
308
+
309
+ 78
310
+ 00:05:43,000 --> 00:05:46,000
311
+ Probably in your production code.
312
+
313
+ 79
314
+ 00:05:46,000 --> 00:05:51,000
315
+ You want to use this method very often, but you are going to use it very often during your learning
316
+
317
+ 80
318
+ 00:05:51,000 --> 00:05:53,000
319
+ process for debugging purposes.
320
+
321
+ 81
322
+ 00:05:53,000 --> 00:05:58,000
323
+ Often you would like to print the object, to consult, to check its state, or to interact with your
324
+
325
+ 82
326
+ 00:05:58,000 --> 00:06:02,000
327
+ user in console applications by default.
328
+
329
+ 83
330
+ 00:06:02,000 --> 00:06:08,000
331
+ To string method creates a string which comprises of class name at sine and hexadecimal representation
332
+
333
+ 84
334
+ 00:06:08,000 --> 00:06:09,000
335
+ of the hash code.
336
+
337
+ 85
338
+ 00:06:09,000 --> 00:06:13,000
339
+ We already understand that we can easily override this method in our classes.
340
+
341
+ 86
342
+ 00:06:14,000 --> 00:06:17,000
343
+ Usually we want to bring state of the object in the console.
344
+
345
+ 87
346
+ 00:06:18,000 --> 00:06:24,000
347
+ Probably you remember that in one of our lessons we review source code of the card class and the string
348
+
349
+ 88
350
+ 00:06:24,000 --> 00:06:26,000
351
+ method was overridden there.
352
+
353
+ 89
354
+ 00:06:27,000 --> 00:06:33,000
355
+ You can see here that we used the fields to bring their values to console, to not override this method
356
+
357
+ 90
358
+ 00:06:33,000 --> 00:06:34,000
359
+ by yourself.
360
+
361
+ 91
362
+ 00:06:34,000 --> 00:06:36,000
363
+ You can ask Leap's to generate this method for you.
364
+
365
+ 92
366
+ 00:06:37,000 --> 00:06:41,000
367
+ Just press old plus shift plus s and select generate the string method.
368
+
369
+ 93
370
+ 00:06:42,000 --> 00:06:46,000
371
+ You will be able to specify fields which you want to use in your to string method.
372
+
373
+ 94
374
+ 00:06:47,000 --> 00:06:54,000
375
+ The next method, identifying the all over overloaded wait method and methods to control interaction
376
+
377
+ 95
378
+ 00:06:54,000 --> 00:06:54,000
379
+ with objects.
380
+
381
+ 96
382
+ 00:06:54,000 --> 00:06:59,000
383
+ Monitor this topic is closely connected with multi topic.
384
+
385
+ 97
386
+ 00:06:59,000 --> 00:07:05,000
387
+ To explain how this method works, I need to explain first what Monteith's readiness and how synchronization
388
+
389
+ 98
390
+ 00:07:05,000 --> 00:07:07,000
391
+ of multiple threads happens.
392
+
393
+ 99
394
+ 00:07:07,000 --> 00:07:10,000
395
+ That's why I suggest to park this question.
396
+
397
+ 100
398
+ 00:07:10,000 --> 00:07:15,000
399
+ Promise you to give details overview of these methods during mulches writing topic.
400
+
401
+ 101
402
+ 00:07:15,000 --> 00:07:21,000
403
+ For now, you can learn that each object in Java has special methods to control interaction with objects.
404
+
405
+ 102
406
+ 00:07:21,000 --> 00:07:21,000
407
+ Monitor.
408
+
409
+ 103
410
+ 00:07:22,000 --> 00:07:27,000
411
+ And the last method, which I would like to mention today, is finalized, originally this method was
412
+
413
+ 104
414
+ 00:07:27,000 --> 00:07:33,000
415
+ created to serve as a distracter method, special message, which always will be invoked during the
416
+
417
+ 105
418
+ 00:07:33,000 --> 00:07:35,000
419
+ object destruction in Java.
420
+
421
+ 106
422
+ 00:07:35,000 --> 00:07:41,000
423
+ We have automated memory management and one of the tools which ensure efficient memory management is
424
+
425
+ 107
426
+ 00:07:41,000 --> 00:07:42,000
427
+ the garbage collector.
428
+
429
+ 108
430
+ 00:07:43,000 --> 00:07:48,000
431
+ We are going to have separate lessons regarding garbage collector, but in short, this tool removes
432
+
433
+ 109
434
+ 00:07:48,000 --> 00:07:52,000
435
+ from heap objects that don't have strong references in the program anymore.
436
+
437
+ 110
438
+ 00:07:53,000 --> 00:07:59,000
439
+ You know that objects are stored in the heat of memory and it is not endless, that means that time
440
+
441
+ 111
442
+ 00:07:59,000 --> 00:08:01,000
443
+ to time we have to remove objects.
444
+
445
+ 112
446
+ 00:08:01,000 --> 00:08:08,000
447
+ And when a garbage collector removes objects from the memory, finalized method is invoked that was
448
+
449
+ 113
450
+ 00:08:08,000 --> 00:08:14,000
451
+ needed to perform critical and important actions like resource closure or something else before objects
452
+
453
+ 114
454
+ 00:08:14,000 --> 00:08:15,000
455
+ will be completely destroyed.
456
+
457
+ 115
458
+ 00:08:16,000 --> 00:08:20,000
459
+ It also has to modifier and can be overridden in the class.
460
+
461
+ 116
462
+ 00:08:20,000 --> 00:08:25,000
463
+ But another important thing you need to know about this method is that it is deprecated.
464
+
465
+ 117
466
+ 00:08:26,000 --> 00:08:32,000
467
+ It is marked as deprecated because finalization mechanism is problematic and in some specific cases
468
+
469
+ 118
470
+ 00:08:32,000 --> 00:08:34,000
471
+ can lead to memory leaks and deadlocks.
472
+
473
+ 119
474
+ 00:08:35,000 --> 00:08:38,000
475
+ That's why it is not recommended to use this method anymore.
476
+
477
+ 120
478
+ 00:08:39,000 --> 00:08:45,000
479
+ In Java, a lot of deprecated methods are not removed just to ensure a backwards compatibility to make
480
+
481
+ 121
482
+ 00:08:45,000 --> 00:08:50,000
483
+ sure that application, which was written with Java version first, will be successfully executed on
484
+
485
+ 122
486
+ 00:08:50,000 --> 00:08:52,000
487
+ Java version 14 and later.
488
+
489
+ 123
490
+ 00:08:53,000 --> 00:08:57,000
491
+ But this annotation means that this method should no longer be used.
492
+
493
+ 124
494
+ 00:08:57,000 --> 00:09:00,000
495
+ It looks like we reviewed all methods from the object class.
496
+
497
+ 125
498
+ 00:09:01,000 --> 00:09:03,000
499
+ Let's recall what we have learned today.
500
+
501
+ 126
502
+ 00:09:04,000 --> 00:09:04,000
503
+ Today, billions.
504
+
505
+ 127
506
+ 00:09:04,000 --> 00:09:07,000
507
+ What is the object and what is the object class with it?
508
+
509
+ 128
510
+ 00:09:07,000 --> 00:09:12,000
511
+ Overview of all methods which exist in the object class and which are present in each object.
512
+
513
+ 129
514
+ 00:09:13,000 --> 00:09:20,000
515
+ You learn new keyword, native keyword and you know what it is for today we discussed what Jeani is
516
+
517
+ 130
518
+ 00:09:21,000 --> 00:09:24,000
519
+ really one that we can easily overwrite methods in our class.
520
+
521
+ 131
522
+ 00:09:25,000 --> 00:09:28,000
523
+ Also, we discussed what does deprecated annotation mean.
524
+
525
+ 132
526
+ 00:09:29,000 --> 00:09:31,000
527
+ That's all what I have for you for today.
528
+
529
+ 133
530
+ 00:09:31,000 --> 00:09:34,000
531
+ Thanks a lot for your attention and see you in the next lesson.
532
+
13 - Object-oriented programming/010 Quiz Object-oriented programming - Check yourself.html ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Quiz Object-oriented programming - Check yourself</title>
7
+
8
+ <style>
9
+ * {
10
+ box-sizing: border-box;
11
+ margin: 0;
12
+ padding: 0;
13
+ }
14
+ body {
15
+ font-family: var(--font-stack-text);
16
+ font-weight: 400;
17
+ line-height: 1.4;
18
+ font-size: 1.6rem;
19
+ color: #2d2f31;
20
+ }
21
+ .container {
22
+ position: relative;
23
+ height: 100%;
24
+ overflow-y: auto;
25
+ }
26
+ .content {
27
+ padding: 3.2rem 4.8rem;
28
+ word-break: break-word;
29
+ max-width: 69.6rem;
30
+ margin: 0 auto;
31
+ }
32
+ .heading {
33
+ margin-bottom: 24px;
34
+ font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
35
+ "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
36
+ font-weight: 700;
37
+ line-height: 1.2;
38
+ letter-spacing: 0;
39
+ font-size: 32px;
40
+ max-width: 36em;
41
+ }
42
+ .article-asset-container {
43
+ padding: 2.4rem;
44
+ }
45
+ .article-asset-container p {
46
+ font-size: 19px;
47
+ }
48
+ code {
49
+ background-color: #fff;
50
+ border: 1px solid #d1d7dc;
51
+ color: #b4690e;
52
+ font-size: 80%;
53
+ padding: 0.2rem 0.4rem;
54
+ font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
55
+ }
56
+ p {
57
+ font-weight: 400;
58
+ }
59
+ </style>
60
+ </head>
61
+ <body>
62
+ <div class="container">
63
+ <div class="content">
64
+ <div class="heading">Quiz Object-oriented programming - Check yourself</div>
65
+ <div class="article-asset-container"><p><strong>Quiz Link: </strong><a href="https://forms.gle/NZmCGDrFk2hfCQLs5" rel="noopener noreferrer" target="_blank"><strong>https://forms.gle/NZmCGDrFk2hfCQLs5</strong></a></p><p>The quiz doesn’t require you to log in or submit any personal information. Your data privacy is my priority.</p><p>The Quiz covers content from the following lessons:</p><ul><li><p>Object-Oriented Programming: Basics</p></li><li><p>Classes &amp; Objects</p></li><li><p>Different types of Classes, Abstract keyword and Abstract classes</p></li><li><p>Interfaces</p></li><li><p>Inheritance</p></li><li><p>Polymorphism</p></li><li><p>Static in Java - ‘static’ keyword</p></li><li><p>Encapsulation</p></li><li><p>Object, JNI and Object class overview</p></li></ul><p><strong>Quiz Instructions:</strong></p><p>This quiz is designed to help you check your understanding of the content from the previous lessons. All questions are based only on material covered in the lessons you've already watched, so there’s no need to worry about unfamiliar topics.</p><ul><li><p>Each question has one correct answer. Select the best answer and click "Submit" when you're ready.</p></li><li><p>After submitting, you'll see your score. For each question, you earn 1 point.</p></li><li><p>Click "View Results" to see the explanations for each correct answer. Reviewing these explanations can help reinforce your understanding.</p></li><li><p>If you score below 70%, I recommend revisiting the previous lessons. However, if the explanations make sense and you’re confident in your understanding, feel free to move on.</p></li><li><p>If any explanations are unclear, please don’t hesitate to post questions in the Q&amp;A section—I’m here to help!</p></li></ul></div>
66
+ </div>
67
+ </div>
68
+ </body>
69
+ </html>