Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +8 -0
- 09 - Iteration Statements (Loops) in Java/001 'while' loop.mp4 +3 -0
- 09 - Iteration Statements (Loops) in Java/002 'do-while' loop.mp4 +3 -0
- 09 - Iteration Statements (Loops) in Java/003 'for' with condition loop.mp4 +3 -0
- 09 - Iteration Statements (Loops) in Java/004 'for each' loop.mp4 +3 -0
- 09 - Iteration Statements (Loops) in Java/005 Nested loops.mp4 +3 -0
- 09 - Iteration Statements (Loops) in Java/006 Jump Statements - Break and Continue.mp4 +3 -0
- 09 - Iteration Statements (Loops) in Java/007 Labels in Java.mp4 +3 -0
- 09 - Iteration Statements (Loops) in Java/011 Homework review Iteration Statements (Loops).mp4 +3 -0
- 22 - Functional Programming in Java (including lambda functions & method references)/004 Source-code-All-examples-from-the-lecture-CONSUMERS.url +2 -0
- 22 - Functional Programming in Java (including lambda functions & method references)/004 Source-code-All-examples-from-the-lecture-PREDICATES.url +2 -0
- 22 - Functional Programming in Java (including lambda functions & method references)/external-links.txt +21 -0
- 23 - Stream API/001 Documentation-for-java.util.stream-package.url +2 -0
- 23 - Stream API/001 Homework-Solution-Books-Management.url +2 -0
- 23 - Stream API/001 Homework-Solution-Filter-words-by-length.url +2 -0
- 23 - Stream API/001 Homework-Solution-Present-Sweets.url +2 -0
- 23 - Stream API/001 Homework.url +2 -0
- 23 - Stream API/001 Source-code-All-examples-from-the-lecture.url +2 -0
- 23 - Stream API/001 Stream API with Practical Exercises_en.srt +1312 -0
- 23 - Stream API/002 Quiz Functional Programming in Java - Check yourself.html +69 -0
- 23 - Stream API/external-links.txt +18 -0
- 24 - ===== Functional Programming in Java Interview Preparation =====/001 How to be prepared for the interview.html +69 -0
- 24 - ===== Functional Programming in Java Interview Preparation =====/002 Part 1 Java Functional Programming Interview - Questions and Answers.html +69 -0
- 24 - ===== Functional Programming in Java Interview Preparation =====/003 Part 2 Java Functional Programming Interview - Questions and Answers.html +69 -0
- 25 - Input and Output Streams in Java/001 Homework.url +2 -0
- 25 - Input and Output Streams in Java/001 Input and Output Streams in Java_en.srt +1900 -0
- 25 - Input and Output Streams in Java/001 Solution-of-Homework-Online-store-with-data-storage.url +2 -0
- 25 - Input and Output Streams in Java/001 Solution-of-homework.url +2 -0
- 25 - Input and Output Streams in Java/001 Source-code-examples-from-lesson.url +2 -0
- 25 - Input and Output Streams in Java/005 Homework-solution.url +2 -0
- 25 - Input and Output Streams in Java/005 Homework.url +2 -0
- 25 - Input and Output Streams in Java/005 Serialization and Cloning_en.srt +1096 -0
- 25 - Input and Output Streams in Java/005 Source-code-examples-from-the-lesson-Cloning.url +2 -0
- 25 - Input and Output Streams in Java/005 Source-code-examples-from-the-lesson-Serialization.url +2 -0
- 25 - Input and Output Streams in Java/006 Quiz InputOutput Streams - Check yourself.html +69 -0
- 25 - Input and Output Streams in Java/external-links.txt +24 -0
- 26 - ===== IO in Java Interview Preparation =====/001 Part 1 Java IO Interview - Questions and Answers.html +69 -0
- 26 - ===== IO in Java Interview Preparation =====/002 Part 2 Java IO Interview - Questions and Answers.html +69 -0
- 27 - Multithreading/001 Multithreading Overview_en.srt +740 -0
- 27 - Multithreading/002 First Multithreading Program Thread & Runnable_en.srt +1480 -0
- 27 - Multithreading/002 Source-code-of-the-First-multithreading-program.url +2 -0
- 27 - Multithreading/002 Source-code-of-thread-interruption-demo.url +2 -0
- 27 - Multithreading/003 Source-code-of-the-Priority-demo.url +2 -0
- 27 - Multithreading/003 Source-code-of-the-Thread-group.url +2 -0
- 27 - Multithreading/003 Source-code-of-the-daemon-threads.url +2 -0
- 27 - Multithreading/003 Source-code-of-the-yield-method-demo.url +2 -0
- 27 - Multithreading/003 Source-code-of-throwing-exception-from-run-method-example.url +2 -0
- 27 - Multithreading/003 Thread Scheduler, Race Condition, Daemon Threads & Thread Groups_en.srt +1128 -0
- 27 - Multithreading/004 Source-code-of-all-examples-from-the-lesson.url +2 -0
- 27 - Multithreading/004 Synchronization Basics_en.srt +1532 -0
.gitattributes
CHANGED
|
@@ -65,3 +65,11 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 65 |
07[[:space:]]-[[:space:]]Control[[:space:]]Statements/007[[:space:]]Homework[[:space:]]review[[:space:]]'switch'[[:space:]]statement.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 66 |
08[[:space:]]-[[:space:]]Miscellaneous/001[[:space:]]Random[[:space:]]numbers[[:space:]]generation.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 67 |
07[[:space:]]-[[:space:]]Control[[:space:]]Statements/005[[:space:]]'switch'[[:space:]]construction.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
07[[:space:]]-[[:space:]]Control[[:space:]]Statements/007[[:space:]]Homework[[:space:]]review[[:space:]]'switch'[[:space:]]statement.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 66 |
08[[:space:]]-[[:space:]]Miscellaneous/001[[:space:]]Random[[:space:]]numbers[[:space:]]generation.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 67 |
07[[:space:]]-[[:space:]]Control[[:space:]]Statements/005[[:space:]]'switch'[[:space:]]construction.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/001[[:space:]]'while'[[:space:]]loop.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 69 |
+
09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/002[[:space:]]'do-while'[[:space:]]loop.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 70 |
+
09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/004[[:space:]]'for[[:space:]]each'[[:space:]]loop.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 71 |
+
09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/003[[:space:]]'for'[[:space:]]with[[:space:]]condition[[:space:]]loop.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 72 |
+
09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/005[[:space:]]Nested[[:space:]]loops.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 73 |
+
09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/006[[:space:]]Jump[[:space:]]Statements[[:space:]]-[[:space:]]Break[[:space:]]and[[:space:]]Continue.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 74 |
+
09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/007[[:space:]]Labels[[:space:]]in[[:space:]]Java.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 75 |
+
09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/011[[:space:]]Homework[[:space:]]review[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops).mp4 filter=lfs diff=lfs merge=lfs -text
|
09 - Iteration Statements (Loops) in Java/001 'while' loop.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c629d1d6f638fb968214957658e97c6eb23095272a0bbe7087e6c1348b9c13f0
|
| 3 |
+
size 27823271
|
09 - Iteration Statements (Loops) in Java/002 'do-while' loop.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5eb2e2c5e7fa0f6dd1adca8edbfab3a5e65e319870309f617ff33511a4dca3f3
|
| 3 |
+
size 35783857
|
09 - Iteration Statements (Loops) in Java/003 'for' with condition loop.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ec119ea6d92fcd2a3e8d78f2f667e382468584679b989705b9634e0732800192
|
| 3 |
+
size 63924486
|
09 - Iteration Statements (Loops) in Java/004 'for each' loop.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:71190e257dd46f2405ec5bb73456ccb7cb82f788203ef363051da9451bb18b32
|
| 3 |
+
size 37813640
|
09 - Iteration Statements (Loops) in Java/005 Nested loops.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b67654f3d53938bf16e584d8ceb6b56cb940f55c5d8368de61776bf849b63161
|
| 3 |
+
size 20391609
|
09 - Iteration Statements (Loops) in Java/006 Jump Statements - Break and Continue.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0c422194b3c80416d91dd612aa7b34bb0fbd3688604d92bed32e47a808e4f942
|
| 3 |
+
size 50604865
|
09 - Iteration Statements (Loops) in Java/007 Labels in Java.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:df3f86d63fc059acc141b4411ce931f9c3c444246d42669aa3b5e7d7dd0821c3
|
| 3 |
+
size 61053752
|
09 - Iteration Statements (Loops) in Java/011 Homework review Iteration Statements (Loops).mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2522b8e6587dd3c05d2ed70e5944ba7ab190e5b0291ac55d1e7e5e22d7e2d34e
|
| 3 |
+
size 28394427
|
22 - Functional Programming in Java (including lambda functions & method references)/004 Source-code-All-examples-from-the-lecture-CONSUMERS.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/consumers
|
22 - Functional Programming in Java (including lambda functions & method references)/004 Source-code-All-examples-from-the-lecture-PREDICATES.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/predicates
|
22 - Functional Programming in Java (including lambda functions & method references)/external-links.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
001 Documentation-of-java.util.function-package
|
| 3 |
+
https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/function/package-summary.html
|
| 4 |
+
|
| 5 |
+
002 Source-code-All-examples-from-the-lecture
|
| 6 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/lambdaandmethodreference
|
| 7 |
+
|
| 8 |
+
003 Source-code-All-examples-from-the-lecture
|
| 9 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/functionandbifunction
|
| 10 |
+
|
| 11 |
+
004 Source-code-All-examples-from-the-lecture-CONSUMERS
|
| 12 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/consumers
|
| 13 |
+
|
| 14 |
+
004 Source-code-All-examples-from-the-lecture-PREDICATES
|
| 15 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/predicates
|
| 16 |
+
|
| 17 |
+
004 Homework
|
| 18 |
+
https://docs.google.com/document/d/1hMA300MS2UJhRDfh5VUviGrGiQzfsV5rReH5KTwDdvc/edit?usp=sharing
|
| 19 |
+
|
| 20 |
+
004 Solution-for-Homework
|
| 21 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/hw
|
23 - Stream API/001 Documentation-for-java.util.stream-package.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/stream/package-summary.html
|
23 - Stream API/001 Homework-Solution-Books-Management.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/hw/books
|
23 - Stream API/001 Homework-Solution-Filter-words-by-length.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/methods/hw/FilterStringArray.java
|
23 - Stream API/001 Homework-Solution-Present-Sweets.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/hw/present
|
23 - Stream API/001 Homework.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://docs.google.com/document/d/1TLRPMHsciAdeHn8XFWXQYrO3dVGv6b_THev6nKE2ewY/edit?usp=sharing
|
23 - Stream API/001 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/functions/streams
|
23 - Stream API/001 Stream API with Practical Exercises_en.srt
ADDED
|
@@ -0,0 +1,1312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:10,000
|
| 3 |
+
I know there are students in this class and we're going to discuss topics that will help to make your
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:10,000 --> 00:00:13,000
|
| 7 |
+
code clean and concise while working with collections in the race.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:14,000 --> 00:00:19,000
|
| 11 |
+
They will talk about Stream API at the beginning of the lesson, will give an answer what stream API
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:19,000 --> 00:00:20,000
|
| 15 |
+
is.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:20,000 --> 00:00:26,000
|
| 19 |
+
I will explain to you why we need to use three API with race and collection sometimes after this class
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:26,000 --> 00:00:31,000
|
| 23 |
+
and you will understand what the conveyor belt is and what terminal and non terminal operations are.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:32,000 --> 00:00:37,000
|
| 27 |
+
You are going to learn how to create stream and how to process elements with the help of Stream API.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:37,000 --> 00:00:40,000
|
| 31 |
+
I'm going to show you really a lot of examples today.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:40,000 --> 00:00:46,000
|
| 35 |
+
I will teach you how to create a stream from array and how to convert at to map with the help of Stream
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:46,000 --> 00:00:46,000
|
| 39 |
+
API.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:46,000 --> 00:00:52,000
|
| 43 |
+
In this lesson, we are going to have a lot of practice because one of the ways to understand this topic
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:52,000 --> 00:00:56,000
|
| 47 |
+
better is to understand how you can apply this knowledge on practice.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:56,000 --> 00:01:01,000
|
| 51 |
+
Let's start and to start with, let's create a definition of stream API.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:02,000 --> 00:01:07,000
|
| 55 |
+
If we would open official documentation from Oracle for Jayaweera to Stream Package will see that this
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:07,000 --> 00:01:14,000
|
| 59 |
+
package contains classes to support functional style operations on streams of elements such as mass
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:14,000 --> 00:01:16,000
|
| 63 |
+
produced transformations, onco actions.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:17,000 --> 00:01:22,000
|
| 67 |
+
I believe for people who didn't work with streams, this definition doesn't bring a lot of clarity.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:22,000 --> 00:01:24,000
|
| 71 |
+
So let me explain you the same.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:24,000 --> 00:01:31,000
|
| 75 |
+
In more simple words, stream application programming interface is a set of interfaces that allow to
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:31,000 --> 00:01:37,000
|
| 79 |
+
process elements and to perform operations with them in containers and arrays with the help of functional
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:37,000 --> 00:01:38,000
|
| 83 |
+
interfaces.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:39,000 --> 00:01:45,000
|
| 87 |
+
So to perform operation on the group of elements, you can create lambda functions or use Macit references
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:45,000 --> 00:01:49,000
|
| 91 |
+
that in turn significantly simplifies your code.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:49,000 --> 00:01:50,000
|
| 95 |
+
Does it make sense?
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:51,000 --> 00:01:56,000
|
| 99 |
+
Now let me perform an overview of one important interface from Jowett Ustream package.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:56,000 --> 00:02:00,000
|
| 103 |
+
This will help you to understand our practice examples.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:00,000 --> 00:02:05,000
|
| 107 |
+
I would say that one of the most important interfaces is stream interface.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:05,000 --> 00:02:11,000
|
| 111 |
+
What it is for string interface represents a sequence of elements supporting sequential and parallel
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:11,000 --> 00:02:13,000
|
| 115 |
+
aggregate operations.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:13,000 --> 00:02:15,000
|
| 119 |
+
This is hard to understand.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:15,000 --> 00:02:17,000
|
| 123 |
+
Believe me, I know what you feel.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:17,000 --> 00:02:24,000
|
| 127 |
+
Usually I ask my students to imagine conveyor belt and on this conveyor you have elements from your
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:24,000 --> 00:02:31,000
|
| 131 |
+
collection and as a conveyor belt rolling, you take each element from it and perform any modifications
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:31,000 --> 00:02:32,000
|
| 135 |
+
with it.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:33,000 --> 00:02:38,000
|
| 139 |
+
Before we dive deeper to code examples, I want you to understand, at least on a high level, the next
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:38,000 --> 00:02:39,000
|
| 143 |
+
example.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:39,000 --> 00:02:46,000
|
| 147 |
+
Imagine that you have a list of products and you have a task to keep on that products that has more
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:46,000 --> 00:02:53,000
|
| 151 |
+
than one thousand items in the warehouse and decrease price for these products on 10 percent.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:53,000 --> 00:02:59,000
|
| 155 |
+
This business logic should change the price for products, and this in turn should motivate customers
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:59,000 --> 00:03:03,000
|
| 159 |
+
of the online store to buy these products while price is reduced.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:04,000 --> 00:03:05,000
|
| 163 |
+
How would you do that?
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:05,000 --> 00:03:08,000
|
| 167 |
+
You would create the container of products.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:08,000 --> 00:03:14,000
|
| 171 |
+
Let's imagine that this is a box that is full of products and put all products on conveyor belt.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:14,000 --> 00:03:19,000
|
| 175 |
+
After that, you will check what products has more than one thousand items in warehouse.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:20,000 --> 00:03:24,000
|
| 179 |
+
You will remove from Canberra products that you are not interested in.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:24,000 --> 00:03:29,000
|
| 183 |
+
That means you have to apply a function that knows how to filter elements.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:29,000 --> 00:03:32,000
|
| 187 |
+
After that, you will modify price for each product.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:33,000 --> 00:03:40,000
|
| 191 |
+
That means you have to apply functions that modify state of the product and only after that the end
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:40,000 --> 00:03:44,000
|
| 195 |
+
of the conveyor belt, you would gather all elements together back to the box.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:45,000 --> 00:03:52,000
|
| 199 |
+
Is it clear now you can understand that the functions that was applied for each element on the conveyor
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:52,000 --> 00:03:55,000
|
| 203 |
+
belt, they are called non terminal also.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:55,000 --> 00:04:02,000
|
| 207 |
+
They might be called intermediate functions or it would be opportunism, conveyor operations and the
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:02,000 --> 00:04:06,000
|
| 211 |
+
mass that terminate conveyor are called terminal operations.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:07,000 --> 00:04:15,000
|
| 215 |
+
We also can say that each non terminal operation at Listener to the Stream listener modifies the element
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:15,000 --> 00:04:17,000
|
| 219 |
+
and pass it to another listener.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:17,000 --> 00:04:22,000
|
| 223 |
+
This is called stream processing terminal and non terminal operations.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:22,000 --> 00:04:24,000
|
| 227 |
+
Create Stream Pipeline.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:24,000 --> 00:04:31,000
|
| 231 |
+
Stream Pipeline consists of the source that is our collection of elements or array followed by intermediate
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:31,000 --> 00:04:34,000
|
| 235 |
+
operations and ended with terminal operation.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:35,000 --> 00:04:37,000
|
| 239 |
+
Let's consider another case.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:37,000 --> 00:04:39,000
|
| 243 |
+
You may have multiple lists of products.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:39,000 --> 00:04:40,000
|
| 247 |
+
How it can be.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:41,000 --> 00:04:48,000
|
| 251 |
+
You have different warehouses and each warehouse contains information about the products there.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:48,000 --> 00:04:52,000
|
| 255 |
+
So you have multiple lists of products from each warehouse.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:53,000 --> 00:04:59,000
|
| 259 |
+
This may happen when Demand-Driven design of your application declares that you have type warehouse
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:04:59,000 --> 00:05:01,000
|
| 263 |
+
that in turn can return list of products.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:02,000 --> 00:05:08,000
|
| 267 |
+
And imagine that you have a list, our houses in our example, you have a lot of their houses with products
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:09,000 --> 00:05:15,000
|
| 271 |
+
we can create, can aware of their houses, but we can also have the functions that would tell how to
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:15,000 --> 00:05:20,000
|
| 275 |
+
extract products from these warehouses to have conveyor of products.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:20,000 --> 00:05:25,000
|
| 279 |
+
And after that, we are going to have similar to previous example, logic will filter elements and will
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:25,000 --> 00:05:28,000
|
| 283 |
+
perform price modification, I believe.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:28,000 --> 00:05:31,000
|
| 287 |
+
Now you understand what we are going to learn today.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:32,000 --> 00:05:37,000
|
| 291 |
+
We're going to learn terminal and not terminal functions to perform operations with elements in streams.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:38,000 --> 00:05:42,000
|
| 295 |
+
Now, let's look at the good examples that I prepared for this lesson.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:42,000 --> 00:05:49,000
|
| 299 |
+
To understand how streams work will start from reproducing the case that you saw on slides.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:49,000 --> 00:05:56,000
|
| 303 |
+
All classes are stored in one file to keep all examples related to this lesson grouped and to not switch
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:56,000 --> 00:05:58,000
|
| 307 |
+
between the different types during the lesson.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:58,000 --> 00:06:03,000
|
| 311 |
+
Here we have a class in its price name and the amount of items in their house.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:04,000 --> 00:06:10,000
|
| 315 |
+
Also, you can see a special constructor getters and setters to string Masset for the bag and purposes.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:11,000 --> 00:06:15,000
|
| 319 |
+
And here you can see a warehouse type for the sake of our next examples.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:15,000 --> 00:06:18,000
|
| 323 |
+
This class has only one field list of products.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:19,000 --> 00:06:24,000
|
| 327 |
+
Also, there are two masses, getter and setter, to retrieve and to set products accordingly.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:25,000 --> 00:06:27,000
|
| 331 |
+
Now imagine that I have a list of products.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:27,000 --> 00:06:34,000
|
| 335 |
+
You can see that I created multiple different products here and put all of them into the list to create
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:34,000 --> 00:06:34,000
|
| 339 |
+
stream.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:34,000 --> 00:06:40,000
|
| 343 |
+
From this list, I have to just go through Method Stream is the default method in collection interface.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:41,000 --> 00:06:44,000
|
| 347 |
+
So all collections have be method.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:44,000 --> 00:06:49,000
|
| 351 |
+
After we create a stream we can call intermediate operations and at least inners.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:49,000 --> 00:06:54,000
|
| 355 |
+
For example, let's reproduce a situation from the slides that we saw at the beginning of our lesson
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:55,000 --> 00:06:56,000
|
| 359 |
+
I call filter method.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:57,000 --> 00:06:58,000
|
| 363 |
+
Let me open the source code of Feltham.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:58,000 --> 00:07:06,000
|
| 367 |
+
As you can see, that filter method takes predicate all intermediate functions, return the stream objects
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:06,000 --> 00:07:10,000
|
| 371 |
+
that allows us to create a chain of MassArt in locations.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:10,000 --> 00:07:16,000
|
| 375 |
+
Filter message returns a stream consisting of the elements of the stream that match the given predicate.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:17,000 --> 00:07:23,000
|
| 379 |
+
That means in case predicates returns true for some element, we should keep this element in the stream.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:24,000 --> 00:07:26,000
|
| 383 |
+
Let's get back to the demo file.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:26,000 --> 00:07:28,000
|
| 387 |
+
We use simple predicate here.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:29,000 --> 00:07:35,000
|
| 391 |
+
We want to keep on our conveyor belt only products that have more than 1000 items in the warehouse.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:36,000 --> 00:07:39,000
|
| 395 |
+
After that, I want to apply function to each element.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:40,000 --> 00:07:42,000
|
| 399 |
+
I use math method for this.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:42,000 --> 00:07:45,000
|
| 403 |
+
Let me open the source code of math, Macit.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:46,000 --> 00:07:52,000
|
| 407 |
+
This message returns a stream consisting of the results of a the given function to the aliments in the
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:52,000 --> 00:07:52,000
|
| 411 |
+
stream.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:53,000 --> 00:07:59,000
|
| 415 |
+
In our particular case, we modify product and we return the same product to the stream we set.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:07:59,000 --> 00:08:02,000
|
| 419 |
+
The new price set is ten percent less than the original.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:02,000 --> 00:08:07,000
|
| 423 |
+
One important thing to know here is that intermediate operations are lazy.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:08,000 --> 00:08:14,000
|
| 427 |
+
This means that they will be invoked only if it is necessary for the terminal operation execution.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:14,000 --> 00:08:21,000
|
| 431 |
+
Let's give you the understanding that this lambda functions will be executed only in case a terminal
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:21,000 --> 00:08:23,000
|
| 435 |
+
operation and the end of the chain.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:23,000 --> 00:08:29,000
|
| 439 |
+
And now when I did everything I wanted, I want to create a collection of items that are currently on
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:29,000 --> 00:08:32,000
|
| 443 |
+
the conveyor belt I call terminal function collect.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:33,000 --> 00:08:36,000
|
| 447 |
+
Let's review the source code of collect Macit here.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:36,000 --> 00:08:39,000
|
| 451 |
+
We can see that this massive tax collector as an argument.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:40,000 --> 00:08:41,000
|
| 455 |
+
But what is a collector?
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:42,000 --> 00:08:45,000
|
| 459 |
+
We have only one way to learn this from the source code.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:45,000 --> 00:08:52,000
|
| 463 |
+
We can understand that collector is a specific type that accumulates input elements into mutable result
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:52,000 --> 00:08:53,000
|
| 467 |
+
content.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:08:54,000 --> 00:08:56,000
|
| 471 |
+
But where to get the implementation of collector?
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:08:57,000 --> 00:09:01,000
|
| 475 |
+
Usually engineers use collectors glass to get any collector that is needed.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:02,000 --> 00:09:08,000
|
| 479 |
+
Let me show you the source code of collectors glass this glass also from Jemmett Ustream package.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:08,000 --> 00:09:13,000
|
| 483 |
+
And in the Masset outline you can see that we can get different collectors.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:13,000 --> 00:09:20,000
|
| 487 |
+
The most popular, in my opinion, are the ones that are returned by the next masses to least to set
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:20,000 --> 00:09:21,000
|
| 491 |
+
the map.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:21,000 --> 00:09:26,000
|
| 495 |
+
Also, you can get collectors that will collect all your elements to modify modifiable least.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:26,000 --> 00:09:30,000
|
| 499 |
+
For example, most of the masses are describing here.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:09:30,000 --> 00:09:34,000
|
| 503 |
+
That's why I don't see the sense into naming all of this matter.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:35,000 --> 00:09:40,000
|
| 507 |
+
Just open the source code of this class to investigate what other collectors you can use.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:40,000 --> 00:09:47,000
|
| 511 |
+
By the way, at the end of the lesson, I will leave a cheat sheet for you where I will gather all the
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:47,000 --> 00:09:50,000
|
| 515 |
+
most popular masses, including the terminal functions.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:51,000 --> 00:09:53,000
|
| 519 |
+
Let's get back to our demo file.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:09:53,000 --> 00:09:58,000
|
| 523 |
+
In this case, I want to group all elements from my stream into the container.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:09:58,000 --> 00:10:01,000
|
| 527 |
+
I call collect method and pass collect the.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:01,000 --> 00:10:10,000
|
| 531 |
+
Is it a might the least Masset implication, is this example clear so you can see massive change here
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:10,000 --> 00:10:14,000
|
| 535 |
+
with multiple intermediate functions and then I have one terminal operation.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:15,000 --> 00:10:17,000
|
| 539 |
+
Where did they get these intermediate masses?
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:18,000 --> 00:10:20,000
|
| 543 |
+
You can open string type to investigate.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:20,000 --> 00:10:24,000
|
| 547 |
+
The rest of the masses here will review these in a minute.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:10:24,000 --> 00:10:26,000
|
| 551 |
+
Let me finish the example we already started.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:10:27,000 --> 00:10:29,000
|
| 555 |
+
Let me get back to the demo file.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:10:30,000 --> 00:10:35,000
|
| 559 |
+
And after I created the list, I want to print all elements to console from the new line.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:35,000 --> 00:10:40,000
|
| 563 |
+
But instead of creating foreach loop, I will use the feature of Stream API.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:40,000 --> 00:10:43,000
|
| 567 |
+
I create a stream using the variable of modified products.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:44,000 --> 00:10:51,000
|
| 571 |
+
After that, I call for each method that takes consumer as an argument and I pass mast reference here
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:10:51,000 --> 00:10:54,000
|
| 575 |
+
out property of a system class.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:10:54,000 --> 00:10:59,000
|
| 579 |
+
His method printer lan that we use very often during the bargain of our programs.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:10:59,000 --> 00:11:05,000
|
| 583 |
+
So I just use reference to this massive let me run the program to prove you that it works.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:05,000 --> 00:11:07,000
|
| 587 |
+
And here we go.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:07,000 --> 00:11:11,000
|
| 591 |
+
You can see that I have only three products with modified price.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:11,000 --> 00:11:12,000
|
| 595 |
+
Awesome.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:11:12,000 --> 00:11:14,000
|
| 599 |
+
Everything works as expected.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:11:15,000 --> 00:11:19,000
|
| 603 |
+
Now let me reproduce the second example from our presentation.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:11:19,000 --> 00:11:22,000
|
| 607 |
+
Imagine that we have multiple warehouses.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:11:22,000 --> 00:11:25,000
|
| 611 |
+
I create a few warehouses, objects here.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:25,000 --> 00:11:27,000
|
| 615 |
+
Each warehouse has lists of products.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:28,000 --> 00:11:32,000
|
| 619 |
+
That's why I add a different list of objects to the warehouses here.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:11:33,000 --> 00:11:39,000
|
| 623 |
+
And imagine we have to iterate over all products to decrease price only for products that have more
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:11:39,000 --> 00:11:41,000
|
| 627 |
+
than 1000 items.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:11:41,000 --> 00:11:46,000
|
| 631 |
+
First of all, I group all my warehouse objects into one list.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:11:46,000 --> 00:11:49,000
|
| 635 |
+
Now I create a stream out of this list.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:11:49,000 --> 00:11:52,000
|
| 639 |
+
After that I call flat my math.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:11:53,000 --> 00:11:54,000
|
| 643 |
+
What is it for?
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:11:54,000 --> 00:12:02,000
|
| 647 |
+
This method exists to extract elements from NASA once this method will return stream consistent of the
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:12:02,000 --> 00:12:09,000
|
| 651 |
+
result of replacing each element of the stream with the contents of a mapped stream produced by applying
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:12:09,000 --> 00:12:13,000
|
| 655 |
+
the provided map and function to each element.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:12:13,000 --> 00:12:22,000
|
| 659 |
+
Is it clear will path function to this method that will produce stream of elements from each element?
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:12:22,000 --> 00:12:29,000
|
| 663 |
+
In our particular case, we have to get products from each warehouse object and create a stream on list
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:12:29,000 --> 00:12:30,000
|
| 667 |
+
of products.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:30,000 --> 00:12:38,000
|
| 671 |
+
Before we call this flat map method, we have conveyor belt of warehouse elements and after we called
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:38,000 --> 00:12:41,000
|
| 675 |
+
flat map, we have stream of product elements.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:12:41,000 --> 00:12:46,000
|
| 679 |
+
Can you understand now how we can transform data in our stream?
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:12:46,000 --> 00:12:51,000
|
| 683 |
+
After that, we are filtering and applying function to all elements.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:12:51,000 --> 00:12:53,000
|
| 687 |
+
Now let me show you one more thing.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:12:54,000 --> 00:13:00,000
|
| 691 |
+
Imagine that according to some massive contracts requirements, you have to reach an array we can call
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:13:00,000 --> 00:13:02,000
|
| 695 |
+
to array Massud instead of collect.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:13:03,000 --> 00:13:07,000
|
| 699 |
+
But in case we would just call Thouret Array method, we would get array of objects.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:08,000 --> 00:13:14,000
|
| 703 |
+
What to do in this case, I have to pass the Massud that will create array of the specific types that
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:13:14,000 --> 00:13:15,000
|
| 707 |
+
I need.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:13:15,000 --> 00:13:19,000
|
| 711 |
+
What method can create an array of product constructor?
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:13:20,000 --> 00:13:28,000
|
| 715 |
+
That's why I specify type here array of product and positive reference to a constructor according to
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:13:28,000 --> 00:13:29,000
|
| 719 |
+
syntax requirements.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:13:29,000 --> 00:13:31,000
|
| 723 |
+
I have to write the new keyword here.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:13:32,000 --> 00:13:34,000
|
| 727 |
+
Can you understand now what this meant?
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:13:35,000 --> 00:13:38,000
|
| 731 |
+
Now Java can create object of product array.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:13:39,000 --> 00:13:43,000
|
| 735 |
+
After that I want to print all elements to console from new line.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:13:44,000 --> 00:13:48,000
|
| 739 |
+
But we have an array this time can create stream from array.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:13:48,000 --> 00:13:49,000
|
| 743 |
+
Yes I can.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:13:50,000 --> 00:13:54,000
|
| 747 |
+
I have to call stream Massud from arrays class and parse array of products there.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:13:55,000 --> 00:13:59,000
|
| 751 |
+
That's how easily you can create three from any array.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:13:59,000 --> 00:14:06,000
|
| 755 |
+
Also during the discussion of functional interfaces, I promise to show you one method and how it might
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:14:06,000 --> 00:14:07,000
|
| 759 |
+
be helpful.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:14:07,000 --> 00:14:12,000
|
| 763 |
+
While working with Stream API, I'm talking about identity Masset from function type.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:14:13,000 --> 00:14:19,000
|
| 767 |
+
Imagine that you want to convert list of products to the map type where you're going to have product
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:14:19,000 --> 00:14:23,000
|
| 771 |
+
name as a key and product type as a value that is mapped to this key.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:14:24,000 --> 00:14:25,000
|
| 775 |
+
How to do that.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:14:25,000 --> 00:14:30,000
|
| 779 |
+
You'll remember at the beginning of the lesson I created products placed in this example.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:14:30,000 --> 00:14:35,000
|
| 783 |
+
I use the same list of products, I create stream code, collect method.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:14:35,000 --> 00:14:40,000
|
| 787 |
+
And after that I called to map Masset from collectors' class and past two functions.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:14:41,000 --> 00:14:47,000
|
| 791 |
+
The first one should create keys, and the second one is a function that can create product values that
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:14:47,000 --> 00:14:49,000
|
| 795 |
+
are associated with a specific case.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:14:50,000 --> 00:14:56,000
|
| 799 |
+
Taking into account, I don't need to modify a product, I should return the same product.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:14:56,000 --> 00:15:00,000
|
| 803 |
+
That's why I use identity MASSATA function type here.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:15:00,000 --> 00:15:08,000
|
| 807 |
+
Identity MassArt returns the same object, does it make sense, the last good example that I want to
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:15:08,000 --> 00:15:15,000
|
| 811 |
+
share with you is map to end and some that I would even say that a group of mass that you will use and
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:15:15,000 --> 00:15:17,000
|
| 815 |
+
these two are just one of many.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:15:18,000 --> 00:15:23,000
|
| 819 |
+
There are numerous of business cases when they need to process collection of elements and find is a
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:15:23,000 --> 00:15:28,000
|
| 823 |
+
max price or some old values of some field or something similar.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:15:29,000 --> 00:15:35,000
|
| 827 |
+
To perform these operations, we have to convert our regular stream to in stream or double stream along
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:15:35,000 --> 00:15:36,000
|
| 831 |
+
stream.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:15:36,000 --> 00:15:44,000
|
| 835 |
+
That's why Stream Type has such masses as map to end, map to double mapped along this massive stage
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:15:44,000 --> 00:15:52,000
|
| 839 |
+
function as an argument then can extract some no value out of current item in stream and these masses
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:15:52,000 --> 00:15:56,000
|
| 843 |
+
rich on specific stream type like any stream that will stream along stream.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:15:57,000 --> 00:15:59,000
|
| 847 |
+
These types declare new methods.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:16:00,000 --> 00:16:06,000
|
| 851 |
+
For example, imagine the case when you need to calculate total amount of items of all products in the
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:16:06,000 --> 00:16:08,000
|
| 855 |
+
warehouse aggregate stream.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:16:08,000 --> 00:16:14,000
|
| 859 |
+
And after that cool map to Inmarsat and parse function that returns into value based on each product,
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:16:15,000 --> 00:16:16,000
|
| 863 |
+
is that clear?
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:16:17,000 --> 00:16:20,000
|
| 867 |
+
And after that I can call some method.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:16:20,000 --> 00:16:27,000
|
| 871 |
+
This mass at will sum all integers in my end stream that I received after map to Inmarsat invocation.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:16:28,000 --> 00:16:35,000
|
| 875 |
+
And here I bring the total items amount to consult, by the way, instead of some you can call Max mean
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:16:35,000 --> 00:16:38,000
|
| 879 |
+
average or any other methods you would like.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:16:38,000 --> 00:16:45,000
|
| 883 |
+
Myside examples from this file, I also prepared a lot of other examples for you, which are the masses,
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:16:45,000 --> 00:16:48,000
|
| 887 |
+
I believe, linked to this file in attachment to this lesson.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:16:49,000 --> 00:16:54,000
|
| 891 |
+
I want you to investigate these good examples by yourself after the lesson, because technical is a
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:16:54,000 --> 00:16:56,000
|
| 895 |
+
syntax is the same.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:16:56,000 --> 00:16:58,000
|
| 899 |
+
And you saw already a few examples.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:16:58,000 --> 00:17:01,000
|
| 903 |
+
Some of the methods are used very rare.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:17:01,000 --> 00:17:03,000
|
| 907 |
+
Some of them are used more often.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:17:03,000 --> 00:17:06,000
|
| 911 |
+
We'll talk about the masses in a minute.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:17:06,000 --> 00:17:12,000
|
| 915 |
+
But remember that you can find any good example with any message from Stream API by searching through
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:17:12,000 --> 00:17:12,000
|
| 919 |
+
this file.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:17:13,000 --> 00:17:19,000
|
| 923 |
+
Now, when you saw how you can use the masses and stream API, it is only a matter of what that you
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:17:19,000 --> 00:17:20,000
|
| 927 |
+
want to call.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:17:20,000 --> 00:17:24,000
|
| 931 |
+
We cover all aspects of using stream API from the syntax standpoint.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:17:24,000 --> 00:17:29,000
|
| 935 |
+
Now we have to learn the masses that you might want to use while working with streams.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:17:30,000 --> 00:17:32,000
|
| 939 |
+
I want to show you a cheat sheet, I call it.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:17:32,000 --> 00:17:37,000
|
| 943 |
+
So was the main operations with streams and shared examples.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:17:37,000 --> 00:17:42,000
|
| 947 |
+
Remember, you can use a cheat sheet in case you forgot something on this slide.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:17:42,000 --> 00:17:45,000
|
| 951 |
+
You can see how you can create a stream with examples.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:17:45,000 --> 00:17:47,000
|
| 955 |
+
Some of them we already reviewed.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:17:47,000 --> 00:17:50,000
|
| 959 |
+
I'm talking about creating a stream from collections and from array.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:17:51,000 --> 00:17:52,000
|
| 963 |
+
Let's review other options.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:17:53,000 --> 00:17:56,000
|
| 967 |
+
We can create stream of elements if we want.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:17:56,000 --> 00:17:59,000
|
| 971 |
+
We can create stream of lines in case we read file.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:18:00,000 --> 00:18:02,000
|
| 975 |
+
We will learn more about this during the topic.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:18:02,000 --> 00:18:04,000
|
| 979 |
+
Input output streams in Java.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:18:05,000 --> 00:18:08,000
|
| 983 |
+
Also, as you can see here, we can create a stream from stream.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:18:08,000 --> 00:18:11,000
|
| 987 |
+
We can use Stream Builder to add elements.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:18:11,000 --> 00:18:18,000
|
| 991 |
+
And after that stream also you can invoke parallel stream that would process all elements in different
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:18:18,000 --> 00:18:20,000
|
| 995 |
+
threats of execution.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:18:20,000 --> 00:18:26,000
|
| 999 |
+
Ensured parallel stream will not always bring you better performance because coordination of multiple
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:18:26,000 --> 00:18:30,000
|
| 1003 |
+
threats of execution also requires some calculations.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:18:30,000 --> 00:18:35,000
|
| 1007 |
+
That's why use parallel stream only with the amount of data.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:18:35,000 --> 00:18:41,000
|
| 1011 |
+
It is hard to see what should be considered as Beke because it will depend on the operations you are
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:18:41,000 --> 00:18:43,000
|
| 1015 |
+
going to perform and stream.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:18:43,000 --> 00:18:49,000
|
| 1019 |
+
It will also depends on the type of the object that you are going to use and how big it is.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:18:49,000 --> 00:18:56,000
|
| 1023 |
+
I would even say that in case you are not sure whether the parallel stream in some particular case always
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:18:56,000 --> 00:18:58,000
|
| 1027 |
+
opt for regular stream in such cases.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:18:59,000 --> 00:19:05,000
|
| 1031 |
+
Also, we can create infinite sequential order stream produced by iterative application of a function
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:19:05,000 --> 00:19:07,000
|
| 1035 |
+
to an initial element.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:19:08,000 --> 00:19:14,000
|
| 1039 |
+
Besides that, we can create an infinite sequential stream where each element is generated by the provided
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:19:14,000 --> 00:19:14,000
|
| 1043 |
+
supply.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:19:15,000 --> 00:19:19,000
|
| 1047 |
+
In other words, we can pass a function that can generate elements and create a stream.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:19:20,000 --> 00:19:24,000
|
| 1051 |
+
To be honest, I didn't use the last two options very often.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:19:24,000 --> 00:19:28,000
|
| 1055 |
+
So now you know all possible ways to create stream.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:19:28,000 --> 00:19:29,000
|
| 1059 |
+
Let's move on.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:19:30,000 --> 00:19:33,000
|
| 1063 |
+
On this slide, you can see different intermediate methods.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:19:33,000 --> 00:19:38,000
|
| 1067 |
+
Some of them looks familiar to you because we had examples with those masses.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:19:38,000 --> 00:19:45,000
|
| 1071 |
+
You already know when you might want to use filter, map, map to end flatman methods, don't you?
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:19:45,000 --> 00:19:52,000
|
| 1075 |
+
You also can use skip method to skip specific number of elements you can call distant Masad to get stream
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:19:52,000 --> 00:19:59,000
|
| 1079 |
+
without duplication in case you want to apply consumer function to each element you can call peak MassArt.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:19:59,000 --> 00:20:05,000
|
| 1083 |
+
Usually it is used for debugging purposes, the print element to console to investigate the state of
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:20:05,000 --> 00:20:07,000
|
| 1087 |
+
a stream lamet.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:20:07,000 --> 00:20:11,000
|
| 1091 |
+
Masset allows you to limit the number of elements in your stream source.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:20:12,000 --> 00:20:16,000
|
| 1095 |
+
It allows us to source elements in stream by natural ordering.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:20:16,000 --> 00:20:22,000
|
| 1099 |
+
There is also overloaded version of this method that takes Comparator as an argument to define the source
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:20:22,000 --> 00:20:23,000
|
| 1103 |
+
and order.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:20:23,000 --> 00:20:28,000
|
| 1107 |
+
Using these intermediate operations, you can do amazing things with data manipulation.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:20:29,000 --> 00:20:35,000
|
| 1111 |
+
Let's look at the next slide and on this slide you can find a list of terminal operations.
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:20:35,000 --> 00:20:42,000
|
| 1115 |
+
Today during the demo, you saw collect Masset for each entero find first method returns, the first
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:20:42,000 --> 00:20:43,000
|
| 1119 |
+
element from stream.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:20:43,000 --> 00:20:49,000
|
| 1123 |
+
This might be useful in case your source elements in stream and want to take the first elements after
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:20:49,000 --> 00:20:57,000
|
| 1127 |
+
sorting, find any MACIT returns, any element from stream patterns that these two methods return object
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:20:57,000 --> 00:20:58,000
|
| 1131 |
+
of type optional.
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:20:58,000 --> 00:21:05,000
|
| 1135 |
+
This is not the lesson about optional, but ensured optional is a type that is used as a container for
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:21:05,000 --> 00:21:10,000
|
| 1139 |
+
objects that may or may not contain and nonono value.
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:21:10,000 --> 00:21:17,000
|
| 1143 |
+
Also, these types introduce API to extract value from container or perform as operations in case a
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:21:17,000 --> 00:21:18,000
|
| 1147 |
+
container is empty.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:21:19,000 --> 00:21:27,000
|
| 1151 |
+
We can call Count Massud in case we want to get a number of elements in this stream and any match non-match
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:21:27,000 --> 00:21:30,000
|
| 1155 |
+
and all march methods take predicate to return.
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:21:30,000 --> 00:21:31,000
|
| 1159 |
+
True or false?
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:21:32,000 --> 00:21:38,000
|
| 1163 |
+
I believe that it is clear from the method names that any match will return true in case at least one.
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:21:38,000 --> 00:21:45,000
|
| 1167 |
+
The elements from streamy, the conditions of predicates that we passed to this massive non-match will
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:21:45,000 --> 00:21:52,000
|
| 1171 |
+
return true in case non of elements Margitza Predicate and all March will return true only in case all
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:21:52,000 --> 00:21:56,000
|
| 1175 |
+
elements march pre-cut main and maximizers.
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:21:56,000 --> 00:22:03,000
|
| 1179 |
+
I believe these are self describing this massive state comparator as an argument for each order.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:22:03,000 --> 00:22:09,000
|
| 1183 |
+
It must is similar to for each Massett, but it also supports order of elements in the stream.
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:22:10,000 --> 00:22:16,000
|
| 1187 |
+
Reduce mass performs reduction stream operations that allows us to produce one single result from a
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:22:16,000 --> 00:22:21,000
|
| 1191 |
+
sequence of elements in this operation usually take part three participants.
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:22:21,000 --> 00:22:23,000
|
| 1195 |
+
They are a regional element.
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:22:24,000 --> 00:22:26,000
|
| 1199 |
+
It is also called identity.
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:22:26,000 --> 00:22:29,000
|
| 1203 |
+
The second participant is an accumulator.
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:22:29,000 --> 00:22:36,000
|
| 1207 |
+
This is a function that takes two parameters, a partial result of the reduction operation and the next
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:22:36,000 --> 00:22:37,000
|
| 1211 |
+
element of the string.
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:22:37,000 --> 00:22:40,000
|
| 1215 |
+
And the third participant is a combiner.
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:22:40,000 --> 00:22:46,000
|
| 1219 |
+
This is a function that is used to combine the partial result of the reduction operation once the reduction
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:22:46,000 --> 00:22:52,000
|
| 1223 |
+
is paralyzed or when there is a mismatch between the types of the accumulator arguments and the types
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:22:52,000 --> 00:22:54,000
|
| 1227 |
+
of the accumulator implementation.
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:22:55,000 --> 00:23:01,000
|
| 1231 |
+
And I know that this can sound not clear, but don't worry about that after this lesson.
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:23:01,000 --> 00:23:03,000
|
| 1235 |
+
Take your time to investigate the examples.
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:23:04,000 --> 00:23:10,000
|
| 1239 |
+
I didn't show you this example because to be honest, this function is not used super often, really.
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:23:11,000 --> 00:23:16,000
|
| 1243 |
+
So take your time to investigate examples and feel free to ask questions in case you have any.
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:23:17,000 --> 00:23:19,000
|
| 1247 |
+
That's all what I wanted to share with you today.
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:23:19,000 --> 00:23:24,000
|
| 1251 |
+
Now let's recap what we have learned today so that we learned really a lot of things.
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:23:25,000 --> 00:23:26,000
|
| 1255 |
+
But let's try to sum it up.
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:23:27,000 --> 00:23:30,000
|
| 1259 |
+
We understand what Stream API is now.
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:23:30,000 --> 00:23:36,000
|
| 1263 |
+
We know how to create stream, how to use intermediate operations and how to use terminal operations
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:23:37,000 --> 00:23:38,000
|
| 1267 |
+
on real life examples.
|
| 1268 |
+
|
| 1269 |
+
318
|
| 1270 |
+
00:23:38,000 --> 00:23:41,000
|
| 1271 |
+
You saw how you can apply your knowledge about Stream API.
|
| 1272 |
+
|
| 1273 |
+
319
|
| 1274 |
+
00:23:41,000 --> 00:23:47,000
|
| 1275 |
+
Also, you got a lot of examples that you can use during the development when you need.
|
| 1276 |
+
|
| 1277 |
+
320
|
| 1278 |
+
00:23:47,000 --> 00:23:49,000
|
| 1279 |
+
And now let me show your homework.
|
| 1280 |
+
|
| 1281 |
+
321
|
| 1282 |
+
00:23:50,000 --> 00:23:52,000
|
| 1283 |
+
You can find multiple tasks here.
|
| 1284 |
+
|
| 1285 |
+
322
|
| 1286 |
+
00:23:53,000 --> 00:23:59,000
|
| 1287 |
+
The important thing in each task is to implement those with the help of Stream API and functional interfaces.
|
| 1288 |
+
|
| 1289 |
+
323
|
| 1290 |
+
00:24:00,000 --> 00:24:06,000
|
| 1291 |
+
You can practice a lot in writing your own lambda expressions and then processing elements in stream
|
| 1292 |
+
|
| 1293 |
+
324
|
| 1294 |
+
00:24:06,000 --> 00:24:08,000
|
| 1295 |
+
read tasks attentively.
|
| 1296 |
+
|
| 1297 |
+
325
|
| 1298 |
+
00:24:08,000 --> 00:24:15,000
|
| 1299 |
+
I edit as much details as I could in each task and remember, in case you have any question gunshy to
|
| 1300 |
+
|
| 1301 |
+
326
|
| 1302 |
+
00:24:15,000 --> 00:24:17,000
|
| 1303 |
+
ask me that.
|
| 1304 |
+
|
| 1305 |
+
327
|
| 1306 |
+
00:24:17,000 --> 00:24:20,000
|
| 1307 |
+
So what I have for you for today, thanks a lot for your attention.
|
| 1308 |
+
|
| 1309 |
+
328
|
| 1310 |
+
00:24:20,000 --> 00:24:23,000
|
| 1311 |
+
Have a great day and see you in the next lesson.
|
| 1312 |
+
|
23 - Stream API/002 Quiz Functional Programming in Java - 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 Functional Programming in Java - 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 Functional Programming in Java - Check yourself</div>
|
| 65 |
+
<div class="article-asset-container"><p><strong>Quiz Link: </strong><a href="https://forms.gle/uYL6fghm9AJnCQfa9" rel="noopener noreferrer" target="_blank"><strong>https://forms.gle/uYL6fghm9AJnCQfa9</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>Functional Programming in Java - Overview</p></li><li><p>Functional Interface, Lambda Functions & Method References</p></li><li><p>Function & BiFunction: Theory & Practice</p></li><li><p>Consumer, BiConsumer, Predicate & BiPredicate</p></li><li><p>Stream API</p></li></ul><p><br></p><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&A section—I’m here to help!</p></li></ul></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
23 - Stream API/external-links.txt
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
001 Documentation-for-java.util.stream-package
|
| 3 |
+
https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/stream/package-summary.html
|
| 4 |
+
|
| 5 |
+
001 Homework
|
| 6 |
+
https://docs.google.com/document/d/1TLRPMHsciAdeHn8XFWXQYrO3dVGv6b_THev6nKE2ewY/edit?usp=sharing
|
| 7 |
+
|
| 8 |
+
001 Source-code-All-examples-from-the-lecture
|
| 9 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/streams
|
| 10 |
+
|
| 11 |
+
001 Homework-Solution-Books-Management
|
| 12 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/oop/hw/books
|
| 13 |
+
|
| 14 |
+
001 Homework-Solution-Present-Sweets
|
| 15 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/oop/hw/present
|
| 16 |
+
|
| 17 |
+
001 Homework-Solution-Filter-words-by-length
|
| 18 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/methods/hw/FilterStringArray.java
|
24 - ===== Functional Programming in Java Interview Preparation =====/001 How to be prepared for the interview.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>How to be prepared for the interview</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">How to be prepared for the interview</div>
|
| 65 |
+
<div class="article-asset-container"><p>I gathered for you the most popular questions during the Java Interview in JAVA FUNCTIONAL PROGRAMMING topic. How you can be prepared for the interview?</p><p>Just read the question first. Try to answer the question by yourself. After that, compare your answer with the answer provided. Remember, that this is just a reference to the answer. Because sometimes the topic is big, and you can go really deep with your answer. In case you feel like you don’t understand what the answer is about - feel free to get back in the course and review the relevant section, and relevant lesson one more time.</p><p>Also, you are always welcome to ask your questions and I will be happy to answer. I’m sure that these questions will help you to be prepared for the JAVA FUNCTIONAL PROGRAMMING interview. You need to be ready to answer perfectly on these questions.</p><p>In case there are questions that you don't know the answers to, please, feel free to check my full and the most complete course "Java From Zero to First Job".</p><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
24 - ===== Functional Programming in Java Interview Preparation =====/002 Part 1 Java Functional Programming Interview - Questions and Answers.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>Part 1 Java Functional Programming Interview - Questions and Answers</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">Part 1 Java Functional Programming Interview - Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>WHAT IS THE STRUCTURE OF A LAMBDA EXPRESSION?</strong></p></li></ul><p><br></p><p>The lambda expression has the following structure:</p><ul><li><p>(method params) -> {lambda expression body}</p></li></ul><p><br></p><p>where</p><ul><li><p>method params - a list of input parameters separated by commas (if there are more than one parameters, they are enclosed in brackets).</p></li><li><p>operator "->" - serves as a separator between the list of parameters of our method and the body in which its implementation takes place.</p></li><li><p>lambda expression body - method body, consisting of one or more expressions enclosed in curly braces.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT VARIABLES DO LAMBDA EXPRESSIONS ACCESS TO?</strong></p></li></ul><p><br></p><p>Lambda expressions have access to the variables of the scope in which they are defined. But access is possible only if the variables are effective final, that is, either explicitly have the final modifier, or in case they do not change their value after initialization, if the variable is assigned a value for the second time, the lambda expression causes a compilation error.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS METHOD REFERENCES?</strong></p></li></ul><p><br></p><p>Method references are compact lambda expressions that allow you to pass references to methods or constructors. To do this, use the "::" keyword.</p><p>Reference methods implement a useful syntax to refer to existing methods or constructors of Java classes or objects (instances). Together with lambda expressions, reference methods make language constructs compact and concise, making it boilerplate.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT TYPES OF REFERENCES TO METHODS DO YOU KNOW?</strong></p></li></ul><p><br></p><p>There are three kinds of method references:</p><ul><li><p>Reference to a static method(ContainingClass::staticMethodName)</p></li><li><p>Reference to a concrete object method(containingObject::instanceMethodName)</p></li><li><p>Reference to constructor(ClassName::new), for generics (generics) Class< T >::new.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>EXPLAIN THE SYSTEM.OUT::PRINTLN EXPRESSION.</strong></p></li></ul><p><br></p><p>The System.out::println expression is a reference to the static println method of the out object of the System class, which is equivalent to the x -> System.out.println(x) lambda expression.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE FUNCTIONAL INTERFACES?</strong></p></li></ul><p><br></p><p>A functional interface is one that defines exactly one abstract method.</p><p><br></p><p>Java 8 introduced a new @FunctionalInterface annotation to mark an interface as functional, this annotation is used to avoid accidentally adding abstract methods to a functional interface. It's not required, but it's good coding practice.</p><p><br></p><p>Functional interfaces allow us to use lambda expressions to instantiate such interfaces.</p><p><br></p><p>The best example of a functional interface would be the java.lang.Runnable interface with a single abstract run() method. Note that an interface can include any number of default or static methods and still be functional, because default and static methods are not abstract.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE STREAMS IN JAVA?</strong></p></li></ul><p><br></p><p>java.util.stream - introduced to support parallelization of computations in streams. Provides the ability to process a sequence of elements by executing one or more operations, which can be performed either sequentially or in parallel. Streams are divided into serial and parallel. The biggest benefit of this is when working with collections.</p><p><br></p><p>Operations on a stream are either intermediate or terminal. All intermediate operations return a stream, so we can combine multiple intermediate operations without using a semicolon. Terminal operations return void or a non-stream result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE COLLECT METHOD FOR?</strong></p></li></ul><p><br></p><p>Most operations of the Stream class that modify a dataset return that dataset as a stream. However, there are situations when you would like to receive data not as a stream, but as a regular collection, for example, ArrayList or HashSet. And for this, the Stream class has a collect method. The method takes as a parameter a conversion function to a collection:</p><p><R,A> R collect(Collector<? super T,A,R> collector)</p><p>The R parameter represents the result type of the method, the T parameter is the type of the element in the stream, and the A parameter is the type of the intermediate accumulated data. As a result, the collector parameter represents the function of converting the stream into a collection.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DIFFERENCE BETWEEN A COLLECTION AND A STREAM?</strong></p></li></ul><p><br></p><p>The difference between a Collection (Collection) of data and a stream (Stream) from the new JDK8 is that collections allow you to work with elements individually, while a stream (Stream) does not. For example, with collections, you can add items, remove items, and insert in the middle. A Stream does not allow you to manipulate individual elements from a data set, but instead allows you to perform functions on the data as a whole.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE FOREACH METHOD IN STREAMS FOR?</strong></p></li></ul><p><br></p><p>Method void forEach(Consumer<? super T> action) - action is performed for each element. forEach is a terminal operation, used to iterate over each element of the stream.</p><p>forEach does not guarantee the sequence of displaying elements in a parallel stream, for this the forEachOrdered method is used - it guarantees the order.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE MAP METHOD IN STREAMS FOR?</strong></p></li></ul><p><br></p><p>Method <R> Stream<R> map(Function<? super T,? extends R> mapper) - converts elements of type T into elements of type R and returns a stream with elements of R.</p><p><br></p><p>map() is an intermediate operation, the method is used to convert elements to another object using the passed function.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE PURPOSE OF THE FILTER METHOD IN STREAMS?</strong></p></li></ul><p><br></p><p>Method Stream<T> filter(Predicate<? super T> predicate) - filters elements according to the condition in the predicate. filter is an intermediate operation, used to filter an array through a function.</p><p><br></p><p>In fact, filter does not perform filtering, instead it creates a new stream, which, when completed, contains the elements of the original stream that match the given predicate.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE LIMIT METHOD IN STREAMS FOR?</strong></p></li></ul><p><br></p><p>Method Stream<T> limit(long maxSize) - leaves only maxSize elements in the stream. limit is an intermediate operation, used to fetch the first maxSize elements of the stream. This method also returns a modified stream that has no more than maxSize elements.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE SORTED METHOD IN STREAMS FOR?</strong></p></li></ul><p><br></p><p>The Stream<T> sorted()/Stream<T> sorted(Comparator<? super T> comparator) method returns a sorted stream. sorted() is an intermediate operation, a method used to sort a stream using the natural order of comparison of its elements. There is also a second sorted() method that takes either a Comparable instance or its corresponding lambda expression.</p><p><br></p><p><br></p><ul><li><p><strong>PARALLEL STREAM PROCESSING IN JAVA?</strong></p></li></ul><p><br></p><p>To make a normal serial stream parallel, call the parallel method on the Stream object.</p><p><br></p><p>Alternatively, you can also use the parallelStream() method of the Collection interface to create a parallel stream from a collection.</p><p><br></p><p>At the same time, if the working machine is not multi-core, then the thread will be executed as serial.</p><p><br></p><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
24 - ===== Functional Programming in Java Interview Preparation =====/003 Part 2 Java Functional Programming Interview - Questions and Answers.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>Part 2 Java Functional Programming Interview - Questions and Answers</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">Part 2 Java Functional Programming Interview - Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>WHAT IS THE BICONSUMER<T,U> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents an operation that takes two input parameters and returns no result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE BIFUNCTION<T,U,R> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>It is a function that takes two arguments and returns a result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE BINARYOPERATOR<T> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents an operation on two operands of the same type, performs a binary operation on them, and returns a result of the same type as the operands.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE BIPREDICATE<T,U> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents a predicate (boolean function) of two arguments.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE BOOLEANSUPPLIER FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents a boolean result provider.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE CONSUMER<T> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents an operation that takes one input argument, performs some action on an object of type T, and returns nothing.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DOUBLEBINARYOPERATOR FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents an operation on two operands of type double, returns a result of type double.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DOUBLECONSUMER FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents an operation that takes one double argument and does not return a result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DOUBLEFUNCTION<R> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents a function that takes one double argument and returns a result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DOUBLEPREDICATE FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p>Represents a predicate (boolean function) of one double argument.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DOUBLESUPPLIER FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents the provider of double results.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DOUBLETOINTFUNCTION FOR?</strong></p></li></ul><p><br></p><p>It is a function that takes one argument of type double and returns the result of type int.</p><p><br></p><p><br></p><ul><li><p><strong>WHY IS THE DOUBLETOLONGFUNCTION FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents a function that takes one argument of type double and returns a result of type long.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DOUBLEUNARYOPERATOR FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents an operation on one argument of double type, returns a result of type double.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE FUNCTION<T,R> INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents a transition function from an object of type T to an object of type R.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE INTBINARYOPERATOR FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents an operation on two operands of type int, returns a result of type int.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT DOES THE INTCONSUMER FUNCTIONAL INTERFACE NEED FOR?</strong></p></li></ul><p><br></p><p>Represents an operation that takes a single int argument and returns no result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS INTFUNCTION<R> FOR?</strong></p></li></ul><p><br></p><p>Represents an operation that takes one int argument and returns a result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE INTPREDICATE FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents a predicate (boolean function) of one int argument.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT DOES THE INTSUPPLIER FUNCTIONAL INTERFACE NEED FOR?</strong></p></li></ul><p><br></p><p>Represents an int result provider.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT DOES INTTODOUBLEFUNCTION DO FOR?</strong></p></li></ul><p><br></p><p>Represents a function that takes one argument of type int and returns a result of type double.</p><p><br></p><p><br></p><ul><li><p><strong>WHY IS THE INTTOLONGFUNCTION FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents a function that takes one argument of type int and returns a result of type long.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT DOES THE INTUNARYOPERATOR FUNCTIONAL INTERFACE NEED FOR?</strong></p></li></ul><p><br></p><p>Represents an operation on a single argument of type int, returns a result of type int.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS A LONGBINARYOPERATOR FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents an operation on two operands of type long, returns a result of type long.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE LONGCONSUMER FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents an operation that takes one long argument and does not return a result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE LONGFUNCTION<R> FUNCTION INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents a function that takes one long argument and returns a result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE LONGPREDICATE FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents a predicate (boolean function) of one argument of type long.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT DOES THE LONGSUPPLIER FUNCTIONAL INTERFACE NEED FOR?</strong></p></li></ul><p><br></p><p>Represents a provider of long results.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE LONGTODOUBLEFUNCTION FUNCTION INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents a function that takes one argument of type long and returns a result of type double.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS A LONGTOINTFUNCTION FUNCTION INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents a function that takes one argument of type long and returns a result of type int.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT DOES THE LONGUNARYOPERATOR FUNCTIONAL INTERFACE NEED FOR?</strong></p></li></ul><p><br></p><p>Represents an operation on a single argument of type long, returns a result of type long.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE OBJDOUBLECONSUMER<T> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents an operation that takes one argument of type object and a second of type double, and does not return a result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE OBJINTCONSUMER<T> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents an operation that takes one argument of type object and a second of type int and does not return a result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE OBJLONGCONSUMER<T> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents an operation that takes one argument of type object and a second of type long, and does not return a result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE PREDICATE<T> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents a predicate (boolean function) of one argument.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE SUPPLIER<T> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents a results provider.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS TODOUBLEBIFUNCTION<T,U> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>It is a function that takes two arguments and returns a result of double type.</p><p><br></p><ul><li><p><strong>WHAT IS THE TODOUBLEFUNCTION<T> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>It is a function that takes one argument and returns a double result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS TOINTBIFUNCTION<T,U> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>It is a function that takes two arguments and returns an int result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS TOINTFUNCTION<T> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>It is a function that takes one argument and returns an int result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS TOLONGBIFUNCTION<T,U> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>It is a function that takes two arguments and returns a long result.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE TOLONGFUNCTION<T> FUNCTION INTERFACE FOR?</strong></p></li></ul><p><br></p><p>It is a function that takes one argument and returns a result of type long.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE UNARYOPERATOR<T> FUNCTIONAL INTERFACE FOR?</strong></p></li></ul><p><br></p><p>Represents an operation on a single operand, returns a result of the same type as the operand.</p><p><br></p><p><br></p><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
25 - Input and Output Streams in Java/001 Homework.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://docs.google.com/document/d/12mpGjQti9SwYrCS-0RU-WNYtEQCKSFwjgiCS8iKDnTw/edit?usp=sharing
|
25 - Input and Output Streams in Java/001 Input and Output Streams in Java_en.srt
ADDED
|
@@ -0,0 +1,1900 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
They were going to loan with you how to work with inputs and outputs streams in Java.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:11,000 --> 00:00:14,000
|
| 11 |
+
We will start our lesson from learning how to work with files in Java.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:15,000 --> 00:00:22,000
|
| 15 |
+
We learned today how to create byte and input streams and also will create byte and charter output streams
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:22,000 --> 00:00:23,000
|
| 19 |
+
on real examples.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:23,000 --> 00:00:27,000
|
| 23 |
+
You are going to see how to work with files with the help of Java today.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:27,000 --> 00:00:32,000
|
| 27 |
+
You are going to learn how to close resources and how to use blog driveway's resources.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:32,000 --> 00:00:37,000
|
| 31 |
+
After today's lesson, you will understand how to use different encoding while reading and writing to
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:37,000 --> 00:00:39,000
|
| 35 |
+
file at the end of the lesson.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:39,000 --> 00:00:42,000
|
| 39 |
+
We will talk about classes and interfaces from Joany Your package.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:42,000 --> 00:00:46,000
|
| 43 |
+
I'll show you how you can process files with the help of Stream API.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:46,000 --> 00:00:50,000
|
| 47 |
+
You are going to learn what Buffer's dreams are and how to work with them.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:50,000 --> 00:00:55,000
|
| 51 |
+
Also, I'll share with you tasks that will help you to practice your skills of working with streams.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:55,000 --> 00:01:03,000
|
| 55 |
+
Let's start Java IO package is about reading data from a data source and writing of raw data to a destination.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:03,000 --> 00:01:05,000
|
| 59 |
+
There are various or data destinations.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:05,000 --> 00:01:12,000
|
| 63 |
+
Some of them are files by network, connections in memory buffers and so on.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:12,000 --> 00:01:18,000
|
| 67 |
+
Work with different data sources are similar from the application programming interface standpoint.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:18,000 --> 00:01:24,000
|
| 71 |
+
That's why I suggest to review all examples of input output streams while working with files.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:24,000 --> 00:01:28,000
|
| 75 |
+
We have to learn what files are and how to work with files.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:28,000 --> 00:01:35,000
|
| 79 |
+
To be honest, input output streams topic in Java is one of the most unstructured, a lot of packages,
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:35,000 --> 00:01:38,000
|
| 83 |
+
a lot of Iraqis, a lot of classes and so on.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:38,000 --> 00:01:43,000
|
| 87 |
+
That's why I believe that this topic is the best way to learn it by example.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:44,000 --> 00:01:48,000
|
| 91 |
+
I prepared a lot of my files to help you understand the topic better.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:48,000 --> 00:01:49,000
|
| 95 |
+
Let me open the eclipse.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:50,000 --> 00:01:55,000
|
| 99 |
+
As I already mentioned, I think it is better to start from over here what files are and how to work
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:55,000 --> 00:01:56,000
|
| 103 |
+
with them from Java.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:57,000 --> 00:02:01,000
|
| 107 |
+
I wrote a program here, let me run it and explore its output together with you.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:02,000 --> 00:02:05,000
|
| 111 |
+
In this example, we'll review time from packaged Java Io.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:06,000 --> 00:02:08,000
|
| 115 |
+
We have type to represent file.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:08,000 --> 00:02:14,000
|
| 119 |
+
I can easily create file object by calling constructor and patterns the file name to constructor and
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:14,000 --> 00:02:19,000
|
| 123 |
+
then want to pay attention that we didn't create a file in file system.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:19,000 --> 00:02:25,000
|
| 127 |
+
We have just created file instant's and now we can call mascot's on this object that will help us to
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:25,000 --> 00:02:27,000
|
| 131 |
+
create files in working directory.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:27,000 --> 00:02:32,000
|
| 135 |
+
The string that we gave to constructor is converted into abstract Bazzani.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:33,000 --> 00:02:36,000
|
| 139 |
+
I can create a catalog using this object.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:36,000 --> 00:02:40,000
|
| 143 |
+
In other words, I can create a folder by calling M Khadir method.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:40,000 --> 00:02:46,000
|
| 147 |
+
In case you want to create a hierarchy of folders, you can specify directories name using file past
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:46,000 --> 00:02:49,000
|
| 151 |
+
separator operator and call mkdir smashup.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:49,000 --> 00:02:56,000
|
| 155 |
+
But creating programs with Java will create cross platform applications and we should use platform independent
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:56,000 --> 00:02:57,000
|
| 159 |
+
characters.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:57,000 --> 00:03:03,000
|
| 163 |
+
Class file contains platform independent files separate and Kendzior returns.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:03,000 --> 00:03:04,000
|
| 167 |
+
True or false?
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:04,000 --> 00:03:07,000
|
| 171 |
+
You can build a logic around this API here.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:07,000 --> 00:03:12,000
|
| 175 |
+
I will print the console file separate in one operating systems.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:12,000 --> 00:03:13,000
|
| 179 |
+
It is a backslash.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:13,000 --> 00:03:15,000
|
| 183 |
+
In other it is a slash.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:15,000 --> 00:03:21,000
|
| 187 |
+
Java will determine what operating system is used and will provide you with platform specific files.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:21,000 --> 00:03:26,000
|
| 191 |
+
Separate file also provides us with a constant firebase separator.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:26,000 --> 00:03:29,000
|
| 195 |
+
Do remember when we configure Jabel Normal computer?
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:29,000 --> 00:03:31,000
|
| 199 |
+
We are to set environment.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:31,000 --> 00:03:39,000
|
| 203 |
+
Variables would change the value of past variable and as a separate that we use semicolon that is specific
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:39,000 --> 00:03:40,000
|
| 207 |
+
to Windows operating system.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:40,000 --> 00:03:45,000
|
| 211 |
+
Separate that and you can see it in console in other operating system.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:03:45,000 --> 00:03:51,000
|
| 215 |
+
It could be a column here, by the way, talking about plot from independent characters.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:03:51,000 --> 00:03:57,000
|
| 219 |
+
I want to pay attention to line separate in some operating systems line separate.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:03:57,000 --> 00:04:03,000
|
| 223 |
+
That is a combination of characters like carriage return and new line in other operating systems.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:03,000 --> 00:04:05,000
|
| 227 |
+
It is just a new line character.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:05,000 --> 00:04:12,000
|
| 231 |
+
So whenever you need to express a new line, for example, in cases when you prepare text that should
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:12,000 --> 00:04:17,000
|
| 235 |
+
be read into the file, I recommend you to use Mass from system class with name lines separator.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:18,000 --> 00:04:22,000
|
| 239 |
+
Now imagine that you have to create not directory, but just a file.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:23,000 --> 00:04:30,000
|
| 243 |
+
Imagine that content manager of our online store wants to do an expert of all products to the specific
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:30,000 --> 00:04:33,000
|
| 247 |
+
file we have to create file for him.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:33,000 --> 00:04:39,000
|
| 251 |
+
At first we create file object and after that we create file by calling in mass.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:39,000 --> 00:04:45,000
|
| 255 |
+
It creates new file after this letter and I recommend you to open source code of the file class and
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:45,000 --> 00:04:47,000
|
| 259 |
+
explore all of its methods.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:04:48,000 --> 00:04:53,000
|
| 263 |
+
But I want to show you your methods that may come in handy while working with files.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:04:53,000 --> 00:04:59,000
|
| 267 |
+
For example, you might always check was a file exists because it exists MassArt or you can check if
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:04:59,000 --> 00:05:01,000
|
| 271 |
+
s specific file is directory.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:02,000 --> 00:05:04,000
|
| 275 |
+
When you need this, you are going to have.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:04,000 --> 00:05:10,000
|
| 279 |
+
Homework, where you would need to implement the program to solve real life case, you can build the
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:10,000 --> 00:05:17,000
|
| 283 |
+
logic of iterating and navigate in your file system by identifying whether some specific item is a directory
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:17,000 --> 00:05:17,000
|
| 287 |
+
or a file.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:18,000 --> 00:05:24,000
|
| 291 |
+
In case this item is a directory and you want iterate over all elements, you have to get files from
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:24,000 --> 00:05:27,000
|
| 295 |
+
this directory to do this.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:27,000 --> 00:05:29,000
|
| 299 |
+
You can call list files Macit.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:29,000 --> 00:05:33,000
|
| 303 |
+
It will return array of files and you can work with the file array.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:33,000 --> 00:05:37,000
|
| 307 |
+
As with any other array, you can iterate over it if you need.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:38,000 --> 00:05:43,000
|
| 311 |
+
You can get absolute parts of the file by calling it absolute Balmaceda.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:05:43,000 --> 00:05:47,000
|
| 315 |
+
Also, you can check whether files that you have is executable.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:05:48,000 --> 00:05:54,000
|
| 319 |
+
For example, files with a DOT board extension, executable files on the Unix systems.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:05:54,000 --> 00:06:01,000
|
| 323 |
+
There are shell scripts with Dot S.H. extension, those executable too similar to the way you can check
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:01,000 --> 00:06:02,000
|
| 327 |
+
what a specific item is.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:02,000 --> 00:06:03,000
|
| 331 |
+
A directory or not.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:04,000 --> 00:06:08,000
|
| 335 |
+
You can check if a specific item is a file by Colon is file Macit.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:09,000 --> 00:06:15,000
|
| 339 |
+
Sometimes the hidden files in the file system, for example, get folder of our local repository is
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:15,000 --> 00:06:16,000
|
| 343 |
+
a hidden by default.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:17,000 --> 00:06:19,000
|
| 347 |
+
You can check it by colon is hidden last.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:19,000 --> 00:06:20,000
|
| 351 |
+
Is it clear.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:21,000 --> 00:06:26,000
|
| 355 |
+
Feel free to press a pause to review these matters and make sure that you understood them.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:26,000 --> 00:06:32,000
|
| 359 |
+
Also, I want to remind you that you are always welcome to ask any questions and Q&A section.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:32,000 --> 00:06:38,000
|
| 363 |
+
If you understood the masses that we have just reviewed, I suggest to move further, you know, just
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:38,000 --> 00:06:41,000
|
| 367 |
+
Solly's files, MassArt, but it is overloaded.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:06:41,000 --> 00:06:44,000
|
| 371 |
+
Let me open the source code of this version of the Massett.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:06:45,000 --> 00:06:48,000
|
| 375 |
+
And right near this method we have another one.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:06:48,000 --> 00:06:54,000
|
| 379 |
+
This method takes file filter as an argument to filter files and return only files that that means the
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:06:54,000 --> 00:07:01,000
|
| 383 |
+
condition that is specified in file filter lets open file filter to understand this interface better.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:01,000 --> 00:07:07,000
|
| 387 |
+
And here and the source code we can see that file filter is a functional interface assumes that by this
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:07,000 --> 00:07:13,000
|
| 391 |
+
moment and now of course you already know functional programming and can understand what functional
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:13,000 --> 00:07:14,000
|
| 395 |
+
interface annotation is.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:15,000 --> 00:07:22,000
|
| 399 |
+
Just to remind you, this annotation means that the interface is only one aspect Masset and we can use
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:22,000 --> 00:07:25,000
|
| 403 |
+
is a massive reference or lambda function to implement this type.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:26,000 --> 00:07:33,000
|
| 407 |
+
Indeed, file filter has only one abasic Masset with name except the text file as an argument and should
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:33,000 --> 00:07:35,000
|
| 411 |
+
return is a true or false.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:35,000 --> 00:07:42,000
|
| 415 |
+
Let's get back to our demo file was filed, for example, here in the example you can see that I created
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:07:42,000 --> 00:07:47,000
|
| 419 |
+
Lambda Functions that meets the definition of accept Masset from file filter interface.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:07:47,000 --> 00:07:49,000
|
| 423 |
+
It takes file object and returns.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:07:49,000 --> 00:07:56,000
|
| 427 |
+
True or false based on it, you can see that I get filename and after that I check with a file.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:07:56,000 --> 00:07:58,000
|
| 431 |
+
Name is ended with Java.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:07:58,000 --> 00:08:02,000
|
| 435 |
+
This lambda function will return me only Java source code files.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:03,000 --> 00:08:04,000
|
| 439 |
+
Does it make sense?
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:04,000 --> 00:08:08,000
|
| 443 |
+
Let me run this program to execute all the code that we have just reviewed.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:08,000 --> 00:08:16,000
|
| 447 |
+
By the way, after execution of this program, all folders are created here and here is our result since
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:16,000 --> 00:08:18,000
|
| 451 |
+
we file that we also created in our program.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:18,000 --> 00:08:26,000
|
| 455 |
+
So now you can understand that the path that we specified for file here is relative and it is relative
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:26,000 --> 00:08:27,000
|
| 459 |
+
to our Java project.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:28,000 --> 00:08:30,000
|
| 463 |
+
You can use absolute powers if you want.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:30,000 --> 00:08:35,000
|
| 467 |
+
The absolute pass on Windows would include your disk C and all the folders.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:08:36,000 --> 00:08:39,000
|
| 471 |
+
For example, here you can see absolute file pass.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:08:40,000 --> 00:08:45,000
|
| 475 |
+
Usually in your programs you don't want to specify absolute pass y.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:08:45,000 --> 00:08:50,000
|
| 479 |
+
You have to understand that your program is going to be executed on different computers and on different
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:08:50,000 --> 00:08:54,000
|
| 483 |
+
servers and file system will look differently on each computer.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:08:55,000 --> 00:08:59,000
|
| 487 |
+
For example, on Unix like operating system, there is no use C at all.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:00,000 --> 00:09:01,000
|
| 491 |
+
Can you understand that?
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:01,000 --> 00:09:06,000
|
| 495 |
+
That's why in real life you would usually use relative to your project.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:06,000 --> 00:09:08,000
|
| 499 |
+
Just makes sense cuz.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:09:09,000 --> 00:09:16,000
|
| 503 |
+
Now, I want to share with you and as a way to manipulate files besides Java, I hope there is also
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:16,000 --> 00:09:17,000
|
| 507 |
+
Java new package.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:18,000 --> 00:09:21,000
|
| 511 |
+
It is called as new output input streams.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:21,000 --> 00:09:28,000
|
| 515 |
+
That's why it has end letter in the name Unions and National Review and parallel classes and types from
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:28,000 --> 00:09:29,000
|
| 519 |
+
Java I.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:09:29,000 --> 00:09:31,000
|
| 523 |
+
O Package and classes and types from Jouni.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:09:31,000 --> 00:09:32,000
|
| 527 |
+
A package.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:09:32,000 --> 00:09:36,000
|
| 531 |
+
From the practical side, I can say that classes from both.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:09:36,000 --> 00:09:39,000
|
| 535 |
+
I mean I o and newer packages are used.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:09:40,000 --> 00:09:42,000
|
| 539 |
+
There are no specific preferences.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:09:42,000 --> 00:09:46,000
|
| 543 |
+
It is just a matter of APIs and how you would like to work with streams.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:09:47,000 --> 00:09:50,000
|
| 547 |
+
There is a way to do the same things but with different classes.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:09:50,000 --> 00:09:57,000
|
| 551 |
+
And we as developers should be aware of different interfaces in Java because different APIs would use
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:09:57,000 --> 00:09:58,000
|
| 555 |
+
different types.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:09:59,000 --> 00:10:04,000
|
| 559 |
+
Let me open another file with examples that will help you to understand how you can manipulate with
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:04,000 --> 00:10:04,000
|
| 563 |
+
files.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:04,000 --> 00:10:10,000
|
| 567 |
+
With the help of Java new package in your package, there is one important difference.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:10,000 --> 00:10:15,000
|
| 571 |
+
The concept and all API is built around Naza abstraction.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:10:15,000 --> 00:10:16,000
|
| 575 |
+
It is name POS.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:10:17,000 --> 00:10:19,000
|
| 579 |
+
You don't have a file like in Java I o package.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:10:20,000 --> 00:10:27,000
|
| 583 |
+
What you can do is to manipulate with a resource by its boss to create path object we have to use first
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:10:27,000 --> 00:10:33,000
|
| 587 |
+
class was asked at the end and static method get let me open the source code of POS class.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:10:34,000 --> 00:10:37,000
|
| 591 |
+
This specific method takes verbal arguments.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:10:37,000 --> 00:10:44,000
|
| 595 |
+
You can pass one string that contains file pass separators, but also you can pass multiple strings
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:10:44,000 --> 00:10:51,000
|
| 599 |
+
to indicate in the directories you can see that this is Ovalau, that we also have another version of
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:10:51,000 --> 00:10:53,000
|
| 603 |
+
it to pass your right object.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:10:53,000 --> 00:10:59,000
|
| 607 |
+
But in my opinion, this version of get matched with variable string arguments is more popular.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:10:59,000 --> 00:11:04,000
|
| 611 |
+
Let's get back to the demo file and I will show you Boss API in your package.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:04,000 --> 00:11:11,000
|
| 615 |
+
There is files class that contains a lot of masses to work with files and the same as other classes
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:11,000 --> 00:11:11,000
|
| 619 |
+
from John.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:11:11,000 --> 00:11:19,000
|
| 623 |
+
Your package, it uses POS type in its own API, the same operations that we did with the file object.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:11:19,000 --> 00:11:22,000
|
| 627 |
+
In the previous example, we can do with the help of files class.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:11:23,000 --> 00:11:29,000
|
| 631 |
+
For example, we can check whether the file behind this passes the directory or it is a regular file.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:11:29,000 --> 00:11:33,000
|
| 635 |
+
We can create a hierarchy of directories by and create directories.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:11:33,000 --> 00:11:36,000
|
| 639 |
+
Masset, you can create a file when you want.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:11:36,000 --> 00:11:38,000
|
| 643 |
+
We can also delete directory bytes.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:11:38,000 --> 00:11:44,000
|
| 647 |
+
But as you can see, you can do pretty much everything you want to do with files, with the help of
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:11:44,000 --> 00:11:45,000
|
| 651 |
+
files class.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:11:46,000 --> 00:11:52,000
|
| 655 |
+
What I would recommend you also to do is to open the source code of files class and to review all of
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:11:52,000 --> 00:11:53,000
|
| 659 |
+
its methods.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:11:53,000 --> 00:11:59,000
|
| 663 |
+
I believe you are smart enough already to read the documentation and to understand what each method
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:11:59,000 --> 00:12:04,000
|
| 667 |
+
is all about, because we did that with other classes and you know how to do this.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:04,000 --> 00:12:11,000
|
| 671 |
+
And there is not so much sense to go over each method and with documentation outloud also take into
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:11,000 --> 00:12:14,000
|
| 675 |
+
account we reviewed the most popular methods in my opinion.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:12:14,000 --> 00:12:18,000
|
| 679 |
+
So just take your time at home to review the source code of files.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:12:18,000 --> 00:12:24,000
|
| 683 |
+
Class by yourself, meanwhile, will go further and I will explain you the structure of input and output
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:12:24,000 --> 00:12:26,000
|
| 687 |
+
streams now.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:12:26,000 --> 00:12:30,000
|
| 691 |
+
And once you understand the hierarchy of all types in Java I.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:12:30,000 --> 00:12:37,000
|
| 695 |
+
O package, we have two main Iraqis, Zaya Iraqiya, by streams and character streams.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:12:37,000 --> 00:12:39,000
|
| 699 |
+
What is the difference between them?
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:12:39,000 --> 00:12:43,000
|
| 703 |
+
My streams can work with data with size eight bits.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:12:43,000 --> 00:12:44,000
|
| 707 |
+
That is one byte.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:12:45,000 --> 00:12:49,000
|
| 711 |
+
So all reading and writing operations work was a bit.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:12:49,000 --> 00:12:56,000
|
| 715 |
+
These types were created since Java creation and after that time that can process data of two bytes
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:12:56,000 --> 00:12:57,000
|
| 719 |
+
were created.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:12:57,000 --> 00:13:03,000
|
| 723 |
+
Now there is a possibility to process Unicode characters and describe them in sixteen bits.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:13:03,000 --> 00:13:06,000
|
| 727 |
+
That is two bytes all possible.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:13:06,000 --> 00:13:12,000
|
| 731 |
+
The Unicode characters, definitely characters streams are used to work with text data in case you need
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:13:12,000 --> 00:13:14,000
|
| 735 |
+
to read or write text data.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:13:14,000 --> 00:13:20,000
|
| 739 |
+
It is recommended to use characters streams to ensure that you can read all characters from the file
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:13:21,000 --> 00:13:22,000
|
| 743 |
+
on the other end.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:13:22,000 --> 00:13:25,000
|
| 747 |
+
But streams are widely used in reading and writing resources.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:13:26,000 --> 00:13:32,000
|
| 751 |
+
For example, in case you want to store image in your file system, user uploaded and Avatar and you
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:13:32,000 --> 00:13:39,000
|
| 755 |
+
want to store profile image on the file system of your server, you can transform this image and bitstream
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:13:39,000 --> 00:13:43,000
|
| 759 |
+
and store it as a sequence of bytes on your file system and when it will be needed.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:13:44,000 --> 00:13:47,000
|
| 763 |
+
You can read stream of bytes to restore the image.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:13:47,000 --> 00:13:48,000
|
| 767 |
+
Does it make sense?
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:13:49,000 --> 00:13:56,000
|
| 771 |
+
On the top of the bitstream, Iraqis are to abstract classes, inputs and outputs stream and there are
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:13:56,000 --> 00:14:03,000
|
| 775 |
+
dozens of implementations classes like file input stream, Vitara input stream, object, input stream
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:14:03,000 --> 00:14:04,000
|
| 779 |
+
and Osas.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:14:04,000 --> 00:14:08,000
|
| 783 |
+
If we talk about classes that extends output stream, it is worth Dimanche on such.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:14:08,000 --> 00:14:16,000
|
| 787 |
+
Losses as file output stream by output stream, object's output stream and osos on the top of character
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:14:16,000 --> 00:14:19,000
|
| 791 |
+
stream, Iraqis are also to abstract classes.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:14:19,000 --> 00:14:26,000
|
| 795 |
+
They are reader and writer and you can see on the slides that multiple classes extended zis to all classes
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:14:26,000 --> 00:14:30,000
|
| 799 |
+
usually have appropriate suffix reader or writer.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:14:31,000 --> 00:14:33,000
|
| 803 |
+
Take a look at this Iraqi press.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:14:33,000 --> 00:14:38,000
|
| 807 |
+
Pause for a second and make sure the slide looks clear and logical to you.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:14:38,000 --> 00:14:41,000
|
| 811 |
+
If you think you understood this, let's move on.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:14:41,000 --> 00:14:44,000
|
| 815 |
+
Let me now show you how you can work with inputs and outputs.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:14:44,000 --> 00:14:45,000
|
| 819 |
+
Streams.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:14:46,000 --> 00:14:51,000
|
| 823 |
+
I will share with you this demo file and I want you to execute these examples on your computer separately
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:14:52,000 --> 00:14:53,000
|
| 827 |
+
and would investigate the result.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:14:54,000 --> 00:14:59,000
|
| 831 |
+
This will help you better understand how input and output streams work right now.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:14:59,000 --> 00:15:02,000
|
| 835 |
+
I walk you through these examples to share with you my thoughts.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:15:03,000 --> 00:15:08,000
|
| 839 |
+
At the beginning of our program, we specify a file pass that will be used as a test directory for the
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:15:08,000 --> 00:15:10,000
|
| 843 |
+
sake of our examples.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:15:10,000 --> 00:15:15,000
|
| 847 |
+
And also we have here tags that contains different characters, including Cyrillic characters.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:15:15,000 --> 00:15:18,000
|
| 851 |
+
This will help us to understand encoding examples.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:15:18,000 --> 00:15:23,000
|
| 855 |
+
Let's start our first example is right, text or file.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:15:23,000 --> 00:15:24,000
|
| 859 |
+
With the help of BitStream.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:15:25,000 --> 00:15:28,000
|
| 863 |
+
We have this method here that takes path and string.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:15:28,000 --> 00:15:30,000
|
| 867 |
+
Let's investigate the source code.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:15:30,000 --> 00:15:32,000
|
| 871 |
+
I have tried finally block here.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:15:32,000 --> 00:15:33,000
|
| 875 |
+
Why do I need it?
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:15:34,000 --> 00:15:40,000
|
| 879 |
+
It is a rule of thumb to close their sources once you use them because having multiple resources open
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:15:41,000 --> 00:15:43,000
|
| 883 |
+
will make it harm to your application.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:15:43,000 --> 00:15:50,000
|
| 887 |
+
This could lead to resource leak to close any of inputs and outputs streams we have to call close Masset
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:15:50,000 --> 00:15:54,000
|
| 891 |
+
on the resource to have access to output stream reference.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:15:55,000 --> 00:16:02,000
|
| 895 |
+
I declare it outside of the try block inside the trial block and create an instance of file output stream
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:16:02,000 --> 00:16:04,000
|
| 899 |
+
and specify parts to the file.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:16:04,000 --> 00:16:10,000
|
| 903 |
+
After that, I get bytes from the string and I call write method to write bytes to the file.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:16:11,000 --> 00:16:13,000
|
| 907 |
+
After I did, everything I need was a resource.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:16:13,000 --> 00:16:15,000
|
| 911 |
+
I close it and finally block.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:16:16,000 --> 00:16:18,000
|
| 915 |
+
That's why I have such construction.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:16:18,000 --> 00:16:20,000
|
| 919 |
+
Let's proceed with the next example.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:16:21,000 --> 00:16:24,000
|
| 923 |
+
In the next example, there are a few more things to learn.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:16:24,000 --> 00:16:28,000
|
| 927 |
+
First of all, then all the construction to close the resources.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:16:28,000 --> 00:16:30,000
|
| 931 |
+
It is called Trivers Resources Block.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:16:31,000 --> 00:16:32,000
|
| 935 |
+
Let's go line by line.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:16:32,000 --> 00:16:39,000
|
| 939 |
+
I write right keyword and after that in parentheses, I specify resources that should be closed automatically
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:16:40,000 --> 00:16:42,000
|
| 943 |
+
outside of the Trivers resources block.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:16:42,000 --> 00:16:47,000
|
| 947 |
+
All types that implements closable interface can be used in this block.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:16:47,000 --> 00:16:53,000
|
| 951 |
+
Let me open the source code of file output stream and here you can see that it extends output stream
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:16:53,000 --> 00:16:56,000
|
| 955 |
+
type that in turn implements closable interface.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:16:56,000 --> 00:17:01,000
|
| 959 |
+
That's why this type can be placed inside thrivers resources block.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:17:01,000 --> 00:17:05,000
|
| 963 |
+
The next thing to learn here is using the word keyword.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:17:05,000 --> 00:17:12,000
|
| 967 |
+
This is exactly the case when using the keyword is justified because this is just local variable that
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:17:12,000 --> 00:17:15,000
|
| 971 |
+
is going to be used right after its declaration.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:17:15,000 --> 00:17:21,000
|
| 975 |
+
That's why there is no need to declare abstract type of this variable and it can be the same as a specific
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:17:21,000 --> 00:17:21,000
|
| 979 |
+
type.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:17:22,000 --> 00:17:28,000
|
| 983 |
+
For example, there is no need for me to specify output stream type for variable if I want to use buffer
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:17:28,000 --> 00:17:31,000
|
| 987 |
+
output stream and all of its features and masses.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:17:32,000 --> 00:17:38,000
|
| 991 |
+
Let's talk about the next thing you can see that I create object of file output stream and Robert with
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:17:38,000 --> 00:17:46,000
|
| 995 |
+
a type Barford output stream later one architectural partners, you are going to learn that there is
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:17:46,000 --> 00:17:50,000
|
| 999 |
+
a create structural partan that is implemented just like this.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:17:51,000 --> 00:17:55,000
|
| 1003 |
+
You can add new features to the object by wrapping it with new type.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:17:55,000 --> 00:18:00,000
|
| 1007 |
+
Literally, you pass the one object as an argument to the constructor of another one.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:18:01,000 --> 00:18:05,000
|
| 1011 |
+
In this particular case, we are adding feature of buffer writing.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:18:05,000 --> 00:18:08,000
|
| 1015 |
+
What is a buffer buffer in the computer?
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:18:08,000 --> 00:18:15,000
|
| 1019 |
+
Science is a region of physical memory storage used to temporarily store data while it is being moved
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:18:15,000 --> 00:18:22,000
|
| 1023 |
+
from one place to another buffer to either use memory efficiently by writing everything to the buffer
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:18:22,000 --> 00:18:26,000
|
| 1027 |
+
first and after that right and everything to the target at once.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:18:27,000 --> 00:18:33,000
|
| 1031 |
+
This is considered more efficient than to perform right operations to the destination file back by byte.
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:18:34,000 --> 00:18:38,000
|
| 1035 |
+
Can you understand now why we might want to use buffer inputs and outputs streams?
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:18:39,000 --> 00:18:46,000
|
| 1039 |
+
And now I can write all string to the file outside of the TRIVERS resources block buffer is flushed
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:18:46,000 --> 00:18:47,000
|
| 1043 |
+
automatically.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:18:48,000 --> 00:18:51,000
|
| 1047 |
+
There is one more thing you have to know about the buffer.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:18:51,000 --> 00:18:58,000
|
| 1051 |
+
It is flashed automatically into cases when maximum size of the buffer is reached and the second case
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:18:58,000 --> 00:18:59,000
|
| 1055 |
+
is when stream is closed.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:19:00,000 --> 00:19:06,000
|
| 1059 |
+
That means that in case you wrote, just not so much information to the buffer and you forgot to close
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:19:06,000 --> 00:19:06,000
|
| 1063 |
+
the buffer.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:19:07,000 --> 00:19:10,000
|
| 1067 |
+
You will write Nassan to the file in the next Masset.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:19:10,000 --> 00:19:12,000
|
| 1071 |
+
You can see exactly this case.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:19:13,000 --> 00:19:19,000
|
| 1075 |
+
Let me comment on matters that are called after this one and now I can run the program.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:19:20,000 --> 00:19:25,000
|
| 1079 |
+
Now, when program is executed, I want to check output file just as directory.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:19:26,000 --> 00:19:32,000
|
| 1083 |
+
And here is how a demo text file you can see that is empty because Buffer is not flushed.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:19:33,000 --> 00:19:35,000
|
| 1087 |
+
Now let's get back to our demo file.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:19:35,000 --> 00:19:39,000
|
| 1091 |
+
And I vividly called Flash Masset to phlogiston buffer.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:19:39,000 --> 00:19:41,000
|
| 1095 |
+
I execute the program one more time.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:19:42,000 --> 00:19:45,000
|
| 1099 |
+
And if we would look to our output file where.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:19:45,000 --> 00:19:52,000
|
| 1103 |
+
And to find that the tax was successfully written and you understand now what Buffer is, you can investigate
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:19:52,000 --> 00:19:54,000
|
| 1107 |
+
the source code to learn more.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:19:54,000 --> 00:20:00,000
|
| 1111 |
+
For example, let me open bar for output stream and to explore its close method together with you.
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:20:01,000 --> 00:20:06,000
|
| 1115 |
+
There is no closed Manhattan buffer at output stream because it is implemented in the parent type.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:20:07,000 --> 00:20:10,000
|
| 1119 |
+
Lets open parent type and find close massive here.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:20:10,000 --> 00:20:11,000
|
| 1123 |
+
Awesome.
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:20:11,000 --> 00:20:12,000
|
| 1127 |
+
Here it is.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:20:13,000 --> 00:20:18,000
|
| 1131 |
+
And you can see that during the closing of this resource flash, it is called automatically.
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:20:18,000 --> 00:20:25,000
|
| 1135 |
+
That is exactly the reason why we can see that text was written in the file in case we use Buffer,
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:20:25,000 --> 00:20:32,000
|
| 1139 |
+
its output stream with strivings resources block because close method is called automatically for all
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:20:32,000 --> 00:20:34,000
|
| 1143 |
+
resources specified in Trie lock.
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:20:35,000 --> 00:20:36,000
|
| 1147 |
+
Does it make more sense now?
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:20:36,000 --> 00:20:37,000
|
| 1151 |
+
Great.
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:20:37,000 --> 00:20:38,000
|
| 1155 |
+
Let's move on.
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:20:38,000 --> 00:20:42,000
|
| 1159 |
+
And before we proceed, let me comment on other matters.
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:20:42,000 --> 00:20:42,000
|
| 1163 |
+
Cool.
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:20:43,000 --> 00:20:47,000
|
| 1167 |
+
We'll review the next examples a little bit faster because they are similar.
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:20:47,000 --> 00:20:52,000
|
| 1171 |
+
These examples shows us how to write to the file with character streams.
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:20:52,000 --> 00:20:53,000
|
| 1175 |
+
We just create file, right?
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:20:53,000 --> 00:20:55,000
|
| 1179 |
+
An object that extends right to type.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:20:56,000 --> 00:21:01,000
|
| 1183 |
+
By the way, I believe you understood that you can use any other type besides those that works with
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:21:01,000 --> 00:21:02,000
|
| 1187 |
+
files.
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:21:02,000 --> 00:21:07,000
|
| 1191 |
+
The way how you will use those types are pretty similar to the way how you use types that work with
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:21:07,000 --> 00:21:08,000
|
| 1195 |
+
files.
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:21:08,000 --> 00:21:12,000
|
| 1199 |
+
So just feel free to use any implementations of input.
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:21:12,000 --> 00:21:15,000
|
| 1203 |
+
Stream output stream reader and writer.
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:21:15,000 --> 00:21:22,000
|
| 1207 |
+
Classis example was Bufford writer a similar pay attention that in these matters you can pass a whole
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:21:22,000 --> 00:21:24,000
|
| 1211 |
+
string to the method instead of array of bytes.
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:21:25,000 --> 00:21:28,000
|
| 1215 |
+
Make sure you understood these examples before moving further.
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:21:28,000 --> 00:21:29,000
|
| 1219 |
+
If you.
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:21:29,000 --> 00:21:30,000
|
| 1223 |
+
OK, let's proceed.
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:21:31,000 --> 00:21:38,000
|
| 1227 |
+
Now, let me show you next examples, these examples about reading from file, the first example shows
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:21:38,000 --> 00:21:41,000
|
| 1231 |
+
us how to read from a file with the help of BitStream.
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:21:41,000 --> 00:21:47,000
|
| 1235 |
+
As you can see, we create an object of file input stream in Shrivers resources block.
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:21:47,000 --> 00:21:52,000
|
| 1239 |
+
Here you can see that I read file by Might's until I would face with minus one.
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:21:52,000 --> 00:21:58,000
|
| 1243 |
+
That would mean I reached the end of the file and print Arrison to console.
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:21:58,000 --> 00:22:03,000
|
| 1247 |
+
I have to convert integer variable to char but during the reading of files was bitstream.
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:22:04,000 --> 00:22:05,000
|
| 1251 |
+
You're going to face one issue.
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:22:06,000 --> 00:22:11,000
|
| 1255 |
+
You will be able to read on the first two hundred fifty six characters from Unicode Table.
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:22:11,000 --> 00:22:15,000
|
| 1259 |
+
That means you won't be able to read Cyrillic symbols.
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:22:15,000 --> 00:22:20,000
|
| 1263 |
+
For example, let me run the program to show you this UNcancel output.
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:22:20,000 --> 00:22:26,000
|
| 1267 |
+
You can see that also religious symbols are turned into question marks because it is not possible to
|
| 1268 |
+
|
| 1269 |
+
318
|
| 1270 |
+
00:22:26,000 --> 00:22:28,000
|
| 1271 |
+
represent all symbols of Unicode with one bite.
|
| 1272 |
+
|
| 1273 |
+
319
|
| 1274 |
+
00:22:29,000 --> 00:22:31,000
|
| 1275 |
+
You need two bytes for this.
|
| 1276 |
+
|
| 1277 |
+
320
|
| 1278 |
+
00:22:31,000 --> 00:22:35,000
|
| 1279 |
+
The next example is an example of Barford in between.
|
| 1280 |
+
|
| 1281 |
+
321
|
| 1282 |
+
00:22:36,000 --> 00:22:42,000
|
| 1283 |
+
Here you can see that you can declare multiple resources and add different features to a stream by wrapping
|
| 1284 |
+
|
| 1285 |
+
322
|
| 1286 |
+
00:22:42,000 --> 00:22:43,000
|
| 1287 |
+
it in different objects.
|
| 1288 |
+
|
| 1289 |
+
323
|
| 1290 |
+
00:22:44,000 --> 00:22:48,000
|
| 1291 |
+
For example, data input stream allows you to read specific data type.
|
| 1292 |
+
|
| 1293 |
+
324
|
| 1294 |
+
00:22:49,000 --> 00:22:55,000
|
| 1295 |
+
It declares additional masses like retained, for example, as returns in value and so on.
|
| 1296 |
+
|
| 1297 |
+
325
|
| 1298 |
+
00:22:56,000 --> 00:23:02,000
|
| 1299 |
+
And you can see and understand how to add additional features to existing stream.
|
| 1300 |
+
|
| 1301 |
+
326
|
| 1302 |
+
00:23:02,000 --> 00:23:05,000
|
| 1303 |
+
You have to create some base stream first.
|
| 1304 |
+
|
| 1305 |
+
327
|
| 1306 |
+
00:23:05,000 --> 00:23:09,000
|
| 1307 |
+
And after that, Robert was othertimes in adolescence.
|
| 1308 |
+
|
| 1309 |
+
328
|
| 1310 |
+
00:23:09,000 --> 00:23:12,000
|
| 1311 |
+
Will these architectural patterns in details?
|
| 1312 |
+
|
| 1313 |
+
329
|
| 1314 |
+
00:23:13,000 --> 00:23:19,000
|
| 1315 |
+
I believe you can also understand that you can declare each object in a new line, but also you can
|
| 1316 |
+
|
| 1317 |
+
330
|
| 1318 |
+
00:23:19,000 --> 00:23:24,000
|
| 1319 |
+
get reference only to the last object by calling constructor of different types in one line.
|
| 1320 |
+
|
| 1321 |
+
331
|
| 1322 |
+
00:23:25,000 --> 00:23:28,000
|
| 1323 |
+
Take into account this is Bufford input stream.
|
| 1324 |
+
|
| 1325 |
+
332
|
| 1326 |
+
00:23:28,000 --> 00:23:32,000
|
| 1327 |
+
We can read file not bound by byte, but by lines.
|
| 1328 |
+
|
| 1329 |
+
333
|
| 1330 |
+
00:23:32,000 --> 00:23:35,000
|
| 1331 |
+
That's why Red Line MassArt is available for us here.
|
| 1332 |
+
|
| 1333 |
+
334
|
| 1334 |
+
00:23:36,000 --> 00:23:41,000
|
| 1335 |
+
It is crossed because according to the official documentation, it is deprecated and it is recommended
|
| 1336 |
+
|
| 1337 |
+
335
|
| 1338 |
+
00:23:41,000 --> 00:23:44,000
|
| 1339 |
+
to use characters streams to read files.
|
| 1340 |
+
|
| 1341 |
+
336
|
| 1342 |
+
00:23:44,000 --> 00:23:46,000
|
| 1343 |
+
This is exactly what we have already discussed.
|
| 1344 |
+
|
| 1345 |
+
337
|
| 1346 |
+
00:23:47,000 --> 00:23:54,000
|
| 1347 |
+
And below you can see two maps that show how to read file with characters, streams with buffer reader.
|
| 1348 |
+
|
| 1349 |
+
338
|
| 1350 |
+
00:23:54,000 --> 00:23:55,000
|
| 1351 |
+
You can read file by lines.
|
| 1352 |
+
|
| 1353 |
+
339
|
| 1354 |
+
00:23:56,000 --> 00:23:59,000
|
| 1355 |
+
Please explore these examples by yourself after the lesson.
|
| 1356 |
+
|
| 1357 |
+
340
|
| 1358 |
+
00:24:00,000 --> 00:24:05,000
|
| 1359 |
+
From the syntax standpoint, there is nothing special just using of different types.
|
| 1360 |
+
|
| 1361 |
+
341
|
| 1362 |
+
00:24:05,000 --> 00:24:10,000
|
| 1363 |
+
By the way, in console output you can see that Cyrillic symbols are read properly with the help of
|
| 1364 |
+
|
| 1365 |
+
342
|
| 1366 |
+
00:24:10,000 --> 00:24:14,000
|
| 1367 |
+
characters symbols and there are no more question marks.
|
| 1368 |
+
|
| 1369 |
+
343
|
| 1370 |
+
00:24:14,000 --> 00:24:20,000
|
| 1371 |
+
Now I want to show you how to perform the same operations, but with the help of type from Jowett in
|
| 1372 |
+
|
| 1373 |
+
344
|
| 1374 |
+
00:24:20,000 --> 00:24:28,000
|
| 1375 |
+
your package, you can easily right next to the file with the help of Files Class Just Goldreich MassArt
|
| 1376 |
+
|
| 1377 |
+
345
|
| 1378 |
+
00:24:28,000 --> 00:24:30,000
|
| 1379 |
+
and pass the next arguments.
|
| 1380 |
+
|
| 1381 |
+
346
|
| 1382 |
+
00:24:30,000 --> 00:24:32,000
|
| 1383 |
+
The first argument is a pass object.
|
| 1384 |
+
|
| 1385 |
+
347
|
| 1386 |
+
00:24:33,000 --> 00:24:40,000
|
| 1387 |
+
You already know how to get past object after that pass bytes that you want to write and after that
|
| 1388 |
+
|
| 1389 |
+
348
|
| 1390 |
+
00:24:40,000 --> 00:24:42,000
|
| 1391 |
+
you can optionally pass open options.
|
| 1392 |
+
|
| 1393 |
+
349
|
| 1394 |
+
00:24:43,000 --> 00:24:45,000
|
| 1395 |
+
Let me open the source code of rights, Macit.
|
| 1396 |
+
|
| 1397 |
+
350
|
| 1398 |
+
00:24:46,000 --> 00:24:51,000
|
| 1399 |
+
You can see that there is variable lengths argument of the type open option.
|
| 1400 |
+
|
| 1401 |
+
351
|
| 1402 |
+
00:24:51,000 --> 00:24:57,000
|
| 1403 |
+
That means you can either pass nothing or multiple open options would open option type s.
|
| 1404 |
+
|
| 1405 |
+
352
|
| 1406 |
+
00:24:58,000 --> 00:24:59,000
|
| 1407 |
+
Let me open this interface.
|
| 1408 |
+
|
| 1409 |
+
353
|
| 1410 |
+
00:25:00,000 --> 00:25:06,000
|
| 1411 |
+
This is markhor interface that declares a type that can tell program how to open or create file.
|
| 1412 |
+
|
| 1413 |
+
354
|
| 1414 |
+
00:25:06,000 --> 00:25:10,000
|
| 1415 |
+
I press F for key to see implementations of this type.
|
| 1416 |
+
|
| 1417 |
+
355
|
| 1418 |
+
00:25:11,000 --> 00:25:14,000
|
| 1419 |
+
The most popular in my opinion, is standard open options.
|
| 1420 |
+
|
| 1421 |
+
356
|
| 1422 |
+
00:25:15,000 --> 00:25:16,000
|
| 1423 |
+
Let me open it.
|
| 1424 |
+
|
| 1425 |
+
357
|
| 1426 |
+
00:25:16,000 --> 00:25:19,000
|
| 1427 |
+
This is an informal type that declares main options.
|
| 1428 |
+
|
| 1429 |
+
358
|
| 1430 |
+
00:25:19,000 --> 00:25:27,000
|
| 1431 |
+
How to open access to the file user you want to open, only read the access to the file or also write
|
| 1432 |
+
|
| 1433 |
+
359
|
| 1434 |
+
00:25:27,000 --> 00:25:27,000
|
| 1435 |
+
access.
|
| 1436 |
+
|
| 1437 |
+
360
|
| 1438 |
+
00:25:27,000 --> 00:25:31,000
|
| 1439 |
+
You can specify that you want to add tags to the bottom of the file.
|
| 1440 |
+
|
| 1441 |
+
361
|
| 1442 |
+
00:25:32,000 --> 00:25:33,000
|
| 1443 |
+
By using append option.
|
| 1444 |
+
|
| 1445 |
+
362
|
| 1446 |
+
00:25:34,000 --> 00:25:37,000
|
| 1447 |
+
You can create a file before writing new information there.
|
| 1448 |
+
|
| 1449 |
+
363
|
| 1450 |
+
00:25:37,000 --> 00:25:41,000
|
| 1451 |
+
To do this, we have to pass truncate existant option.
|
| 1452 |
+
|
| 1453 |
+
364
|
| 1454 |
+
00:25:41,000 --> 00:25:46,000
|
| 1455 |
+
If we want to create file, we have to pass create option in case we want to get failer.
|
| 1456 |
+
|
| 1457 |
+
365
|
| 1458 |
+
00:25:46,000 --> 00:25:50,000
|
| 1459 |
+
In case file already exists, we have to use create new option.
|
| 1460 |
+
|
| 1461 |
+
366
|
| 1462 |
+
00:25:51,000 --> 00:25:55,000
|
| 1463 |
+
This is important when you're afraid accidentally overwrite already created file.
|
| 1464 |
+
|
| 1465 |
+
367
|
| 1466 |
+
00:25:55,000 --> 00:25:58,000
|
| 1467 |
+
I believe that delete unclosed is self describing.
|
| 1468 |
+
|
| 1469 |
+
368
|
| 1470 |
+
00:25:59,000 --> 00:25:59,000
|
| 1471 |
+
In my opinion.
|
| 1472 |
+
|
| 1473 |
+
369
|
| 1474 |
+
00:25:59,000 --> 00:26:02,000
|
| 1475 |
+
Those are the main options that we might want to use.
|
| 1476 |
+
|
| 1477 |
+
370
|
| 1478 |
+
00:26:02,000 --> 00:26:06,000
|
| 1479 |
+
You can review documentation for the rest of the options by yourself.
|
| 1480 |
+
|
| 1481 |
+
371
|
| 1482 |
+
00:26:06,000 --> 00:26:08,000
|
| 1483 |
+
Let's get back now to the demo file.
|
| 1484 |
+
|
| 1485 |
+
372
|
| 1486 |
+
00:26:08,000 --> 00:26:15,000
|
| 1487 |
+
And in our practical case, I specify that I want to create file in case it doesn't exist and append
|
| 1488 |
+
|
| 1489 |
+
373
|
| 1490 |
+
00:26:15,000 --> 00:26:17,000
|
| 1491 |
+
tax to the bottom of the file.
|
| 1492 |
+
|
| 1493 |
+
374
|
| 1494 |
+
00:26:17,000 --> 00:26:18,000
|
| 1495 |
+
Is that clear?
|
| 1496 |
+
|
| 1497 |
+
375
|
| 1498 |
+
00:26:18,000 --> 00:26:19,000
|
| 1499 |
+
Great.
|
| 1500 |
+
|
| 1501 |
+
376
|
| 1502 |
+
00:26:19,000 --> 00:26:23,000
|
| 1503 |
+
Also, in case you have a list of things, you can write them to the file.
|
| 1504 |
+
|
| 1505 |
+
377
|
| 1506 |
+
00:26:23,000 --> 00:26:26,000
|
| 1507 |
+
Each string from the list will be written from the new line.
|
| 1508 |
+
|
| 1509 |
+
378
|
| 1510 |
+
00:26:27,000 --> 00:26:30,000
|
| 1511 |
+
Right method is overloaded and you can also specify in.
|
| 1512 |
+
|
| 1513 |
+
379
|
| 1514 |
+
00:26:31,000 --> 00:26:37,000
|
| 1515 |
+
In case you want to write to the file with UTF eight and Cordin just use Constant from Standard Chartered
|
| 1516 |
+
|
| 1517 |
+
380
|
| 1518 |
+
00:26:37,000 --> 00:26:43,000
|
| 1519 |
+
class, the next example shows us how we can read from the file with the help of Joe.
|
| 1520 |
+
|
| 1521 |
+
381
|
| 1522 |
+
00:26:43,000 --> 00:26:50,000
|
| 1523 |
+
In your package, you read file with the help of the stream lines, mistakes pass and optionally you
|
| 1524 |
+
|
| 1525 |
+
382
|
| 1526 |
+
00:26:50,000 --> 00:26:56,000
|
| 1527 |
+
can pass and code and to read from file and when you have stream you can work with it.
|
| 1528 |
+
|
| 1529 |
+
383
|
| 1530 |
+
00:26:56,000 --> 00:27:01,000
|
| 1531 |
+
Likewise, in your regular stream where each string is, each line from the file is as clear.
|
| 1532 |
+
|
| 1533 |
+
384
|
| 1534 |
+
00:27:02,000 --> 00:27:08,000
|
| 1535 |
+
In our particular case, I passed the reference to the masses that can print each line from the new
|
| 1536 |
+
|
| 1537 |
+
385
|
| 1538 |
+
00:27:08,000 --> 00:27:09,000
|
| 1539 |
+
line to console.
|
| 1540 |
+
|
| 1541 |
+
386
|
| 1542 |
+
00:27:09,000 --> 00:27:12,000
|
| 1543 |
+
And here you can see content of the file income.
|
| 1544 |
+
|
| 1545 |
+
387
|
| 1546 |
+
00:27:12,000 --> 00:27:19,000
|
| 1547 |
+
So you can see that the last time when we wrote an array of characters, we overwrite everything that
|
| 1548 |
+
|
| 1549 |
+
388
|
| 1550 |
+
00:27:19,000 --> 00:27:26,000
|
| 1551 |
+
we had that here in command line you can see that we could use lambda function, but I believe you already
|
| 1552 |
+
|
| 1553 |
+
389
|
| 1554 |
+
00:27:26,000 --> 00:27:28,000
|
| 1555 |
+
know how to use functional programming.
|
| 1556 |
+
|
| 1557 |
+
390
|
| 1558 |
+
00:27:29,000 --> 00:27:32,000
|
| 1559 |
+
There is also another way to read content from the file.
|
| 1560 |
+
|
| 1561 |
+
391
|
| 1562 |
+
00:27:32,000 --> 00:27:35,000
|
| 1563 |
+
There is a massive call called Read All Lines.
|
| 1564 |
+
|
| 1565 |
+
392
|
| 1566 |
+
00:27:35,000 --> 00:27:37,000
|
| 1567 |
+
It returns list of strings.
|
| 1568 |
+
|
| 1569 |
+
393
|
| 1570 |
+
00:27:37,000 --> 00:27:43,000
|
| 1571 |
+
The specifics of this method is that all file content will be stored in Java memory.
|
| 1572 |
+
|
| 1573 |
+
394
|
| 1574 |
+
00:27:43,000 --> 00:27:49,000
|
| 1575 |
+
For example, in case you want to process huge files that contains tons of information.
|
| 1576 |
+
|
| 1577 |
+
395
|
| 1578 |
+
00:27:49,000 --> 00:27:54,000
|
| 1579 |
+
Imagine that you want a process to gigabytes of information that contains information about patients
|
| 1580 |
+
|
| 1581 |
+
396
|
| 1582 |
+
00:27:54,000 --> 00:27:58,000
|
| 1583 |
+
from all hospitals around all United States from the last 10 years.
|
| 1584 |
+
|
| 1585 |
+
397
|
| 1586 |
+
00:27:59,000 --> 00:28:05,000
|
| 1587 |
+
And imagine that you have only one gigabyte memory reserved for Heap's base of your Java program.
|
| 1588 |
+
|
| 1589 |
+
398
|
| 1590 |
+
00:28:05,000 --> 00:28:12,000
|
| 1591 |
+
That means you will face with error during programming execution because all text data will be stored
|
| 1592 |
+
|
| 1593 |
+
399
|
| 1594 |
+
00:28:12,000 --> 00:28:14,000
|
| 1595 |
+
in memory of Java program.
|
| 1596 |
+
|
| 1597 |
+
400
|
| 1598 |
+
00:28:14,000 --> 00:28:20,000
|
| 1599 |
+
But you won't face without a memory error in case you would process file stream because it reads file
|
| 1600 |
+
|
| 1601 |
+
401
|
| 1602 |
+
00:28:20,000 --> 00:28:21,000
|
| 1603 |
+
line by line.
|
| 1604 |
+
|
| 1605 |
+
402
|
| 1606 |
+
00:28:22,000 --> 00:28:28,000
|
| 1607 |
+
Always remember that reading and writing operations that can block threat of execution, for example,
|
| 1608 |
+
|
| 1609 |
+
403
|
| 1610 |
+
00:28:28,000 --> 00:28:30,000
|
| 1611 |
+
in this particular case was read.
|
| 1612 |
+
|
| 1613 |
+
404
|
| 1614 |
+
00:28:30,000 --> 00:28:37,000
|
| 1615 |
+
The main threat of execution will be stopped in this line until all file will be read.
|
| 1616 |
+
|
| 1617 |
+
405
|
| 1618 |
+
00:28:37,000 --> 00:28:40,000
|
| 1619 |
+
That's why we're often separate.
|
| 1620 |
+
|
| 1621 |
+
406
|
| 1622 |
+
00:28:40,000 --> 00:28:44,000
|
| 1623 |
+
Threat of execution is used to read or to read information from the file.
|
| 1624 |
+
|
| 1625 |
+
407
|
| 1626 |
+
00:28:44,000 --> 00:28:46,000
|
| 1627 |
+
How to create a separate threat.
|
| 1628 |
+
|
| 1629 |
+
408
|
| 1630 |
+
00:28:46,000 --> 00:28:51,000
|
| 1631 |
+
You are going to learn a little bit later when we'll get this and we'll just read in topic.
|
| 1632 |
+
|
| 1633 |
+
409
|
| 1634 |
+
00:28:51,000 --> 00:28:54,000
|
| 1635 |
+
If you understood this example, let's move on.
|
| 1636 |
+
|
| 1637 |
+
410
|
| 1638 |
+
00:28:55,000 --> 00:28:56,000
|
| 1639 |
+
You're all examples today.
|
| 1640 |
+
|
| 1641 |
+
411
|
| 1642 |
+
00:28:56,000 --> 00:28:58,000
|
| 1643 |
+
You saw that specify in coding.
|
| 1644 |
+
|
| 1645 |
+
412
|
| 1646 |
+
00:28:58,000 --> 00:29:01,000
|
| 1647 |
+
I use special clause that contains a few constants.
|
| 1648 |
+
|
| 1649 |
+
413
|
| 1650 |
+
00:29:01,000 --> 00:29:03,000
|
| 1651 |
+
It is called standard charge sets.
|
| 1652 |
+
|
| 1653 |
+
414
|
| 1654 |
+
00:29:04,000 --> 00:29:08,000
|
| 1655 |
+
Let me open the source code of this class in class outline.
|
| 1656 |
+
|
| 1657 |
+
415
|
| 1658 |
+
00:29:08,000 --> 00:29:12,000
|
| 1659 |
+
You can see that it contains a very limited amount of charge sets.
|
| 1660 |
+
|
| 1661 |
+
416
|
| 1662 |
+
00:29:12,000 --> 00:29:16,000
|
| 1663 |
+
What to do in case you need to specify some custom encoding.
|
| 1664 |
+
|
| 1665 |
+
417
|
| 1666 |
+
00:29:16,000 --> 00:29:20,000
|
| 1667 |
+
You can create object of which are set by the specific charge set name.
|
| 1668 |
+
|
| 1669 |
+
418
|
| 1670 |
+
00:29:20,000 --> 00:29:24,000
|
| 1671 |
+
To do this you can use for name method of charge.
|
| 1672 |
+
|
| 1673 |
+
419
|
| 1674 |
+
00:29:24,000 --> 00:29:31,000
|
| 1675 |
+
That class you have to parse and code name to this method to get exactly charge said that you expect,
|
| 1676 |
+
|
| 1677 |
+
420
|
| 1678 |
+
00:29:31,000 --> 00:29:37,000
|
| 1679 |
+
in case you would like to explore all available charge sets, you can print them to console charge.
|
| 1680 |
+
|
| 1681 |
+
421
|
| 1682 |
+
00:29:37,000 --> 00:29:43,000
|
| 1683 |
+
That class has available charge sets, methods that can return sorted map of jerseyed name mapped to
|
| 1684 |
+
|
| 1685 |
+
422
|
| 1686 |
+
00:29:43,000 --> 00:29:44,000
|
| 1687 |
+
charge that objects.
|
| 1688 |
+
|
| 1689 |
+
423
|
| 1690 |
+
00:29:45,000 --> 00:29:50,000
|
| 1691 |
+
If you understood this, I want to show you a few more interesting matters that will be helpful during
|
| 1692 |
+
|
| 1693 |
+
424
|
| 1694 |
+
00:29:50,000 --> 00:29:54,000
|
| 1695 |
+
your homework and hopefully during your career files.
|
| 1696 |
+
|
| 1697 |
+
425
|
| 1698 |
+
00:29:54,000 --> 00:30:00,000
|
| 1699 |
+
Mercedez has find methods that can help you to find files that match specific condition and you can
|
| 1700 |
+
|
| 1701 |
+
426
|
| 1702 |
+
00:30:00,000 --> 00:30:02,000
|
| 1703 |
+
create a stream out of these files.
|
| 1704 |
+
|
| 1705 |
+
427
|
| 1706 |
+
00:30:02,000 --> 00:30:06,000
|
| 1707 |
+
But to be more specific, you can create a stream for past objects.
|
| 1708 |
+
|
| 1709 |
+
428
|
| 1710 |
+
00:30:07,000 --> 00:30:13,000
|
| 1711 |
+
To do this, you can go find Masset and pass it, pass where you want to start looking from and into
|
| 1712 |
+
|
| 1713 |
+
429
|
| 1714 |
+
00:30:13,000 --> 00:30:15,000
|
| 1715 |
+
value of daps.
|
| 1716 |
+
|
| 1717 |
+
430
|
| 1718 |
+
00:30:15,000 --> 00:30:20,000
|
| 1719 |
+
That is how deep we should go into inner directories while looking for files.
|
| 1720 |
+
|
| 1721 |
+
431
|
| 1722 |
+
00:30:21,000 --> 00:30:28,000
|
| 1723 |
+
And the key argument you have to pass by predicate that will define the logic, what file you are looking
|
| 1724 |
+
|
| 1725 |
+
432
|
| 1726 |
+
00:30:28,000 --> 00:30:32,000
|
| 1727 |
+
for, the byproduct to expose and file attributes.
|
| 1728 |
+
|
| 1729 |
+
433
|
| 1730 |
+
00:30:32,000 --> 00:30:39,000
|
| 1731 |
+
You can see that in this lambda function we use only POS and we want to find all files with Java extension.
|
| 1732 |
+
|
| 1733 |
+
434
|
| 1734 |
+
00:30:40,000 --> 00:30:43,000
|
| 1735 |
+
After that, I use the stream to process all posts.
|
| 1736 |
+
|
| 1737 |
+
435
|
| 1738 |
+
00:30:44,000 --> 00:30:45,000
|
| 1739 |
+
I saw them after that.
|
| 1740 |
+
|
| 1741 |
+
436
|
| 1742 |
+
00:30:45,000 --> 00:30:50,000
|
| 1743 |
+
A turn parser object to string and collect all strings in one line.
|
| 1744 |
+
|
| 1745 |
+
437
|
| 1746 |
+
00:30:50,000 --> 00:30:57,000
|
| 1747 |
+
And in case I found such files and final string is not now and it is not empty, I printed tokens.
|
| 1748 |
+
|
| 1749 |
+
438
|
| 1750 |
+
00:30:57,000 --> 00:30:59,000
|
| 1751 |
+
So can you understand this?
|
| 1752 |
+
|
| 1753 |
+
439
|
| 1754 |
+
00:30:59,000 --> 00:31:05,000
|
| 1755 |
+
You're always welcome to ask questions and Q&A section in case something is still unclear.
|
| 1756 |
+
|
| 1757 |
+
440
|
| 1758 |
+
00:31:05,000 --> 00:31:12,000
|
| 1759 |
+
The results and other helpful Macit you can iterate over all files by calling Walk Masset the different
|
| 1760 |
+
|
| 1761 |
+
441
|
| 1762 |
+
00:31:12,000 --> 00:31:14,000
|
| 1763 |
+
variations of these method.
|
| 1764 |
+
|
| 1765 |
+
442
|
| 1766 |
+
00:31:14,000 --> 00:31:17,000
|
| 1767 |
+
One of them also allows you to set daps during the iteration.
|
| 1768 |
+
|
| 1769 |
+
443
|
| 1770 |
+
00:31:18,000 --> 00:31:22,000
|
| 1771 |
+
This massive returns you stream and you can process it as you wish.
|
| 1772 |
+
|
| 1773 |
+
444
|
| 1774 |
+
00:31:23,000 --> 00:31:25,000
|
| 1775 |
+
That's all what I wanted to share with you today.
|
| 1776 |
+
|
| 1777 |
+
445
|
| 1778 |
+
00:31:26,000 --> 00:31:28,000
|
| 1779 |
+
Let's recap what we have learned today.
|
| 1780 |
+
|
| 1781 |
+
446
|
| 1782 |
+
00:31:29,000 --> 00:31:31,000
|
| 1783 |
+
Today, we learned how to work with files.
|
| 1784 |
+
|
| 1785 |
+
447
|
| 1786 |
+
00:31:32,000 --> 00:31:36,000
|
| 1787 |
+
We also learned how to work with type from jail new package.
|
| 1788 |
+
|
| 1789 |
+
448
|
| 1790 |
+
00:31:36,000 --> 00:31:41,000
|
| 1791 |
+
After that, we learned what bite and character streams are after this lesson.
|
| 1792 |
+
|
| 1793 |
+
449
|
| 1794 |
+
00:31:41,000 --> 00:31:44,000
|
| 1795 |
+
You know how to use thrivers resources block.
|
| 1796 |
+
|
| 1797 |
+
450
|
| 1798 |
+
00:31:44,000 --> 00:31:50,000
|
| 1799 |
+
Now, you know what is a buffer and how to use buffer streams on real examples.
|
| 1800 |
+
|
| 1801 |
+
451
|
| 1802 |
+
00:31:50,000 --> 00:31:53,000
|
| 1803 |
+
You saw how to use and call you in writing and reading.
|
| 1804 |
+
|
| 1805 |
+
452
|
| 1806 |
+
00:31:53,000 --> 00:31:59,000
|
| 1807 |
+
And at the end of the lesson, we learned how to read and write from files with the help of Jouni,
|
| 1808 |
+
|
| 1809 |
+
453
|
| 1810 |
+
00:31:59,000 --> 00:32:00,000
|
| 1811 |
+
your package.
|
| 1812 |
+
|
| 1813 |
+
454
|
| 1814 |
+
00:32:01,000 --> 00:32:03,000
|
| 1815 |
+
Now I want to share with you your homework.
|
| 1816 |
+
|
| 1817 |
+
455
|
| 1818 |
+
00:32:04,000 --> 00:32:08,000
|
| 1819 |
+
I mean, do your homework and attachments, your homework.
|
| 1820 |
+
|
| 1821 |
+
456
|
| 1822 |
+
00:32:08,000 --> 00:32:12,000
|
| 1823 |
+
It is recommended to implement the next task to make sure that you learned this topic.
|
| 1824 |
+
|
| 1825 |
+
457
|
| 1826 |
+
00:32:13,000 --> 00:32:18,000
|
| 1827 |
+
I want you to review the documentation for Java I o package, including file class.
|
| 1828 |
+
|
| 1829 |
+
458
|
| 1830 |
+
00:32:19,000 --> 00:32:24,000
|
| 1831 |
+
Similar to that, I want you to review documentation for Java in your package, including files class
|
| 1832 |
+
|
| 1833 |
+
459
|
| 1834 |
+
00:32:24,000 --> 00:32:27,000
|
| 1835 |
+
that is located in the same package file.
|
| 1836 |
+
|
| 1837 |
+
460
|
| 1838 |
+
00:32:28,000 --> 00:32:32,000
|
| 1839 |
+
Also you have for coding exercises to implement according to the task.
|
| 1840 |
+
|
| 1841 |
+
461
|
| 1842 |
+
00:32:32,000 --> 00:32:37,000
|
| 1843 |
+
Number three, you have to implement MassArt that would read configuration map and would be able to
|
| 1844 |
+
|
| 1845 |
+
462
|
| 1846 |
+
00:32:37,000 --> 00:32:41,000
|
| 1847 |
+
reach an value of the specific property from the config map.
|
| 1848 |
+
|
| 1849 |
+
463
|
| 1850 |
+
00:32:41,000 --> 00:32:46,000
|
| 1851 |
+
And the task number for you would need to iterate over files to calculate the number of files with a
|
| 1852 |
+
|
| 1853 |
+
464
|
| 1854 |
+
00:32:46,000 --> 00:32:49,000
|
| 1855 |
+
specific extension in the exercise.
|
| 1856 |
+
|
| 1857 |
+
465
|
| 1858 |
+
00:32:49,000 --> 00:32:56,000
|
| 1859 |
+
Number five, you have to implement console text editor, user can interact with console to write text
|
| 1860 |
+
|
| 1861 |
+
466
|
| 1862 |
+
00:32:56,000 --> 00:32:58,000
|
| 1863 |
+
to the file and the exercise.
|
| 1864 |
+
|
| 1865 |
+
467
|
| 1866 |
+
00:32:58,000 --> 00:33:00,000
|
| 1867 |
+
Number six is the most interesting in my opinion.
|
| 1868 |
+
|
| 1869 |
+
468
|
| 1870 |
+
00:33:01,000 --> 00:33:06,000
|
| 1871 |
+
As you already understood along, of course, we are going to implement online store application and
|
| 1872 |
+
|
| 1873 |
+
469
|
| 1874 |
+
00:33:06,000 --> 00:33:13,000
|
| 1875 |
+
add additional features to it as we learn new topics in this exercise and of you to add functionality
|
| 1876 |
+
|
| 1877 |
+
470
|
| 1878 |
+
00:33:13,000 --> 00:33:16,000
|
| 1879 |
+
of storing users and products in the file.
|
| 1880 |
+
|
| 1881 |
+
471
|
| 1882 |
+
00:33:16,000 --> 00:33:23,000
|
| 1883 |
+
That will be our first external data storage and one program will be started will read the state from
|
| 1884 |
+
|
| 1885 |
+
472
|
| 1886 |
+
00:33:23,000 --> 00:33:28,000
|
| 1887 |
+
the files that said they are going to have a lot of opportunities to shape your skills.
|
| 1888 |
+
|
| 1889 |
+
473
|
| 1890 |
+
00:33:29,000 --> 00:33:30,000
|
| 1891 |
+
Thanks a lot for your attention.
|
| 1892 |
+
|
| 1893 |
+
474
|
| 1894 |
+
00:33:30,000 --> 00:33:34,000
|
| 1895 |
+
The students hope you found this lesson interesting and useful for you.
|
| 1896 |
+
|
| 1897 |
+
475
|
| 1898 |
+
00:33:35,000 --> 00:33:36,000
|
| 1899 |
+
See you in the next lesson.
|
| 1900 |
+
|
25 - Input and Output Streams in Java/001 Solution-of-Homework-Online-store-with-data-storage.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/finaltask/storage
|
25 - Input and Output Streams in Java/001 Solution-of-homework.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/io/hw
|
25 - Input and Output Streams in Java/001 Source-code-examples-from-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/io
|
25 - Input and Output Streams in Java/005 Homework-solution.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/finaltask/storage/impl/DefaultUserStoringService.java
|
25 - Input and Output Streams in Java/005 Homework.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://docs.google.com/document/d/1gAwAtOMhaQOCIhc_QM8XreCn_QThfOxAKmw-ufTCk7Y/edit?usp=sharing
|
25 - Input and Output Streams in Java/005 Serialization and Cloning_en.srt
ADDED
|
@@ -0,0 +1,1096 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:11,000
|
| 3 |
+
Hello, there are students in this lesson, we are going to learn what serialisation is and talk about
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:11,000 --> 00:00:15,000
|
| 7 |
+
Object Clonan, we'll start from understanding why do we need signalization?
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:15,000 --> 00:00:21,000
|
| 11 |
+
I will explain you what the serializable interface for after that unreal example.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:21,000 --> 00:00:22,000
|
| 15 |
+
We'll try to serialize.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:22,000 --> 00:00:27,000
|
| 19 |
+
And the last few objects also will learn Externalisation.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:27,000 --> 00:00:33,000
|
| 23 |
+
Today you're going to find what the difference between serializable and externalising is.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:33,000 --> 00:00:39,000
|
| 27 |
+
Once you learn that, we'll talk about object and we'll review what is deep and shallow.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:39,000 --> 00:00:44,000
|
| 31 |
+
Clonan, I'll tell you how to override clone method to support Deep Clonan.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:44,000 --> 00:00:47,000
|
| 35 |
+
In this lesson, you're going to see a lot of examples.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:48,000 --> 00:00:49,000
|
| 39 |
+
So let's start.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:50,000 --> 00:00:53,000
|
| 43 |
+
First of all, let me give the answer and question.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:53,000 --> 00:00:55,000
|
| 47 |
+
What serialisation is serialisation?
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:55,000 --> 00:00:59,000
|
| 51 |
+
Is a process of converting objects to a stream of bytes.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:59,000 --> 00:01:03,000
|
| 55 |
+
Decimalization is a process of converting stream of bytes to an object.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:04,000 --> 00:01:08,000
|
| 59 |
+
In simple words, you can represent your Java object in sequence of bytes.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:09,000 --> 00:01:15,000
|
| 63 |
+
After that, you can either store it on local computer or centralized object over Internet.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:15,000 --> 00:01:16,000
|
| 67 |
+
It's up to you.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:16,000 --> 00:01:19,000
|
| 71 |
+
In case you understood what serialization is.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:19,000 --> 00:01:23,000
|
| 75 |
+
Let's understand the problem and why we might want to use terrorization.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:24,000 --> 00:01:28,000
|
| 79 |
+
To help you understand this, I'm going to discuss with you a few real life cases.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:28,000 --> 00:01:35,000
|
| 83 |
+
Imagine that you have to service that are in the same code and you need pass information from one machine
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:35,000 --> 00:01:36,000
|
| 87 |
+
to another.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:36,000 --> 00:01:43,000
|
| 91 |
+
You can create an object and serialize it and pass a sequence of bytes over the network to another server.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:44,000 --> 00:01:50,000
|
| 95 |
+
The second server will decentralize your message and construct a new object out of the bytes that we
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:50,000 --> 00:01:51,000
|
| 99 |
+
have sent.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:51,000 --> 00:01:55,000
|
| 103 |
+
That's how you can pass information from one server to another.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:56,000 --> 00:01:57,000
|
| 107 |
+
Another example.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:57,000 --> 00:02:00,000
|
| 111 |
+
It's when you need to store some data on the local computer.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:00,000 --> 00:02:06,000
|
| 115 |
+
Imagine that you have a game or another desktop application, for example, your diary.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:06,000 --> 00:02:13,000
|
| 119 |
+
And when the user close the program you want to say is a state of the program, it could be game progress,
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:13,000 --> 00:02:15,000
|
| 123 |
+
a list of users plans.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:15,000 --> 00:02:16,000
|
| 127 |
+
It doesn't matter.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:16,000 --> 00:02:20,000
|
| 131 |
+
And you can serialize objects that contains this information.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:20,000 --> 00:02:23,000
|
| 135 |
+
One program is closed and decentralized.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:23,000 --> 00:02:24,000
|
| 139 |
+
That one program has started again.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:25,000 --> 00:02:26,000
|
| 143 |
+
It is pretty convenient, don't you think?
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:26,000 --> 00:02:33,000
|
| 147 |
+
So one more practical need for serialization is to make an exact copy of an object.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:33,000 --> 00:02:39,000
|
| 151 |
+
Today we'll talk about this and you learn how to clone object with the help of civilization mechanism.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:40,000 --> 00:02:43,000
|
| 155 |
+
How else you can use a translation mechanism.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:43,000 --> 00:02:48,000
|
| 159 |
+
Imagine that you have really huge objects that takes ten minutes to construct.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:48,000 --> 00:02:54,000
|
| 163 |
+
Just imagine that it is better for you to cache this object because this resolution of this object will
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:02:54,000 --> 00:02:56,000
|
| 167 |
+
take up to ten seconds, for example.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:02:56,000 --> 00:03:00,000
|
| 171 |
+
So sometimes you may want to cacio objects.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:01,000 --> 00:03:04,000
|
| 175 |
+
These are just a few examples when you might want to use serialisation.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:05,000 --> 00:03:06,000
|
| 179 |
+
Interesting if.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:06,000 --> 00:03:11,000
|
| 183 |
+
Yes, let's run how the resolution works for this lesson.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:11,000 --> 00:03:13,000
|
| 187 |
+
I prepared examples that I'm going to share with you today.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:14,000 --> 00:03:15,000
|
| 191 |
+
Let's jump to Eclipse.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:16,000 --> 00:03:23,000
|
| 195 |
+
Imagine that we have class employee that is some class from our application and this class has next
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:23,000 --> 00:03:27,000
|
| 199 |
+
properties, idea, name and list of properties of map type.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:28,000 --> 00:03:34,000
|
| 203 |
+
This class also has getters and setters and imagines that at some point in our program we want to serialize
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:34,000 --> 00:03:35,000
|
| 207 |
+
this object.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:35,000 --> 00:03:41,000
|
| 211 |
+
The first thing we have to do is to mark specific type with serializable interface.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:03:41,000 --> 00:03:47,000
|
| 215 |
+
This is important because without implementing this interface, you will get an exception during the
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:03:47,000 --> 00:03:51,000
|
| 219 |
+
serialization to be more specific, not serializable exception.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:03:51,000 --> 00:03:57,000
|
| 223 |
+
Let's review the source code of this interface and you can see that this interface declares no mascot's.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:03:58,000 --> 00:04:00,000
|
| 227 |
+
This is a marker interface.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:00,000 --> 00:04:07,000
|
| 231 |
+
It is a rule in Java that enables the ability of a class it should implements this interface.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:07,000 --> 00:04:10,000
|
| 235 |
+
OK, now let's get back to our file.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:11,000 --> 00:04:14,000
|
| 239 |
+
Now we have employee time that is ready to be centralized.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:15,000 --> 00:04:16,000
|
| 243 |
+
Let's open our demo file.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:17,000 --> 00:04:19,000
|
| 247 |
+
I create object of type employee.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:19,000 --> 00:04:23,000
|
| 251 |
+
I satija name and map with properties.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:23,000 --> 00:04:27,000
|
| 255 |
+
Our A map includes salary and the city great.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:27,000 --> 00:04:29,000
|
| 259 |
+
The Serialize object.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:04:29,000 --> 00:04:35,000
|
| 263 |
+
I created a separate matter that is called centralized simply lets you use a source code of that massive.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:04:35,000 --> 00:04:38,000
|
| 267 |
+
I want to declare object outputs three type.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:04:38,000 --> 00:04:41,000
|
| 271 |
+
It can be created on the basis of output stream.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:04:42,000 --> 00:04:48,000
|
| 275 |
+
So I create object output stream and POS but array output stream into it.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:04:48,000 --> 00:04:56,000
|
| 279 |
+
Pay attention here instead of battery output stream, you can specify any other type that extends output
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:04:56,000 --> 00:04:56,000
|
| 283 |
+
stream.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:04:57,000 --> 00:05:04,000
|
| 287 |
+
I declare all streams in Try with their sources blog inside the blog, I called MassArt right object
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:04,000 --> 00:05:12,000
|
| 291 |
+
and pass the reference to my employee object that from this Massett I return by the output stream because
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:12,000 --> 00:05:14,000
|
| 295 |
+
I want to source in reference to this object.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:15,000 --> 00:05:21,000
|
| 299 |
+
When times come, I will use this battery output stream object to decentralize my employee object.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:21,000 --> 00:05:22,000
|
| 303 |
+
That's it.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:22,000 --> 00:05:27,000
|
| 307 |
+
I have just generalized and play object how I can decentralize it.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:28,000 --> 00:05:31,000
|
| 311 |
+
Let's review the source code of another method decentralized.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:05:31,000 --> 00:05:38,000
|
| 315 |
+
Simply, I posta this massive battery output stream that is a stream where my employee object was written
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:05:38,000 --> 00:05:40,000
|
| 319 |
+
as a sequence of bytes.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:05:40,000 --> 00:05:47,000
|
| 323 |
+
In this method I create object input stream and pass to it by three input stream object that is created
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:05:47,000 --> 00:05:50,000
|
| 327 |
+
on the basis of my battery output stream.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:05:51,000 --> 00:05:58,000
|
| 331 |
+
In simple words, I redirected my output stream to input stream and now I want to read it.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:05:59,000 --> 00:06:02,000
|
| 335 |
+
Other sources are declared in other sources.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:02,000 --> 00:06:03,000
|
| 339 |
+
Block one.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:03,000 --> 00:06:06,000
|
| 343 |
+
All objects are created equal object.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:06,000 --> 00:06:11,000
|
| 347 |
+
Masset pay attention that this mass returns object of type object.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:12,000 --> 00:06:19,000
|
| 351 |
+
In case you want to have specific type, you have to cost this object to your time and I return employee
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:19,000 --> 00:06:22,000
|
| 355 |
+
object from this massive in our main Macit.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:22,000 --> 00:06:26,000
|
| 359 |
+
I want to bring the employee that we got after the serialization.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:27,000 --> 00:06:30,000
|
| 363 |
+
Let me run the program to show you and transload.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:31,000 --> 00:06:37,000
|
| 367 |
+
My program created an object after that, the program centralized template and after that the program
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:06:37,000 --> 00:06:44,000
|
| 371 |
+
decentralized it and printed object to console and you can see that it is an absolute copy of our original
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:06:44,000 --> 00:06:45,000
|
| 375 |
+
employee.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:06:45,000 --> 00:06:49,000
|
| 379 |
+
Can you understand now what centralization and decentralization is?
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:06:49,000 --> 00:06:50,000
|
| 383 |
+
Great.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:06:50,000 --> 00:06:54,000
|
| 387 |
+
Let me add a few more details to serialisation and this realization.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:06:54,000 --> 00:06:56,000
|
| 391 |
+
Let's go one by one.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:06:56,000 --> 00:07:02,000
|
| 395 |
+
First of all, you saw that my employee class has specific properties, serial version Yagi.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:02,000 --> 00:07:10,000
|
| 399 |
+
What does this variable for serial version UIGEA is a constant that uniquely in the device, a version
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:10,000 --> 00:07:14,000
|
| 403 |
+
of a serializable class universalization process.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:14,000 --> 00:07:18,000
|
| 407 |
+
Java virtual machine verifies this constant why?
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:18,000 --> 00:07:26,000
|
| 411 |
+
Imagine that we have original version of an employee class visualized the object and on the other machine
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:26,000 --> 00:07:29,000
|
| 415 |
+
where our program is running or even on our machine.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:07:29,000 --> 00:07:35,000
|
| 419 |
+
But after user updated version of our application, imagine that there is an updated version of employee
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:07:35,000 --> 00:07:42,000
|
| 423 |
+
class, for example, instead of the map with properties, we have separate properties for salary and
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:07:42,000 --> 00:07:45,000
|
| 427 |
+
C.G. and there is no more property of type map anymore.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:07:45,000 --> 00:07:52,000
|
| 431 |
+
That means that error will happen during institutionalization and our sequence of byte won't be able
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:07:52,000 --> 00:07:59,000
|
| 435 |
+
to be mapped against the current employee type and to distinguish versions of classes that are serialized.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:07:59,000 --> 00:08:04,000
|
| 439 |
+
This constant exists sometimes, developer said default serial version.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:04,000 --> 00:08:10,000
|
| 443 |
+
Yazji This is equal to one and that's it known that the serial version is optional.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:11,000 --> 00:08:15,000
|
| 447 |
+
You can just ignore this eclipse will show you a warning, but nothing about that.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:16,000 --> 00:08:19,000
|
| 451 |
+
Let's talk about what a transient keyword is.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:19,000 --> 00:08:21,000
|
| 455 |
+
It is better to understand this.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:21,000 --> 00:08:21,000
|
| 459 |
+
An example.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:22,000 --> 00:08:28,000
|
| 463 |
+
Let me add a transient keyword in the property and now let me run my program one more time.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:28,000 --> 00:08:30,000
|
| 467 |
+
Look at the console output.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:08:30,000 --> 00:08:33,000
|
| 471 |
+
Can its users name property is now.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:08:33,000 --> 00:08:34,000
|
| 475 |
+
Why?
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:08:34,000 --> 00:08:39,000
|
| 479 |
+
Because Transend keyword tells to ignore this property during the serialization.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:08:39,000 --> 00:08:43,000
|
| 483 |
+
The string value of name is just not stored to the output stream.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:08:44,000 --> 00:08:46,000
|
| 487 |
+
Let's get back to inplay class.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:08:46,000 --> 00:08:48,000
|
| 491 |
+
I will remove transient keywords.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:08:49,000 --> 00:08:52,000
|
| 495 |
+
I want you to pay attention to two matters here, right?
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:08:52,000 --> 00:08:54,000
|
| 499 |
+
Object and object.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:08:54,000 --> 00:09:01,000
|
| 503 |
+
Especially pay attention to the access modifiers, return type of data and potential exceptions that
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:01,000 --> 00:09:01,000
|
| 507 |
+
can be thrown.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:02,000 --> 00:09:07,000
|
| 511 |
+
This is just a convention and this is something what we have just to remember, in case you want to
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:07,000 --> 00:09:13,000
|
| 515 |
+
customize your object before serialization or after decimalization, you can declare these methods in
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:13,000 --> 00:09:16,000
|
| 519 |
+
your type and perform anything you need.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:09:16,000 --> 00:09:22,000
|
| 523 |
+
For example, I have can so random text just to prove you that these methods are invoked.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:09:23,000 --> 00:09:29,000
|
| 527 |
+
You can always use default, write, object and default to object to process your serialization further.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:09:29,000 --> 00:09:33,000
|
| 531 |
+
In this methods, you can handle initialization of transient fields.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:09:33,000 --> 00:09:36,000
|
| 535 |
+
For example, Hobbs's makes things clearer.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:09:36,000 --> 00:09:38,000
|
| 539 |
+
Let's move on now.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:09:38,000 --> 00:09:44,000
|
| 543 |
+
Imagine the case that you want to serialize object and you want explicitly tell that process of civilization
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:09:44,000 --> 00:09:45,000
|
| 547 |
+
should be customized.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:09:46,000 --> 00:09:52,000
|
| 551 |
+
For example, each user has a password or any other sensitive information and you want to encrypt this
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:09:52,000 --> 00:09:56,000
|
| 555 |
+
information before serialization and decrypt after serialization.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:09:57,000 --> 00:10:04,000
|
| 559 |
+
For the sake of them, I create one more type called user attention, it implements externalizes.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:04,000 --> 00:10:10,000
|
| 563 |
+
All this time has only two fields, Zaya nickname and password.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:11,000 --> 00:10:14,000
|
| 567 |
+
You can see two constructors, getters and setters.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:14,000 --> 00:10:20,000
|
| 571 |
+
And the most interesting part in case you implement externalise all you have to implement, right?
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:10:20,000 --> 00:10:22,000
|
| 575 |
+
External and with external mascot's.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:10:23,000 --> 00:10:28,000
|
| 579 |
+
It is similar to the way we view it with the serializable type employee and private marcedes.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:10:29,000 --> 00:10:35,000
|
| 583 |
+
This is more object oriented way to say that this type contains custom logic for serialisation and decentralization.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:10:36,000 --> 00:10:37,000
|
| 587 |
+
We would open this interface.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:10:37,000 --> 00:10:44,000
|
| 591 |
+
We would notice that it extends serializable in this messenger as a serialisation and right to the output
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:10:44,000 --> 00:10:46,000
|
| 595 |
+
nickname and custom passwords.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:10:47,000 --> 00:10:49,000
|
| 599 |
+
We can encode password here, for example.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:10:50,000 --> 00:10:54,000
|
| 603 |
+
And in the read External Masset, I should read properties one by one.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:10:54,000 --> 00:10:57,000
|
| 607 |
+
You have to read properties in the same sequence.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:10:57,000 --> 00:11:02,000
|
| 611 |
+
We wrote them here and you can see that I initialize state of the current object.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:03,000 --> 00:11:09,000
|
| 615 |
+
Let me open our demo program to test utilization and decentralization and create user object first.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:10,000 --> 00:11:16,000
|
| 619 |
+
And after that I call similar methods that we saw during the serialization example that tensions that
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:11:16,000 --> 00:11:18,000
|
| 623 |
+
I created user with this specific password.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:11:19,000 --> 00:11:25,000
|
| 627 |
+
Let me run the program now in console output, you can see that password is different.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:11:25,000 --> 00:11:30,000
|
| 631 |
+
That is because we implemented custom logic of civilization and serialization.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:11:30,000 --> 00:11:31,000
|
| 635 |
+
Does it make sense?
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:11:32,000 --> 00:11:33,000
|
| 639 |
+
Awesome.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:11:34,000 --> 00:11:38,000
|
| 643 |
+
Now, when you completely learn serialisation, let me talk about a different topic.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:11:38,000 --> 00:11:40,000
|
| 647 |
+
Let's discuss cloning now.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:11:41,000 --> 00:11:45,000
|
| 651 |
+
Sometimes in a program you might want to create exact copy of the same object.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:11:45,000 --> 00:11:52,000
|
| 655 |
+
For example, you want to do some modifications in user object, but you also need to store that reference
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:11:52,000 --> 00:11:53,000
|
| 659 |
+
to the original object.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:11:53,000 --> 00:12:00,000
|
| 663 |
+
That is helpful in some specific cases when you need to keep both data objects original and updated
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:12:00,000 --> 00:12:04,000
|
| 667 |
+
one and pass them to the front end to compare them together.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:05,000 --> 00:12:08,000
|
| 671 |
+
Each Java object has access to clone masses.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:08,000 --> 00:12:11,000
|
| 675 |
+
Let me open the source code of object class.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:12:11,000 --> 00:12:13,000
|
| 679 |
+
You can find clone method here.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:12:14,000 --> 00:12:20,000
|
| 683 |
+
As you can see, this is a native Macit and we can explore its original source code right now.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:12:20,000 --> 00:12:24,000
|
| 687 |
+
But what we can see is that the massive has protected access modifier.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:12:25,000 --> 00:12:26,000
|
| 691 |
+
What does it mean?
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:12:26,000 --> 00:12:33,000
|
| 695 |
+
That mean we can't call clone Masset on each object by default, but we have access to this.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:12:33,000 --> 00:12:35,000
|
| 699 |
+
Protect MassArt inside the class.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:12:36,000 --> 00:12:37,000
|
| 703 |
+
Let me show you this.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:12:37,000 --> 00:12:41,000
|
| 707 |
+
All examples that are related to cloning will be stored in cloning package.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:12:42,000 --> 00:12:45,000
|
| 711 |
+
Let me open this cloning demo file here.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:12:45,000 --> 00:12:48,000
|
| 715 |
+
You can see that I created the object of a user type.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:12:48,000 --> 00:12:53,000
|
| 719 |
+
And when I call clone MassArt on this object, I get a completion error.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:12:53,000 --> 00:13:00,000
|
| 723 |
+
That is because Clone Massett has a protected access modifier and available inside the user type in
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:13:00,000 --> 00:13:01,000
|
| 727 |
+
this class.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:13:01,000 --> 00:13:07,000
|
| 731 |
+
Java compiler just can see it to make it available outside of the class.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:13:07,000 --> 00:13:14,000
|
| 735 |
+
We have to override this method inside the type and increase the visibility by changing the access modifier
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:13:14,000 --> 00:13:16,000
|
| 739 |
+
from protected to public.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:13:17,000 --> 00:13:19,000
|
| 743 |
+
For example, here is an all the time.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:13:19,000 --> 00:13:24,000
|
| 747 |
+
It contains fields, constructors, getters and setters and clone MassArt.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:13:24,000 --> 00:13:30,000
|
| 751 |
+
Here you can see that I override clone Masset and make it public inside the method.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:13:30,000 --> 00:13:36,000
|
| 755 |
+
I just invoke original clone method from the object class you Mycenae that I implemented clone MassArt.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:13:36,000 --> 00:13:40,000
|
| 759 |
+
Let's check how it works inside the main message.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:13:40,000 --> 00:13:41,000
|
| 763 |
+
I create a list of products first.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:13:42,000 --> 00:13:44,000
|
| 767 |
+
Now I can create an object of all the time.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:13:45,000 --> 00:13:52,000
|
| 771 |
+
I pass some random creditcard no list of products that are associated with this or the end user i.e.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:13:52,000 --> 00:13:55,000
|
| 775 |
+
who made this so that this is my original order.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:13:55,000 --> 00:13:58,000
|
| 779 |
+
I printed the console in the next line.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:13:58,000 --> 00:14:02,000
|
| 783 |
+
I want to clone my original or the object pad tensions.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:14:02,000 --> 00:14:10,000
|
| 787 |
+
That clone MassArt maestro clone not supported exception when one type that is cloned doesn't implement
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:14:10,000 --> 00:14:12,000
|
| 791 |
+
Coonamble interface.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:14:12,000 --> 00:14:15,000
|
| 795 |
+
Let me open the source code of all the type one more time.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:14:16,000 --> 00:14:20,000
|
| 799 |
+
You can see that my order type implements cleanable interface.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:14:20,000 --> 00:14:21,000
|
| 803 |
+
Let's open this interface.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:14:22,000 --> 00:14:29,000
|
| 807 |
+
You can see that this is also an interface and Java verifies during the clone and sometimes it is going
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:14:29,000 --> 00:14:29,000
|
| 811 |
+
to be cloned.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:14:30,000 --> 00:14:32,000
|
| 815 |
+
Implements Cleanable interface.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:14:33,000 --> 00:14:40,000
|
| 819 |
+
Take this as a permission to all object of this type to be cloned and in case this interface is implemented
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:14:40,000 --> 00:14:45,000
|
| 823 |
+
in the time Java believes you that this permission has been granted, is that clear?
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:14:46,000 --> 00:14:47,000
|
| 827 |
+
Awesome.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:14:47,000 --> 00:14:49,000
|
| 831 |
+
Let's get back to our demo file.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:14:49,000 --> 00:14:52,000
|
| 835 |
+
When I cloned object, I printed tokens.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:14:52,000 --> 00:14:56,000
|
| 839 |
+
So let's run this program in console output.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:14:56,000 --> 00:15:01,000
|
| 843 |
+
We can compare these two orders, but believe me, they are the same.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:15:01,000 --> 00:15:03,000
|
| 847 |
+
But they're interesting things to come.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:15:04,000 --> 00:15:11,000
|
| 851 |
+
What if in the cloned object I will modify state, for example, I will clear all products from the
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:15:11,000 --> 00:15:16,000
|
| 855 |
+
cloned order and get all products and Cochlear Massud on the list.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:15:17,000 --> 00:15:23,000
|
| 859 |
+
After that I print original order and you can see that list of products is also clean here.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:15:24,000 --> 00:15:25,000
|
| 863 |
+
How that can be.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:15:26,000 --> 00:15:31,000
|
| 867 |
+
This may seem to be a weird thing, but this is the way how clone Masset works by default.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:15:31,000 --> 00:15:38,000
|
| 871 |
+
This is called Shallow Clonan, you shallow clonan only references are copied.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:15:38,000 --> 00:15:44,000
|
| 875 |
+
Shallow clone in the works just fine for primitive types because they are already stores the value in
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:15:44,000 --> 00:15:53,000
|
| 879 |
+
themselves with reference types of data only references are cloned during shallow cloning, but objects
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:15:53,000 --> 00:15:56,000
|
| 883 |
+
that stand behind those references are not cloned.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:15:57,000 --> 00:16:04,000
|
| 887 |
+
Geep cloning is focused on the cloning of the whole object's graph, including properties of reference
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:16:04,000 --> 00:16:08,000
|
| 891 |
+
types inside the object and properties of reference types inside those objects.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:16:09,000 --> 00:16:10,000
|
| 895 |
+
Can you understand this?
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:16:11,000 --> 00:16:11,000
|
| 899 |
+
Awesome.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:16:12,000 --> 00:16:17,000
|
| 903 |
+
So what we have to do, we have to override clone Masset to make it also clone objects.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:16:17,000 --> 00:16:19,000
|
| 907 |
+
That stands behind the references.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:16:20,000 --> 00:16:25,000
|
| 911 |
+
For the sake of the Dharma, I created one more order type that supports the cloning.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:16:25,000 --> 00:16:28,000
|
| 915 |
+
Let's open the step and explore its clone method.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:16:28,000 --> 00:16:33,000
|
| 919 |
+
At the beginning, I called the whole object and after that I put all.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:16:33,000 --> 00:16:39,000
|
| 923 |
+
Only on mutable objects in this particular time, I have only one mutable property.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:16:39,000 --> 00:16:41,000
|
| 927 |
+
This is a list of products.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:16:41,000 --> 00:16:43,000
|
| 931 |
+
Spring type is immutable.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:16:43,000 --> 00:16:46,000
|
| 935 |
+
It will be impossible to change its state after creation.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:16:46,000 --> 00:16:49,000
|
| 939 |
+
It will be possible only to Saturnus three.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:16:49,000 --> 00:16:53,000
|
| 943 |
+
That's why I am not worrying about it also.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:16:53,000 --> 00:16:56,000
|
| 947 |
+
And don't worry about in the field since this is a primitive time.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:16:56,000 --> 00:17:02,000
|
| 951 |
+
But for products list, I did a copy and I said this copy to my client object.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:17:02,000 --> 00:17:06,000
|
| 955 |
+
Now let's check how deep coding works for this type.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:17:07,000 --> 00:17:11,000
|
| 959 |
+
I initialize product list that was cleared one more time after that.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:17:11,000 --> 00:17:14,000
|
| 963 |
+
A great object of our new type zann.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:17:14,000 --> 00:17:21,000
|
| 967 |
+
I clone this object and similar to the previous example, actually as a list of products in my client
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:17:21,000 --> 00:17:28,000
|
| 971 |
+
object and print two objects to consult, I expect that products placed in original order won't be empty.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:17:29,000 --> 00:17:35,000
|
| 975 |
+
In Arkansas, we can see that we achieved our goal and product list is not empty in my original order
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:17:35,000 --> 00:17:37,000
|
| 979 |
+
and it is empty in cloned order.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:17:38,000 --> 00:17:38,000
|
| 983 |
+
Great.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:17:39,000 --> 00:17:41,000
|
| 987 |
+
Now you know how to do Geep Clonan.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:17:41,000 --> 00:17:44,000
|
| 991 |
+
Feel free to let me know in case you have any questions.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:17:45,000 --> 00:17:47,000
|
| 995 |
+
None how serialization works.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:17:47,000 --> 00:17:53,000
|
| 999 |
+
You might think that serialize and visualize an object doesn't sound like a better year in case you
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:17:53,000 --> 00:18:00,000
|
| 1003 |
+
want to clone an object because implement clone MassArt that would properly clone old graph of objects.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:18:00,000 --> 00:18:02,000
|
| 1007 |
+
It can be very complicated task.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:18:02,000 --> 00:18:07,000
|
| 1011 |
+
Sometimes you may consider serialisation mechanism to make a clone very fast.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:18:08,000 --> 00:18:10,000
|
| 1015 |
+
That's all what I wanted to share with you today.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:18:10,000 --> 00:18:12,000
|
| 1019 |
+
Let's recap what we have learned today.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:18:13,000 --> 00:18:19,000
|
| 1023 |
+
In this lesson we learned what serialization is rereviewed serializable Marka interface.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:18:19,000 --> 00:18:23,000
|
| 1027 |
+
Now you know how centralized and decentralized your objects.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:18:23,000 --> 00:18:27,000
|
| 1031 |
+
You also learned what externalise interface is.
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:18:27,000 --> 00:18:30,000
|
| 1035 |
+
After that, we learned how Clonan Java works.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:18:31,000 --> 00:18:33,000
|
| 1039 |
+
Now, you know, cleanable interface.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:18:33,000 --> 00:18:37,000
|
| 1043 |
+
Today we learned what is the difference between deep and shallow clonan.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:18:37,000 --> 00:18:41,000
|
| 1047 |
+
Also, we had a lot of practice that will help you to complete your homework.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:18:42,000 --> 00:18:43,000
|
| 1051 |
+
Let's review your homework now.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:18:44,000 --> 00:18:48,000
|
| 1055 |
+
After this topic, you are going to have only one simple coding exercise.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:18:48,000 --> 00:18:54,000
|
| 1059 |
+
I promise you, we keep improving our online shop, taking into account all the time, has a list of
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:18:54,000 --> 00:18:55,000
|
| 1063 |
+
products inside.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:18:55,000 --> 00:18:59,000
|
| 1067 |
+
It will be not very convenient to store it in comma separated files.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:18:59,000 --> 00:19:06,000
|
| 1071 |
+
In scope of this task, you have to serialize all orders to the file and one program will be started
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:19:06,000 --> 00:19:06,000
|
| 1075 |
+
again.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:19:06,000 --> 00:19:10,000
|
| 1079 |
+
You have to decentralize or this again home.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:19:10,000 --> 00:19:11,000
|
| 1083 |
+
This is clear.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:19:11,000 --> 00:19:13,000
|
| 1087 |
+
That's all what I wanted to share with you today.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:19:14,000 --> 00:19:15,000
|
| 1091 |
+
Thanks a lot for your attention.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:19:15,000 --> 00:19:18,000
|
| 1095 |
+
Have a great day here in the next lesson.
|
| 1096 |
+
|
25 - Input and Output Streams in Java/005 Source-code-examples-from-the-lesson-Cloning.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/cloning
|
25 - Input and Output Streams in Java/005 Source-code-examples-from-the-lesson-Serialization.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/io/serialization
|
25 - Input and Output Streams in Java/006 Quiz InputOutput Streams - 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 InputOutput Streams - 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 InputOutput Streams - Check yourself</div>
|
| 65 |
+
<div class="article-asset-container"><p><strong>Quiz Link: </strong><a href="https://forms.gle/jpwGZB1p7raYHuZ69" rel="noopener noreferrer" target="_blank"><strong>https://forms.gle/jpwGZB1p7raYHuZ69</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>Input and Output Streams in Java</p></li><li><p>Serialization and Object Cloning</p></li></ul><p><br></p><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&A section—I’m here to help!</p></li></ul></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
25 - Input and Output Streams in Java/external-links.txt
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
001 Source-code-examples-from-lesson
|
| 3 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/io
|
| 4 |
+
|
| 5 |
+
001 Homework
|
| 6 |
+
https://docs.google.com/document/d/12mpGjQti9SwYrCS-0RU-WNYtEQCKSFwjgiCS8iKDnTw/edit?usp=sharing
|
| 7 |
+
|
| 8 |
+
001 Solution-of-homework
|
| 9 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/io/hw
|
| 10 |
+
|
| 11 |
+
001 Solution-of-Homework-Online-store-with-data-storage
|
| 12 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/finaltask/storage
|
| 13 |
+
|
| 14 |
+
005 Source-code-examples-from-the-lesson-Serialization
|
| 15 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/io/serialization
|
| 16 |
+
|
| 17 |
+
005 Source-code-examples-from-the-lesson-Cloning
|
| 18 |
+
https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/cloning
|
| 19 |
+
|
| 20 |
+
005 Homework
|
| 21 |
+
https://docs.google.com/document/d/1gAwAtOMhaQOCIhc_QM8XreCn_QThfOxAKmw-ufTCk7Y/edit?usp=sharing
|
| 22 |
+
|
| 23 |
+
005 Homework-solution
|
| 24 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/finaltask/storage/impl/DefaultUserStoringService.java
|
26 - ===== IO in Java Interview Preparation =====/001 Part 1 Java IO Interview - Questions and Answers.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>Part 1 Java IO Interview - Questions and Answers</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">Part 1 Java IO Interview - Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>WHAT TYPES OF I/O STREAMS ARE THERE?</strong></p></li></ul><p><br></p><p>I/O streams are used to transfer data to file streams, to the console, or to network connections. There are two kinds of I/O streams: byte and character.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DIFFERENCE BETWEEN I/O AND NIO?</strong></p></li></ul><p><br></p><p>I / O (input / output, input-output) - the interaction between the information processor and its provider and / or recipient. Input is the signal or data received by the handler, and output is the signal or data sent by (or from) it.</p><p><br></p><p>NIO (/*in the context of Java*/ Non-blocking I/O, New I/O) is a collection of application programming interfaces for the Java language designed to implement high-performance I/O operations.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT FEATURES OF NIO DO YOU KNOW?</strong></p></li></ul><p><br></p><p>Key features of NIO:</p><ul><li><p>Channels and Selectors: NIO supports various types of channels. A pipe is an abstraction of lower-level file system objects (such as memory-mapped files and file locks) that allow data to be transferred at a faster rate. Channels are non-blocking, and therefore Java provides other tools such as a selector, which allows you to choose a ready channel for data transfer, and a socket, which is a tool for blocking.</p></li><li><p>Buffers: Java 7 introduced buffering for all primitive wrapper classes (except Boolean). An abstract Buffer class has appeared, which provides operations such as clear, flip, mark, etc. Its subclasses provide methods for getting and setting data.</p></li><li><p>Encodings: Java 7 introduced encodings (java.nio.charset), encoders and decoders for displaying Unicode bytes and characters.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>NAME THE MAIN CLASSES OF I/O STREAMS.</strong></p></li></ul><p><br></p><p>Byte streams: java.io.InputStream, java.io.OutputStream;</p><p>Character streams: java.io.Reader, java.io.Writer;</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>HOW ARE OUTPUTSTREAM, INPUTSTREAM, WRITER AND READER DIFFERENT?</strong></p></li></ul><p><br></p><p>The OutputStream class is an abstract class that defines streaming byte output. This category contains classes that define whether your data is going into a byte array (but not directly to a String; you are supposed to be able to create it from a byte array), to a file, or to a pipe.</p><p><br></p><p>The base class InputStream represents classes that receive data from various sources:</p><ul><li><p>byte array</p></li><li><p>string</p></li><li><p>file</p></li><li><p>channel (pipe): data is placed at one end and retrieved from the other</p></li><li><p>a sequence of different streams that can be combined into a single stream</p></li><li><p>other sources (for example, internet connection)</p></li></ul><p><br></p><p>Character streams have two main abstract classes, Reader and Writer, that manage streams of Unicode characters. The Reader class is an abstract class that defines character stream input. The Writer class is an abstract class that defines character stream output. In case of errors, all methods of the class throw an IOException.</p><p><br></p><p><br></p><ul><li><p><strong>WHICH SUBCLASSES OF THE INPUTSTREAM BASE CLASS DO YOU KNOW WHAT THEY ARE FOR?</strong></p></li></ul><p><br></p><p>Popular Subclasses of the base InputStream class:</p><ul><li><p>StringBufferInputStream - turns a string (String) into an InputStream.</p></li><li><p>SequenceInputStream - merges two or more InputStreams into a single stream.</p></li><li><p>PushbackInputStream - an input stream that supports a one-byte return to the input stream.</p></li><li><p>PipedInputStream - implements the concept of an input channel.</p></li><li><p>ObjectInputStream - input stream for objects.</p></li><li><p>InputStream is an abstract class that describes an input stream.</p></li><li><p>FilterInputStream is an abstract class that provides an interface for add-on classes that add useful properties to existing streams.</p></li><li><p>FileInputStream - for reading information from a file.</p></li><li><p>DataInputStream - An input stream that includes methods for reading standard Java data types.</p></li><li><p>ByteArrayInputStream - allows you to use an in-memory buffer (byte array) as the data source for the input stream.</p></li><li><p>BufferedInputStream - buffered input stream.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT DO YOU KNOW ABOUT RANDOMACCESSFILE?</strong></p></li></ul><p><br></p><p>RandomAccessFile is a class that inherits directly from Object and does not inherit from the I/O base classes above. Designed to work with files, supporting random access to their contents.</p><p><br></p><p>Working with the RandomAccessFile class is similar to using the DataInputStream and DataOutputStream streams combined in the same class (they implement the same DataInput and DataOutput interfaces). In addition, the seek() method allows you to move to a specific position and change the value stored there.</p><p><br></p><p>When using RandomAccessFile, you need to know the structure of the file. The RandomAccessFile class contains methods for reading and writing UTF-8 primitives and strings.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT FILE ACCESS MODES DO RANDOMACCESSFILE HAVE?</strong></p></li></ul><p><br></p><p>RandomAccessFile can be opened in read ("r") or read/write ("rw") mode. There is also an "rws" mode where the file is opened for read/write operations and every change to the file's data is immediately written to the physical device.</p><p><br></p><p><br></p><ul><li><p><strong>WHICH SUBCLASSES OF THE BASE CLASS OUTPUTSTREAM DO YOU KNOW WHAT THEY ARE FOR?</strong></p></li></ul><p><br></p><p>The OutputStream class is an abstract class that defines streaming byte output.</p><p>This category contains classes that define whether your data is going to a byte array (but not directly to a String; you are supposed to be able to create it from a byte array), to a file, or to a pipe.</p><p><br></p><p>Subclasses of the base class OutputStream:</p><ul><li><p>PipedOutputStream - implements the concept of an output channel.</p></li><li><p>ObjectOutputStream - output stream for objects</p></li><li><p>FilterOutputStream is an abstract class that provides an interface for add-on classes that add useful properties to existing streams.</p></li><li><p>FileOutputStream - send data to a file on disk. Implementation of the OutputStream class.</p></li><li><p>DataOutputStream - An output stream that includes methods for writing standard Java data types.</p></li><li><p>ByteArrayOutputStream - Creates an in-memory buffer. All data sent to this stream is placed in the created buffer.</p></li><li><p>BufferedOutputStream - buffered output stream.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS PUSHBACKINPUTSTREAM USED FOR?</strong></p></li></ul><p><br></p><p>A type of buffering that reads a byte and then returns it to the stream. The PushbackInputStream class provides a mechanism to "look" into the input stream and see what will come from there next time without extracting information.</p><p><br></p><p>The class has an additional unread() method.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS SEQUENCEINPUTSTREAM USED FOR?</strong></p></li></ul><p><br></p><p>The SequenceInputStream class allows multiple instances of the InputStream class to be chained together. The constructor takes as an argument either a pair of objects of the InputStream class or the Enumeration interface.</p><p>During operation, the class makes requests to read from the first object of the InputStream class to the end, and then switches to the second. When using the interface, work will continue on all objects of the InputStream class. When the end of each file is reached, the associated stream is closed. Closing a stream created by an object of the SequenceInputStream class closes all open streams.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHICH SUBCLASS OF THE READER BASE CLASS DO YOU KNOW WHAT THEY ARE FOR?</strong></p></li></ul><p><br></p><p>Subclasses of the Reader base class:</p><ul><li><p>StringReader is an input stream reading from a string.</p></li><li><p>Reader is an abstract class that describes character input.</p></li><li><p>PushbackReader is an input stream that allows characters to be pushed back into the stream.</p></li><li><p>PipedReader - input channel.</p></li><li><p>LineNumberReader - an input stream that counts lines.</p></li><li><p>InputStreamReader - an input stream that translates bytes into characters.</p></li><li><p>FilterReader - filter reader.</p></li><li><p>FileReader is an input stream that reads a file.</p></li><li><p>CharArrayReader - an input stream that reads from a character array.</p></li><li><p>BufferedReader - buffered input character stream.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHICH SUBCLASSES OF THE WRITER BASE CLASS DO YOU KNOW WHAT THEY ARE FOR?</strong></p></li></ul><p><br></p><p>Subclasses of the Writer base class:</p><ul><li><p>Writer - an abstract class that describes character output</p></li><li><p>StringWriter - the output stream writing to the string</p></li><li><p>PrintWriter - output stream including print() and println() methods</p></li><li><p>PipedWriter - the output pipe</p></li><li><p>OutputStreamWriter - output stream that translates bytes into characters</p></li><li><p>FilterWriter - filter writer</p></li><li><p>FileWriter - the output stream that writes to the file</p></li><li><p>CharArrayWriter - the output stream that writes to the character array</p></li><li><p>BufferedWriter - buffered output character stream</p></li></ul><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
26 - ===== IO in Java Interview Preparation =====/002 Part 2 Java IO Interview - Questions and Answers.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>Part 2 Java IO Interview - Questions and Answers</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">Part 2 Java IO Interview - Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>WHAT IS THE ABSOLUTE PATH AND RELATIVE PATH?</strong></p></li></ul><p><br></p><p>An absolute path is a path that points to the same location in the file system, regardless of the current directory. The full path always starts from the root directory.</p><p><br></p><p>A relative path is a path relative to the current working directory.</p><p><br></p><p><br></p><ul><li><p><strong>IN WHAT PACKAGES DO THE I/O CLASSES BE IN?</strong></p></li></ul><p><br></p><p>The standard I/O classes in Java are in the java.io.* package. JDK 7 added a more modern way of working with threads called Java NIO or Java New IO, these classes are in the java.nio.* package. To work with archives, classes from the java.util.* package are used.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT DO YOU KNOW ABOUT I/O WRAPPER CLASSES?</strong></p></li></ul><p>I/O wrapper classes are classes that add useful additional properties to existing streams.</p><p><br></p><p>Class examples: BufferedOutputStream, BufferedInputStrem, BufferedWriter , BufferedReader - buffer the stream and improve performance.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHICH CLASS ALLOWS READING DATA FROM INPUT BYTESTREAM IN THE FORMAT OF PRIMITIVE DATA TYPES?</strong></p></li></ul><p><br></p><p>To read byte data (not strings), use the DataInputStream class. In this case, you must use the classes from the InputStream group.</p><p><br></p><p>The getBytes() method is provided in the String class to convert a string into an array of bytes suitable for putting into a ByteArrayInputStream. The resulting ByteArrayInputStream is an InputStream suitable for passing the DataInputStream.</p><p><br></p><p>When reading characters byte-by-byte from a formatted DataInputStream using the readByte() method, any value received will be considered valid, so the return value is not applicable to identify the end of the stream. Instead, you can use the available() method, which tells you how many characters are left.</p><p><br></p><p>The DataInputStream class allows you to read primitive data types from a stream through the DataInput interface, which defines methods that convert elementary values to a sequence of bytes. Such streams make it easy to store binary data in a file.</p><p><br></p><p><br></p><ul><li><p><strong>WHICH CLASS-SUPPLIERS ALLOW TO ACCELERATE READ/WRITE BY USE OF THE BUFFER?</strong></p></li></ul><p><br></p><p>For this, classes are used that allow buffering the stream:</p><ul><li><p>java.io.BufferedInputStream - buffered input stream. Constructors: BufferedInputStream(InputStream in), BufferedInputStream(InputStream in, int size).</p></li><li><p>java.io.BufferedOutputStream - buffered output stream. Constructors: BufferedOutputStream(OutputStream out), BufferedOutputStream(OutputStream out, int size).</p></li><li><p>java.io.BufferedReader - buffered input character stream. Constructors: BufferedReader(Reader r), BufferedReader(Reader in, int sz).</p></li><li><p>java.io.BufferedWriter - buffered output character stream. Constructors: BufferedWriter(Writer out), BufferedWriter(Writer out, int sz).</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DIFFERENCE OF THE PRINTWRITER CLASS FROM PRINTSTREAM?</strong></p></li></ul><p><br></p><p>First of all, the PrintWriter class uses an improved way of working with UNICODE characters and a different output buffering mechanism.</p><p><br></p><p>In the PrintStream class, the output buffer was flushed whenever the print or println method was called. When using the PrintWriter class, you can disable automatically flushing buffers by doing it explicitly with the flush method.</p><p><br></p><p>The PrintWriter class provides two constructors that allow you to work with the output streams of the OutputStream class:</p><ul><li><p>public PrintWriter(OutputStream out); - creates a stream without automatically flushing buffers.</p></li><li><p>public PrintWriter(OutputStream out, boolean autoFlush); - the way buffers are flushed when using the second constructor depends on the value of the autoFlush parameter. If it is true, automatic flushing of buffers is performed, and if it is false, it is not.</p></li></ul><p><br></p><p>The set of implementations of the main print and println methods of the PrintWriter class is similar to the set of implementations of these methods of the PrintStream class.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHICH CLASS IS INTENDED TO WORK WITH FILE SYSTEM ELEMENTS?</strong></p></li></ul><p><br></p><p>Unlike most I/O classes, the File class does not work with streams, but directly with files. This class allows you to get information about the file: access rights, time and date of creation, directory path. And also to navigate through the hierarchies of subdirectories.</p><p><br></p><p>The java.io.File class can represent the name of a specific file, as well as the names of a group of files found in a directory. If the class represents a directory, then its list() method returns an array of strings with the names of all the files.</p><p><br></p><p>You can use one of the following constructors to create objects of the File class.</p><ul><li><p>File(File dir, String name) - you specify object of class File (the directory where file is located) and file name are specified</p></li><li><p>File(String path) - specify the path to the file without specifying the file name</p></li><li><p>File(String dirPath, Sring name) - specifies the path to the file and the file name</p></li><li><p>File(URI url) - specifies the URI object describing the file</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHICH CHARACTER IS THE DIVIDER FOR A PATH IN A FILE SYSTEM?</strong></p></li></ul><p><br></p><p>The delimiter symbol differs for different systems. You can pull it out from the property of the static field File.separator. For Windows it is "\".</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHICH FILE CLASS METHODS DO YOU KNOW?</strong></p></li></ul><p><br></p><p>The File class has a lot of methods, let's list some of them.</p><ul><li><p>getAbsolutePath() - the absolute path of the file, starting from the system root. In Android, the root element is the slash character (/)</p></li><li><p>canRead() - verifies whether the file is available for reading</p></li><li><p>canWrite() - available for writing</p></li><li><p>exists() - file exists or not</p></li><li><p>getName() - returns the file name</p></li><li><p>getParent() - returns the name of the parent directory</p></li><li><p>getPath() - path</p></li><li><p>lastModified() - last modified date</p></li><li><p>isFile() - the object is a file, not a directory</p></li><li><p>isDirectory() - the object is a directory</p></li><li><p>isAbsolute() - returns true if the file has an absolute path</p></li><li><p>renameTo(File newPath) - Renames a file. The parameter specifies the name of the new file name. If the rename was unsuccessful, then false is returned.</p></li><li><p>delete() - deletes a file. You can also delete an empty directory</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT DO YOU KNOW ABOUT THE FILEFILTER INTERFACE?</strong></p></li></ul><p><br></p><p>The FileFilter interface is used to check if a File object matches a certain condition. This interface contains a single boolean accept(File pathName) method. This method must be overridden and implemented.</p><p><br></p><p><br></p><ul><li><p><strong>WHICH CLASSES ALLOW OBJECTS TO ARCHIVE?</strong></p></li></ul><p><br></p><p>DeflaterOutputStream, InflaterInputStream, ZipInputStream, ZipOutputStream, GZIPInputStream, GZIPOutputStream.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS SERIALIZATION?</strong></p></li></ul><p><br></p><p>Serialization is the process of reading or writing an object. It is the process of saving the state of an object and reading that state. To implement serialization, you need to implement an interface - the Serializable marker interface. The reverse operation - translating bytes into an object, is called deserialization.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>HOW TO EXCLUDE FIELDS FROM SERIALIZATION?</strong></p></li></ul><p><br></p><p>In order to exclude fields from the serializable stream, it is necessary to mark the field with the transient modifier.</p><p><br></p><p><br></p><ul><li><p><strong>TRANSIENT WHAT DOES IT MEAN?</strong></p></li></ul><p><br></p><p>Class properties marked with the transient modifier are not serialized. Typically, such fields store the intermediate state of the object, which, for example, is easier to calculate than to serialize and then deserialize. Another example of such a field is a reference to an instance of an object that does not require or cannot be serialized.</p><p><br></p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE ROLE OF THE SERIALVERSIONUID FIELD IN SERIALIZATION?</strong></p></li></ul><p><br></p><p>The private static final long serialVersionUID field contains the unique version identifier of the serialized class. It is calculated from the contents of the class - the fields, their declaration order, the methods, their declaration order. Accordingly, with any change in the class, this field will change its value.</p><p><br></p><p>This field is written to the stream when the class is serialized. By the way, this is perhaps the only known case when a static field is serialized.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT CLASSES ALLOW TO CONVERT BYTE STREAMS TO CHARACTER AND BACK?</strong></p></li></ul><p><br></p><p>The OutputStreamWriter is a bridge between the OutputStream class and the Writer class. Characters written to the stream are converted to bytes.</p><p><br></p><p>InputStreamReader - analogue for reading. Using the methods of the Reader class, bytes are read from the InputStream and then converted into characters.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>HOW TO CHANGE THE STANDARD SERIALIZATION/DESERIALIZATION BEHAVIOR?</strong></p></li></ul><p><br></p><p>In most cases, we do not define behavior manually, but rely on the standard implementation, and it is very inconvenient to constantly override some serialization methods + constantly monitor the addition of new fields, add them to methods. Well and specially for these purposes - there is Externalizable.</p><p>However, we know that you can change the default behavior of serialization by predefining and placing two methods in your class files:</p><p><br></p><ul><li><p>private void writeObject(ObjectOutputStream out) throws IOException;</p></li><li><p>private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException;</p></li></ul><p><br></p><p>Note that both methods are declared private as this ensures that the methods are not overridden or overloaded. The whole trick is that the virtual machine, when calling the corresponding method, automatically checks if they were declared in the object class. The virtual machine can call the private methods of your class at any time, but other objects cannot. This ensures the integrity of the class and the normal operation of the serialization protocol.</p><p><br></p><p><br></p><ul><li><p><strong>HOW TO CREATE YOUR OWN SERIALIZATION PROTOCOL?</strong></p></li></ul><p><br></p><p>Instead of implementing the Serializable interface, you can implement the Externalizable interface, which contains two methods:</p><p><br></p><ul><li><p>public void writeExternal(ObjectOutput out) throws IOException;</p></li><li><p>public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;</p></li></ul><p><br></p><p>To create your own protocol, you just need to override these two methods. Unlike the other two serialization options, nothing is done automatically here. The protocol is completely in your hands. Although this is the most difficult method, it is also brings you the most controll over serialization process.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE PROBLEM OF SERIALIZING SINGLETON OBJECTS?</strong></p></li></ul><p><br></p><p>The problem is that after deserialization we will get another object. So serialization makes it possible to create a Singleton again, which is not what we want when we design singleton. Of course, you can forbid serializing Singletons, but this, in fact, is an avoidance of the problem, not a solution to it.</p><p><br></p><p>The solution is the following. The class defines a method with the following signature:</p><p><br></p><ul><li><p><ANY_ACCESS_MODIFIER> readResolve() throws ObjectStreamException;</p></li></ul><p><br></p><p>The access modifier can be private, protected, and default. The purpose of this method is to return a replacement object instead of the object on which it is called.</p><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
27 - Multithreading/001 Multithreading Overview_en.srt
ADDED
|
@@ -0,0 +1,740 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:11,000
|
| 3 |
+
Hello, yes, students today will start learning a new topic, Moonface Riden, this is huge topic,
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:11,000 --> 00:00:16,000
|
| 7 |
+
and after this course, you will have a lot of knowledge that you can apply in different programming
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:16,000 --> 00:00:21,000
|
| 11 |
+
languages to support not just execution, but in scope of this course.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:21,000 --> 00:00:27,000
|
| 15 |
+
I will show you how MultiThreaded works on Java examples and take into account this is the first lesson
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:27,000 --> 00:00:32,000
|
| 19 |
+
of new topic, this lesson a little bit more theoretical one to be sure that we have enough high level
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:32,000 --> 00:00:37,000
|
| 23 |
+
knowledge and understanding before we'll start sharing, quote, examples in the next lesson.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:37,000 --> 00:00:43,000
|
| 27 |
+
That's why today we'll focus our attention on such questions as what is the process in our computers?
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:43,000 --> 00:00:45,000
|
| 31 |
+
What is the threat of execution?
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:46,000 --> 00:00:52,000
|
| 35 |
+
What is multithreaded in programming also in this lesson and explain how multiscreen works and what
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:52,000 --> 00:00:54,000
|
| 39 |
+
threats and translation means.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:54,000 --> 00:00:59,000
|
| 43 |
+
And the standard answers on these questions will bring us to the point where we can discuss with you
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:59,000 --> 00:01:02,000
|
| 47 |
+
why multiscreen is needed and what a benefit, something which is written.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:03,000 --> 00:01:09,000
|
| 51 |
+
And also we'll discuss dark side of multithreaded to understand it, drawbacks and what we should always
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:09,000 --> 00:01:12,000
|
| 55 |
+
take into account while working as much as freedom.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:12,000 --> 00:01:17,000
|
| 59 |
+
And the end of the lesson, I will give you an overview of what packages and tools we are going to learn
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:17,000 --> 00:01:19,000
|
| 63 |
+
in this course in JDK.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:19,000 --> 00:01:25,000
|
| 67 |
+
Answering all these questions will give you insights on what we are going to learn in this course.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:25,000 --> 00:01:27,000
|
| 71 |
+
I believe we are good with our agenda for today.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:27,000 --> 00:01:34,000
|
| 75 |
+
Let's start and before we even start discussion of multithreaded in the program, let's understand what
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:34,000 --> 00:01:36,000
|
| 79 |
+
the process is in computer science.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:36,000 --> 00:01:40,000
|
| 83 |
+
In simple words, process is an instance of a computer program.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:41,000 --> 00:01:42,000
|
| 87 |
+
You opened a glimpse.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:42,000 --> 00:01:45,000
|
| 91 |
+
It's a separate process to run as a Java program.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:46,000 --> 00:01:47,000
|
| 95 |
+
Is that a separate Java process?
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:48,000 --> 00:01:53,000
|
| 99 |
+
Computer program is nothing more than a set of instructions for a machine but process.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:54,000 --> 00:01:56,000
|
| 103 |
+
It is an execution of these instructions.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:57,000 --> 00:02:00,000
|
| 107 |
+
A process has a self-contained execution environment.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:00,000 --> 00:02:04,000
|
| 111 |
+
That means that each process has its own memory space.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:05,000 --> 00:02:10,000
|
| 115 |
+
And as I said before, usually processes and programs are considered to be very close terms.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:11,000 --> 00:02:18,000
|
| 119 |
+
But what end user interaction with may be a set of processes that interact with each other doing no
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:18,000 --> 00:02:21,000
|
| 123 |
+
such popular Internet browser as Google Chrome?
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:21,000 --> 00:02:24,000
|
| 127 |
+
So long to go home and look at the task manager.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:25,000 --> 00:02:28,000
|
| 131 |
+
You will see separate processes for each stop in your browser.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:28,000 --> 00:02:33,000
|
| 135 |
+
But for the end user, Manglehorn perceived like a single application.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:33,000 --> 00:02:40,000
|
| 139 |
+
This is because most operating system support interpersonal communication resources, sap, pipes and
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:40,000 --> 00:02:41,000
|
| 143 |
+
sockets.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:41,000 --> 00:02:47,000
|
| 147 |
+
These resources are used to interact between different processes, homes, and this is pretty straightforward.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:48,000 --> 00:02:51,000
|
| 151 |
+
Now let's understand what threat of execution is.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:51,000 --> 00:02:56,000
|
| 155 |
+
Each process may be executed in one or more threats of execution.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:56,000 --> 00:02:59,000
|
| 159 |
+
In this case, our program is executed concurrently.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:59,000 --> 00:03:03,000
|
| 163 |
+
In other words, some instructions are executed in parallel.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:03,000 --> 00:03:09,000
|
| 167 |
+
In computer science, concurrency is a duplicate of different parts or units of a program algorithm
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:10,000 --> 00:03:17,000
|
| 171 |
+
or problem to be executed out of order or at the same time simultaneously without affecting the final
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:17,000 --> 00:03:17,000
|
| 175 |
+
outcome.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:18,000 --> 00:03:22,000
|
| 179 |
+
So we can say that each process may be executed in multiple threats.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:23,000 --> 00:03:27,000
|
| 183 |
+
In the learning literature, you might even find mention about different name of abstracts.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:27,000 --> 00:03:34,000
|
| 187 |
+
Sometimes they're called as lightweight processes or threats, share process resources.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:34,000 --> 00:03:37,000
|
| 191 |
+
This is something that may cause issues during the multithreaded.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:38,000 --> 00:03:44,000
|
| 195 |
+
If you're allocated two gigabytes for a GBM, that means all created stress will work within these two
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:44,000 --> 00:03:47,000
|
| 199 |
+
gigabytes and we'll share in between each other.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:48,000 --> 00:03:51,000
|
| 203 |
+
Knowing your memory will be allocated to threat of execution.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:52,000 --> 00:03:54,000
|
| 207 |
+
I hope you already know the answer to my next question.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:55,000 --> 00:03:56,000
|
| 211 |
+
What is a move to threaten?
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:03:57,000 --> 00:04:01,000
|
| 215 |
+
To threaten is the process of execution of program in multiple threats.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:01,000 --> 00:04:04,000
|
| 219 |
+
Most of the operating systems nowadays support this feature.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:05,000 --> 00:04:11,000
|
| 223 |
+
You have multiple course in your processa multithreaded allows you to use all course for execution of
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:11,000 --> 00:04:13,000
|
| 227 |
+
your program instructions.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:13,000 --> 00:04:21,000
|
| 231 |
+
EPU executes one task at a time and we as the software engineers will write instructions how to split
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:22,000 --> 00:04:23,000
|
| 235 |
+
between different threats of execution.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:24,000 --> 00:04:25,000
|
| 239 |
+
That's what we are going to learn.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:26,000 --> 00:04:27,000
|
| 243 |
+
Let me explain it now.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:27,000 --> 00:04:32,000
|
| 247 |
+
How multiscreen program works on the high level, you always have one threat of execution.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:32,000 --> 00:04:34,000
|
| 251 |
+
One program just started.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:34,000 --> 00:04:36,000
|
| 255 |
+
That is your main threat of execution.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:37,000 --> 00:04:43,000
|
| 259 |
+
After that, you can run so-called child threats of execution and describe instructions what those threats
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:04:43,000 --> 00:04:44,000
|
| 263 |
+
should work on.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:04:44,000 --> 00:04:48,000
|
| 267 |
+
In parallel, the different use cases of using Otis Redding.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:04:48,000 --> 00:04:49,000
|
| 271 |
+
And we'll look at them in the minute.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:04:50,000 --> 00:04:56,000
|
| 275 |
+
And now the important thing, how to synchronize the work of different threats imagines at your peril
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:04:56,000 --> 00:04:58,000
|
| 279 |
+
to your work between multiple threats.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:04:59,000 --> 00:05:00,000
|
| 283 |
+
It is another thing that.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:00,000 --> 00:05:06,000
|
| 287 |
+
All of the threats are part of one program, and sometimes threat needs to update on the man's threat
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:06,000 --> 00:05:09,000
|
| 291 |
+
about state of execution or result of execution.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:10,000 --> 00:05:15,000
|
| 295 |
+
But sometimes threats also need to interact with each other, take into account all threats, working
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:15,000 --> 00:05:17,000
|
| 299 |
+
with some shared resource.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:17,000 --> 00:05:23,000
|
| 303 |
+
To rephrase this in simple words, imagine that you have a collection of users and you need to filter
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:23,000 --> 00:05:28,000
|
| 307 |
+
this collection and remove users that have less than one thousand dollars total.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:28,000 --> 00:05:34,000
|
| 311 |
+
Check in your online shop and you decided to split the task between different threats of execution.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:05:34,000 --> 00:05:39,000
|
| 315 |
+
Each threat of execution works with shared resource collection of users.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:05:39,000 --> 00:05:46,000
|
| 319 |
+
Each threat takes users from this common collection to provide the result of the specific part of namely
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:05:46,000 --> 00:05:53,000
|
| 323 |
+
users are equally distributed between different threats but all threats to removing users from the common
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:05:53,000 --> 00:05:55,000
|
| 327 |
+
collection shared between all of them.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:05:55,000 --> 00:05:59,000
|
| 331 |
+
Can you understand what the shared resource mean on this example?
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:00,000 --> 00:06:05,000
|
| 335 |
+
Let's review also other use cases of multithreaded programming and the one we might want to use this
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:05,000 --> 00:06:05,000
|
| 339 |
+
approach.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:06,000 --> 00:06:08,000
|
| 343 |
+
I believe that we have already discussed the first case.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:09,000 --> 00:06:15,000
|
| 347 |
+
That is the case when different threats on these slides are marked with capital key and numbers reaching
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:15,000 --> 00:06:22,000
|
| 351 |
+
out to shared resource that is marked with capital are in this case to modify the state of the resource.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:23,000 --> 00:06:27,000
|
| 355 |
+
So next year's case of using multithreaded is reading and writing operations.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:28,000 --> 00:06:33,000
|
| 359 |
+
You know that in Java, most of the input output streams, blogs and in process of execution.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:34,000 --> 00:06:37,000
|
| 363 |
+
So why don't we use features of malicious reading?
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:37,000 --> 00:06:42,000
|
| 367 |
+
And in case we need to write, let's say, some file, we do this in a separate thread.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:06:42,000 --> 00:06:50,000
|
| 371 |
+
For example, a user asked us to do an expert of all users to see format and wants to download this
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:06:50,000 --> 00:06:50,000
|
| 375 |
+
info.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:06:50,000 --> 00:06:52,000
|
| 379 |
+
No problem at all.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:06:52,000 --> 00:06:58,000
|
| 383 |
+
We are writing a separate threat of execution and other parts of our program proceed, working without
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:06:58,000 --> 00:07:05,000
|
| 387 |
+
any free's user still able to click on other buttons and perform other operations while file downloading
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:05,000 --> 00:07:06,000
|
| 391 |
+
is in progress.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:06,000 --> 00:07:07,000
|
| 395 |
+
Is that clear?
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:07,000 --> 00:07:09,000
|
| 399 |
+
Same situation with redundant info.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:10,000 --> 00:07:16,000
|
| 403 |
+
Let's create a separate threat of execution that will show a status of uploading, and once uploading
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:16,000 --> 00:07:21,000
|
| 407 |
+
is finished, we will be notified about that fact and we'll proceed from there.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:21,000 --> 00:07:27,000
|
| 411 |
+
Pay attention to how your clips is working when your important project or performance some other operations.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:28,000 --> 00:07:32,000
|
| 415 |
+
Eclipse is also Java application was multithreaded feature inside.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:07:32,000 --> 00:07:39,000
|
| 419 |
+
When any operation is performed, UI is not completely blocked and you still can perform as operations
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:07:39,000 --> 00:07:40,000
|
| 423 |
+
with the clips in parallel.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:07:41,000 --> 00:07:47,000
|
| 427 |
+
The third case is a case when once to produce some data and other thread consumes this data.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:07:48,000 --> 00:07:54,000
|
| 431 |
+
These threads are working independently and potentially may interact with the help of the queue between
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:07:54,000 --> 00:07:54,000
|
| 435 |
+
each other.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:07:55,000 --> 00:08:02,000
|
| 439 |
+
On the slide here you can see that we have producer and consumer producer send some item ready for processing
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:02,000 --> 00:08:08,000
|
| 443 |
+
to the queue and consumer take this item from the queue when ready to process the next item.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:08,000 --> 00:08:12,000
|
| 447 |
+
The next case is a typical scenario with writers and readers.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:13,000 --> 00:08:19,000
|
| 451 |
+
Imagine that you have some shared resource, some shared buffer, and from one side you have writers
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:19,000 --> 00:08:21,000
|
| 455 |
+
that might be separate services.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:21,000 --> 00:08:24,000
|
| 459 |
+
Read that, write some information to the buffer.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:24,000 --> 00:08:28,000
|
| 463 |
+
It can be is a strong representation of new objects or requests to the app.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:28,000 --> 00:08:30,000
|
| 467 |
+
Literally everything.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:08:30,000 --> 00:08:34,000
|
| 471 |
+
And on the other side, you have readers that read data from the buffer.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:08:35,000 --> 00:08:41,000
|
| 475 |
+
This example is different from all previous ones that we have discussed because here we have some specific
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:08:41,000 --> 00:08:47,000
|
| 479 |
+
conditions on the ones that can write to the buffer at the point of time readers can to read during
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:08:47,000 --> 00:08:53,000
|
| 483 |
+
the writing, all the readers may read data simultaneously, will have similar tasks in this course.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:08:53,000 --> 00:08:56,000
|
| 487 |
+
And I will show you how to solve this task.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:08:56,000 --> 00:08:58,000
|
| 491 |
+
Really interesting, don't you think so?
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:08:59,000 --> 00:09:03,000
|
| 495 |
+
Probably these are the most popular use cases of using an Otis Redding approach.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:03,000 --> 00:09:10,000
|
| 499 |
+
Definitely there will be variations of these use cases and sometimes even different scenarios, but
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:09:10,000 --> 00:09:13,000
|
| 503 |
+
we'll try to cover as much as we can on this course.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:13,000 --> 00:09:17,000
|
| 507 |
+
Now let's discuss advantages and disadvantages of multi threading approach.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:18,000 --> 00:09:20,000
|
| 511 |
+
Let's start from advantages of multithreaded.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:20,000 --> 00:09:22,000
|
| 515 |
+
It was to name a few important ones.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:22,000 --> 00:09:29,000
|
| 519 |
+
They are effective use of multiple course of your processa, high performance of your program during
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:09:29,000 --> 00:09:32,000
|
| 523 |
+
execution of specific operations and data processing.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:09:33,000 --> 00:09:36,000
|
| 527 |
+
Good to use with operations that block mansard of execution.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:09:37,000 --> 00:09:43,000
|
| 531 |
+
Like I said before, in case of working with input output streams, application responsiveness, if
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:09:43,000 --> 00:09:49,000
|
| 535 |
+
there is a need to perform, some operation application won't be frozen until that operation is completed.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:09:50,000 --> 00:09:53,000
|
| 539 |
+
Instead, I will execute request in a separate thread.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:09:54,000 --> 00:10:00,000
|
| 543 |
+
Probably these are main advantages of using these advantages, maintaining the Australian approach.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:00,000 --> 00:10:06,000
|
| 547 |
+
Across all over the world and in different programming languages, but there are always two sides of
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:10:06,000 --> 00:10:10,000
|
| 551 |
+
a metal, all these advantages come with a group of disadvantages.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:10:10,000 --> 00:10:17,000
|
| 555 |
+
Some of them are it is easy to use is written incorrectly by saying this, I would like to highlight
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:10:17,000 --> 00:10:18,000
|
| 559 |
+
that using what is right.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:18,000 --> 00:10:24,000
|
| 563 |
+
And it requires a good understanding of the toolset to implement concurrent execution of your program.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:24,000 --> 00:10:26,000
|
| 567 |
+
And that is relatively easy to do.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:26,000 --> 00:10:32,000
|
| 571 |
+
A mistake, for example, in synchronous court, sometimes also of execution doesn't play a big role.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:10:33,000 --> 00:10:39,000
|
| 575 |
+
Or you can write code in different ways with the thread and it is not so easy and straightforward.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:10:40,000 --> 00:10:46,000
|
| 579 |
+
You need to be sure about what pieces of code you need to synchronize between different threads, how
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:10:46,000 --> 00:10:50,000
|
| 583 |
+
much stress you need, how to split work between threads and so on.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:10:50,000 --> 00:10:55,000
|
| 587 |
+
Incorrect and suitable usage of Montasser in May cause your performance.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:10:56,000 --> 00:11:00,000
|
| 591 |
+
You need to understand that multithreaded works perfectly, not for all tasks.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:01,000 --> 00:11:06,000
|
| 595 |
+
For example, you might not always see the benefit of using what is written while working with small
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:11:06,000 --> 00:11:12,000
|
| 599 |
+
data in case you want to implement a certain approach and filter an election was one hundred integers.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:11:12,000 --> 00:11:18,000
|
| 603 |
+
More likely, it will take more time than performing the same operation synchronously in one step.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:11:19,000 --> 00:11:19,000
|
| 607 |
+
Why?
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:11:20,000 --> 00:11:26,000
|
| 611 |
+
Because running threads, synchronization time, corporatization of different threads on different CPUs.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:26,000 --> 00:11:31,000
|
| 615 |
+
All of this takes time and we need to be sure that when we apply to certain approach, it is really
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:31,000 --> 00:11:38,000
|
| 619 |
+
worth it and we will benefit from this and some mistakes even can bring it to the deadlock and lifework
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:11:38,000 --> 00:11:39,000
|
| 623 |
+
cases.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:11:39,000 --> 00:11:45,000
|
| 627 |
+
When your program doesn't perform any useful activity, hard to debark application and find the mistake,
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:11:46,000 --> 00:11:52,000
|
| 631 |
+
it is much harder to replicate an error in the multithreaded application than it is to do so in a single
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:11:52,000 --> 00:11:53,000
|
| 635 |
+
threaded application.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:11:53,000 --> 00:11:58,000
|
| 639 |
+
As a result, it is more difficult to identify and verify root causes when error.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:11:58,000 --> 00:12:03,000
|
| 643 |
+
Secure testing process of multithreaded app is more difficult.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:12:03,000 --> 00:12:09,000
|
| 647 |
+
Testing the multithreaded application is more difficult than testing a single application because the
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:12:09,000 --> 00:12:13,000
|
| 651 |
+
effects are often timing related and more difficult to reproduce.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:12:13,000 --> 00:12:19,000
|
| 655 |
+
It is difficult to introduce notice writing approach already created code because all code needs to
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:12:19,000 --> 00:12:24,000
|
| 659 |
+
be analyzed by engineers, static variables, methods and locations and critical areas.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:12:24,000 --> 00:12:30,000
|
| 663 |
+
Everything needs to be reviewed and adjusted to make sure that the implementation of concurrent programming
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:12:30,000 --> 00:12:32,000
|
| 667 |
+
approach will not affect all application.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:33,000 --> 00:12:39,000
|
| 671 |
+
The main disadvantages of multithreaded that we also need to consider when we want to create scalable
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:39,000 --> 00:12:40,000
|
| 675 |
+
app with high performance.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:12:41,000 --> 00:12:47,000
|
| 679 |
+
In this course, we are going to learn tools for concurrent programming most tools, classes and interfaces
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:12:47,000 --> 00:12:48,000
|
| 683 |
+
allocated in Java.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:12:48,000 --> 00:12:50,000
|
| 687 |
+
You can current package.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:12:50,000 --> 00:12:57,000
|
| 691 |
+
This package also has some set packages, also some main types like Runnable and Thread located in general
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:12:57,000 --> 00:12:58,000
|
| 695 |
+
and package.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:12:58,000 --> 00:13:05,000
|
| 699 |
+
But most of the classes and interfaces, including concurrent collections, locks and other mechanisms
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:05,000 --> 00:13:10,000
|
| 703 |
+
for stress synchronization executer services and most of the things that we are going to learn allocated
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:13:10,000 --> 00:13:12,000
|
| 707 |
+
individual concurrent package.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:13:12,000 --> 00:13:15,000
|
| 711 |
+
We have really a lot of interesting things to learn.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:13:15,000 --> 00:13:19,000
|
| 715 |
+
Now let's recap what we have learned in this lesson and this lesson.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:13:19,000 --> 00:13:22,000
|
| 719 |
+
We learned what the process is and what the threat is.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:13:23,000 --> 00:13:28,000
|
| 723 |
+
We also learned what is a multiscreen program programming now, you know, the most popular use cases
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:13:28,000 --> 00:13:30,000
|
| 727 |
+
of not just training programs.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:13:30,000 --> 00:13:34,000
|
| 731 |
+
We learned advantages and disadvantages of concurrent programming.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:13:35,000 --> 00:13:36,000
|
| 735 |
+
That's all for this lesson.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:13:36,000 --> 00:13:39,000
|
| 739 |
+
Looking forward to seeing you in the next lesson.
|
| 740 |
+
|
27 - Multithreading/002 First Multithreading Program Thread & Runnable_en.srt
ADDED
|
@@ -0,0 +1,1480 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
Yes, students in this class and will create our first multithreaded program.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:10,000 --> 00:00:14,000
|
| 11 |
+
It is time to put our theoretical knowledge on practice and learn new things.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:14,000 --> 00:00:20,000
|
| 15 |
+
We'll start from understanding of threat lifecycle and in which states our threat may be and when will
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:20,000 --> 00:00:22,000
|
| 19 |
+
jump to practical examples.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:22,000 --> 00:00:24,000
|
| 23 |
+
You'll have enough knowledge to understand that.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:25,000 --> 00:00:29,000
|
| 27 |
+
And this lesson I will show you how to create a threat with five different ways.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:29,000 --> 00:00:35,000
|
| 31 |
+
We are going to learn such basic laws for multithreaded in general threat and one of the most important
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:35,000 --> 00:00:36,000
|
| 35 |
+
interfaces.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:36,000 --> 00:00:37,000
|
| 39 |
+
Runnable.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:37,000 --> 00:00:43,000
|
| 43 |
+
While showing you examples, I will focus your attention on main properties of threat class to describe
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:43,000 --> 00:00:44,000
|
| 47 |
+
each state.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:44,000 --> 00:00:50,000
|
| 51 |
+
And once we Iran's threats, we will learn with you how we can interact execution of a threat.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:50,000 --> 00:00:56,000
|
| 55 |
+
We'll discuss methods that are deprecated for a long time already and that you never should use.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:56,000 --> 00:00:59,000
|
| 59 |
+
And also we'll talk about proper ways of threat interaction.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:00,000 --> 00:01:03,000
|
| 63 |
+
Today, we're going to have a lot of good examples.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:03,000 --> 00:01:09,000
|
| 67 |
+
And as we will go over the examples, I will also explain specifics of some methods and behavior of
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:09,000 --> 00:01:09,000
|
| 71 |
+
threats.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:10,000 --> 00:01:10,000
|
| 75 |
+
Let's start.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:11,000 --> 00:01:17,000
|
| 79 |
+
And as I said before, let's start from the understanding the whole lifecycle of a threat is considered
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:17,000 --> 00:01:18,000
|
| 83 |
+
to be a new one.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:18,000 --> 00:01:20,000
|
| 87 |
+
We just created an object of a threat.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:21,000 --> 00:01:23,000
|
| 91 |
+
And you know that in Java, everything is an object.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:24,000 --> 00:01:28,000
|
| 95 |
+
That's why threat of execution is also an object to run a threat.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:28,000 --> 00:01:35,000
|
| 99 |
+
We need to start massive because mass that creates a separate threat of execution within the Java process.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:36,000 --> 00:01:38,000
|
| 103 |
+
After that threat is in the running state.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:38,000 --> 00:01:44,000
|
| 107 |
+
In this state, we can make our threat not run by turning our threat into waiting state or block state.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:45,000 --> 00:01:50,000
|
| 111 |
+
During this course, we will discuss all these scenarios, for example, when threat is blocked and
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:50,000 --> 00:01:57,000
|
| 115 |
+
when it's waiting for now, you need just to understand that running threat may be put on pause and
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:57,000 --> 00:02:01,000
|
| 119 |
+
getting back to running state again as engineers will learn how to do this.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:02,000 --> 00:02:06,000
|
| 123 |
+
Sometimes threats waiting their chance to update a shared resource.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:06,000 --> 00:02:12,000
|
| 127 |
+
Sometimes we want to make a threat, wait until other threats will adjust it of our shared resource.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:12,000 --> 00:02:16,000
|
| 131 |
+
And the last possible state of our threat is a Terminator's state.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:16,000 --> 00:02:21,000
|
| 135 |
+
This state tells us that threat finished its execution or it was interrupted.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:22,000 --> 00:02:24,000
|
| 139 |
+
Is it clear now when you're no threat?
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:24,000 --> 00:02:27,000
|
| 143 |
+
Life-cycle it is time to write our first.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:27,000 --> 00:02:32,000
|
| 147 |
+
Just read an application I open file was named first just writing program.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:32,000 --> 00:02:34,000
|
| 151 |
+
I have main message here.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:34,000 --> 00:02:37,000
|
| 155 |
+
Let me go line by line and explain you each role here.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:38,000 --> 00:02:44,000
|
| 159 |
+
You can see that the first thing that I do here, I declare a variable of type Runnable and initialize
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:44,000 --> 00:02:46,000
|
| 163 |
+
it with new object of type default.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:02:46,000 --> 00:02:47,000
|
| 167 |
+
Runnable.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:02:47,000 --> 00:02:52,000
|
| 171 |
+
Let me open source code of Runnable type, because you see this time the first time in this course,
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:02:53,000 --> 00:02:56,000
|
| 175 |
+
as you can see, this is an interface from the Java version.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:02:56,000 --> 00:03:01,000
|
| 179 |
+
What does a functional interface was only one abasic mass with name.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:01,000 --> 00:03:01,000
|
| 183 |
+
Right.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:02,000 --> 00:03:06,000
|
| 187 |
+
We see that this method returns nassan and return type is void.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:06,000 --> 00:03:13,000
|
| 191 |
+
This is exactly the method that we need to implement and where we need to put a code that will be executed
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:13,000 --> 00:03:18,000
|
| 195 |
+
in the separate thread to have separate thread, we need to have instructions about what this thread
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:18,000 --> 00:03:23,000
|
| 199 |
+
is supposed to do and these instructions should be written somewhere.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:23,000 --> 00:03:26,000
|
| 203 |
+
This is exactly the method that will be executed by thread.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:27,000 --> 00:03:33,000
|
| 207 |
+
Let's now check the source code of a default runnable we see as a default Runnable implements Runnable
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:33,000 --> 00:03:34,000
|
| 211 |
+
interface.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:03:34,000 --> 00:03:41,000
|
| 215 |
+
Basically, this is my custom clause that gives implementation to run Macel inside this matter.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:03:41,000 --> 00:03:43,000
|
| 219 |
+
I print such text to console.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:03:43,000 --> 00:03:45,000
|
| 223 |
+
I'm a new threat.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:03:45,000 --> 00:03:52,000
|
| 227 |
+
My name is and here I call static method on class will learn this class in a minute.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:03:52,000 --> 00:03:58,000
|
| 231 |
+
But just to finish explanation of this line, current threat is a static method of threat class that
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:03:58,000 --> 00:04:00,000
|
| 235 |
+
returns the reference to the threat object.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:01,000 --> 00:04:08,000
|
| 239 |
+
And depending on where this method is invoked, we receive the reference to the object of current threat.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:08,000 --> 00:04:13,000
|
| 243 |
+
And after that I just call that name method that returns is a name of the threat.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:13,000 --> 00:04:18,000
|
| 247 |
+
I want to bring this text to console to prove that we have separate threat of execution.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:18,000 --> 00:04:20,000
|
| 251 |
+
One will run our app.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:20,000 --> 00:04:24,000
|
| 255 |
+
But before doing that, let's investigate threat glass.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:24,000 --> 00:04:26,000
|
| 259 |
+
Let me open the source code of this class.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:04:27,000 --> 00:04:31,000
|
| 263 |
+
The first thing is that you can notice here is that threat also implements Runnable.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:04:32,000 --> 00:04:33,000
|
| 267 |
+
What does this mean?
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:04:33,000 --> 00:04:38,000
|
| 271 |
+
This means that the object of threat type also may be executed as a separate threat.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:04:38,000 --> 00:04:42,000
|
| 275 |
+
And this class also has implementation of around MassArt.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:04:42,000 --> 00:04:43,000
|
| 279 |
+
Let's look at it.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:04:43,000 --> 00:04:49,000
|
| 283 |
+
As we can see, the first things that object will try to do is to check whether we have target field
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:04:49,000 --> 00:04:49,000
|
| 287 |
+
initialized.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:04:49,000 --> 00:04:53,000
|
| 291 |
+
And if yes, then we'll call run Masset on that object.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:04:54,000 --> 00:04:57,000
|
| 295 |
+
And if not, then we'll just do nothing.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:04:57,000 --> 00:05:02,000
|
| 299 |
+
Target Field has Runnable type and we can see even Kermanshah above this field.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:02,000 --> 00:05:03,000
|
| 303 |
+
This is something.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:03,000 --> 00:05:08,000
|
| 307 |
+
What will be around so as you can understand, we can do two things here.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:08,000 --> 00:05:16,000
|
| 311 |
+
We can pass Runnable object to the threat glass or we can override run Masad in Third-Class, we can
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:05:16,000 --> 00:05:18,000
|
| 315 |
+
pass Runnable to this class.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:05:18,000 --> 00:05:19,000
|
| 319 |
+
We are constructor.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:05:19,000 --> 00:05:23,000
|
| 323 |
+
We have really a lot of different versions of constructor for this type.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:05:23,000 --> 00:05:30,000
|
| 327 |
+
And one of the constructor is to accept and initialize target field to store the reference to the Runnable
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:05:30,000 --> 00:05:30,000
|
| 331 |
+
object.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:05:31,000 --> 00:05:37,000
|
| 335 |
+
Interesting thing to notice here is that this constructor invokes another version of constructor.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:05:37,000 --> 00:05:39,000
|
| 339 |
+
It passes in reference to the REDgroup.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:05:40,000 --> 00:05:42,000
|
| 343 |
+
We'll discuss a little bit later.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:05:42,000 --> 00:05:48,000
|
| 347 |
+
What does it reference to our Runnable object name of the thread, which consists of the word thread
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:05:48,000 --> 00:05:50,000
|
| 351 |
+
dash and the sequential number.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:05:50,000 --> 00:05:53,000
|
| 355 |
+
Is it a static variable name thread in it?
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:05:53,000 --> 00:06:00,000
|
| 359 |
+
No, that is incremented every time when the next threatener method and the last argument is a stack
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:00,000 --> 00:06:07,000
|
| 363 |
+
size zero because according to the recommendation, in case this argument is zero, we have no requirement
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:07,000 --> 00:06:09,000
|
| 367 |
+
for specific text size for this new threat.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:06:10,000 --> 00:06:15,000
|
| 371 |
+
And the new constructor Interent calls new constructor that passes to more arguments.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:06:15,000 --> 00:06:23,000
|
| 375 |
+
New and true new value is supposed to cover such constructor argument as access control context and
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:06:23,000 --> 00:06:29,000
|
| 379 |
+
true value is the flag to indicate whether we need to inherit initial values for inheritable threat
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:06:29,000 --> 00:06:31,000
|
| 383 |
+
logos from the construction threat.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:06:32,000 --> 00:06:34,000
|
| 387 |
+
Let me explain what these things meant.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:06:35,000 --> 00:06:42,000
|
| 391 |
+
Access control context is a type that is used to create objects that make system access decisions based
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:06:42,000 --> 00:06:44,000
|
| 395 |
+
on the context it encapsulates.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:06:44,000 --> 00:06:50,000
|
| 399 |
+
Check permission Massada that is invoked in the context that access control context encapsulates inside
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:06:51,000 --> 00:06:56,000
|
| 403 |
+
is allowed to process was access to resources or access control exception.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:06:56,000 --> 00:07:00,000
|
| 407 |
+
Anyway, this is not the topic for the first lesson of not just reading.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:00,000 --> 00:07:04,000
|
| 411 |
+
And this is not what you will use on a daily basis directly while working with me.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:04,000 --> 00:07:05,000
|
| 415 |
+
Just read it.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:07:05,000 --> 00:07:07,000
|
| 419 |
+
But just in order to let you know.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:07:08,000 --> 00:07:10,000
|
| 423 |
+
Regarding the second argument inherits read.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:07:10,000 --> 00:07:13,000
|
| 427 |
+
Locals do not pay a lot of attention to this one.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:07:13,000 --> 00:07:20,000
|
| 431 |
+
And this moment will cover concept of threat locals and inheritable threat local separately, but ensured
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:07:20,000 --> 00:07:26,000
|
| 435 |
+
this flag is to tell threat whether we need to inherit values from inheritable threat local from the
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:07:26,000 --> 00:07:27,000
|
| 439 |
+
construction threat.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:07:27,000 --> 00:07:32,000
|
| 443 |
+
And basically after that we proceed with construction of our threat of execution.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:07:33,000 --> 00:07:38,000
|
| 447 |
+
Besides the construction of Runnable that we have just discussed, we have also different constructors
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:07:38,000 --> 00:07:44,000
|
| 451 |
+
that initializes other properties of threat object, for example, threat that takes Runnable and access
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:07:44,000 --> 00:07:51,000
|
| 455 |
+
control context, constructor that takes REDgroup and Runnable also another popular constructor for
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:07:51,000 --> 00:07:54,000
|
| 459 |
+
the bag and purposes is constructor with Runnable and string.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:07:54,000 --> 00:08:00,000
|
| 463 |
+
String represents the name of the threat and other different variations, including constructors with
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:00,000 --> 00:08:04,000
|
| 467 |
+
taxes and boolean flag to indicate the state of the inherited threat.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:08:04,000 --> 00:08:05,000
|
| 471 |
+
The locals flag.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:08:06,000 --> 00:08:07,000
|
| 475 |
+
What are the properties?
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:08:07,000 --> 00:08:08,000
|
| 479 |
+
The threat glass half.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:08:09,000 --> 00:08:16,000
|
| 483 |
+
If we would scroll to the top of this file, will find properties that we also may use during the configuration
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:08:16,000 --> 00:08:16,000
|
| 487 |
+
of the threat.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:08:17,000 --> 00:08:19,000
|
| 491 |
+
You already know about threatening property.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:08:20,000 --> 00:08:22,000
|
| 495 |
+
By the way, here is also new keyword for you.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:08:23,000 --> 00:08:24,000
|
| 499 |
+
Volatile will cover it.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:08:24,000 --> 00:08:28,000
|
| 503 |
+
Do in the separate lesson we have priority property.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:08:29,000 --> 00:08:35,000
|
| 507 |
+
This is a from one to 10 that will be used by threat scheduler to decide what threat is more important
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:08:35,000 --> 00:08:36,000
|
| 511 |
+
to work with.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:08:36,000 --> 00:08:43,000
|
| 515 |
+
So this next, however, we never can rely on the priority property when we have concurrent threat executed.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:08:43,000 --> 00:08:49,000
|
| 519 |
+
Let's call this recommendation, but not mandatory direction to follow for threats.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:08:49,000 --> 00:08:50,000
|
| 523 |
+
Catala What is a threat?
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:08:50,000 --> 00:08:54,000
|
| 527 |
+
Skalla It is part of GM that decides which threats should run.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:08:55,000 --> 00:08:58,000
|
| 531 |
+
Also, it decides which threats should wait, how it is.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:08:59,000 --> 00:09:03,000
|
| 535 |
+
This is a great question, but probably not for the first practical move.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:09:03,000 --> 00:09:06,000
|
| 539 |
+
This riding lesson will also cover this topic separately.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:09:07,000 --> 00:09:10,000
|
| 543 |
+
The next property here is on by default.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:09:10,000 --> 00:09:11,000
|
| 547 |
+
It is false.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:09:12,000 --> 00:09:16,000
|
| 551 |
+
We will discuss later in this course what demons threats are interrupted.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:09:16,000 --> 00:09:23,000
|
| 555 |
+
Flag is used to indicate where the threat is interrupted and we need to stop its execution or we need
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:09:23,000 --> 00:09:25,000
|
| 559 |
+
to proceed execution of a threat.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:09:25,000 --> 00:09:26,000
|
| 563 |
+
Let in this lesson.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:09:26,000 --> 00:09:30,000
|
| 567 |
+
I will also show you how to interact with this property.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:09:31,000 --> 00:09:33,000
|
| 571 |
+
Maxfield's here used by Jovian.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:09:33,000 --> 00:09:36,000
|
| 575 |
+
We will not focus our attention on them in this lesson.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:09:37,000 --> 00:09:40,000
|
| 579 |
+
And probably the one property that we did not talk yet is a threat.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:09:40,000 --> 00:09:48,000
|
| 583 |
+
The group this object is used to groups threats to gather in one group support group forms a three and
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:09:48,000 --> 00:09:50,000
|
| 587 |
+
every threat except a regional threat.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:09:50,000 --> 00:09:51,000
|
| 591 |
+
The group has a parent.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:09:52,000 --> 00:09:58,000
|
| 595 |
+
There are also some specific self-locking mechanism for threat in that group, but probably will cover
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:09:58,000 --> 00:09:59,000
|
| 599 |
+
this in a separate lesson.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:10:00,000 --> 00:10:03,000
|
| 603 |
+
And it looks like that Tetragon high level of.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:10:03,000 --> 00:10:10,000
|
| 607 |
+
You officer red class and its properties definitely as more things to learn here, but we'll do it gradually
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:10:10,000 --> 00:10:12,000
|
| 611 |
+
and with practical examples, case by case.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:10:13,000 --> 00:10:15,000
|
| 615 |
+
Now, let's get back to the demo file here.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:10:15,000 --> 00:10:20,000
|
| 619 |
+
You can see that I created a threat object and positive reference to the Runnable object.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:10:20,000 --> 00:10:25,000
|
| 623 |
+
Why option was a separate class might be needed in this case.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:10:25,000 --> 00:10:27,000
|
| 627 |
+
You can declare some files if needed.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:10:28,000 --> 00:10:34,000
|
| 631 |
+
Also, you can declare constructors and pass external resources to the new objects if needed, because
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:10:34,000 --> 00:10:38,000
|
| 635 |
+
by default, ranma, it doesn't take anything as Masset argument.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:10:38,000 --> 00:10:43,000
|
| 639 |
+
And here's just an example of constructor initialization of the state of this object.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:10:44,000 --> 00:10:51,000
|
| 643 |
+
If we want, we can pass any external object to the constructor and use the state of our runnable object
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:10:51,000 --> 00:10:53,000
|
| 647 |
+
in one method if needed.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:10:53,000 --> 00:10:58,000
|
| 651 |
+
In such a way you can just share the resource that we shared with this thread.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:10:59,000 --> 00:11:05,000
|
| 655 |
+
This is basically the first way to create a threat object that is ready to be executed and that is in
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:11:05,000 --> 00:11:06,000
|
| 659 |
+
your state.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:11:06,000 --> 00:11:09,000
|
| 663 |
+
The next way is another variation of the first one.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:11:10,000 --> 00:11:15,000
|
| 667 |
+
Instead of creating type that implements Runnable, we can just pass instance of anonymous class.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:11:16,000 --> 00:11:19,000
|
| 671 |
+
You can see here that I have similar method implemented.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:11:20,000 --> 00:11:22,000
|
| 675 |
+
Basically nothing special to highlight here.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:11:23,000 --> 00:11:27,000
|
| 679 |
+
And to be honest, this way of creating threat is not very popular.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:11:28,000 --> 00:11:34,000
|
| 683 |
+
The next way to great threat is to extend a new class from the threat and all around Massett, if you
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:11:34,000 --> 00:11:41,000
|
| 687 |
+
remember when we were you in threat object, we saw that there is nothing to execute by default if we
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:11:41,000 --> 00:11:44,000
|
| 691 |
+
didn't pass the reference to the Runnable object.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:11:44,000 --> 00:11:48,000
|
| 695 |
+
That's why so radically we can just override one method.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:11:49,000 --> 00:11:54,000
|
| 699 |
+
You can see that the current class extends threat clause and we overwrite one method here.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:11:55,000 --> 00:12:00,000
|
| 703 |
+
And after that, the main method is simply create the object of the first sorting program type.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:12:01,000 --> 00:12:01,000
|
| 707 |
+
That's it.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:12:02,000 --> 00:12:08,000
|
| 711 |
+
While this option often described in the literature, don't recommend it to you this way.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:12:08,000 --> 00:12:08,000
|
| 715 |
+
Why?
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:12:09,000 --> 00:12:13,000
|
| 719 |
+
Because he extends that class just to overwrite one method.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:12:13,000 --> 00:12:18,000
|
| 723 |
+
Probably it is not the best approach from the single responsibility principle point of view.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:12:19,000 --> 00:12:25,000
|
| 727 |
+
For such purposes we have Runnable type and we can use it to give implementation to run Macit.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:12:25,000 --> 00:12:32,000
|
| 731 |
+
The fourth way to prepare a threat for execution is to use lambda expression to implement around Macit.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:12:32,000 --> 00:12:34,000
|
| 735 |
+
She can see that I created lambda function.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:12:34,000 --> 00:12:37,000
|
| 739 |
+
That takes no arguments and returns nassan.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:12:38,000 --> 00:12:44,000
|
| 743 |
+
Basically I just print the same text and the last, but not least for today, is the way preparing A
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:12:45,000 --> 00:12:46,000
|
| 747 |
+
was MassArt reference.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:12:46,000 --> 00:12:53,000
|
| 751 |
+
I have a static method declared in this class with name execute that takes no parameters and that brings
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:12:53,000 --> 00:12:55,000
|
| 755 |
+
the same text to cancel.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:12:55,000 --> 00:13:00,000
|
| 759 |
+
I just passing method reference here that meets the definition of Runnable interface.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:13:00,000 --> 00:13:06,000
|
| 763 |
+
It doesn't take any arguments and it returns nassan the same as around Massett.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:13:06,000 --> 00:13:12,000
|
| 767 |
+
In case you are not familiar with lambda functions and method references in Java, but you want to learn
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:13:12,000 --> 00:13:12,000
|
| 771 |
+
that.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:13:13,000 --> 00:13:16,000
|
| 775 |
+
Check my functional programming course for Java InGenius.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:13:16,000 --> 00:13:22,000
|
| 779 |
+
We have really a lot of examples that the next thing that you see in this line and a sprinkling of the
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:13:22,000 --> 00:13:27,000
|
| 783 |
+
current threat to console and for the sake of example, call run Nassib.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:13:27,000 --> 00:13:36,000
|
| 787 |
+
Remember, Run Masset doesn't start as a threat of execution, only start MassArt starts separate thread.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:13:36,000 --> 00:13:42,000
|
| 791 |
+
But if you would call directly around MassArt, you would just execute run MassArt synchronously.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:13:43,000 --> 00:13:47,000
|
| 795 |
+
And after that I call starts MassArt on each thread that we created here.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:13:47,000 --> 00:13:53,000
|
| 799 |
+
Let's run the program to see what we have got in the console in the first line with the printed text
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:13:53,000 --> 00:14:02,000
|
| 803 |
+
from my main threat here you can see the text current threatening is and its name is Main Man is the
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:14:02,000 --> 00:14:09,000
|
| 807 |
+
name of the first read that we have in our Java application is the next line is a result of invocation
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:14:09,000 --> 00:14:10,000
|
| 811 |
+
of FRAND method.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:14:10,000 --> 00:14:13,000
|
| 815 |
+
And as you can see, threatening is still man.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:14:13,000 --> 00:14:19,000
|
| 819 |
+
That proves that invocation of method doesn't actually start a new threat.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:14:20,000 --> 00:14:27,000
|
| 823 |
+
And to start a new threat, we need to start Macit after you can see multiple lines with different names
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:14:27,000 --> 00:14:28,000
|
| 827 |
+
of a threat.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:14:29,000 --> 00:14:34,000
|
| 831 |
+
That is exactly what is returned by getting the same method on the current threat involved from the
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:14:34,000 --> 00:14:35,000
|
| 835 |
+
threat.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:14:35,000 --> 00:14:42,000
|
| 839 |
+
And you remember that by default, naming convention for each threat is threat word and sequential number
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:14:42,000 --> 00:14:42,000
|
| 843 |
+
of a threat.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:14:43,000 --> 00:14:47,000
|
| 847 |
+
Can you understand now how to run your threat in real life?
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:14:47,000 --> 00:14:50,000
|
| 851 |
+
You often use executor's to run and manage.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:14:50,000 --> 00:14:53,000
|
| 855 |
+
Your threats will learn executor's later in this course.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:14:54,000 --> 00:15:00,000
|
| 859 |
+
But what we have learned in this lesson, this is basics that you need to understand before moving further.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:15:01,000 --> 00:15:02,000
|
| 863 |
+
Now, what do we know how?
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:15:03,000 --> 00:15:08,000
|
| 867 |
+
To start the threat, let's learn how to interact and stop its execution.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:15:08,000 --> 00:15:16,000
|
| 871 |
+
I have separate file for that was name interrupt them is interesting app that will help you to understand
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:15:16,000 --> 00:15:17,000
|
| 875 |
+
how threat interception works.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:15:18,000 --> 00:15:20,000
|
| 879 |
+
Let's start from the main mast.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:15:20,000 --> 00:15:24,000
|
| 883 |
+
The first thing that I do here, create a task for execution.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:15:24,000 --> 00:15:31,000
|
| 887 |
+
I implement it runnable interface in this class for the sake of this demo and not having multiple classes
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:15:31,000 --> 00:15:31,000
|
| 891 |
+
in this example.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:15:32,000 --> 00:15:35,000
|
| 895 |
+
I will show you around Massud in the minute after this.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:15:35,000 --> 00:15:41,000
|
| 899 |
+
I create a threat object and start a threat and I won't let the main threat sleep for two seconds and
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:15:41,000 --> 00:15:44,000
|
| 903 |
+
interrupt my task after two seconds.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:15:44,000 --> 00:15:45,000
|
| 907 |
+
How I can do this?
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:15:46,000 --> 00:15:49,000
|
| 911 |
+
I invoke sleep masset on the threat object.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:15:49,000 --> 00:15:53,000
|
| 915 |
+
This method takes a number of milliseconds as Masset argument.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:15:54,000 --> 00:15:57,000
|
| 919 |
+
Two seconds are equal to two thousand milliseconds.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:15:57,000 --> 00:16:00,000
|
| 923 |
+
Sleep method is our law that in threat class.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:16:01,000 --> 00:16:02,000
|
| 927 |
+
Let's look at the threat clause.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:16:02,000 --> 00:16:03,000
|
| 931 |
+
Source code.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:16:03,000 --> 00:16:05,000
|
| 935 |
+
We have to sleep massas here.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:16:05,000 --> 00:16:12,000
|
| 939 |
+
One was milliseconds only and another one takes two arguments, milliseconds and nanoseconds.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:16:12,000 --> 00:16:14,000
|
| 943 |
+
To be honest, I never used sleep mass.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:16:14,000 --> 00:16:19,000
|
| 947 |
+
It was nanoseconds, but still it is good to know that such method exists.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:16:19,000 --> 00:16:26,000
|
| 951 |
+
Let's get back to our demo file, another really user friendly interface of making sure that sleep is
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:16:26,000 --> 00:16:28,000
|
| 955 |
+
to use time unit in from Javitz.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:16:28,000 --> 00:16:29,000
|
| 959 |
+
You can current package.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:16:30,000 --> 00:16:36,000
|
| 963 |
+
This enum represents time duration at the given unit of granularity and provides methods to convert
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:16:36,000 --> 00:16:40,000
|
| 967 |
+
across units and perform timing and delay operations.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:16:40,000 --> 00:16:47,000
|
| 971 |
+
In these units, for example, you may perform such operations as making Meinzer slip, and the interface
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:16:47,000 --> 00:16:52,000
|
| 975 |
+
allows us to not calculate milliseconds and convert them between seconds and other time units.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:16:52,000 --> 00:16:53,000
|
| 979 |
+
One unit.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:16:53,000 --> 00:16:59,000
|
| 983 |
+
But we can just take time units that we need and parse the value of the specific time unit that we need.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:17:00,000 --> 00:17:03,000
|
| 987 |
+
For example, here is a line similar to the one above.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:17:04,000 --> 00:17:10,000
|
| 991 |
+
It also uses milliseconds time unit and here is a line that use a second time unit.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:17:10,000 --> 00:17:12,000
|
| 995 |
+
And I'm just saying two seconds.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:17:12,000 --> 00:17:16,000
|
| 999 |
+
To be honest, in my opinion, using this API is more preferable.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:17:17,000 --> 00:17:24,000
|
| 1003 |
+
And after this line, my main threat is in on the running state, in wait in state and the one threat
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:17:24,000 --> 00:17:26,000
|
| 1007 |
+
is awaiting as a threat may interrupt it.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:17:27,000 --> 00:17:31,000
|
| 1011 |
+
That's why Slakey method maestro so called interrupted exception.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:17:32,000 --> 00:17:39,000
|
| 1015 |
+
And that's why Compiler makes us handle this exception case to describe how a system should behave in
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:17:39,000 --> 00:17:41,000
|
| 1019 |
+
case somebody will interrupt this thread.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:17:41,000 --> 00:17:46,000
|
| 1023 |
+
In this example, nobody will interrupt main threat but still interrupted.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:17:46,000 --> 00:17:47,000
|
| 1027 |
+
Exception is checked.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:17:47,000 --> 00:17:53,000
|
| 1031 |
+
That's why we need Searls declaration here in Maine method because for the sake of this demo, I don't
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:17:53,000 --> 00:17:55,000
|
| 1035 |
+
want to create try catch block here.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:17:55,000 --> 00:17:59,000
|
| 1039 |
+
After that I print a console that I interact as a threat.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:18:00,000 --> 00:18:01,000
|
| 1043 |
+
To interrupt as a threat.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:18:01,000 --> 00:18:07,000
|
| 1047 |
+
We should call interrupt method interrupt method interruption flag inside the threat object.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:18:08,000 --> 00:18:12,000
|
| 1051 |
+
That flag basically has two possible values, true or false.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:18:12,000 --> 00:18:19,000
|
| 1055 |
+
With the help of this method, we can change the state of the interaction flag inside the threat and
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:18:19,000 --> 00:18:23,000
|
| 1059 |
+
the last line and my main threat is print and leave in the console.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:18:23,000 --> 00:18:27,000
|
| 1063 |
+
Let's now look at our task and understand how interrupt.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:18:27,000 --> 00:18:30,000
|
| 1067 |
+
Masset interrupts execution of the threat.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:18:30,000 --> 00:18:32,000
|
| 1071 |
+
I open one method.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:18:32,000 --> 00:18:39,000
|
| 1075 |
+
I print text that indicates that I entered one method and the threat is about to execute Vork method.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:18:40,000 --> 00:18:41,000
|
| 1079 |
+
I invoke Vork method.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:18:42,000 --> 00:18:43,000
|
| 1083 |
+
Let's look at it now.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:18:44,000 --> 00:18:47,000
|
| 1087 |
+
Work method is that was the infinite loop.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:18:47,000 --> 00:18:49,000
|
| 1091 |
+
After that we just print one word.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:18:50,000 --> 00:18:52,000
|
| 1095 |
+
Verkin in f close.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:18:52,000 --> 00:18:55,000
|
| 1099 |
+
I check if threat is interrupted is interrupted.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:18:55,000 --> 00:19:02,000
|
| 1103 |
+
Matthew Chance is a state of the interaction flat and in case somebody from as a threat called MassArt
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:19:02,000 --> 00:19:07,000
|
| 1107 |
+
interrupt like we did in our main threat, then this method will return.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:19:07,000 --> 00:19:07,000
|
| 1111 |
+
True.
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:19:08,000 --> 00:19:13,000
|
| 1115 |
+
Right now you already know what is done by interrupt and by is interrupted masses.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:19:14,000 --> 00:19:16,000
|
| 1119 |
+
But why do we need interrupted?
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:19:16,000 --> 00:19:24,000
|
| 1123 |
+
Macit interrupted Massata returns also boolean value and return state of the interaction flac but it
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:19:24,000 --> 00:19:28,000
|
| 1127 |
+
also clears it and return it back to false.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:19:28,000 --> 00:19:35,000
|
| 1131 |
+
So in case what uncommon this line and will executed interruption flag will be turned back to false
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:19:35,000 --> 00:19:36,000
|
| 1135 |
+
again.
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:19:36,000 --> 00:19:42,000
|
| 1139 |
+
To interrupt this thread I will keep this line commanded and we'll just leave it as an example for you.
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:19:42,000 --> 00:19:49,000
|
| 1143 |
+
By the way, I encourage you to download this service code example from the GitHub and run it locally
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:19:49,000 --> 00:19:49,000
|
| 1147 |
+
on your computer.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:19:50,000 --> 00:19:55,000
|
| 1151 |
+
By doing this, you can play with values and comment and comment the lines that you are interested in
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:19:55,000 --> 00:20:00,000
|
| 1155 |
+
and as always, service code examples in attachments to this lesson.
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:20:00,000 --> 00:20:02,000
|
| 1159 |
+
OK, so now I believe.
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:20:03,000 --> 00:20:08,000
|
| 1163 |
+
The difference between these three methods interact is interrupted and interrupted.
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:20:08,000 --> 00:20:14,000
|
| 1167 |
+
Now pay attention that threat is moved to the white state because and will sleep mass at here.
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:20:14,000 --> 00:20:21,000
|
| 1171 |
+
And by the way, no matter how long sleep will be, I put one millisecond here for sleep.
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:20:21,000 --> 00:20:24,000
|
| 1175 |
+
But still, it is enough to interrupt the threat.
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:20:24,000 --> 00:20:25,000
|
| 1179 |
+
What will happen?
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:20:25,000 --> 00:20:28,000
|
| 1183 |
+
One threat will be a sleep take into account.
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:20:28,000 --> 00:20:35,000
|
| 1187 |
+
I'm in this safe block because interrupted FLAC is equal to true and the threat is invading state.
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:20:35,000 --> 00:20:38,000
|
| 1191 |
+
My threat will be interrupted and interrupted.
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:20:38,000 --> 00:20:40,000
|
| 1195 |
+
Exceptions will be thrown.
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:20:40,000 --> 00:20:48,000
|
| 1199 |
+
This line will not be executed never because interrupted exception will be thrown this mass Atheros
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:20:48,000 --> 00:20:52,000
|
| 1203 |
+
interrupted exception without any handlin to the upper level.
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:20:53,000 --> 00:20:58,000
|
| 1207 |
+
And here we should print interrupted in the work method and return from around Macit.
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:20:58,000 --> 00:21:05,000
|
| 1211 |
+
As you can see here, I have tried Kedge Block because sleep mass my throat checked exception and work
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:21:05,000 --> 00:21:08,000
|
| 1215 |
+
method doesn't handle this potential exception inside.
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:21:08,000 --> 00:21:11,000
|
| 1219 |
+
Let's run this program now for two seconds.
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:21:11,000 --> 00:21:18,000
|
| 1223 |
+
Program will bring to console working until threat will be interrupted and once it is interrupted,
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:21:18,000 --> 00:21:19,000
|
| 1227 |
+
let's see what we have.
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:21:19,000 --> 00:21:26,000
|
| 1231 |
+
The first thing that happened is threat interruption and even after that you can see that I printed
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:21:26,000 --> 00:21:27,000
|
| 1235 |
+
reconvert.
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:21:27,000 --> 00:21:34,000
|
| 1239 |
+
That is because I just changed interaction flac and I still need to wait until the threat will be in
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:21:34,000 --> 00:21:34,000
|
| 1243 |
+
a waiting mode.
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:21:35,000 --> 00:21:43,000
|
| 1247 |
+
This text in the main living tells us that Main Street finished its execution and after that we see
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:21:43,000 --> 00:21:44,000
|
| 1251 |
+
that we enter it if block.
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:21:44,000 --> 00:21:47,000
|
| 1255 |
+
And here is a status of interrupted flac.
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:21:47,000 --> 00:21:49,000
|
| 1259 |
+
It is equal to true.
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:21:49,000 --> 00:21:56,000
|
| 1263 |
+
The next step in our execution is entering the catch block and print and that threat was interrupted
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:21:56,000 --> 00:21:56,000
|
| 1267 |
+
in the work.
|
| 1268 |
+
|
| 1269 |
+
318
|
| 1270 |
+
00:21:56,000 --> 00:21:57,000
|
| 1271 |
+
MassArt.
|
| 1272 |
+
|
| 1273 |
+
319
|
| 1274 |
+
00:21:57,000 --> 00:21:58,000
|
| 1275 |
+
That's it.
|
| 1276 |
+
|
| 1277 |
+
320
|
| 1278 |
+
00:21:59,000 --> 00:22:05,000
|
| 1279 |
+
So the rule of thumb, when you're creating all rain app, think about what is a logical point in your
|
| 1280 |
+
|
| 1281 |
+
321
|
| 1282 |
+
00:22:05,000 --> 00:22:08,000
|
| 1283 |
+
thread to allow other threats to interrupt it.
|
| 1284 |
+
|
| 1285 |
+
322
|
| 1286 |
+
00:22:08,000 --> 00:22:12,000
|
| 1287 |
+
In case you have such possibility to introduce this point, do it.
|
| 1288 |
+
|
| 1289 |
+
323
|
| 1290 |
+
00:22:13,000 --> 00:22:16,000
|
| 1291 |
+
Usually you would let your threat fall asleep.
|
| 1292 |
+
|
| 1293 |
+
324
|
| 1294 |
+
00:22:16,000 --> 00:22:21,000
|
| 1295 |
+
After all, resources are adjusted and state of the system is consistent.
|
| 1296 |
+
|
| 1297 |
+
325
|
| 1298 |
+
00:22:21,000 --> 00:22:24,000
|
| 1299 |
+
In this case, there is no harm to interrupt the threat.
|
| 1300 |
+
|
| 1301 |
+
326
|
| 1302 |
+
00:22:25,000 --> 00:22:31,000
|
| 1303 |
+
There are some methods that you should never use and that are marked as deprecated but not removed from
|
| 1304 |
+
|
| 1305 |
+
327
|
| 1306 |
+
00:22:31,000 --> 00:22:34,000
|
| 1307 |
+
Janicki only because of the backwards compatibility.
|
| 1308 |
+
|
| 1309 |
+
328
|
| 1310 |
+
00:22:34,000 --> 00:22:38,000
|
| 1311 |
+
Ziya, stop, suspend and resume.
|
| 1312 |
+
|
| 1313 |
+
329
|
| 1314 |
+
00:22:39,000 --> 00:22:46,000
|
| 1315 |
+
These are dangerous masses in terms they are stop, suspend or resume threat execution instantly without
|
| 1316 |
+
|
| 1317 |
+
330
|
| 1318 |
+
00:22:46,000 --> 00:22:47,000
|
| 1319 |
+
bothering.
|
| 1320 |
+
|
| 1321 |
+
331
|
| 1322 |
+
00:22:47,000 --> 00:22:53,000
|
| 1323 |
+
What process is happening right now inside the threat, taking into account not all operations at ATOMIC
|
| 1324 |
+
|
| 1325 |
+
332
|
| 1326 |
+
00:22:53,000 --> 00:22:57,000
|
| 1327 |
+
and performed with one single operation of updating data in the memory.
|
| 1328 |
+
|
| 1329 |
+
333
|
| 1330 |
+
00:22:58,000 --> 00:23:01,000
|
| 1331 |
+
You can start somewhere in the middle of data processing in your threat.
|
| 1332 |
+
|
| 1333 |
+
334
|
| 1334 |
+
00:23:02,000 --> 00:23:05,000
|
| 1335 |
+
At the meantime, resource will be updated as a threat.
|
| 1336 |
+
|
| 1337 |
+
335
|
| 1338 |
+
00:23:05,000 --> 00:23:11,000
|
| 1339 |
+
And when you will resume execution, you may end up with not consistent state of your objects.
|
| 1340 |
+
|
| 1341 |
+
336
|
| 1342 |
+
00:23:11,000 --> 00:23:18,000
|
| 1343 |
+
We will talk about atomic operations in adolescence, but I believe you understood that stopping a suspension
|
| 1344 |
+
|
| 1345 |
+
337
|
| 1346 |
+
00:23:18,000 --> 00:23:25,000
|
| 1347 |
+
and after that resume and execution of the threat in case it is made some calculation process is not
|
| 1348 |
+
|
| 1349 |
+
338
|
| 1350 |
+
00:23:25,000 --> 00:23:26,000
|
| 1351 |
+
the best idea.
|
| 1352 |
+
|
| 1353 |
+
339
|
| 1354 |
+
00:23:26,000 --> 00:23:29,000
|
| 1355 |
+
And one more interesting and lasting for today's lesson.
|
| 1356 |
+
|
| 1357 |
+
340
|
| 1358 |
+
00:23:30,000 --> 00:23:34,000
|
| 1359 |
+
Probably you saw one comment line here where I invoke June Masset.
|
| 1360 |
+
|
| 1361 |
+
341
|
| 1362 |
+
00:23:35,000 --> 00:23:36,000
|
| 1363 |
+
What is it?
|
| 1364 |
+
|
| 1365 |
+
342
|
| 1366 |
+
00:23:36,000 --> 00:23:40,000
|
| 1367 |
+
Let me uncommented first and run up one more time.
|
| 1368 |
+
|
| 1369 |
+
343
|
| 1370 |
+
00:23:40,000 --> 00:23:44,000
|
| 1371 |
+
What's changed now in this version line?
|
| 1372 |
+
|
| 1373 |
+
344
|
| 1374 |
+
00:23:44,000 --> 00:23:47,000
|
| 1375 |
+
Zatarain's in the main Leesville will always be printed.
|
| 1376 |
+
|
| 1377 |
+
345
|
| 1378 |
+
00:23:47,000 --> 00:23:48,000
|
| 1379 |
+
Lost.
|
| 1380 |
+
|
| 1381 |
+
346
|
| 1382 |
+
00:23:48,000 --> 00:23:49,000
|
| 1383 |
+
Why?
|
| 1384 |
+
|
| 1385 |
+
347
|
| 1386 |
+
00:23:49,000 --> 00:23:56,000
|
| 1387 |
+
Because Join Masset also put our main threat in great state until this threat will be completely finished.
|
| 1388 |
+
|
| 1389 |
+
348
|
| 1390 |
+
00:23:56,000 --> 00:23:59,000
|
| 1391 |
+
So I gave a command with this line to join.
|
| 1392 |
+
|
| 1393 |
+
349
|
| 1394 |
+
00:23:59,000 --> 00:24:01,000
|
| 1395 |
+
This thread does a current one.
|
| 1396 |
+
|
| 1397 |
+
350
|
| 1398 |
+
00:24:02,000 --> 00:24:08,000
|
| 1399 |
+
That's why my app will wait until Perry's threat will be completely executed during Masad.
|
| 1400 |
+
|
| 1401 |
+
351
|
| 1402 |
+
00:24:08,000 --> 00:24:15,000
|
| 1403 |
+
Also, Masroor interrupted exception, taking into account it puts current threat wait in state and
|
| 1404 |
+
|
| 1405 |
+
352
|
| 1406 |
+
00:24:15,000 --> 00:24:20,000
|
| 1407 |
+
other threats might interrupt this threat while it is innervate state.
|
| 1408 |
+
|
| 1409 |
+
353
|
| 1410 |
+
00:24:20,000 --> 00:24:21,000
|
| 1411 |
+
Is it clear?
|
| 1412 |
+
|
| 1413 |
+
354
|
| 1414 |
+
00:24:21,000 --> 00:24:25,000
|
| 1415 |
+
Basically, that's all what I wanted to share with you in this lesson.
|
| 1416 |
+
|
| 1417 |
+
355
|
| 1418 |
+
00:24:26,000 --> 00:24:28,000
|
| 1419 |
+
Let's recap what we have learned today.
|
| 1420 |
+
|
| 1421 |
+
356
|
| 1422 |
+
00:24:28,000 --> 00:24:34,000
|
| 1423 |
+
In this lesson, we learned the life cycle of the threat and how state of the threat is changed from
|
| 1424 |
+
|
| 1425 |
+
357
|
| 1426 |
+
00:24:34,000 --> 00:24:36,000
|
| 1427 |
+
the new disseminated.
|
| 1428 |
+
|
| 1429 |
+
358
|
| 1430 |
+
00:24:36,000 --> 00:24:39,000
|
| 1431 |
+
We learned five ways how to run a threat.
|
| 1432 |
+
|
| 1433 |
+
359
|
| 1434 |
+
00:24:39,000 --> 00:24:43,000
|
| 1435 |
+
Also in this lesson, we performed over a year of threat class.
|
| 1436 |
+
|
| 1437 |
+
360
|
| 1438 |
+
00:24:43,000 --> 00:24:48,000
|
| 1439 |
+
Now, you know, main properties of this type, we learned a radical interface.
|
| 1440 |
+
|
| 1441 |
+
361
|
| 1442 |
+
00:24:48,000 --> 00:24:51,000
|
| 1443 |
+
Now you know how to use it to execute a separate threat.
|
| 1444 |
+
|
| 1445 |
+
362
|
| 1446 |
+
00:24:52,000 --> 00:24:55,000
|
| 1447 |
+
And at the end of the lesson, we learned how to interrupt threat.
|
| 1448 |
+
|
| 1449 |
+
363
|
| 1450 |
+
00:24:56,000 --> 00:24:59,000
|
| 1451 |
+
Hope you enjoyed the lesson and you like the examples.
|
| 1452 |
+
|
| 1453 |
+
364
|
| 1454 |
+
00:24:59,000 --> 00:25:02,000
|
| 1455 |
+
We still have a lot of other things to learn, but.
|
| 1456 |
+
|
| 1457 |
+
365
|
| 1458 |
+
00:25:02,000 --> 00:25:08,000
|
| 1459 |
+
I think that they will have enough information to remember, make sure you understand this lesson before
|
| 1460 |
+
|
| 1461 |
+
366
|
| 1462 |
+
00:25:08,000 --> 00:25:12,000
|
| 1463 |
+
moving further, because multithreaded is not the easiest topic.
|
| 1464 |
+
|
| 1465 |
+
367
|
| 1466 |
+
00:25:12,000 --> 00:25:18,000
|
| 1467 |
+
And we need to be very careful with understanding each concept in sequential order, because it would
|
| 1468 |
+
|
| 1469 |
+
368
|
| 1470 |
+
00:25:18,000 --> 00:25:22,000
|
| 1471 |
+
be hard to understand one thing without understanding the previous one.
|
| 1472 |
+
|
| 1473 |
+
369
|
| 1474 |
+
00:25:22,000 --> 00:25:23,000
|
| 1475 |
+
Thanks a lot for your attention.
|
| 1476 |
+
|
| 1477 |
+
370
|
| 1478 |
+
00:25:24,000 --> 00:25:27,000
|
| 1479 |
+
Have a great day and see you in the next lesson.
|
| 1480 |
+
|
27 - Multithreading/002 Source-code-of-the-First-multithreading-program.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/FirstMultithreadingProgram.java
|
27 - Multithreading/002 Source-code-of-thread-interruption-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/multithreading/InterruptDemo.java
|
27 - Multithreading/003 Source-code-of-the-Priority-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/multithreading/PriorityDemo.java
|
27 - Multithreading/003 Source-code-of-the-Thread-group.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/ThreadGroupDemo.java
|
27 - Multithreading/003 Source-code-of-the-daemon-threads.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/DaemonThreadDemo.java
|
27 - Multithreading/003 Source-code-of-the-yield-method-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/multithreading/YieldDemo.java
|
27 - Multithreading/003 Source-code-of-throwing-exception-from-run-method-example.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/ThrowingExceptionFromRunnableDemo.java
|
27 - Multithreading/003 Thread Scheduler, Race Condition, Daemon Threads & Thread Groups_en.srt
ADDED
|
@@ -0,0 +1,1128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:10,000
|
| 3 |
+
How came in this lesson, we're going to learn more about threats, the threats and threat groups,
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:11,000 --> 00:00:17,000
|
| 7 |
+
basically that's what we have in our agenda for the day as we review these topics one by one, I will
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:17,000 --> 00:00:23,000
|
| 11 |
+
also explain what's raised of condition is how priority works with threats and why do we need you to
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:23,000 --> 00:00:24,000
|
| 15 |
+
MASSETT.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:24,000 --> 00:00:29,000
|
| 19 |
+
And also, at the end of this lesson, I will show you how we can throw an exception from the wrong
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:29,000 --> 00:00:30,000
|
| 23 |
+
message.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:30,000 --> 00:00:35,000
|
| 27 |
+
And as always, we are going through different examples today that will help you to understand the topic
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:35,000 --> 00:00:36,000
|
| 31 |
+
better.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:36,000 --> 00:00:40,000
|
| 35 |
+
All source code examples are in attachments to this lesson.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:40,000 --> 00:00:41,000
|
| 39 |
+
Let's start.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:41,000 --> 00:00:44,000
|
| 43 |
+
And the first thing that we are going to learn today is the threats.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:44,000 --> 00:00:49,000
|
| 47 |
+
Cédula in Paris, less than I already mentioned about threats Cédula and told you that this is part
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:49,000 --> 00:00:54,000
|
| 51 |
+
of GM that decides which threats will be executed next and which threats should wait.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:55,000 --> 00:01:00,000
|
| 55 |
+
Also, I mentioned the threats CÉDULA, which is a threat that is in Runnable state.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:00,000 --> 00:01:04,000
|
| 59 |
+
That means the threat is running or waiting are blocked.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:04,000 --> 00:01:10,000
|
| 63 |
+
But imagine that you have multiple threats running right now and your computer doesn't have enough computing
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:10,000 --> 00:01:13,000
|
| 67 |
+
capacity to start work on all threats at once.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:14,000 --> 00:01:20,000
|
| 71 |
+
So it's Canada will need to make a decision in such case, what threat to run first and which one should
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:20,000 --> 00:01:27,000
|
| 75 |
+
go after was not an easy decision for a threat schedule, but how it would make a decision or what factors
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:27,000 --> 00:01:30,000
|
| 79 |
+
will be part of the decision making process.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:30,000 --> 00:01:32,000
|
| 83 |
+
The first factor is priority.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:32,000 --> 00:01:35,000
|
| 87 |
+
The remember priority property from a threat class.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:35,000 --> 00:01:42,000
|
| 91 |
+
This is in the valley as it may be in range from one to ten is the high priority really should indicate
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:42,000 --> 00:01:49,000
|
| 95 |
+
the threat that this threat should be prioritized over threats that have lower priority during the threat
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:49,000 --> 00:01:49,000
|
| 99 |
+
of association.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:50,000 --> 00:01:53,000
|
| 103 |
+
New threat takes the same priority as parents threat.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:54,000 --> 00:01:58,000
|
| 107 |
+
Also, we have certain message that should help us to set new priorities if needed.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:58,000 --> 00:01:59,000
|
| 111 |
+
But what to do in this case?
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:59,000 --> 00:02:01,000
|
| 115 |
+
Multiple threats have the same priority.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:02,000 --> 00:02:06,000
|
| 119 |
+
In this case, it is really hard to predict what would be the decision of threats.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:06,000 --> 00:02:12,000
|
| 123 |
+
Cédula that's why it is fair to make an assumption that random threat will be selected.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:12,000 --> 00:02:19,000
|
| 127 |
+
But we know that random is something human related only there is a programming code in place to make
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:19,000 --> 00:02:20,000
|
| 131 |
+
a random decision.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:20,000 --> 00:02:23,000
|
| 135 |
+
We'll discuss this in the details later today.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:23,000 --> 00:02:26,000
|
| 139 |
+
And the second factor is in the arrival time.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:26,000 --> 00:02:33,000
|
| 143 |
+
Threats can also take into account the fact when threat arrived and how long each of them waited in
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:33,000 --> 00:02:36,000
|
| 147 |
+
case with similar priority of threats.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:36,000 --> 00:02:40,000
|
| 151 |
+
Arrival time is one of the things that will be considered by threat schedule.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:40,000 --> 00:02:44,000
|
| 155 |
+
But again, this fact is not the final one in making the final decision.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:45,000 --> 00:02:51,000
|
| 159 |
+
So how the threats works, let's try to understand in a multi threat environment, multiple threats
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:51,000 --> 00:02:59,000
|
| 163 |
+
executed concurrently, but processer allocates a small amount of time that is usually called time slice
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:02:59,000 --> 00:03:00,000
|
| 167 |
+
through each threat.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:01,000 --> 00:03:05,000
|
| 171 |
+
So the task of threats CÉDULA is to verify each threat and make a decision.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:06,000 --> 00:03:08,000
|
| 175 |
+
What threat will get processers down first?
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:09,000 --> 00:03:13,000
|
| 179 |
+
There is different scale algorithm used to answer this question.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:13,000 --> 00:03:14,000
|
| 183 |
+
Let's review them.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:14,000 --> 00:03:16,000
|
| 187 |
+
Preemptive priorities.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:16,000 --> 00:03:20,000
|
| 191 |
+
Keadilan this is algorithms that we partially discussed already.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:20,000 --> 00:03:23,000
|
| 195 |
+
Sweat's killer also at his highest priority.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:24,000 --> 00:03:26,000
|
| 199 |
+
The rest of the threats will be ignored.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:26,000 --> 00:03:30,000
|
| 203 |
+
But in this case, is it possible at all for other threats to be executed?
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:31,000 --> 00:03:31,000
|
| 207 |
+
Yes.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:32,000 --> 00:03:38,000
|
| 211 |
+
In case as a threat has high priority or current threat, went to Washington state or was interrupted
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:03:38,000 --> 00:03:42,000
|
| 215 |
+
or with the help of field marshal, what is yield massive?
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:03:42,000 --> 00:03:48,000
|
| 219 |
+
This is akin to the scale of the current threat is willing to yield its current use of process and execution
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:03:48,000 --> 00:03:49,000
|
| 223 |
+
time.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:03:49,000 --> 00:03:52,000
|
| 227 |
+
But the scandal is free to ignore this.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:03:52,000 --> 00:03:57,000
|
| 231 |
+
But to be honest regarding this particular matter, it is really appropriate to use it.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:03:57,000 --> 00:04:00,000
|
| 235 |
+
It may be usable for the bargain for testing purposes.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:00,000 --> 00:04:07,000
|
| 239 |
+
With my help to reproduce the race condition, we'll talk about what race condition is a little bit
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:07,000 --> 00:04:08,000
|
| 243 |
+
later in this lesson.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:08,000 --> 00:04:11,000
|
| 247 |
+
The next algorithm is first come, first serve.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:11,000 --> 00:04:13,000
|
| 251 |
+
Scheduling rules are simple here.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:14,000 --> 00:04:20,000
|
| 255 |
+
Zaretsky assigns CPU time to the threads that appear to be the one who requested it first.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:21,000 --> 00:04:23,000
|
| 259 |
+
Also, we shouldn't forget about slice and schedule.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:04:24,000 --> 00:04:28,000
|
| 263 |
+
You already understood that piece of time for each thread is called a time slice.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:04:28,000 --> 00:04:35,000
|
| 267 |
+
Each thread gets executed cyclically one after another as Reskin will track where the threads finished.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:04:35,000 --> 00:04:38,000
|
| 271 |
+
His execution was in a time slice or no in case.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:04:38,000 --> 00:04:43,000
|
| 275 |
+
Yes, this threat will be removed from CU and Schoettler will work with other threats.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:04:43,000 --> 00:04:45,000
|
| 279 |
+
Only is it clear.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:04:46,000 --> 00:04:50,000
|
| 283 |
+
Now let's check how all these algorithms work together on the simple example.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:04:51,000 --> 00:04:54,000
|
| 287 |
+
Imagine that we have five threads and only one processor.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:04:55,000 --> 00:04:59,000
|
| 291 |
+
Let's make an assumption that all threats have different priorities and different arrival time.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:00,000 --> 00:05:01,000
|
| 295 |
+
The together that uses.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:02,000 --> 00:05:07,000
|
| 299 |
+
Algorithms that we have discussed, it will decide which thread to select to give a time of crisis.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:08,000 --> 00:05:14,000
|
| 303 |
+
At first, Zaretsky should select the highest priority and in case of a threat, was high priority with
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:14,000 --> 00:05:16,000
|
| 307 |
+
request access to processer.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:17,000 --> 00:05:24,000
|
| 311 |
+
Then you will get access to the CPU during the first opportunity and once will deal with the same priority
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:05:24,000 --> 00:05:28,000
|
| 315 |
+
Skidder will use first come first serve scale algorithms to those threats.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:05:29,000 --> 00:05:33,000
|
| 319 |
+
So hope now you have the vision how threats are executed in the current environment.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:05:34,000 --> 00:05:40,000
|
| 323 |
+
Now let me quickly explain what is the condition then, multiple definitions of this term.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:05:41,000 --> 00:05:46,000
|
| 327 |
+
Let me share with you, some of them in some sort of serious condition is explained like I can issue
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:05:46,000 --> 00:05:53,000
|
| 331 |
+
an error in multistorey and program design when program execution depends on the sequence of Seurat's
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:05:53,000 --> 00:05:54,000
|
| 335 |
+
execution.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:05:54,000 --> 00:06:00,000
|
| 339 |
+
The error guernseys name from the similar mistake in electronic circuit design signals race.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:01,000 --> 00:06:07,000
|
| 343 |
+
And as a leader, you may find definitions of race condition as not an issue, but as a state of the
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:07,000 --> 00:06:14,000
|
| 347 |
+
system where substantive behavior of an application is dependent on the sequence or of other events.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:15,000 --> 00:06:20,000
|
| 351 |
+
So is it an issue or just a state without any consequences and without any impact?
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:21,000 --> 00:06:25,000
|
| 355 |
+
Actually, race condition may cause various impact on your execution.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:26,000 --> 00:06:27,000
|
| 359 |
+
Let's review some of them.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:27,000 --> 00:06:34,000
|
| 363 |
+
Memory leak and controlled access to the common memory during the race condition, mainly due to having
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:34,000 --> 00:06:35,000
|
| 367 |
+
memory leak.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:06:35,000 --> 00:06:39,000
|
| 371 |
+
It can visit memory that is needed is not released by some thread.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:06:39,000 --> 00:06:42,000
|
| 375 |
+
For example, inconsistent data.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:06:42,000 --> 00:06:48,000
|
| 379 |
+
It may happen that both threads managed to get access to the same resource and one of the mistakes of
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:06:48,000 --> 00:06:50,000
|
| 383 |
+
concurrent interaction happened.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:06:50,000 --> 00:06:56,000
|
| 387 |
+
Probably one thread of data to resource was one value, but another threat overrides its value with
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:06:56,000 --> 00:06:56,000
|
| 391 |
+
new one.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:06:57,000 --> 00:07:02,000
|
| 395 |
+
And you have lost update or for example, once to use a resource to read data from it.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:02,000 --> 00:07:08,000
|
| 399 |
+
But in the meantime, in parallel as a threat, updating this resource and the first resource with our
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:08,000 --> 00:07:10,000
|
| 403 |
+
data data, this is called virtual.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:11,000 --> 00:07:13,000
|
| 407 |
+
It is also possible to face other issues.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:14,000 --> 00:07:18,000
|
| 411 |
+
But I believe you understand the potential impact for data consistency in your app.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:19,000 --> 00:07:22,000
|
| 415 |
+
Dedlock and liveblog is a separate lesson.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:07:22,000 --> 00:07:25,000
|
| 419 |
+
I will show you examples of Dedlock and liveblog.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:07:25,000 --> 00:07:30,000
|
| 423 |
+
Ensure this situation in your app decreased productivity of each threat to zero.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:07:31,000 --> 00:07:32,000
|
| 427 |
+
Is that technically working?
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:07:32,000 --> 00:07:38,000
|
| 431 |
+
But they don't produce any results and also there might be other impacts caused by race conditions.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:07:39,000 --> 00:07:43,000
|
| 435 |
+
So these are just a few potential impacts that you may face with Ingres.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:07:43,000 --> 00:07:46,000
|
| 439 |
+
Conditions state how to avoid race condition.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:07:47,000 --> 00:07:53,000
|
| 443 |
+
We can avoid risk conditions by building proper synchronization in critical sections of execution.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:07:53,000 --> 00:07:59,000
|
| 447 |
+
DigiCam provides different ways for stress synchronization, and we'll run them in a separate lessons.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:07:59,000 --> 00:08:02,000
|
| 451 |
+
We learned a lot of new things for the day.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:02,000 --> 00:08:07,000
|
| 455 |
+
Let's start practical part of our lesson and review the source code of our examples.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:07,000 --> 00:08:09,000
|
| 459 |
+
Let's start from priority to demo.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:09,000 --> 00:08:15,000
|
| 463 |
+
I was shown now that you know I should count on property property as we discussed.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:15,000 --> 00:08:20,000
|
| 467 |
+
Yes, it will be considered, but take into account that might be different cases.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:08:21,000 --> 00:08:25,000
|
| 471 |
+
When threat arrived and ready for execution, one processor time is available.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:08:25,000 --> 00:08:32,000
|
| 475 |
+
The greatest threat and one processor ready to process said a lot of things happen literally in milliseconds.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:08:32,000 --> 00:08:35,000
|
| 479 |
+
I have files, as is called priority demo.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:08:35,000 --> 00:08:36,000
|
| 483 |
+
What do we have here?
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:08:37,000 --> 00:08:39,000
|
| 487 |
+
We have static MassArt with name executes it.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:08:39,000 --> 00:08:44,000
|
| 491 |
+
I will use to create objects of a threat that this is a similar method, the one we had in previous
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:08:44,000 --> 00:08:45,000
|
| 495 |
+
demo.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:08:45,000 --> 00:08:48,000
|
| 499 |
+
I just bring the name of the threat to console.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:08:48,000 --> 00:08:53,000
|
| 503 |
+
I create five threats and pay attention to the naming convention of the variables.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:08:53,000 --> 00:08:55,000
|
| 507 |
+
I'm starting indexing from zero.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:08:56,000 --> 00:09:00,000
|
| 511 |
+
This will help us to match variable name and threatening and cancel.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:00,000 --> 00:09:04,000
|
| 515 |
+
I use certain method to set different priorities, can use threats.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:04,000 --> 00:09:07,000
|
| 519 |
+
You can see the threat zero has the lowest priority.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:09:07,000 --> 00:09:13,000
|
| 523 |
+
So I want to have the highest priority and the rest of threats also have different priorities here.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:09:14,000 --> 00:09:20,000
|
| 527 |
+
Also, you need to know that threat clause has different constants already to separate the three constants.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:09:20,000 --> 00:09:27,000
|
| 531 |
+
The main priority that is equal to one naum priority is equal to five and max priorities.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:09:27,000 --> 00:09:28,000
|
| 535 |
+
That is equal to that.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:09:29,000 --> 00:09:32,000
|
| 539 |
+
You can use this constant in setting masses if you want.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:09:32,000 --> 00:09:39,000
|
| 543 |
+
And after all these configurations, I run my app, I will run it multiple times, try to pay attention
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:09:39,000 --> 00:09:43,000
|
| 547 |
+
to what stories will be printed to console first and what will be printed last.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:09:44,000 --> 00:09:50,000
|
| 551 |
+
And you can see that in most cases read no one is printed most of the times to console in the first
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:09:50,000 --> 00:09:50,000
|
| 555 |
+
row.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:09:50,000 --> 00:09:56,000
|
| 559 |
+
And the strange thing is that a threat to that is also brought it then maybe printed the last one.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:09:57,000 --> 00:09:59,000
|
| 563 |
+
So something strange is happening here.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:09:59,000 --> 00:10:00,000
|
| 567 |
+
Threads it has.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:10:00,000 --> 00:10:05,000
|
| 571 |
+
Highest priority and not the last arrival time will be painted the last one.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:10:06,000 --> 00:10:08,000
|
| 575 |
+
Why was the magic is happening here?
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:10:09,000 --> 00:10:10,000
|
| 579 |
+
You're right.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:10:10,000 --> 00:10:12,000
|
| 583 |
+
This is magic of concurrent execution.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:10:12,000 --> 00:10:18,000
|
| 587 |
+
Imagine that you have multiple tasks at once, great threads, running threads, synchronized access
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:10:18,000 --> 00:10:19,000
|
| 591 |
+
to the Queensland method.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:10:20,000 --> 00:10:21,000
|
| 595 |
+
And we'll get to synchronization soon.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:10:22,000 --> 00:10:28,000
|
| 599 |
+
And you will learn that Sprint alone is synchronized and time slices for each thread are not infinite.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:10:28,000 --> 00:10:35,000
|
| 603 |
+
And while a lot of things happen, not always our brains can understand why we see this result, but
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:10:35,000 --> 00:10:36,000
|
| 607 |
+
not the last one.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:10:37,000 --> 00:10:38,000
|
| 611 |
+
But at least my brain for sure.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:10:38,000 --> 00:10:40,000
|
| 615 |
+
Not always can understand this.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:10:40,000 --> 00:10:45,000
|
| 619 |
+
But anyway, this is what you should know about MultiThreaded before you start creating lots of training
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:10:45,000 --> 00:10:46,000
|
| 623 |
+
programs.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:10:46,000 --> 00:10:50,000
|
| 627 |
+
You can't always predict the sequence of execution.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:10:50,000 --> 00:10:51,000
|
| 631 |
+
That's why.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:10:51,000 --> 00:10:51,000
|
| 635 |
+
Will it always?
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:10:51,000 --> 00:10:58,000
|
| 639 |
+
You have to create programs that will not depend on the sequence of execution with race condition and
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:10:58,000 --> 00:11:01,000
|
| 643 |
+
unexpected impact on the results of our application.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:11:02,000 --> 00:11:07,000
|
| 647 |
+
Now, when I show you that you shouldn't completely rely on priority property, let me also show you
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:11:07,000 --> 00:11:08,000
|
| 651 |
+
another thing.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:11:08,000 --> 00:11:11,000
|
| 655 |
+
This time I'll show you the massive example.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:11:11,000 --> 00:11:13,000
|
| 659 |
+
We have two threats.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:11:13,000 --> 00:11:19,000
|
| 663 |
+
The first threat gives a hint of threats, cédula that the threat is ready to yield its current use
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:11:19,000 --> 00:11:22,000
|
| 667 |
+
of a processor and after that freeze its name.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:11:23,000 --> 00:11:26,000
|
| 671 |
+
The second threat, Princetonian of the threat straight away.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:11:27,000 --> 00:11:28,000
|
| 675 |
+
I believe this is clear.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:11:28,000 --> 00:11:34,000
|
| 679 |
+
Let's execute our app multiple times and we can see that output is not deterministic.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:11:35,000 --> 00:11:39,000
|
| 683 |
+
Sometimes zero is printed to console first and sometimes otherwise.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:11:40,000 --> 00:11:44,000
|
| 687 |
+
It looks like it doesn't make a lot of sense whether I'm using static method.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:11:44,000 --> 00:11:51,000
|
| 691 |
+
You know, we can even make an assumption that access to such a centralized method as printer land is
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:11:51,000 --> 00:11:55,000
|
| 695 |
+
random no matter what they use method or no.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:11:55,000 --> 00:12:00,000
|
| 699 |
+
That's why in documentation, it's clearly written that threats cannot ignore this hint.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:12:01,000 --> 00:12:08,000
|
| 703 |
+
And all my life I ask different people multiple times the question why isn't we need to yield massive
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:12:08,000 --> 00:12:09,000
|
| 707 |
+
and broad use?
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:12:09,000 --> 00:12:13,000
|
| 711 |
+
They don't bring us to the same expected result every time.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:12:13,000 --> 00:12:19,000
|
| 715 |
+
And I been answered, like I explained to you, different algorithms, time slicing, and probably even
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:12:19,000 --> 00:12:20,000
|
| 719 |
+
the business world can yield massive.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:12:21,000 --> 00:12:24,000
|
| 723 |
+
The chances are different to execute one or another threat.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:12:24,000 --> 00:12:31,000
|
| 727 |
+
But in real life and in Damos cases, it is almost impossible to visualize the benefit of this methods.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:12:31,000 --> 00:12:36,000
|
| 731 |
+
Unfortunately, that is something that you should know about Lucas writing in Paris last month when
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:12:36,000 --> 00:12:43,000
|
| 735 |
+
we performed an overview of a threat glass and I promised you to explain what demon threats are actually
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:12:43,000 --> 00:12:45,000
|
| 739 |
+
are not so much things to here.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:12:46,000 --> 00:12:48,000
|
| 743 |
+
Jim is stopped once.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:12:48,000 --> 00:12:50,000
|
| 747 |
+
There are only demons, rats running.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:12:50,000 --> 00:12:56,000
|
| 751 |
+
This is very useful to great demon threats, like supporters of another threat, for example, in case
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:12:56,000 --> 00:13:03,000
|
| 755 |
+
when demons can't exist without us a threat because it's not so important without another threat.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:13:03,000 --> 00:13:10,000
|
| 759 |
+
In one of home tasks, I would ask you to create demon threats that will recent events in another thread.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:13:10,000 --> 00:13:12,000
|
| 763 |
+
And in the case there is known as a threat.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:13:12,000 --> 00:13:14,000
|
| 767 |
+
There is nothing to listen.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:13:14,000 --> 00:13:16,000
|
| 771 |
+
I know from demons, threats, demon class.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:13:17,000 --> 00:13:22,000
|
| 775 |
+
I create a thread that contains infinite loop and brings the demon is in each half of the second.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:13:23,000 --> 00:13:30,000
|
| 779 |
+
I start the thread and make my mind sweat sleep for two seconds and after that I pray that the main
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:13:30,000 --> 00:13:31,000
|
| 783 |
+
threat is finished.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:13:31,000 --> 00:13:34,000
|
| 787 |
+
I will keep this land commanded for the first round.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:13:35,000 --> 00:13:41,000
|
| 791 |
+
I run the program and as you can see, even after two seconds and even after my strength was finished
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:13:41,000 --> 00:13:48,000
|
| 795 |
+
and Nasrat is still working, the only way for me to stop it now is to stop Jaba process.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:13:49,000 --> 00:13:50,000
|
| 799 |
+
I press the stop sign here.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:13:51,000 --> 00:13:53,000
|
| 803 |
+
Let's do another thing now.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:13:53,000 --> 00:13:54,000
|
| 807 |
+
I have a lot in common.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:13:54,000 --> 00:14:03,000
|
| 811 |
+
This line I call set a massive here and set jemal flat to true now key once thread is demon and will
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:14:03,000 --> 00:14:05,000
|
| 815 |
+
be stopped right after the threat is created.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:14:05,000 --> 00:14:10,000
|
| 819 |
+
It will be finished because after the threats have created it will be finished.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:14:10,000 --> 00:14:12,000
|
| 823 |
+
Only demons wrath will stay.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:14:12,000 --> 00:14:20,000
|
| 827 |
+
And considering the fact that one of the demon threats you will stop execution the generals or machine
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:14:20,000 --> 00:14:25,000
|
| 831 |
+
exits and stop execution when the only threats is running at all demon threats.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:14:25,000 --> 00:14:30,000
|
| 835 |
+
Let's run our app now and we can see that once main threat is finished.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:14:30,000 --> 00:14:32,000
|
| 839 |
+
Jimmy, I am a stop.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:14:32,000 --> 00:14:37,000
|
| 843 |
+
Is it clear hope that this example helped you to understand what demons rates are?
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:14:38,000 --> 00:14:42,000
|
| 847 |
+
Also, in previous lesson I promised to show you how to work with different groups.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:14:43,000 --> 00:14:43,000
|
| 851 |
+
In this lesson.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:14:43,000 --> 00:14:46,000
|
| 855 |
+
I also prepare them file to share it with you.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:14:46,000 --> 00:14:48,000
|
| 859 |
+
Let me remind you what social group?
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:14:48,000 --> 00:14:51,000
|
| 863 |
+
S Support group is a set of threats.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:14:51,000 --> 00:14:57,000
|
| 867 |
+
The threat group forms that we in which every group except the initial threat group has apparent its
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:14:57,000 --> 00:15:00,000
|
| 871 |
+
threat is allowed to access information about.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:15:00,000 --> 00:15:06,000
|
| 875 |
+
Its own strength group, but not the access information about its groups, parents or the group or any
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:15:06,000 --> 00:15:11,000
|
| 879 |
+
other group, this that helps us to manage a group of threats as a single unit.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:15:11,000 --> 00:15:17,000
|
| 883 |
+
This is extremely valuable when you want to perform such operations as interrupt, for example, for
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:15:17,000 --> 00:15:19,000
|
| 887 |
+
all threats, I will not lie to you.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:15:19,000 --> 00:15:22,000
|
| 891 |
+
And I'm going to say that this type is not very popular today.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:15:23,000 --> 00:15:28,000
|
| 895 |
+
In this search code, you can find and mentions a certain group is pretty old type that was created
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:15:28,000 --> 00:15:30,000
|
| 899 |
+
in Java version one.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:15:30,000 --> 00:15:36,000
|
| 903 |
+
That's why I don't see a lot of sense to go over each message here and show you an example for each
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:15:36,000 --> 00:15:41,000
|
| 907 |
+
Massett, because it is very less likely that you will use this class in production.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:15:41,000 --> 00:15:47,000
|
| 911 |
+
But still, I believe it was me sharing it with you for general educational purposes, at least on the
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:15:47,000 --> 00:15:52,000
|
| 915 |
+
high level, because programming languages is constantly improved and new types are introduced.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:15:53,000 --> 00:15:59,000
|
| 919 |
+
But core principles are the same and understand in such basics as this class will help you to grasp
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:15:59,000 --> 00:16:00,000
|
| 923 |
+
new knowledge faster.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:16:01,000 --> 00:16:02,000
|
| 927 |
+
I open them a file.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:16:03,000 --> 00:16:10,000
|
| 931 |
+
The first things that I do in this example, Ikarus object basically very different constructors.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:16:10,000 --> 00:16:15,000
|
| 935 |
+
You can create a group with name or person as interest groups are supposed to be a parent for the new
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:16:15,000 --> 00:16:15,000
|
| 939 |
+
one.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:16:16,000 --> 00:16:22,000
|
| 943 |
+
And then after that I create multiple threats and possible reference to the third group in constructor.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:16:22,000 --> 00:16:28,000
|
| 947 |
+
Also, I incommensurable interface by persons, a reference to the execute method so each threat will
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:16:28,000 --> 00:16:31,000
|
| 951 |
+
have infinite loop and it will print its name.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:16:31,000 --> 00:16:37,000
|
| 955 |
+
Each half of the second and once read will be interrupted while sleeping will break the loop.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:16:37,000 --> 00:16:38,000
|
| 959 |
+
In main method.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:16:38,000 --> 00:16:45,000
|
| 963 |
+
I start all threads and make my main thread sleep for two seconds and after that I don't need to interrupt
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:16:45,000 --> 00:16:46,000
|
| 967 |
+
each thread separately.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:16:47,000 --> 00:16:54,000
|
| 971 |
+
But instead I look into wrapped method on a select group and I expect all threads in this group will
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:16:54,000 --> 00:16:54,000
|
| 975 |
+
be interrupted.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:16:55,000 --> 00:16:59,000
|
| 979 |
+
Let's run this program and see what we have and the result is expected.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:17:00,000 --> 00:17:04,000
|
| 983 |
+
We interrupted all threads and broke infinite loop jam is stopped.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:17:05,000 --> 00:17:11,000
|
| 987 |
+
This is how easily I can interact with a group of threads with the help of threads, group type and
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:17:11,000 --> 00:17:16,000
|
| 991 |
+
the last bit on the list sink for this lesson that I wanted to share with you is how to throw exceptions
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:17:16,000 --> 00:17:17,000
|
| 995 |
+
from the Runnable.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:17:17,000 --> 00:17:23,000
|
| 999 |
+
If you remember, one method in Runnable interface doesn't declare that it makes any exception.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:17:24,000 --> 00:17:29,000
|
| 1003 |
+
This is exactly the reason why we should handle all checked exceptions inside are unnecessary.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:17:29,000 --> 00:17:35,000
|
| 1007 |
+
But what if you don't know how to handle specific exception and you need to throw the exception according
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:17:35,000 --> 00:17:37,000
|
| 1011 |
+
to a logic, how to be in this case?
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:17:38,000 --> 00:17:42,000
|
| 1015 |
+
There is a dirty trick that you can do if needed to throw exceptions from the run.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:17:43,000 --> 00:17:44,000
|
| 1019 |
+
Pay attention.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:17:44,000 --> 00:17:46,000
|
| 1023 |
+
You can't leave without handloom.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:17:46,000 --> 00:17:51,000
|
| 1027 |
+
Check the exceptions, but nobody set any restrictions on unchecked exceptions.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:17:52,000 --> 00:17:53,000
|
| 1031 |
+
They understand what I mean.
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:17:53,000 --> 00:17:58,000
|
| 1035 |
+
We'll wrap our checked exception in and check in our example.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:17:58,000 --> 00:18:03,000
|
| 1039 |
+
You can see how I tried to imitate IO exception by putting illegal pasta sauce.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:18:03,000 --> 00:18:06,000
|
| 1043 |
+
I catch the exception and throw a new one.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:18:06,000 --> 00:18:13,000
|
| 1047 |
+
This time I throw runtime exception and I pass an exception to a constructor like a course of the exception.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:18:13,000 --> 00:18:16,000
|
| 1051 |
+
Let's execute this thread and see what we have.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:18:16,000 --> 00:18:17,000
|
| 1055 |
+
Great.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:18:17,000 --> 00:18:23,000
|
| 1059 |
+
You have runtime exception which caused by no such file exception and now you're Lowgar will be able
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:18:23,000 --> 00:18:30,000
|
| 1063 |
+
to grab this looks to the proper and actual issues that will help you during investigation and debugging
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:18:30,000 --> 00:18:31,000
|
| 1067 |
+
in the future.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:18:32,000 --> 00:18:36,000
|
| 1071 |
+
The information about those exceptional will help you to understand the reason of threat interruption.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:18:37,000 --> 00:18:40,000
|
| 1075 |
+
That's all what I wanted to share with you in this lesson.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:18:40,000 --> 00:18:43,000
|
| 1079 |
+
Let's recap what we have learned in this lesson.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:18:44,000 --> 00:18:45,000
|
| 1083 |
+
Is this lesson learned?
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:18:45,000 --> 00:18:48,000
|
| 1087 |
+
What is a threat scandal and how it works now?
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:18:48,000 --> 00:18:54,000
|
| 1091 |
+
You know what race condition is and what potential impact it can bring in this course, we'll learn
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:18:54,000 --> 00:18:56,000
|
| 1095 |
+
how to deal with race condition.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:18:56,000 --> 00:19:02,000
|
| 1099 |
+
Also, I showed you an example of how property property impacts and the threat and execution and how
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:19:02,000 --> 00:19:04,000
|
| 1103 |
+
your message works.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:19:04,000 --> 00:19:10,000
|
| 1107 |
+
We learned what the threats are and examples I showed you how you can manipulate a group of threats
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:19:10,000 --> 00:19:11,000
|
| 1111 |
+
with a group object.
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:19:12,000 --> 00:19:16,000
|
| 1115 |
+
And at the end of the lesson, I show you how we can throw exemption from randomness.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:19:17,000 --> 00:19:18,000
|
| 1119 |
+
That's it for this lesson.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:19:18,000 --> 00:19:20,000
|
| 1123 |
+
Thanks a lot for your attention.
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:19:20,000 --> 00:19:23,000
|
| 1127 |
+
Have a great day and see you in the next lesson.
|
| 1128 |
+
|
27 - Multithreading/004 Source-code-of-all-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/waitnotify
|
27 - Multithreading/004 Synchronization Basics_en.srt
ADDED
|
@@ -0,0 +1,1532 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:09,000
|
| 3 |
+
How are the students in this lesson, we are going to learn the basics of synchronization.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:10,000 --> 00:00:14,000
|
| 7 |
+
Synchronization is a huge topic and we'll learn it with you during multiple lessons.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:15,000 --> 00:00:20,000
|
| 11 |
+
This is the first lesson about stress and presentations that will give you basic knowledge when you
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:20,000 --> 00:00:22,000
|
| 15 |
+
create concurrent programs.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:22,000 --> 00:00:28,000
|
| 19 |
+
One of the most important things that you should care about is a synchronized access of multiple threats
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:28,000 --> 00:00:29,000
|
| 23 |
+
to the critical errors.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:30,000 --> 00:00:36,000
|
| 27 |
+
What is critical sections will learn with you today in this lesson also will learn with your concepts
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:36,000 --> 00:00:37,000
|
| 31 |
+
of monitor and mutex.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:38,000 --> 00:00:43,000
|
| 35 |
+
After this lesson, you will understand these two concepts where, well, I will explain to you what
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:43,000 --> 00:00:46,000
|
| 39 |
+
is at tormey cooperation and what is not.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:46,000 --> 00:00:53,000
|
| 43 |
+
Once you understand, all this theory will jump to practical examples and will create our first program
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:53,000 --> 00:00:54,000
|
| 47 |
+
with synchronized threats.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:54,000 --> 00:01:00,000
|
| 51 |
+
I will explain how a synchronized keyboard works with Marcedes, and at the end of the lesson I will
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:00,000 --> 00:01:04,000
|
| 55 |
+
explain such methods as a way to notify and notify all.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:04,000 --> 00:01:07,000
|
| 59 |
+
All objects in Java have these methods.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:07,000 --> 00:01:09,000
|
| 63 |
+
Let's start to begin with.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:09,000 --> 00:01:12,000
|
| 67 |
+
Let's understand what a critical section is.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:12,000 --> 00:01:18,000
|
| 71 |
+
It is important for us to learn this first because the rest of what we are going to do in this lesson
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:18,000 --> 00:01:21,000
|
| 75 |
+
is to synchronize access to critical sections.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:21,000 --> 00:01:25,000
|
| 79 |
+
That's why understanding of this term is critically important.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:25,000 --> 00:01:32,000
|
| 83 |
+
Imagine that you have multiple threats that are executed concurrently and there is block of code that
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:32,000 --> 00:01:36,000
|
| 87 |
+
theoretically may be available simultaneously for two threats.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:36,000 --> 00:01:43,000
|
| 91 |
+
This means that in some point of time it might happen that two or more threats will interact with some
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:43,000 --> 00:01:49,000
|
| 95 |
+
resource simultaneously that may cause mistakes in calculations and data.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:49,000 --> 00:01:50,000
|
| 99 |
+
Inconsistency.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:50,000 --> 00:01:57,000
|
| 103 |
+
In other words, critical section is a group of instructions that should be executed concurrently only
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:57,000 --> 00:02:01,000
|
| 107 |
+
by a specific number of threats and performance specific operations.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:01,000 --> 00:02:08,000
|
| 111 |
+
Usually it is one threat, but as we keep learning to read into advanced level, you would understand
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:08,000 --> 00:02:11,000
|
| 115 |
+
that sometimes we want to allow multiple threats to perform.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:11,000 --> 00:02:16,000
|
| 119 |
+
One operation was a resource and allow multiple threats to perform another operation.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:16,000 --> 00:02:22,000
|
| 123 |
+
For example, imagine that you have collection, let's say a list operation of the new elements, or
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:22,000 --> 00:02:25,000
|
| 127 |
+
at least should not allow other threats.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:25,000 --> 00:02:32,000
|
| 131 |
+
Read value from any index at mass should block access for all of the threats to read elements from specific
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:32,000 --> 00:02:38,000
|
| 135 |
+
index, because I can add new element in that position and that would cause there to be read by other
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:38,000 --> 00:02:39,000
|
| 139 |
+
threats.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:39,000 --> 00:02:46,000
|
| 143 |
+
At the same time, there is no need to look at the threats in case all threats only read data from my
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:46,000 --> 00:02:49,000
|
| 147 |
+
array list and don't change its state.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:50,000 --> 00:02:57,000
|
| 151 |
+
That's why I may allow as many threats as there exist to read data from our own list only until the
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:57,000 --> 00:03:01,000
|
| 155 |
+
moment of adding new elements to contain that will count does it make sense.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:02,000 --> 00:03:05,000
|
| 159 |
+
Now let's understand what is an atomic operation.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:05,000 --> 00:03:07,000
|
| 163 |
+
Atomic comes from Greek word atom.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:08,000 --> 00:03:12,000
|
| 167 |
+
That literally means uncuttable in computer science.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:12,000 --> 00:03:17,000
|
| 171 |
+
Atomic operation is operations that is performed with single processing cycle.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:17,000 --> 00:03:21,000
|
| 175 |
+
In other words, atomic operation is an interrupted operation.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:22,000 --> 00:03:23,000
|
| 179 |
+
Let's understand this, an example.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:24,000 --> 00:03:29,000
|
| 183 |
+
Imagine that you perform an increment of your object's property and you want to update its state.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:30,000 --> 00:03:34,000
|
| 187 |
+
What this thing is, this atomic operation, it is not.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:34,000 --> 00:03:35,000
|
| 191 |
+
Why?
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:35,000 --> 00:03:40,000
|
| 195 |
+
Because you have to read values that are stored in the piece of memory dictated to the class property
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:40,000 --> 00:03:41,000
|
| 199 |
+
variable first.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:42,000 --> 00:03:46,000
|
| 203 |
+
After that you need to perform an increment and add one.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:46,000 --> 00:03:51,000
|
| 207 |
+
After that, you need to store the result of additions in some place, and only after that you need
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:51,000 --> 00:03:55,000
|
| 211 |
+
to assign the result of increments to another variable.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:03:55,000 --> 00:03:57,000
|
| 215 |
+
Our class property is that clear.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:03:58,000 --> 00:04:04,000
|
| 219 |
+
So even such simple operation is the first glance like increment is not atomic, but in this case,
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:05,000 --> 00:04:07,000
|
| 223 |
+
what is an atomic operation?
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:07,000 --> 00:04:09,000
|
| 227 |
+
And simple words read and write.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:09,000 --> 00:04:11,000
|
| 231 |
+
Operations are atomic.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:11,000 --> 00:04:18,000
|
| 235 |
+
For example, assigning value to a variable is atomic operation removal value from array is atomic operation.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:18,000 --> 00:04:21,000
|
| 239 |
+
Assigning value is an atomic operation too.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:22,000 --> 00:04:29,000
|
| 243 |
+
Does it make sense also in general with a special package that contains only Tibs that execute not atomic
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:29,000 --> 00:04:35,000
|
| 247 |
+
operations by nature, but actually execute operations that looks like atomic, for example?
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:36,000 --> 00:04:41,000
|
| 251 |
+
You know, that increment and addition is not atomic operation by itself, but atomic integer, for
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:41,000 --> 00:04:48,000
|
| 255 |
+
example, maybe from addition of another in synchronized manner to not allow any other threat interrupt
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:48,000 --> 00:04:55,000
|
| 259 |
+
execution of the separation later in this course, will review is generally two concurrent atomic package
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:04:55,000 --> 00:04:58,000
|
| 263 |
+
that contains such types of perform atomic operations.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:04:59,000 --> 00:05:03,000
|
| 267 |
+
Would it a great single ready now you know what is an atomic.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:03,000 --> 00:05:07,000
|
| 271 |
+
Atomic operations also know what a critical section is.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:07,000 --> 00:05:12,000
|
| 275 |
+
Let's look at example now so that you can understand the problem of performing non atomic operations
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:12,000 --> 00:05:19,000
|
| 279 |
+
with multiple threats and why we need to synchronize access to critical section I open unsynchronized
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:19,000 --> 00:05:20,000
|
| 283 |
+
incremented file.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:20,000 --> 00:05:22,000
|
| 287 |
+
Let's look at the main message here.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:22,000 --> 00:05:29,000
|
| 291 |
+
And I will say you before we start that the quote below is a spaghetti code because we don't use executer
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:29,000 --> 00:05:34,000
|
| 295 |
+
in this example, considering the fact that by this moment in our course, we don't know.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:34,000 --> 00:05:40,000
|
| 299 |
+
Executor's, I will show you this example was BASIX, Red Cross and Runnable interface that we all know
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:41,000 --> 00:05:46,000
|
| 303 |
+
later in this course, we'll show you another solution, which is, in my opinion, more elegant.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:46,000 --> 00:05:53,000
|
| 307 |
+
But I will show it to you once we execute our stoppered hacker, at least that will contain references
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:53,000 --> 00:06:00,000
|
| 311 |
+
to ohmy threat objects, because I'm going to create 10000 thread objects when it's so many threads
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:00,000 --> 00:06:07,000
|
| 315 |
+
objects to be able to demo issues that may happen in case with performing on atomic operation with multiple
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:07,000 --> 00:06:09,000
|
| 319 |
+
threats have falu.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:09,000 --> 00:06:11,000
|
| 323 |
+
And you can see that in condition.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:11,000 --> 00:06:16,000
|
| 327 |
+
I verify that I made 10000 iterations on each iteration.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:16,000 --> 00:06:21,000
|
| 331 |
+
I create a new threat object with the following implementation of Runnable interface.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:21,000 --> 00:06:27,000
|
| 335 |
+
I increment my static int variables that is present in this class and I will perform this increment
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:27,000 --> 00:06:29,000
|
| 339 |
+
10000 times.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:29,000 --> 00:06:37,000
|
| 343 |
+
So what value will be here once all threats will perform increment ten thousand times will look at the
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:37,000 --> 00:06:43,000
|
| 347 |
+
answer in the minutes after that and look at reference of this threat to the common list of threats.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:43,000 --> 00:06:50,000
|
| 351 |
+
I need this to be able to request each threat to join main threat and make main threat, wait until
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:50,000 --> 00:06:52,000
|
| 355 |
+
all other threats will be executed.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:53,000 --> 00:07:00,000
|
| 359 |
+
And again, you need to see this code to feel relief later when you will start to use executer, because
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:00,000 --> 00:07:05,000
|
| 363 |
+
you will understand how executables would simplify interaction with multiple threats.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:05,000 --> 00:07:09,000
|
| 367 |
+
And in Body of the Loop, I start each threat after that.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:09,000 --> 00:07:14,000
|
| 371 |
+
And for each loop I ask each threat, the join main threat and make my main threat.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:14,000 --> 00:07:18,000
|
| 375 |
+
Wait until all other threats will be executed.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:18,000 --> 00:07:24,000
|
| 379 |
+
When all threats did incremented, we can print our variable to cancel and let's see.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:24,000 --> 00:07:28,000
|
| 383 |
+
Instead I will run program multiple times to let you see the issue.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:29,000 --> 00:07:32,000
|
| 387 |
+
Can you see that the result is not always 10000?
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:33,000 --> 00:07:35,000
|
| 391 |
+
They understand why this is happening.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:36,000 --> 00:07:43,000
|
| 395 |
+
That is because at some moment of time, two threats enter this method simultaneously and both threats
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:43,000 --> 00:07:48,000
|
| 399 |
+
read the same value of counter variable and each threat might increment.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:48,000 --> 00:07:51,000
|
| 403 |
+
But logically, this is two increments.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:51,000 --> 00:07:58,000
|
| 407 |
+
But in fact, once we get our right increment result from as a threat and we got lost update, is it
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:58,000 --> 00:08:02,000
|
| 411 |
+
clear now and what to do and how to solve this issue?
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:02,000 --> 00:08:05,000
|
| 415 |
+
You already can easily spot where critical section is.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:06,000 --> 00:08:12,000
|
| 419 |
+
We need to synchronize access of different threats to our critical section where we are careful not
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:12,000 --> 00:08:13,000
|
| 423 |
+
optronics operation.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:14,000 --> 00:08:20,000
|
| 427 |
+
That's why I started the lesson from explanation of critical sections and atomic operations to make
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:20,000 --> 00:08:25,000
|
| 431 |
+
sure that by this moment of time in our lesson, you would understand what I'm talking about.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:25,000 --> 00:08:28,000
|
| 435 |
+
Let's now try to solve this issue.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:28,000 --> 00:08:35,000
|
| 439 |
+
To solve this issue, we need to control concurrent access to the critical area, the basic to enjoy.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:35,000 --> 00:08:37,000
|
| 443 |
+
The key for this is synchronized keyword.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:38,000 --> 00:08:40,000
|
| 447 |
+
Let me open synchronized increment class.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:41,000 --> 00:08:45,000
|
| 451 |
+
This is similar example to the previous one was only one difference.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:45,000 --> 00:08:48,000
|
| 455 |
+
My increment method synchronized keyword here.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:49,000 --> 00:08:51,000
|
| 459 |
+
Let's run our program now multiple times.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:51,000 --> 00:08:59,000
|
| 463 |
+
And you can see now that I constantly have ten thousand and so is it is because this synchronized keyword
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:08:59,000 --> 00:09:03,000
|
| 467 |
+
doesn't allow to stress access is block of code simultaneously.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:04,000 --> 00:09:07,000
|
| 471 |
+
That's why we just eliminated all possible errors.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:07,000 --> 00:09:10,000
|
| 475 |
+
How to synchronize keywords for X.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:10,000 --> 00:09:14,000
|
| 479 |
+
We need to understand this to create more complex solutions with better performance.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:15,000 --> 00:09:21,000
|
| 483 |
+
To understand how to synchronize keyboard works, we need to understand such important concepts in Montessori,
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:21,000 --> 00:09:24,000
|
| 487 |
+
in programming as mutex and monitor.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:24,000 --> 00:09:27,000
|
| 491 |
+
Let's start from understanding of what Moneta is.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:28,000 --> 00:09:33,000
|
| 495 |
+
And once we learned what I wanted to ask, how explain the difference between the index and monitor
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:34,000 --> 00:09:36,000
|
| 499 |
+
my own definition of monitor.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:09:36,000 --> 00:09:42,000
|
| 503 |
+
Sounds like this monitor is a mechanism to synchronize threads, access to critical sections.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:43,000 --> 00:09:50,000
|
| 507 |
+
More common definition from Wikipedia also includes other properties of monitor like ability to allow
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:50,000 --> 00:09:55,000
|
| 511 |
+
stress to have both mutuel exclusion and the ability to wait for a critical condition.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:56,000 --> 00:10:02,000
|
| 515 |
+
By the way, mutuel exclusion is also churl from computer science and describes the property of.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:10:02,000 --> 00:10:09,000
|
| 519 |
+
Currency control, which should prevent a race condition by not allowing any threat, entering a political
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:09,000 --> 00:10:15,000
|
| 523 |
+
section, if some as a threat currently executing the court of critical section somewhere, you married
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:10:15,000 --> 00:10:23,000
|
| 527 |
+
another definition saying that monitor is a threat, safe class object or module that is partially also
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:23,000 --> 00:10:24,000
|
| 531 |
+
makes sense.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:24,000 --> 00:10:31,000
|
| 535 |
+
We can use an object as a flag and as a monitor to indicate which threat captures and monitor of the
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:31,000 --> 00:10:34,000
|
| 539 |
+
object and which threat released monitor of the object.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:35,000 --> 00:10:39,000
|
| 543 |
+
So injera monitor is implicitly associated with an object.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:39,000 --> 00:10:42,000
|
| 547 |
+
Let me support my explanation, which was analyzation.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:10:43,000 --> 00:10:45,000
|
| 551 |
+
Let's look at the example with my car.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:10:45,000 --> 00:10:52,000
|
| 555 |
+
Here is my only Rs5 that can reach 60 miles per hour in less than a three point five seconds.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:10:52,000 --> 00:10:55,000
|
| 559 |
+
This has nothing in common with multiscreen and yet.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:55,000 --> 00:10:56,000
|
| 563 |
+
But we will jump to the details.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:56,000 --> 00:11:01,000
|
| 567 |
+
So imagine that this car is a monitor and critical sections.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:11:01,000 --> 00:11:06,000
|
| 571 |
+
Here are accelerator pedal, brake pedal, steering wheel and so on.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:11:07,000 --> 00:11:08,000
|
| 575 |
+
I'm a threat.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:09,000 --> 00:11:12,000
|
| 579 |
+
And girlfriend of mine is another threat of execution.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:13,000 --> 00:11:16,000
|
| 583 |
+
Those threats can't simultaneously interact with.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:17,000 --> 00:11:22,000
|
| 587 |
+
It will be horrible sink in case me and your friend of mine will be pushing on different pedals simultaneously.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:23,000 --> 00:11:27,000
|
| 591 |
+
I can capture, monitor and do operations with the cars that they need.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:28,000 --> 00:11:30,000
|
| 595 |
+
I open the car and drive to an office.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:11:30,000 --> 00:11:33,000
|
| 599 |
+
And when I got back home, I released the monitor.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:11:34,000 --> 00:11:40,000
|
| 603 |
+
When the monitor is released and a threat, my girlfriend can take it and can go to the beauty salon,
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:11:40,000 --> 00:11:41,000
|
| 607 |
+
for example.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:11:41,000 --> 00:11:49,000
|
| 611 |
+
Is it clear so far there are also some methods that allow to interact with, monitor their weight,
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:49,000 --> 00:11:51,000
|
| 615 |
+
notify and notify all.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:11:51,000 --> 00:11:52,000
|
| 619 |
+
Wait.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:11:52,000 --> 00:11:59,000
|
| 623 |
+
MassArt is overloaded and has versions with arguments that time related arguments milliseconds and nanoseconds
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:12:00,000 --> 00:12:09,000
|
| 627 |
+
zest masses inherited in all types from object class because all objects in Java implicitly extant object
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:12:09,000 --> 00:12:09,000
|
| 631 |
+
class.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:12:10,000 --> 00:12:11,000
|
| 635 |
+
What these methods do.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:12,000 --> 00:12:13,000
|
| 639 |
+
Let's review an example.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:12:14,000 --> 00:12:21,000
|
| 643 |
+
Imagine that my girlfriend took a car and all of a sudden something happened with a car and it was stopped
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:12:21,000 --> 00:12:21,000
|
| 647 |
+
unexpectedly.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:12:22,000 --> 00:12:26,000
|
| 651 |
+
She called me and asked me to pick up her with the car and help.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:12:26,000 --> 00:12:32,000
|
| 655 |
+
When I found her in the city, she went out of the car and let me in what she did.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:12:32,000 --> 00:12:37,000
|
| 659 |
+
She released more nature of the object temporarily and let me capture monitor.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:12:38,000 --> 00:12:44,000
|
| 663 |
+
She still has intention to drive further, but she just let me also perform some actions with the car.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:12:44,000 --> 00:12:46,000
|
| 667 |
+
And that is exactly what the weight method does.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:46,000 --> 00:12:51,000
|
| 671 |
+
It's just really this monitor and let us the capture monitor.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:51,000 --> 00:12:57,000
|
| 675 |
+
I was happy to discover that my girlfriend just didn't activate Immobiliser and the engine appeared
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:12:57,000 --> 00:12:58,000
|
| 679 |
+
to be blocked.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:12:58,000 --> 00:13:03,000
|
| 683 |
+
I think that and told her that she can drive from wherever she needs.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:13:03,000 --> 00:13:11,000
|
| 687 |
+
What I did, I called notify Masset on the monitor, notify Masset makes all threats that we're waiting
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:13:11,000 --> 00:13:14,000
|
| 691 |
+
are aware that they can proceed their work.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:13:14,000 --> 00:13:21,000
|
| 695 |
+
That means we use with Massata to let other threats perform some actions and modify the state of some
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:13:21,000 --> 00:13:24,000
|
| 699 |
+
objects if needed, of some shared resources.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:24,000 --> 00:13:31,000
|
| 703 |
+
And after that, other threats should call notify Masset to update all threats that they've done.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:13:32,000 --> 00:13:34,000
|
| 707 |
+
Another example of wait and notify.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:13:35,000 --> 00:13:39,000
|
| 711 |
+
You're going to have coding exercises soon and there will be a task about readers and writers.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:13:39,000 --> 00:13:46,000
|
| 715 |
+
For example, readers interact with some buffer of memory where readers should find information to read
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:13:47,000 --> 00:13:52,000
|
| 719 |
+
readers captions and monitor of buffer object and doesn't allow anyone to work with it.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:13:53,000 --> 00:13:59,000
|
| 723 |
+
Once readers read all information from Buffer and Buffer is empty, they're turned into the waiting
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:13:59,000 --> 00:14:04,000
|
| 727 |
+
state and they wait until right to put your information into the buffer.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:14:05,000 --> 00:14:11,000
|
| 731 |
+
Once the writer finished its job and put all information and buffer it, notifies our readers that we're
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:14:11,000 --> 00:14:16,000
|
| 735 |
+
in a weakened state by and notify all Masset on buffer object.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:14:16,000 --> 00:14:20,000
|
| 739 |
+
And now readers continue with information from Buffer and so on.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:14:20,000 --> 00:14:27,000
|
| 743 |
+
Notify all is a matter to notify not only once residents in waiting queue, but notify us all threats
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:14:27,000 --> 00:14:28,000
|
| 747 |
+
that time in the waiting queue.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:14:29,000 --> 00:14:33,000
|
| 751 |
+
Hope that now you understood what is and wanted to know.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:14:33,000 --> 00:14:38,000
|
| 755 |
+
Let's understand the difference between two terms monitor and mutex.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:14:38,000 --> 00:14:44,000
|
| 759 |
+
Conceptually, these two terms are similar zooni difference is how they are implemented inside.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:14:45,000 --> 00:14:52,000
|
| 763 |
+
Usually the implementation of monitors is faster light weight since it is designed for multiple threaded
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:14:52,000 --> 00:14:54,000
|
| 767 |
+
synchronization within the same process.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:14:55,000 --> 00:15:01,000
|
| 771 |
+
Also, usually it is provided by a framework library itself and not request the operating system.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:15:01,000 --> 00:15:05,000
|
| 775 |
+
Usually matrixes are provided by the operating system.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:15:05,000 --> 00:15:12,000
|
| 779 |
+
Kernell what is always Curnoe in simple words, it is a computer program at the core of the computer's
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:15:12,000 --> 00:15:16,000
|
| 783 |
+
operating system and has complete control over everything in the system.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:15:17,000 --> 00:15:21,000
|
| 787 |
+
It also handles data processing instructions for the central processing unit.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:15:22,000 --> 00:15:27,000
|
| 791 |
+
It is a portion of the operating system code that is always resident in memory.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:15:28,000 --> 00:15:33,000
|
| 795 |
+
Usually libraries frameworks simply provide an interface to invoke mutex.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:15:33,000 --> 00:15:40,000
|
| 799 |
+
This makes them heavy weight slower, but allows us to achieve expected to result to synchronize threads
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:15:40,000 --> 00:15:42,000
|
| 803 |
+
between each other and lock on.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:15:42,000 --> 00:15:49,000
|
| 807 |
+
Mutex from neutral exclusion is a mechanism that enforces limits on access to resource.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:15:49,000 --> 00:15:55,000
|
| 811 |
+
When there are many threats of execution, a lock is designed to enforce a mutual exclusion.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:15:55,000 --> 00:16:01,000
|
| 815 |
+
Concurrency Control Policy and Monitor consists of a mutex lock object and condition variables.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:16:01,000 --> 00:16:07,000
|
| 819 |
+
A condition variable essentially is a container of threats that are waiting for a certain condition
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:16:08,000 --> 00:16:08,000
|
| 823 |
+
more.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:16:08,000 --> 00:16:14,000
|
| 827 |
+
Charters provide a mechanism for threats to temporarily give up exclusive access in order to wait for
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:16:14,000 --> 00:16:19,000
|
| 831 |
+
some conditions to be met before gaining exclusive access and resuming their task.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:16:20,000 --> 00:16:26,000
|
| 835 |
+
So monitor is different than mutex, but they can be considered similar in the sense that the monitor
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:16:26,000 --> 00:16:31,000
|
| 839 |
+
is built on top of mutex in this lesson we'll use to monitor transfers.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:16:31,000 --> 00:16:36,000
|
| 843 |
+
But just in case you heard that somebody uses mutex term, you'll really know the difference.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:16:37,000 --> 00:16:43,000
|
| 847 |
+
Now, let's look at the Korean example and we'll try to understand how monitor works, how synchronization
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:16:43,000 --> 00:16:47,000
|
| 851 |
+
happens and practice example, a way to notify interaction.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:16:47,000 --> 00:16:51,000
|
| 855 |
+
Let's get back to synchronized examples that we already saw today.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:16:51,000 --> 00:16:54,000
|
| 859 |
+
There is one more method here that is similar to synchronized one.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:16:55,000 --> 00:17:00,000
|
| 863 |
+
Pay attention that this method doesn't have synchronized keywords in the same line was messed name,
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:17:00,000 --> 00:17:02,000
|
| 867 |
+
but it contains synchronized block.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:17:03,000 --> 00:17:03,000
|
| 871 |
+
What is this?
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:17:04,000 --> 00:17:09,000
|
| 875 |
+
So when you have synchronized Masad, it is fair to say that you captured the monitor of this object
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:17:10,000 --> 00:17:12,000
|
| 879 |
+
of object which he used to Vogues and mastered.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:17:13,000 --> 00:17:19,000
|
| 883 |
+
But what object you used to walk in Inmarsat in this case and also how it works with static methods,
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:17:19,000 --> 00:17:21,000
|
| 887 |
+
with static methods.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:17:21,000 --> 00:17:25,000
|
| 891 |
+
You capture Moneta of this class to create synchronized block.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:17:25,000 --> 00:17:31,000
|
| 895 |
+
You have to pass the reference to an object where you want to capture monitor right now.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:17:31,000 --> 00:17:33,000
|
| 899 |
+
And this block may enter only once read.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:17:33,000 --> 00:17:40,000
|
| 903 |
+
And once the threat will leave this block, it will release monitor of this class and the next threat
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:17:40,000 --> 00:17:45,000
|
| 907 |
+
will enter this block and will capture monitor, of course, with synchronized methods.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:17:45,000 --> 00:17:51,000
|
| 911 |
+
That principle is the same, but you just have synchronized access to the whole method, and not only
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:17:51,000 --> 00:17:56,000
|
| 915 |
+
for a specific part of it, why you might want to use synchronize blocks.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:17:56,000 --> 00:18:02,000
|
| 919 |
+
So this part of the spreading optimization, because it may be that actually not aligned in your methods
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:18:02,000 --> 00:18:04,000
|
| 923 |
+
is a critical section.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:18:04,000 --> 00:18:09,000
|
| 927 |
+
Probably there are some operations that have multiple threads may perform in parallel.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:18:09,000 --> 00:18:11,000
|
| 931 |
+
That might be really different cases.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:18:11,000 --> 00:18:16,000
|
| 935 |
+
For example, here you will print some text to console or you just want to log that.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:18:16,000 --> 00:18:22,000
|
| 939 |
+
You enter this method and you want to log some message after critical section, or it can be some preparation
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:18:22,000 --> 00:18:24,000
|
| 943 |
+
activities before the duration.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:18:24,000 --> 00:18:27,000
|
| 947 |
+
Anyway, log in print and text.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:18:27,000 --> 00:18:30,000
|
| 951 |
+
The console in this case is not a critical section.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:18:30,000 --> 00:18:34,000
|
| 955 |
+
This will not bring you to inconsistent state of your system.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:18:34,000 --> 00:18:41,000
|
| 959 |
+
That's why there is no need to make your threats, wait to do operations that they can do now without
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:18:41,000 --> 00:18:42,000
|
| 963 |
+
waiting.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:18:42,000 --> 00:18:47,000
|
| 967 |
+
So all core outside of the synchronized block may be executed concurrently.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:18:48,000 --> 00:18:54,000
|
| 971 |
+
When you will create a certain program, always ask yourself, do I need to synchronize access to this
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:18:54,000 --> 00:19:00,000
|
| 975 |
+
chunk of code or know what will happen if the threat will execute this code simultaneously?
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:19:00,000 --> 00:19:06,000
|
| 979 |
+
And in case you discover that nothing bad would happen, do not with this code in synchronized lock,
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:19:07,000 --> 00:19:12,000
|
| 983 |
+
because in this case you would improve performance of your app by not making your sweats.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:19:12,000 --> 00:19:12,000
|
| 987 |
+
Wait.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:19:12,000 --> 00:19:19,000
|
| 991 |
+
And when they shouldn't be waiting in general, this is rule of thumb to have a small synchronized block
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:19:19,000 --> 00:19:19,000
|
| 995 |
+
as possible.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:19:20,000 --> 00:19:25,000
|
| 999 |
+
In case this method won't be static, you will capture monitor of another object.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:19:25,000 --> 00:19:32,000
|
| 1003 |
+
In this case, you would capture monitor of this object, the one that invokes this method.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:19:32,000 --> 00:19:34,000
|
| 1007 |
+
So these two methods now are similar.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:19:35,000 --> 00:19:40,000
|
| 1011 |
+
What potential drawback you see in using synchronize locks with synchronized locks?
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:19:40,000 --> 00:19:45,000
|
| 1015 |
+
You can't capture a monitor in one place and release it completely in another place.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:19:46,000 --> 00:19:52,000
|
| 1019 |
+
You can't describe synchronized lock in multiple methods, but there is so called a lock API that we
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:19:52,000 --> 00:19:54,000
|
| 1023 |
+
are going to learn all kinds.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:19:54,000 --> 00:19:59,000
|
| 1027 |
+
Of course, that will allow you to capture more data in one place and release it somewhere else.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:20:00,000 --> 00:20:06,000
|
| 1031 |
+
Now let's look at WAF not for example, I grouped all the classes related to this example in a separate
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:20:06,000 --> 00:20:06,000
|
| 1035 |
+
package.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:20:06,000 --> 00:20:08,000
|
| 1039 |
+
Here was name with Latifi.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:20:09,000 --> 00:20:14,000
|
| 1043 |
+
Let me open them a file and will start from one could imagine that I have some message.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:20:14,000 --> 00:20:19,000
|
| 1047 |
+
I create object of this type and left some message to process it.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:20:19,000 --> 00:20:25,000
|
| 1051 |
+
Let's have a look at the source code of message type message has one properties and describes its state.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:20:26,000 --> 00:20:32,000
|
| 1055 |
+
It is called message and need this type fostering position because he already knows that string itself
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:20:32,000 --> 00:20:34,000
|
| 1059 |
+
immutable object.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:20:34,000 --> 00:20:36,000
|
| 1063 |
+
Once a great object of type string.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:20:36,000 --> 00:20:38,000
|
| 1067 |
+
I can't change it state.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:20:39,000 --> 00:20:46,000
|
| 1071 |
+
That's why I created separate type that has API that allows me to update the state of the same object.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:20:46,000 --> 00:20:48,000
|
| 1075 |
+
Also, there are two matters here.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:20:48,000 --> 00:20:49,000
|
| 1079 |
+
Getter and setter.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:20:50,000 --> 00:20:50,000
|
| 1083 |
+
That's it.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:20:51,000 --> 00:20:52,000
|
| 1087 |
+
Let's get back to the demo file.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:20:53,000 --> 00:20:56,000
|
| 1091 |
+
The second object that I create here is a reader object.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:20:56,000 --> 00:20:58,000
|
| 1095 |
+
I pass a reference to the message object.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:20:58,000 --> 00:20:59,000
|
| 1099 |
+
We are constructor.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:21:00,000 --> 00:21:06,000
|
| 1103 |
+
After that I create a threat object based reference to the readers and name as threat as reader one
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:21:06,000 --> 00:21:07,000
|
| 1107 |
+
and start the threat.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:21:08,000 --> 00:21:14,000
|
| 1111 |
+
Probably already understands its rather implements Runnable interface, and you're right where you source
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:21:14,000 --> 00:21:16,000
|
| 1115 |
+
code of reading type in a few seconds.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:21:17,000 --> 00:21:19,000
|
| 1119 |
+
Also another reader and pay attention.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:21:20,000 --> 00:21:22,000
|
| 1123 |
+
I pass the same message, object to the constructor.
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:21:23,000 --> 00:21:26,000
|
| 1127 |
+
This would be exactly the object that I would use for multiple threads.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:21:26,000 --> 00:21:32,000
|
| 1131 |
+
Synchronization here I create another thread, object to his name reader to and run this thread.
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:21:33,000 --> 00:21:39,000
|
| 1135 |
+
So after this line we would have three threads running my main threat and to readers threats.
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:21:40,000 --> 00:21:44,000
|
| 1139 |
+
Let's learn what will be executed inside our readers around method.
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:21:45,000 --> 00:21:49,000
|
| 1143 |
+
As you can see, reader class implements Runnable Interface.
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:21:49,000 --> 00:21:50,000
|
| 1147 |
+
It has one property.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:21:51,000 --> 00:21:58,000
|
| 1151 |
+
This is property of message type inside the one massive yet name of the thread for our demo purposes
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:21:58,000 --> 00:21:59,000
|
| 1155 |
+
to print its name to consult.
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:22:00,000 --> 00:22:02,000
|
| 1159 |
+
And after that I have synchronized S..
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:22:03,000 --> 00:22:09,000
|
| 1163 |
+
I didn't make synchronized maps because in this case all reader objects would have separate monitor
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:22:10,000 --> 00:22:11,000
|
| 1167 |
+
and need common monitoring.
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:22:11,000 --> 00:22:13,000
|
| 1171 |
+
There's a shared between two threats.
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:22:14,000 --> 00:22:20,000
|
| 1175 |
+
This is additional advantage of synchronized block because you can pass any object as a reference to
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:22:20,000 --> 00:22:21,000
|
| 1179 |
+
capture monitor.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:22:22,000 --> 00:22:26,000
|
| 1183 |
+
And I have this massive object that is shared between two waiters.
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:22:26,000 --> 00:22:29,000
|
| 1187 |
+
So I kept your monitor off message object.
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:22:29,000 --> 00:22:37,000
|
| 1191 |
+
After that, I claim to cancel and indicate that this threat is waiting to be notified and Prince Current
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:22:37,000 --> 00:22:41,000
|
| 1195 |
+
milliseconds after that I go wait Masad on my message object.
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:22:41,000 --> 00:22:47,000
|
| 1199 |
+
One more important thing you can call way Massud only in specific context.
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:22:47,000 --> 00:22:53,000
|
| 1203 |
+
You can call this method only from synchronized sections and from synchronized methods in case you would
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:22:53,000 --> 00:22:54,000
|
| 1207 |
+
invoke weight.
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:22:54,000 --> 00:23:00,000
|
| 1211 |
+
Massive note in synchronized context, you will get runtime exception with name, illegal and interstate
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:23:00,000 --> 00:23:04,000
|
| 1215 |
+
exception because Red is not an owner of a monitor.
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:23:05,000 --> 00:23:11,000
|
| 1219 |
+
Once I call Weight Masset, this thread is in the waiting queue to proceed execution when it will be
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:23:11,000 --> 00:23:12,000
|
| 1223 |
+
notified.
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:23:12,000 --> 00:23:16,000
|
| 1227 |
+
At the same time, the second reader managed to enter this section.
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:23:16,000 --> 00:23:23,000
|
| 1231 |
+
Considering the first reader called Wait Masset on monitor, that means that the monitor is not blocked
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:23:23,000 --> 00:23:26,000
|
| 1235 |
+
and another reader can enter the section.
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:23:26,000 --> 00:23:29,000
|
| 1239 |
+
Now it is time to learn what is happening next.
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:23:29,000 --> 00:23:31,000
|
| 1243 |
+
Let's get back to our demo file.
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:23:31,000 --> 00:23:34,000
|
| 1247 |
+
Now it's time to create a notifier object.
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:23:34,000 --> 00:23:39,000
|
| 1251 |
+
Notifier type is my custom type that I also described in this package.
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:23:39,000 --> 00:23:43,000
|
| 1255 |
+
Pay attention that I pass the reference to the same message object.
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:23:43,000 --> 00:23:44,000
|
| 1259 |
+
Great.
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:23:44,000 --> 00:23:48,000
|
| 1263 |
+
A threat was named Notifier and started after that.
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:23:48,000 --> 00:23:49,000
|
| 1267 |
+
I printed all threads I started.
|
| 1268 |
+
|
| 1269 |
+
318
|
| 1270 |
+
00:23:50,000 --> 00:23:52,000
|
| 1271 |
+
Let's investigate what this notified do.
|
| 1272 |
+
|
| 1273 |
+
319
|
| 1274 |
+
00:23:52,000 --> 00:23:58,000
|
| 1275 |
+
As you can see, objects of this type also will store as a reference to the message object.
|
| 1276 |
+
|
| 1277 |
+
320
|
| 1278 |
+
00:23:58,000 --> 00:23:59,000
|
| 1279 |
+
This is our monitor.
|
| 1280 |
+
|
| 1281 |
+
321
|
| 1282 |
+
00:24:00,000 --> 00:24:07,000
|
| 1283 |
+
In one method we get the name of the threat and indicate that this threat started its work after Z,
|
| 1284 |
+
|
| 1285 |
+
322
|
| 1286 |
+
00:24:07,000 --> 00:24:10,000
|
| 1287 |
+
I made this threat sleep for one hundred milliseconds.
|
| 1288 |
+
|
| 1289 |
+
323
|
| 1290 |
+
00:24:10,000 --> 00:24:14,000
|
| 1291 |
+
This is to ensure that the reader objects captured monitor first.
|
| 1292 |
+
|
| 1293 |
+
324
|
| 1294 |
+
00:24:14,000 --> 00:24:22,000
|
| 1295 |
+
Once the threat wakes up, I try to enter, synchronize the book and undo any other threat is captured
|
| 1296 |
+
|
| 1297 |
+
325
|
| 1298 |
+
00:24:22,000 --> 00:24:23,000
|
| 1299 |
+
in message monitor.
|
| 1300 |
+
|
| 1301 |
+
326
|
| 1302 |
+
00:24:23,000 --> 00:24:30,000
|
| 1303 |
+
All other threats, including this one will stay right before the critical section and would not enter
|
| 1304 |
+
|
| 1305 |
+
327
|
| 1306 |
+
00:24:30,000 --> 00:24:34,000
|
| 1307 |
+
it until get notified from the threats that the monitor is released.
|
| 1308 |
+
|
| 1309 |
+
328
|
| 1310 |
+
00:24:34,000 --> 00:24:37,000
|
| 1311 |
+
You remember that in other threats we invoked.
|
| 1312 |
+
|
| 1313 |
+
329
|
| 1314 |
+
00:24:37,000 --> 00:24:38,000
|
| 1315 |
+
Wait Massett.
|
| 1316 |
+
|
| 1317 |
+
330
|
| 1318 |
+
00:24:38,000 --> 00:24:43,000
|
| 1319 |
+
That means that Notifier may enter this section and capture Monisha.
|
| 1320 |
+
|
| 1321 |
+
331
|
| 1322 |
+
00:24:43,000 --> 00:24:45,000
|
| 1323 |
+
In this critical section.
|
| 1324 |
+
|
| 1325 |
+
332
|
| 1326 |
+
00:24:45,000 --> 00:24:47,000
|
| 1327 |
+
We perform message processing.
|
| 1328 |
+
|
| 1329 |
+
333
|
| 1330 |
+
00:24:47,000 --> 00:24:51,000
|
| 1331 |
+
We change the text to indicate which Notifier updated the message.
|
| 1332 |
+
|
| 1333 |
+
334
|
| 1334 |
+
00:24:51,000 --> 00:24:59,000
|
| 1335 |
+
And after that I invoke is to notify or notify all assets in case I would invoke notify massive on the
|
| 1336 |
+
|
| 1337 |
+
335
|
| 1338 |
+
00:24:59,000 --> 00:25:01,000
|
| 1339 |
+
one threat will be notified.
|
| 1340 |
+
|
| 1341 |
+
336
|
| 1342 |
+
00:25:01,000 --> 00:25:03,000
|
| 1343 |
+
Is a reader one or reader.
|
| 1344 |
+
|
| 1345 |
+
337
|
| 1346 |
+
00:25:03,000 --> 00:25:04,000
|
| 1347 |
+
So let's check this.
|
| 1348 |
+
|
| 1349 |
+
338
|
| 1350 |
+
00:25:05,000 --> 00:25:06,000
|
| 1351 |
+
I run them a file.
|
| 1352 |
+
|
| 1353 |
+
339
|
| 1354 |
+
00:25:06,000 --> 00:25:11,000
|
| 1355 |
+
Here is a notification about we do once read started notify us.
|
| 1356 |
+
|
| 1357 |
+
340
|
| 1358 |
+
00:25:11,000 --> 00:25:16,000
|
| 1359 |
+
Threats started here and we are to start started and waiting to get notified here at this time.
|
| 1360 |
+
|
| 1361 |
+
341
|
| 1362 |
+
00:25:17,000 --> 00:25:22,000
|
| 1363 |
+
And once I called notify MassArt reader finished its execution.
|
| 1364 |
+
|
| 1365 |
+
342
|
| 1366 |
+
00:25:22,000 --> 00:25:27,000
|
| 1367 |
+
So now you can see that we do one, get notified and read other one message.
|
| 1368 |
+
|
| 1369 |
+
343
|
| 1370 |
+
00:25:27,000 --> 00:25:30,000
|
| 1371 |
+
Protest in the source code of reader class.
|
| 1372 |
+
|
| 1373 |
+
344
|
| 1374 |
+
00:25:30,000 --> 00:25:36,000
|
| 1375 |
+
You can see that I print this text to console after wait Macit at the end of round method.
|
| 1376 |
+
|
| 1377 |
+
345
|
| 1378 |
+
00:25:36,000 --> 00:25:39,000
|
| 1379 |
+
So often defecation all code that is below.
|
| 1380 |
+
|
| 1381 |
+
346
|
| 1382 |
+
00:25:39,000 --> 00:25:41,000
|
| 1383 |
+
Wait Massata got executed.
|
| 1384 |
+
|
| 1385 |
+
347
|
| 1386 |
+
00:25:41,000 --> 00:25:44,000
|
| 1387 |
+
Pay attention that our game isn't stopped yet.
|
| 1388 |
+
|
| 1389 |
+
348
|
| 1390 |
+
00:25:44,000 --> 00:25:50,000
|
| 1391 |
+
You can see this red stop sign that tells us that I can stop game but it is run.
|
| 1392 |
+
|
| 1393 |
+
349
|
| 1394 |
+
00:25:50,000 --> 00:25:53,000
|
| 1395 |
+
But why another idle threat is working now.
|
| 1396 |
+
|
| 1397 |
+
350
|
| 1398 |
+
00:25:54,000 --> 00:25:56,000
|
| 1399 |
+
It actually does nothing at the moment.
|
| 1400 |
+
|
| 1401 |
+
351
|
| 1402 |
+
00:25:56,000 --> 00:25:59,000
|
| 1403 |
+
It is just waiting to be notified in this line.
|
| 1404 |
+
|
| 1405 |
+
352
|
| 1406 |
+
00:26:00,000 --> 00:26:05,000
|
| 1407 |
+
But only we know that there are no threats left in the app right now that would be able to notify us
|
| 1408 |
+
|
| 1409 |
+
353
|
| 1410 |
+
00:26:05,000 --> 00:26:08,000
|
| 1411 |
+
with their object all as a threat.
|
| 1412 |
+
|
| 1413 |
+
354
|
| 1414 |
+
00:26:08,000 --> 00:26:15,000
|
| 1415 |
+
I mean, the main threat with the one threat notifier already executed and finished, and this is the
|
| 1416 |
+
|
| 1417 |
+
355
|
| 1418 |
+
00:26:15,000 --> 00:26:17,000
|
| 1419 |
+
last threat that is waiting right now.
|
| 1420 |
+
|
| 1421 |
+
356
|
| 1422 |
+
00:26:17,000 --> 00:26:24,000
|
| 1423 |
+
Let me stop again if you know that such case may happen, in case you know that two more threats might
|
| 1424 |
+
|
| 1425 |
+
357
|
| 1426 |
+
00:26:24,000 --> 00:26:30,000
|
| 1427 |
+
enter a critical section and wait until being notified, you should think about your multiscreen logic
|
| 1428 |
+
|
| 1429 |
+
358
|
| 1430 |
+
00:26:30,000 --> 00:26:32,000
|
| 1431 |
+
very carefully to avoid cases like this.
|
| 1432 |
+
|
| 1433 |
+
359
|
| 1434 |
+
00:26:33,000 --> 00:26:37,000
|
| 1435 |
+
One thread is waiting as low as a threat, always a threat.
|
| 1436 |
+
|
| 1437 |
+
360
|
| 1438 |
+
00:26:37,000 --> 00:26:38,000
|
| 1439 |
+
How to figure this?
|
| 1440 |
+
|
| 1441 |
+
361
|
| 1442 |
+
00:26:39,000 --> 00:26:45,000
|
| 1443 |
+
You should control how many times you call Wakamatsu and how many times you call notify Mass.
|
| 1444 |
+
|
| 1445 |
+
362
|
| 1446 |
+
00:26:46,000 --> 00:26:53,000
|
| 1447 |
+
Considering we have one point in our app where we call notify MassArt in our single Notify Threat and
|
| 1448 |
+
|
| 1449 |
+
363
|
| 1450 |
+
00:26:53,000 --> 00:26:55,000
|
| 1451 |
+
we have to either objects where we call with Macit.
|
| 1452 |
+
|
| 1453 |
+
364
|
| 1454 |
+
00:26:56,000 --> 00:27:03,000
|
| 1455 |
+
Let's invoke notify all Massett in our notify I open, notify a class and will invoke notify all Masset
|
| 1456 |
+
|
| 1457 |
+
365
|
| 1458 |
+
00:27:03,000 --> 00:27:05,000
|
| 1459 |
+
instead simply notify Mass.
|
| 1460 |
+
|
| 1461 |
+
366
|
| 1462 |
+
00:27:06,000 --> 00:27:07,000
|
| 1463 |
+
Let's run our F one more time.
|
| 1464 |
+
|
| 1465 |
+
367
|
| 1466 |
+
00:27:08,000 --> 00:27:13,000
|
| 1467 |
+
Now you can see that all threats finished their work and no other threats running.
|
| 1468 |
+
|
| 1469 |
+
368
|
| 1470 |
+
00:27:14,000 --> 00:27:15,000
|
| 1471 |
+
We have both.
|
| 1472 |
+
|
| 1473 |
+
369
|
| 1474 |
+
00:27:15,000 --> 00:27:17,000
|
| 1475 |
+
Neither one and we are to notify.
|
| 1476 |
+
|
| 1477 |
+
370
|
| 1478 |
+
00:27:17,000 --> 00:27:22,000
|
| 1479 |
+
You can verify this when instigation of console output is clear.
|
| 1480 |
+
|
| 1481 |
+
371
|
| 1482 |
+
00:27:22,000 --> 00:27:28,000
|
| 1483 |
+
It is great that now you know how to work with notified masses and synchronization basics.
|
| 1484 |
+
|
| 1485 |
+
372
|
| 1486 |
+
00:27:28,000 --> 00:27:31,000
|
| 1487 |
+
Let's recap what we have learned in this lesson.
|
| 1488 |
+
|
| 1489 |
+
373
|
| 1490 |
+
00:27:31,000 --> 00:27:34,000
|
| 1491 |
+
In this lesson we learned what critical section is.
|
| 1492 |
+
|
| 1493 |
+
374
|
| 1494 |
+
00:27:35,000 --> 00:27:38,000
|
| 1495 |
+
You understood what atomic and atomic operations are.
|
| 1496 |
+
|
| 1497 |
+
375
|
| 1498 |
+
00:27:39,000 --> 00:27:41,000
|
| 1499 |
+
And we are still going to learn with you.
|
| 1500 |
+
|
| 1501 |
+
376
|
| 1502 |
+
00:27:41,000 --> 00:27:45,000
|
| 1503 |
+
Jabiri two concurrent atomic package in the next lessons.
|
| 1504 |
+
|
| 1505 |
+
377
|
| 1506 |
+
00:27:45,000 --> 00:27:46,000
|
| 1507 |
+
So stay tuned.
|
| 1508 |
+
|
| 1509 |
+
378
|
| 1510 |
+
00:27:47,000 --> 00:27:51,000
|
| 1511 |
+
Now, you know what monitor and mutex are and what is the difference between them?
|
| 1512 |
+
|
| 1513 |
+
379
|
| 1514 |
+
00:27:51,000 --> 00:27:56,000
|
| 1515 |
+
Also, you know what a synchronized method and what a synchronized block.
|
| 1516 |
+
|
| 1517 |
+
380
|
| 1518 |
+
00:27:56,000 --> 00:28:01,000
|
| 1519 |
+
And at the end of the lesson, we have learned what weight notify and notify all methods are.
|
| 1520 |
+
|
| 1521 |
+
381
|
| 1522 |
+
00:28:02,000 --> 00:28:05,000
|
| 1523 |
+
That's all for today, hope you enjoyed this lesson.
|
| 1524 |
+
|
| 1525 |
+
382
|
| 1526 |
+
00:28:06,000 --> 00:28:07,000
|
| 1527 |
+
Thank you for your attention.
|
| 1528 |
+
|
| 1529 |
+
383
|
| 1530 |
+
00:28:07,000 --> 00:28:09,000
|
| 1531 |
+
See you in the next lesson.
|
| 1532 |
+
|