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 +3 -0
- 02 - Java Basics/002 JDK Installation.mp4 +3 -0
- 02 - Java Basics/005 Integrated Development Environment, Eclipse Overview.mp4 +3 -0
- 02 - Java Basics/006 Comments in Java source code.mp4 +3 -0
- 05 - Operators and Operations with primitive types/external-links.txt +39 -0
- 06 - Strings in Java/001 Source-code-of-the-example-used-in-the-lesson.url +2 -0
- 06 - Strings in Java/001 String object creation and main methods overview_en.srt +336 -0
- 06 - Strings in Java/002 Source-code-of-the-example-used-in-the-lesson.url +2 -0
- 06 - Strings in Java/002 String comparison How to compare Strings and what is String Pool_en.srt +244 -0
- 06 - Strings in Java/003 Escape Sequences in Java_en.srt +148 -0
- 06 - Strings in Java/003 Source-code-of-the-example-used-in-the-lesson.url +2 -0
- 06 - Strings in Java/004 Source-code-from-the-lesson-Formatter-Demo.url +2 -0
- 06 - Strings in Java/004 Source-code-of-the-example-used-in-the-lesson.url +2 -0
- 06 - Strings in Java/004 String Formatting_en.srt +164 -0
- 06 - Strings in Java/005 Homework.url +2 -0
- 06 - Strings in Java/005 Regular expressions in Java_en.srt +380 -0
- 06 - Strings in Java/005 Source-code-of-the-example-used-in-the-lesson.url +2 -0
- 06 - Strings in Java/006 Format floating-point number.html +122 -0
- 06 - Strings in Java/007 Split Words.html +122 -0
- 06 - Strings in Java/008 Homework review String_en.srt +120 -0
- 06 - Strings in Java/008 Source-code-SOLUTION-Floating-point-number-formatting.url +2 -0
- 06 - Strings in Java/008 Source-code-SOLUTION-Split-words-regular-expression.url +2 -0
- 06 - Strings in Java/009 Quiz Strings in Java - Check yourself.html +69 -0
- 06 - Strings in Java/external-links.txt +27 -0
- 07 - Control Statements/001 'if - else' construction_en.srt +160 -0
- 07 - Control Statements/001 Homework.url +2 -0
- 07 - Control Statements/001 Source-code-of-the-example-used-in-the-lesson.url +2 -0
- 07 - Control Statements/002 Admin and Guest mode for application.html +122 -0
- 07 - Control Statements/003 Simple Number Calculator.html +122 -0
- 07 - Control Statements/004 Homework review 'if' statement_en.srt +96 -0
- 07 - Control Statements/004 Source-code-SOLUTION-Add-Numbers.url +2 -0
- 07 - Control Statements/004 Source-code-SOLUTION-Admin-Guest-Mode.url +2 -0
- 07 - Control Statements/005 'switch' construction_en.srt +220 -0
- 07 - Control Statements/005 Homework.url +2 -0
- 07 - Control Statements/005 Source-code-of-the-example-used-in-the-lesson.url +2 -0
- 07 - Control Statements/006 User Activity Selector.html +122 -0
- 07 - Control Statements/007 Homework review 'switch' statement_en.srt +32 -0
- 07 - Control Statements/007 Source-code-SOLUTION-User-Activity-Selector.url +2 -0
- 07 - Control Statements/008 Quiz Control Statements - Check yourself.html +69 -0
- 07 - Control Statements/external-links.txt +21 -0
- 08 - Miscellaneous/001 Random numbers generation_en.srt +128 -0
- 08 - Miscellaneous/001 Source-code-of-the-example-used-in-the-lesson.url +2 -0
- 08 - Miscellaneous/external-links.txt +3 -0
- 09 - Iteration Statements (Loops) in Java/001 'while' loop_en.srt +100 -0
- 09 - Iteration Statements (Loops) in Java/001 Source-code-of-the-example-used-in-the-lesson.url +2 -0
- 09 - Iteration Statements (Loops) in Java/002 'do-while' loop_en.srt +76 -0
- 09 - Iteration Statements (Loops) in Java/002 Source-code-of-the-example-used-in-the-lesson.url +2 -0
- 09 - Iteration Statements (Loops) in Java/003 'for' with condition loop_en.srt +140 -0
- 09 - Iteration Statements (Loops) in Java/003 Source-code-of-the-example-used-in-the-lesson.url +2 -0
- 09 - Iteration Statements (Loops) in Java/004 'for each' loop_en.srt +92 -0
.gitattributes
CHANGED
|
@@ -38,3 +38,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 38 |
01[[:space:]]-[[:space:]]Introduction/004[[:space:]]Unlimited[[:space:]]access[[:space:]]to[[:space:]]'Learn[[:space:]]IT'[[:space:]]application[[:space:]]for[[:space:]]students.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 39 |
02[[:space:]]-[[:space:]]Java[[:space:]]Basics/004[[:space:]]Homework[[:space:]]Solution[[:space:]].bat[[:space:]]file[[:space:]]creation.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 40 |
02[[:space:]]-[[:space:]]Java[[:space:]]Basics/003[[:space:]]First[[:space:]]application[[:space:]]Hello[[:space:]]World[[:space:]]App.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
01[[:space:]]-[[:space:]]Introduction/004[[:space:]]Unlimited[[:space:]]access[[:space:]]to[[:space:]]'Learn[[:space:]]IT'[[:space:]]application[[:space:]]for[[:space:]]students.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 39 |
02[[:space:]]-[[:space:]]Java[[:space:]]Basics/004[[:space:]]Homework[[:space:]]Solution[[:space:]].bat[[:space:]]file[[:space:]]creation.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 40 |
02[[:space:]]-[[:space:]]Java[[:space:]]Basics/003[[:space:]]First[[:space:]]application[[:space:]]Hello[[:space:]]World[[:space:]]App.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
02[[:space:]]-[[:space:]]Java[[:space:]]Basics/002[[:space:]]JDK[[:space:]]Installation.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
02[[:space:]]-[[:space:]]Java[[:space:]]Basics/006[[:space:]]Comments[[:space:]]in[[:space:]]Java[[:space:]]source[[:space:]]code.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
02[[:space:]]-[[:space:]]Java[[:space:]]Basics/005[[:space:]]Integrated[[:space:]]Development[[:space:]]Environment,[[:space:]]Eclipse[[:space:]]Overview.mp4 filter=lfs diff=lfs merge=lfs -text
|
02 - Java Basics/002 JDK Installation.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5021b5800f8d666faa29e4c5ef994cec17c280812bb1089f41de79d3d7df6a24
|
| 3 |
+
size 181550096
|
02 - Java Basics/005 Integrated Development Environment, Eclipse Overview.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d364e09ba986f96eef9ef7db72a5d7c446436a2a212b7453002dbf9150d2988e
|
| 3 |
+
size 201678692
|
02 - Java Basics/006 Comments in Java source code.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a0ec8f6039b3f54702c6cb4f9c65d9cac53c5644e1bdd5818639ba59243f1484
|
| 3 |
+
size 166533972
|
05 - Operators and Operations with primitive types/external-links.txt
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
001 Homework
|
| 3 |
+
https://docs.google.com/document/d/159vwvLmhStIcYp4Lug3fM5AizDPXXMJ5W3SexJQC11M/edit?usp=sharing
|
| 4 |
+
|
| 5 |
+
001 Source-code-of-the-example-used-in-the-lesson
|
| 6 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/operators/JavaOperators.java
|
| 7 |
+
|
| 8 |
+
002 Source-code-of-the-example-used-in-the-lesson
|
| 9 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/operations/OperationsWithIntegersAndDoubles.java
|
| 10 |
+
|
| 11 |
+
003 Source-code-of-the-example-used-in-the-lesson
|
| 12 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/math/MathClassDemo.java
|
| 13 |
+
|
| 14 |
+
004 Source-code-of-the-example-used-in-the-lesson
|
| 15 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/operations/ExpressionTypeExample.java
|
| 16 |
+
|
| 17 |
+
005 Source-code-of-the-example-used-in-the-lesson
|
| 18 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/operations/PrimitiveAndRefferenceTypesComparison.java
|
| 19 |
+
|
| 20 |
+
006 Homework
|
| 21 |
+
https://docs.google.com/document/d/1g5Nl9tqjgs8taUA7jJQeMaGfnWuSeLB_zSFrbozfT-c/edit?folder=1XkdXhkewYf3n2ak7mRbUNW3HDc_mCMvP
|
| 22 |
+
|
| 23 |
+
006 Source-code-of-the-example-used-in-the-lesson
|
| 24 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/operations/ReadFromConsole.java
|
| 25 |
+
|
| 26 |
+
010 Homework
|
| 27 |
+
https://docs.google.com/document/d/1g5Nl9tqjgs8taUA7jJQeMaGfnWuSeLB_zSFrbozfT-c/edit?folder=1XkdXhkewYf3n2ak7mRbUNW3HDc_mCMvP
|
| 28 |
+
|
| 29 |
+
010 Integers-Calculator-Solution
|
| 30 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/operations/hw/AddIntegers.java
|
| 31 |
+
|
| 32 |
+
010 Area-of-Triangle-Solution
|
| 33 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/operations/hw/AreaOfTriangle.java
|
| 34 |
+
|
| 35 |
+
010 Circle-Circumference-Solution
|
| 36 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/operations/hw/CircleCircumference.java
|
| 37 |
+
|
| 38 |
+
010 Homework-Demo-Class
|
| 39 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/operations/hw/Demo.java
|
06 - Strings in Java/001 Source-code-of-the-example-used-in-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/StringMainMethodsOverview.java
|
06 - Strings in Java/001 String object creation and main methods overview_en.srt
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:01,000
|
| 3 |
+
Hello, Tim.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:01,000 --> 00:00:03,000
|
| 7 |
+
Today we have a very important topic.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:03,000 --> 00:00:05,000
|
| 11 |
+
Today we'll learn more about strings.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:06,000 --> 00:00:06,000
|
| 15 |
+
Why?
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:06,000 --> 00:00:11,000
|
| 19 |
+
It is very important because every time you will do data manipulation in your program, you will manipulate
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:11,000 --> 00:00:12,000
|
| 23 |
+
with string objects.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:12,000 --> 00:00:17,000
|
| 27 |
+
Most of the times we start series of lessons about string type.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:18,000 --> 00:00:21,000
|
| 31 |
+
In this section of training course we will review source code of string class.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:21,000 --> 00:00:25,000
|
| 35 |
+
I will put a stress on the most important methods that most likely you will use.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:26,000 --> 00:00:33,000
|
| 39 |
+
Also, we will talk about string comparison, escape sequences, string formatting, and regular expressions.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:34,000 --> 00:00:39,000
|
| 43 |
+
In this lesson, we will take a look how to create string object and will review main string methods
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:40,000 --> 00:00:41,000
|
| 47 |
+
to understand topic better.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:41,000 --> 00:00:43,000
|
| 51 |
+
Let's start with examples.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:44,000 --> 00:00:49,000
|
| 55 |
+
To create string object, declare a variable of string type first and after that assign string literal
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:49,000 --> 00:00:50,000
|
| 59 |
+
to this variable.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:50,000 --> 00:00:55,000
|
| 63 |
+
Pay attention that in this string we have spaces at the beginning and at the end.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:56,000 --> 00:00:58,000
|
| 67 |
+
Now let me briefly cover main string methods.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:59,000 --> 00:01:04,000
|
| 71 |
+
String length method allow you to understand how much characters do you have in the string?
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:05,000 --> 00:01:12,000
|
| 75 |
+
Contains method will return you true or false in case string contains the string you specified as method
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:12,000 --> 00:01:17,000
|
| 79 |
+
argument true will be returned and false otherwise.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:17,000 --> 00:01:22,000
|
| 83 |
+
In this case, this string really contains this sequence of characters.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:22,000 --> 00:01:30,000
|
| 87 |
+
That's why true is returned as is empty is very useful method when you want to verify whether this string
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:30,000 --> 00:01:33,000
|
| 91 |
+
object contains any characters or no.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:34,000 --> 00:01:39,000
|
| 95 |
+
You will use this method very often in your code to validate string before working with it.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:40,000 --> 00:01:44,000
|
| 99 |
+
You can turn all characters to uppercase or lowercase if you wish.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:44,000 --> 00:01:51,000
|
| 103 |
+
For example, you may want to store all user nicknames in lowercase in your game to have consistent
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:51,000 --> 00:01:51,000
|
| 107 |
+
style.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:52,000 --> 00:01:57,000
|
| 111 |
+
You can check if specified string started or ended with specific sequence of characters.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:57,000 --> 00:02:00,000
|
| 115 |
+
In this case, our string not started with H.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:00,000 --> 00:02:07,000
|
| 119 |
+
That's why false is returned and our string is ended with space character.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:07,000 --> 00:02:09,000
|
| 123 |
+
That's why true is returned.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:10,000 --> 00:02:16,000
|
| 127 |
+
By the way, you can run this program on your local computer and investigate console output when it
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:16,000 --> 00:02:17,000
|
| 131 |
+
is needed.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:17,000 --> 00:02:20,000
|
| 135 |
+
You can replace characters in the string like I do.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:20,000 --> 00:02:29,000
|
| 139 |
+
In this example, I replaced lowercase double L with uppercase double L trim and strip methods.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:29,000 --> 00:02:31,000
|
| 143 |
+
Very important ones.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:31,000 --> 00:02:35,000
|
| 147 |
+
Often you will work with strings which have leading or trailing spaces.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:35,000 --> 00:02:38,000
|
| 151 |
+
Sometimes this might cause different errors.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:39,000 --> 00:02:45,000
|
| 155 |
+
To eliminate cases when leading or trailing spaces cause errors, you will call trim or strip methods
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:45,000 --> 00:02:49,000
|
| 159 |
+
on string objects before doing other operations with them.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:50,000 --> 00:02:55,000
|
| 163 |
+
As you can see from this example, trim and strip methods remove leading and trailing spaces.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:02:57,000 --> 00:03:03,000
|
| 167 |
+
The strip method is available starting from JDK 11 and it is Unicode whitespace aware.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:04,000 --> 00:03:08,000
|
| 171 |
+
In case you are working with JDK version eight, feel free to use trim method.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:08,000 --> 00:03:09,000
|
| 175 |
+
Instead.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:10,000 --> 00:03:13,000
|
| 179 |
+
You can get substring from string object.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:13,000 --> 00:03:20,000
|
| 183 |
+
To do this, you need to specify characters index from index inclusively and to index exclusively.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:21,000 --> 00:03:25,000
|
| 187 |
+
There are different business cases when you need to get part of the string from string.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:26,000 --> 00:03:27,000
|
| 191 |
+
In Greek.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:27,000 --> 00:03:33,000
|
| 195 |
+
You can find different classes that not always work with string objects, but works with array of bytes.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:33,000 --> 00:03:38,000
|
| 199 |
+
Probably you will face with such cases during learning of input output stream topic.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:38,000 --> 00:03:44,000
|
| 203 |
+
So for now, just be aware that you can convert each string to an array of bytes just like this.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:45,000 --> 00:03:48,000
|
| 207 |
+
You can get array of characters if you wish.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:48,000 --> 00:03:52,000
|
| 211 |
+
Just call to char array method and you will have array of characters.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:03:53,000 --> 00:03:58,000
|
| 215 |
+
If you want to get characters from specific index, you need to use char at method.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:03:59,000 --> 00:04:02,000
|
| 219 |
+
Another very important method split.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:02,000 --> 00:04:08,000
|
| 223 |
+
You will use it very often because a lot of times your program receives one single string and you need
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:08,000 --> 00:04:11,000
|
| 227 |
+
to split it first to process further.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:11,000 --> 00:04:14,000
|
| 231 |
+
For example, you receive string of data with users.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:14,000 --> 00:04:18,000
|
| 235 |
+
Information about each user is described in separate line.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:18,000 --> 00:04:20,000
|
| 239 |
+
But you have single string object.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:20,000 --> 00:04:22,000
|
| 243 |
+
What do you need to do?
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:22,000 --> 00:04:25,000
|
| 247 |
+
You need just to split the string by new line character.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:26,000 --> 00:04:29,000
|
| 251 |
+
Split method takes regular expression as an argument.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:29,000 --> 00:04:32,000
|
| 255 |
+
We will talk about regular expressions a bit later.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:04:32,000 --> 00:04:38,000
|
| 259 |
+
Right now understand that you can split string by regular expression and get an array of strings.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:04:38,000 --> 00:04:42,000
|
| 263 |
+
Like in this example, I split our word using e character.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:04:43,000 --> 00:04:44,000
|
| 267 |
+
And look here what we got.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:04:45,000 --> 00:04:47,000
|
| 271 |
+
Array of two elements a a a.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:04:48,000 --> 00:04:50,000
|
| 275 |
+
And here you can see our initial string.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:04:51,000 --> 00:04:54,000
|
| 279 |
+
You need to understand that string objects are immutable.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:04:54,000 --> 00:05:00,000
|
| 283 |
+
No matter how many times you will call different methods on string object, the initial object will
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:00,000 --> 00:05:01,000
|
| 287 |
+
remain the same.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:01,000 --> 00:05:07,000
|
| 291 |
+
This type designed in such way that you can't change state of the object once you created it.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:08,000 --> 00:05:11,000
|
| 295 |
+
Each method call doesn't modify existing string.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:11,000 --> 00:05:15,000
|
| 299 |
+
Instead it creates and returns reference to new string object.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:16,000 --> 00:05:18,000
|
| 303 |
+
Always keep this in mind.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:18,000 --> 00:05:24,000
|
| 307 |
+
Immutable objects have pros and cons, and we will discuss pros and cons of immutable object during
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:24,000 --> 00:05:25,000
|
| 311 |
+
the next topics.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:05:25,000 --> 00:05:28,000
|
| 315 |
+
When we will talk with you about garbage collector and collections.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:05:29,000 --> 00:05:33,000
|
| 319 |
+
So right now you are know probably all main methods from string class.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:05:34,000 --> 00:05:37,000
|
| 323 |
+
But still, I encourage you to take a look at the source code and investigate.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:05:37,000 --> 00:05:39,000
|
| 327 |
+
What other methods does string type have?
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:05:40,000 --> 00:05:43,000
|
| 331 |
+
Thank you for your attention and see you in the next lesson.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:05:44,000 --> 00:05:45,000
|
| 335 |
+
Baths.
|
| 336 |
+
|
06 - Strings in Java/002 Source-code-of-the-example-used-in-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/StringComparisonDemo.java
|
06 - Strings in Java/002 String comparison How to compare Strings and what is String Pool_en.srt
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:01,000
|
| 3 |
+
Hello guys.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:01,000 --> 00:00:03,000
|
| 7 |
+
We will proceed learning Stringtype.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:03,000 --> 00:00:07,000
|
| 11 |
+
In this lesson we will talk about how we can compare strings.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:07,000 --> 00:00:11,000
|
| 15 |
+
So here I have one more string literal, the same as S.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:11,000 --> 00:00:17,000
|
| 19 |
+
Just to remind you, S is a variable from a previous lesson about strings, and it refers to the same
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:17,000 --> 00:00:18,000
|
| 23 |
+
string.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:18,000 --> 00:00:23,000
|
| 27 |
+
When I compare s and s2 with equals to operator, I get true as a result.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:24,000 --> 00:00:27,000
|
| 31 |
+
But let me create string object in different way.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:27,000 --> 00:00:32,000
|
| 35 |
+
By using new keyword I am going to name new variable s three.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:32,000 --> 00:00:38,000
|
| 39 |
+
I believe you already understand what I'm trying to say here, in case you will compare s and s three
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:38,000 --> 00:00:42,000
|
| 43 |
+
objects with equals to operator, you will get false.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:42,000 --> 00:00:43,000
|
| 47 |
+
Why?
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:43,000 --> 00:00:48,000
|
| 51 |
+
The same answer as we discussed in the lesson regarding comparison of primitive and reference types,
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:49,000 --> 00:00:53,000
|
| 55 |
+
because s and s three refers to different objects in the heap.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:54,000 --> 00:00:56,000
|
| 59 |
+
But why previous example gives us true result.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:57,000 --> 00:01:00,000
|
| 63 |
+
You already aware about pool of integers in the heap memory.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:01,000 --> 00:01:03,000
|
| 67 |
+
We also have pool of strings.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:03,000 --> 00:01:09,000
|
| 71 |
+
When you are using string literal in the program, the string is added to pool of strings, and the
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:09,000 --> 00:01:15,000
|
| 75 |
+
next time you are using the same string literal, Java checks whether such string already exists in
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:15,000 --> 00:01:16,000
|
| 79 |
+
string pool.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:16,000 --> 00:01:22,000
|
| 83 |
+
If yes, then Java returns reference to the object that is already in heap memory instead of creating
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:22,000 --> 00:01:23,000
|
| 87 |
+
a new one.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:24,000 --> 00:01:29,000
|
| 91 |
+
On the other hand, when you are using new keyword, you say Java to allocate memory and to create new
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:29,000 --> 00:01:31,000
|
| 95 |
+
object in heap.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:31,000 --> 00:01:37,000
|
| 99 |
+
Taking into account, we use string literal when initialized s variable and s two variable.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:37,000 --> 00:01:41,000
|
| 103 |
+
These two variables are referring to the same object in pool of strings.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:41,000 --> 00:01:43,000
|
| 107 |
+
Let me visualize this to you.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:44,000 --> 00:01:46,000
|
| 111 |
+
So you have three variables.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:46,000 --> 00:01:49,000
|
| 115 |
+
Two of them are referring to the same object in string pool.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:49,000 --> 00:01:55,000
|
| 119 |
+
That's why equals to operator returns true when you are comparing S1 and S2 variables.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:55,000 --> 00:02:00,000
|
| 123 |
+
In this particular example, the third variable refers to the new object.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:00,000 --> 00:02:05,000
|
| 127 |
+
So how to compare strings the same way as other reference types?
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:06,000 --> 00:02:11,000
|
| 131 |
+
String type has equals method, which allows you to compare strings by their values.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:12,000 --> 00:02:16,000
|
| 135 |
+
So in this example you will get true because these strings are equal.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:16,000 --> 00:02:19,000
|
| 139 |
+
One more trick you need to know about string comparison.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:20,000 --> 00:02:26,000
|
| 143 |
+
If you will compare s variable with result of internal method call and you will do comparison via equal
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:26,000 --> 00:02:27,000
|
| 147 |
+
to operator.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:27,000 --> 00:02:34,000
|
| 151 |
+
You will get true even despite the fact you will not use internal method in production code way too
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:34,000 --> 00:02:34,000
|
| 155 |
+
much.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:34,000 --> 00:02:40,000
|
| 159 |
+
This question is often appeared during the junior developers interview to identify whether developers
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:40,000 --> 00:02:44,000
|
| 163 |
+
are aware about String pool or no in turn method put.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:02:44,000 --> 00:02:49,000
|
| 167 |
+
S3 string in the string pool and return the reference to the object in string pool.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:02:50,000 --> 00:02:56,000
|
| 171 |
+
That's why in this case, you will compare references to the same object, because such string already
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:02:56,000 --> 00:03:00,000
|
| 175 |
+
exists in the string pool and you will get true as a result here.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:00,000 --> 00:03:02,000
|
| 179 |
+
Hope it is clear now.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:03,000 --> 00:03:04,000
|
| 183 |
+
Next example.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:04,000 --> 00:03:10,000
|
| 187 |
+
Let's say I have a variable with my first name, and I have second variable with my first name, but
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:10,000 --> 00:03:12,000
|
| 191 |
+
started with lowercase a.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:12,000 --> 00:03:17,000
|
| 195 |
+
When I will compare these two strings with equals method, I will get false.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:18,000 --> 00:03:19,000
|
| 199 |
+
And that is right.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:19,000 --> 00:03:22,000
|
| 203 |
+
These two strings are different.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:22,000 --> 00:03:29,000
|
| 207 |
+
Capital A and lowercase a are different characters, but we humans understand that this is the same
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:29,000 --> 00:03:30,000
|
| 211 |
+
name.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:03:30,000 --> 00:03:36,000
|
| 215 |
+
So what you can do to compare these strings and get the result which you are expecting, you can call
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:03:36,000 --> 00:03:39,000
|
| 219 |
+
equals to Ignorecase method which will compare two strings.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:03:39,000 --> 00:03:40,000
|
| 223 |
+
Ignoring case.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:03:40,000 --> 00:03:42,000
|
| 227 |
+
Here we will get true.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:03:42,000 --> 00:03:43,000
|
| 231 |
+
That's it.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:03:43,000 --> 00:03:44,000
|
| 235 |
+
Regarding string comparison.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:03:45,000 --> 00:03:48,000
|
| 239 |
+
Thanks a lot for your attention and see you in the next lesson.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:03:49,000 --> 00:03:49,000
|
| 243 |
+
Baths.
|
| 244 |
+
|
06 - Strings in Java/003 Escape Sequences in Java_en.srt
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:01,000
|
| 3 |
+
Hello team!
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:01,000 --> 00:00:04,000
|
| 7 |
+
In this lesson we will learn with you escape sequences in Java.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:05,000 --> 00:00:08,000
|
| 11 |
+
Let me show you what is escape sequence and how to escape characters.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:09,000 --> 00:00:14,000
|
| 15 |
+
I believe you already understood that all string literals need to be enclosed in quotation marks.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:15,000 --> 00:00:19,000
|
| 19 |
+
But what to do in case you need to have string which will contain quotes in itself?
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:20,000 --> 00:00:23,000
|
| 23 |
+
In this example I want to put book name in quotes.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:23,000 --> 00:00:29,000
|
| 27 |
+
To do this, I need to use character escaping by using a special symbol backslash.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:29,000 --> 00:00:31,000
|
| 31 |
+
I can escape quotation marks.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:32,000 --> 00:00:38,000
|
| 35 |
+
In Java, a backslash combined with a character to be escaped is called an escape sequence.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:38,000 --> 00:00:43,000
|
| 39 |
+
In case I don't use backslash in this example, there will be compilation error.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:43,000 --> 00:00:50,000
|
| 43 |
+
Java compiler is very smart program, but it will be hard for it to compile string in such format.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:50,000 --> 00:00:56,000
|
| 47 |
+
Java compiler expects that each string is started with quote and ended with quote.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:56,000 --> 00:01:02,000
|
| 51 |
+
That's why without escape sequence for Java compiler, it will be impossible to understand that you
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:02,000 --> 00:01:05,000
|
| 55 |
+
want to have this string as part of the whole string.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:06,000 --> 00:01:08,000
|
| 59 |
+
Let's consider another example.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:08,000 --> 00:01:14,000
|
| 63 |
+
You want to have string which will contain directory path on your computer and you need to use backslash.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:14,000 --> 00:01:21,000
|
| 67 |
+
But Java compiler knows that in source code will use backslash only in case we want to create escape
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:21,000 --> 00:01:28,000
|
| 71 |
+
sequence, and in this case compiler simply cannot find escape sequence because you don't need to escape
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:28,000 --> 00:01:29,000
|
| 75 |
+
J character.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:29,000 --> 00:01:32,000
|
| 79 |
+
That's why you need to escape your backslash character.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:33,000 --> 00:01:38,000
|
| 83 |
+
And we have here double backslash in the source code but single backslash in the output.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:39,000 --> 00:01:42,000
|
| 87 |
+
In Java there are limited amount of escape sequences.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:42,000 --> 00:01:50,000
|
| 91 |
+
Here you can find all lists of escape sequences for example backslash and t inserts, tab character
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:50,000 --> 00:01:54,000
|
| 95 |
+
backslash and n inserts newline character.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:54,000 --> 00:01:57,000
|
| 99 |
+
Here is an example with two lines in one string object.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:58,000 --> 00:02:01,000
|
| 103 |
+
You see backslash and n here.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:01,000 --> 00:02:03,000
|
| 107 |
+
And here is the output.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:03,000 --> 00:02:06,000
|
| 111 |
+
Here is one line and the second line.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:07,000 --> 00:02:11,000
|
| 115 |
+
I encourage you to try these escape sequences in your source code.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:12,000 --> 00:02:19,000
|
| 119 |
+
Another important thing to know about escaping characters in Java Unicode table includes the symbols
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:19,000 --> 00:02:22,000
|
| 123 |
+
of almost every written language in the world.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:22,000 --> 00:02:28,000
|
| 127 |
+
In case you need to use Unicode character in your string, you can just escape Unicode code.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:28,000 --> 00:02:34,000
|
| 131 |
+
All Unicode characters codes have the form U plus hexadecimal number.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:34,000 --> 00:02:41,000
|
| 135 |
+
So if you need to use character from Unicode table, just escape this value and you will see copyright
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:41,000 --> 00:02:42,000
|
| 139 |
+
character in the output.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:43,000 --> 00:02:44,000
|
| 143 |
+
That's all.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:44,000 --> 00:02:47,000
|
| 147 |
+
Thank you for your attention and see you in the next lesson.
|
| 148 |
+
|
06 - Strings in Java/003 Source-code-of-the-example-used-in-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/EscapeSequences.java
|
06 - Strings in Java/004 Source-code-from-the-lesson-Formatter-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/string/FormatterDemo.java
|
06 - Strings in Java/004 Source-code-of-the-example-used-in-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/StringFormattingDemo.java
|
06 - Strings in Java/004 String Formatting_en.srt
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:01,000
|
| 3 |
+
Hello, Tim.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:01,000 --> 00:00:07,000
|
| 7 |
+
In this lesson, I'd like to show you how you can format your string a bit later in this training course.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:07,000 --> 00:00:13,000
|
| 11 |
+
We'll write with you your own web application, and you will have standard labels to ensure amazing
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:13,000 --> 00:00:16,000
|
| 15 |
+
user experience in your web application.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:16,000 --> 00:00:21,000
|
| 19 |
+
For example, you will have personalized welcome message which will contain user first name and greetings.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:22,000 --> 00:00:25,000
|
| 23 |
+
Greetings will be different based on the current time of the day.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:26,000 --> 00:00:28,000
|
| 27 |
+
Your template string can look like this.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:29,000 --> 00:00:33,000
|
| 31 |
+
Hello dear, some name and good part of the day.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:33,000 --> 00:00:39,000
|
| 35 |
+
During the string formatting, you will be able to insert different strings instead of percent sign
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:39,000 --> 00:00:39,000
|
| 39 |
+
s.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:40,000 --> 00:00:43,000
|
| 43 |
+
Here you have morning, afternoon and evening strings.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:43,000 --> 00:00:49,000
|
| 47 |
+
To format string, you need to call string format method where the first argument will be string you
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:49,000 --> 00:00:56,000
|
| 51 |
+
want to format, and after that you will pass arguments referenced by the format specifiers like these
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:56,000 --> 00:00:57,000
|
| 55 |
+
signs.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:58,000 --> 00:01:05,000
|
| 59 |
+
In our template we have two format specifiers in case you will pass more than two arguments after the
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:05,000 --> 00:01:10,000
|
| 63 |
+
template, they will be ignored in case you will pass not enough arguments.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:10,000 --> 00:01:14,000
|
| 67 |
+
Exception will be thrown by JVM during the runtime format.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:14,000 --> 00:01:20,000
|
| 71 |
+
Method returns the reference to the new string object and we can print it to console.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:21,000 --> 00:01:22,000
|
| 75 |
+
Hello dear Andre.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:22,000 --> 00:01:23,000
|
| 79 |
+
Good morning.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:24,000 --> 00:01:28,000
|
| 83 |
+
Also you can print formatted string directly to console.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:28,000 --> 00:01:31,000
|
| 87 |
+
You can use printf method for such purpose.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:32,000 --> 00:01:36,000
|
| 91 |
+
Here you see different format specifier percent sign.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:36,000 --> 00:01:36,000
|
| 95 |
+
D.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:37,000 --> 00:01:40,000
|
| 99 |
+
This specifier is used to put any digit instead of it.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:41,000 --> 00:01:44,000
|
| 103 |
+
And here you can see that I am passing integer.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:44,000 --> 00:01:47,000
|
| 107 |
+
In console you can see the result which I get.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:48,000 --> 00:01:52,000
|
| 111 |
+
There are different specifiers and flags and I prepared examples for you.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:53,000 --> 00:01:57,000
|
| 115 |
+
You can find source code in separate file formatted demo.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:58,000 --> 00:02:03,000
|
| 119 |
+
I will share a link with you to this file in the lesson resources or in video description.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:04,000 --> 00:02:09,000
|
| 123 |
+
Here you will be able to find link to the official Oracle documentation where all specifiers and flags
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:09,000 --> 00:02:10,000
|
| 127 |
+
are listed.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:11,000 --> 00:02:14,000
|
| 131 |
+
Let me run this program to walk you through the program output.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:15,000 --> 00:02:22,000
|
| 135 |
+
The examples describe different ways to format numbers, justification, hexadecimal numbers, formatting,
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:22,000 --> 00:02:30,000
|
| 139 |
+
precision formatting, etc. I don't think that it is necessary to pay attention to each example here
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:30,000 --> 00:02:35,000
|
| 143 |
+
in this video, because from the syntax point of view, they are all similar.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:35,000 --> 00:02:39,000
|
| 147 |
+
The only thing you need to learn is different specifiers and when to use them.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:40,000 --> 00:02:45,000
|
| 151 |
+
During your homework, I would ask you to run these examples on your computer and to ask me questions
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:45,000 --> 00:02:46,000
|
| 155 |
+
in case you will have any.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:47,000 --> 00:02:48,000
|
| 159 |
+
Thanks a lot for your attention.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:48,000 --> 00:02:50,000
|
| 163 |
+
See you in the next lesson.
|
| 164 |
+
|
06 - Strings in Java/005 Homework.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://docs.google.com/document/d/12ERxY6dUtcxo5ikfBA13_mB_7yeAByXpliDqEQ0Kjrk/edit?usp=sharing
|
06 - Strings in Java/005 Regular expressions in Java_en.srt
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:00,000
|
| 3 |
+
Hello, team.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:00,000 --> 00:00:04,000
|
| 7 |
+
In this lesson, I'd like to talk with you about regular expressions.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:05,000 --> 00:00:06,000
|
| 11 |
+
What is regular expression?
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:06,000 --> 00:00:11,000
|
| 15 |
+
Regular expression is a sequence of characters that define a search pattern.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:11,000 --> 00:00:16,000
|
| 19 |
+
So you can use special set of characters to find all strings that match your pattern.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:17,000 --> 00:00:20,000
|
| 23 |
+
Sometimes you use regular expression to split string.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:20,000 --> 00:00:22,000
|
| 27 |
+
Let's imagine next case.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:22,000 --> 00:00:26,000
|
| 31 |
+
You have a lot of text and you need to find only Google email accounts.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:27,000 --> 00:00:28,000
|
| 35 |
+
How you would do this?
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:28,000 --> 00:00:32,000
|
| 39 |
+
You will try to describe search pattern with the help of special symbols.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:33,000 --> 00:00:35,000
|
| 43 |
+
What are the special symbols?
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:35,000 --> 00:00:36,000
|
| 47 |
+
Here are some of them.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:36,000 --> 00:00:40,000
|
| 51 |
+
Square brackets to identify characters which we need to search.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:41,000 --> 00:00:45,000
|
| 55 |
+
I specified range from A to z lowercase and from A to z capital.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:46,000 --> 00:00:51,000
|
| 59 |
+
Also specified dash character backslash d will match with all digits.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:51,000 --> 00:00:55,000
|
| 63 |
+
And you already learned that we need to escape backslash character.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:55,000 --> 00:00:58,000
|
| 67 |
+
That's why it's double backslash here.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:59,000 --> 00:01:01,000
|
| 71 |
+
Also there are quantifiers.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:01,000 --> 00:01:03,000
|
| 75 |
+
Plus sign might be read like this.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:03,000 --> 00:01:07,000
|
| 79 |
+
In case these characters will be repeated at least one time and more.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:08,000 --> 00:01:10,000
|
| 83 |
+
That is what we need after all of this.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:10,000 --> 00:01:14,000
|
| 87 |
+
We expect at sign gmail dot.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:14,000 --> 00:01:21,000
|
| 91 |
+
Taking into account dot in regular expression means any character we need to escape dot to say that
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:21,000 --> 00:01:26,000
|
| 95 |
+
we don't expect any character, but we are looking for exactly dot.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:26,000 --> 00:01:30,000
|
| 99 |
+
That's why double backslash here and comb.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:30,000 --> 00:01:33,000
|
| 103 |
+
Your homework task will be to learn other special symbols.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:34,000 --> 00:01:36,000
|
| 107 |
+
I will share with you details at the end of the lesson.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:37,000 --> 00:01:43,000
|
| 111 |
+
Definitely, there are a lot of ways to improve the regular expressions for email, and you can find
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:43,000 --> 00:01:48,000
|
| 115 |
+
in internet billions of variations of pattern for email address verification.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:48,000 --> 00:01:55,000
|
| 119 |
+
Our goal right now to learn how to use regular expressions regarding special symbols to use in regular
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:55,000 --> 00:01:55,000
|
| 123 |
+
expression.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:56,000 --> 00:01:59,000
|
| 127 |
+
I will share more details at the end of this lesson.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:59,000 --> 00:02:02,000
|
| 131 |
+
After that you need to compile pattern.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:02,000 --> 00:02:06,000
|
| 135 |
+
Do not forget to import Java.util regex package.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:09,000 --> 00:02:12,000
|
| 139 |
+
We have the sample text with gmail address in it.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:12,000 --> 00:02:19,000
|
| 143 |
+
Now you can get matcher much object out of pattern call matching method on pattern object and pass sample
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:19,000 --> 00:02:20,000
|
| 147 |
+
text into it.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:21,000 --> 00:02:25,000
|
| 151 |
+
Match object can find matches call find method.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:25,000 --> 00:02:32,000
|
| 155 |
+
Find method returns true in case a subsequence of the input sequence matches this matches pattern and
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:32,000 --> 00:02:33,000
|
| 159 |
+
false otherwise.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:33,000 --> 00:02:38,000
|
| 163 |
+
In case there is a match, you will be able to call group method to return the string which matches
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:02:38,000 --> 00:02:39,000
|
| 167 |
+
your pattern.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:02:40,000 --> 00:02:42,000
|
| 171 |
+
And let's print this to console.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:02:43,000 --> 00:02:45,000
|
| 175 |
+
What can be improved here?
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:02:46,000 --> 00:02:50,000
|
| 179 |
+
As you learn loops, topic and control statements topic, you will be able to manage search process
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:02:50,000 --> 00:02:52,000
|
| 183 |
+
in a bit different way.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:02:52,000 --> 00:02:58,000
|
| 187 |
+
For example, probably better solution would be here to call find method in if statement or in while
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:02:58,000 --> 00:03:00,000
|
| 191 |
+
loop to print multiple matches.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:01,000 --> 00:03:04,000
|
| 195 |
+
But don't worry so far we will learn all topics gradually.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:04,000 --> 00:03:07,000
|
| 199 |
+
You will have enough tasks to practice your skills.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:07,000 --> 00:03:10,000
|
| 203 |
+
For now, I don't want to confuse you even more.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:10,000 --> 00:03:15,000
|
| 207 |
+
Solution like this should be fine in case you want to find match in the string.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:16,000 --> 00:03:17,000
|
| 211 |
+
Another example.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:03:17,000 --> 00:03:21,000
|
| 215 |
+
We have sample text and we want to split it by sentences.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:03:21,000 --> 00:03:23,000
|
| 219 |
+
Let's come up with a regular expression.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:03:23,000 --> 00:03:26,000
|
| 223 |
+
We need to split by any of these characters.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:03:26,000 --> 00:03:27,000
|
| 227 |
+
Period.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:03:27,000 --> 00:03:29,000
|
| 231 |
+
Exclamation mark.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:03:29,000 --> 00:03:30,000
|
| 235 |
+
Question mark.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:03:31,000 --> 00:03:33,000
|
| 239 |
+
Now let's split this sample text.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:03:33,000 --> 00:03:36,000
|
| 243 |
+
Using this regex we'll call split method.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:03:36,000 --> 00:03:40,000
|
| 247 |
+
We'll get string array and let's print it to console.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:03:41,000 --> 00:03:44,000
|
| 251 |
+
Here you can see that you have three different sentences.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:03:45,000 --> 00:03:47,000
|
| 255 |
+
Let's recap what you have learned about strings.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:03:48,000 --> 00:03:52,000
|
| 259 |
+
Now you know main string methods how to compare strings.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:03:52,000 --> 00:03:54,000
|
| 263 |
+
You learn what is pool of strings.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:03:54,000 --> 00:04:00,000
|
| 267 |
+
How to use escape sequences in your source code, how you can format strings, and how to use regular
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:04:00,000 --> 00:04:01,000
|
| 271 |
+
expressions.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:04:01,000 --> 00:04:03,000
|
| 275 |
+
Now let's take a look at your homework.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:04:05,000 --> 00:04:09,000
|
| 279 |
+
First of all, take a look one more time to string source code.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:04:09,000 --> 00:04:12,000
|
| 283 |
+
Take a look at other methods which are in string class.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:04:13,000 --> 00:04:15,000
|
| 287 |
+
As usual, I recommend you to read books.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:04:15,000 --> 00:04:17,000
|
| 291 |
+
Chapter about strings.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:04:17,000 --> 00:04:20,000
|
| 295 |
+
Learn format specifiers and flags.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:04:20,000 --> 00:04:23,000
|
| 299 |
+
Here is the link to official Oracle documentation.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:04:24,000 --> 00:04:29,000
|
| 303 |
+
I also did screenshots and left them here so you could faster find the things you need to learn.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:04:30,000 --> 00:04:33,000
|
| 307 |
+
Do not forget to look through the examples of string formatting.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:04:34,000 --> 00:04:36,000
|
| 311 |
+
Link to the source code is here.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:04:36,000 --> 00:04:39,000
|
| 315 |
+
Implement console program according to requirements.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:04:40,000 --> 00:04:43,000
|
| 319 |
+
This task to check your knowledge about string formatting.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:04:44,000 --> 00:04:47,000
|
| 323 |
+
To learn regular expressions, I recommend you to use this resource.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:04:47,000 --> 00:04:49,000
|
| 327 |
+
Let's take a look.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:04:50,000 --> 00:04:51,000
|
| 331 |
+
You have 15 lessons.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:04:51,000 --> 00:04:55,000
|
| 335 |
+
In each lesson you have description and exercise.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:04:55,000 --> 00:04:58,000
|
| 339 |
+
You can always find hints on the right here.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:04:58,000 --> 00:05:01,000
|
| 343 |
+
And in case you can't solve task.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:05:01,000 --> 00:05:03,000
|
| 347 |
+
Take a look at solution here.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:05:07,000 --> 00:05:13,000
|
| 351 |
+
Looking through the solutions will be also very efficient and will help you to learn regular expressions.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:05:13,000 --> 00:05:19,000
|
| 355 |
+
I wouldn't say that you need to spend hours on learning regular expressions because you will not use
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:05:19,000 --> 00:05:20,000
|
| 359 |
+
them literally every day.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:05:20,000 --> 00:05:23,000
|
| 363 |
+
But still, I would recommend you to learn the basics.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:05:24,000 --> 00:05:30,000
|
| 367 |
+
And after that you have one more coding exercise to practice your skills in regular expressions.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:05:30,000 --> 00:05:32,000
|
| 371 |
+
That's all for today.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:05:32,000 --> 00:05:33,000
|
| 375 |
+
See you in the next lesson.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:05:34,000 --> 00:05:34,000
|
| 379 |
+
Your.
|
| 380 |
+
|
06 - Strings in Java/005 Source-code-of-the-example-used-in-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/RegularExpressions.java
|
06 - Strings in Java/006 Format floating-point number.html
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>Coding Assignment</title>
|
| 8 |
+
|
| 9 |
+
<style>
|
| 10 |
+
body {
|
| 11 |
+
font-family: sf pro text, -apple-system, BlinkMacSystemFont, Roboto, segoe ui, Helvetica, Arial,
|
| 12 |
+
sans-serif, apple color emoji, segoe ui emoji, segoe ui symbol;
|
| 13 |
+
font-weight: 400;
|
| 14 |
+
line-height: 22.4px;
|
| 15 |
+
font-size: 16px;
|
| 16 |
+
}
|
| 17 |
+
p,
|
| 18 |
+
ul,
|
| 19 |
+
ol {
|
| 20 |
+
font-size: 16px;
|
| 21 |
+
font-weight: 400;
|
| 22 |
+
}
|
| 23 |
+
h1,
|
| 24 |
+
h2,
|
| 25 |
+
h3,
|
| 26 |
+
h4,
|
| 27 |
+
h5,
|
| 28 |
+
h6 {
|
| 29 |
+
font-weight: bold;
|
| 30 |
+
}
|
| 31 |
+
ul {
|
| 32 |
+
list-style: none;
|
| 33 |
+
margin: 0;
|
| 34 |
+
padding: 0;
|
| 35 |
+
max-width: none;
|
| 36 |
+
}
|
| 37 |
+
.code-snippet {
|
| 38 |
+
background-color: #fff;
|
| 39 |
+
border: 1px solid #d1d7dc;
|
| 40 |
+
color: #b4690e;
|
| 41 |
+
font-size: 90%;
|
| 42 |
+
padding: 0.2rem 0.4rem;
|
| 43 |
+
}
|
| 44 |
+
.code-block {
|
| 45 |
+
background-color: #fff;
|
| 46 |
+
color: #b4690e;
|
| 47 |
+
font-size: 90%;
|
| 48 |
+
}
|
| 49 |
+
.black-block {
|
| 50 |
+
color: #000000;
|
| 51 |
+
}
|
| 52 |
+
.italic-text {
|
| 53 |
+
font-style: italic;
|
| 54 |
+
}
|
| 55 |
+
</style>
|
| 56 |
+
</head>
|
| 57 |
+
|
| 58 |
+
<body onload="main()">
|
| 59 |
+
<h1 id="coding-title"></h1>
|
| 60 |
+
<div>
|
| 61 |
+
<h2>Instructions</h2>
|
| 62 |
+
<div id="coding-instructions"></div>
|
| 63 |
+
</div>
|
| 64 |
+
<div>
|
| 65 |
+
<h2>Test(s)</h2>
|
| 66 |
+
<div id="coding-tests"></div>
|
| 67 |
+
</div>
|
| 68 |
+
<div>
|
| 69 |
+
<h2>Solution(s)</h2>
|
| 70 |
+
<div id="coding-solutions"></div>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
<script>
|
| 74 |
+
const quizData = {"title": "006 Format floating-point number", "hasInstructions": true, "hasTests": true, "hasSolutions": true, "instructions": "<ol><li><p>Implement console program which meet the following requirements:</p><ol><li><p>Program starts and prints Math.PI five times in console output</p></li><li><p>The first Math.PI contains only one fraction digit</p></li><li><p>The second Math.PI contains two fraction digits</p></li><li><p>The third time Math.PI contains three fraction digits</p></li><li><p>The fourth time Math.PI contains four fraction digits</p></li><li><p>The fifth time Math.PI contains five fraction digits</p></li></ol></li></ol>", "tests": [{"file_name": "Evaluate.java", "content": "import org.junit.Test;\nimport org.junit.Assert;\nimport com.udemy.ucp.*;\n\nimport static org.junit.Assert.assertEquals;\n\nimport java.io.ByteArrayOutputStream;\nimport java.io.PrintStream;\n\nimport org.junit.After;\nimport org.junit.Before;\nimport org.junit.Test;\n\npublic class Evaluate {\n\tprivate final ByteArrayOutputStream out = new ByteArrayOutputStream();\n\tprivate final PrintStream originalOut = System.out;\n\n\t@Before\n\tpublic void setStreams() {\n\t\tSystem.setOut(new PrintStream(out));\n\t}\n\n\t@After\n\tpublic void restoreInitialStreams() {\n\t\tSystem.setOut(originalOut);\n\t}\n\t\n\t@Test\n\tpublic void shouldPrintPiNumberFiveTimes() {\n\t PINumberFormatting.main(new String[] {});\n\t\tassertEquals(\"3.1,3.14,3.142,3.1416,3.14159\",out.toString().trim().replace(System.lineSeparator(), \",\"));\n\t}\n}\n"}], "solutions": [{"file_name": "PINumberFormatting.java", "content": "public class PINumberFormatting {\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tSystem.out.printf(\"%.1f%n\", Math.PI);\r\n\t\tSystem.out.printf(\"%.2f%n\", Math.PI);\r\n\t\tSystem.out.printf(\"%.3f%n\", Math.PI);\r\n\t\tSystem.out.printf(\"%.4f%n\", Math.PI);\r\n\t\tSystem.out.printf(\"%.5f%n\", Math.PI);\r\n\t}\r\n\r\n}\r\n"}]};
|
| 75 |
+
|
| 76 |
+
function renderCodeList(rootElement, codeList, className, titlePrefix) {
|
| 77 |
+
for (var i = 0; i < codeList.length; i++) {
|
| 78 |
+
var elem = codeList[i];
|
| 79 |
+
var jsElem = document.createElement("div");
|
| 80 |
+
jsElem.className = className;
|
| 81 |
+
var jsElemTitle = document.createElement("h3");
|
| 82 |
+
jsElemTitle.innerHTML = titlePrefix + " " + (i + 1);
|
| 83 |
+
var jsElemBody = document.createElement("code");
|
| 84 |
+
jsElemBody.className = "code-block black-block";
|
| 85 |
+
jsElemBody.innerHTML = "<pre>" + elem.content + "</pre>";
|
| 86 |
+
jsElem.appendChild(jsElemTitle);
|
| 87 |
+
jsElem.appendChild(jsElemBody);
|
| 88 |
+
rootElement.appendChild(jsElem);
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
function main() {
|
| 93 |
+
// display the assignment
|
| 94 |
+
var codingTitle = document.getElementById("coding-title");
|
| 95 |
+
codingTitle.innerHTML = quizData.title;
|
| 96 |
+
|
| 97 |
+
var codingInstructions = document.getElementById("coding-instructions");
|
| 98 |
+
if (quizData.hasInstructions) {
|
| 99 |
+
codingInstructions.innerHTML = quizData.instructions;
|
| 100 |
+
} else {
|
| 101 |
+
codingInstructions.innerHTML = '<span class="italic-text">' + quizData.instructions + "</span>";
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// display the test(s)
|
| 105 |
+
var codingTests = document.getElementById("coding-tests");
|
| 106 |
+
if (!quizData.hasTests) {
|
| 107 |
+
codingTests.innerHTML = '<span class="italic-text">' + quizData.tests + "</span>";
|
| 108 |
+
} else {
|
| 109 |
+
renderCodeList(codingTests, quizData.tests, "coding-test", "Test");
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// display the solution(s)
|
| 113 |
+
var codingSolutions = document.getElementById("coding-solutions");
|
| 114 |
+
if (!quizData.hasSolutions) {
|
| 115 |
+
codingSolutions.innerHTML = '<span class="italic-text">' + quizData.solutions + "</span>";
|
| 116 |
+
} else {
|
| 117 |
+
renderCodeList(codingSolutions, quizData.solutions, "coding-solution", "Solution");
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
</script>
|
| 121 |
+
</body>
|
| 122 |
+
</html>
|
06 - Strings in Java/007 Split Words.html
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>Coding Assignment</title>
|
| 8 |
+
|
| 9 |
+
<style>
|
| 10 |
+
body {
|
| 11 |
+
font-family: sf pro text, -apple-system, BlinkMacSystemFont, Roboto, segoe ui, Helvetica, Arial,
|
| 12 |
+
sans-serif, apple color emoji, segoe ui emoji, segoe ui symbol;
|
| 13 |
+
font-weight: 400;
|
| 14 |
+
line-height: 22.4px;
|
| 15 |
+
font-size: 16px;
|
| 16 |
+
}
|
| 17 |
+
p,
|
| 18 |
+
ul,
|
| 19 |
+
ol {
|
| 20 |
+
font-size: 16px;
|
| 21 |
+
font-weight: 400;
|
| 22 |
+
}
|
| 23 |
+
h1,
|
| 24 |
+
h2,
|
| 25 |
+
h3,
|
| 26 |
+
h4,
|
| 27 |
+
h5,
|
| 28 |
+
h6 {
|
| 29 |
+
font-weight: bold;
|
| 30 |
+
}
|
| 31 |
+
ul {
|
| 32 |
+
list-style: none;
|
| 33 |
+
margin: 0;
|
| 34 |
+
padding: 0;
|
| 35 |
+
max-width: none;
|
| 36 |
+
}
|
| 37 |
+
.code-snippet {
|
| 38 |
+
background-color: #fff;
|
| 39 |
+
border: 1px solid #d1d7dc;
|
| 40 |
+
color: #b4690e;
|
| 41 |
+
font-size: 90%;
|
| 42 |
+
padding: 0.2rem 0.4rem;
|
| 43 |
+
}
|
| 44 |
+
.code-block {
|
| 45 |
+
background-color: #fff;
|
| 46 |
+
color: #b4690e;
|
| 47 |
+
font-size: 90%;
|
| 48 |
+
}
|
| 49 |
+
.black-block {
|
| 50 |
+
color: #000000;
|
| 51 |
+
}
|
| 52 |
+
.italic-text {
|
| 53 |
+
font-style: italic;
|
| 54 |
+
}
|
| 55 |
+
</style>
|
| 56 |
+
</head>
|
| 57 |
+
|
| 58 |
+
<body onload="main()">
|
| 59 |
+
<h1 id="coding-title"></h1>
|
| 60 |
+
<div>
|
| 61 |
+
<h2>Instructions</h2>
|
| 62 |
+
<div id="coding-instructions"></div>
|
| 63 |
+
</div>
|
| 64 |
+
<div>
|
| 65 |
+
<h2>Test(s)</h2>
|
| 66 |
+
<div id="coding-tests"></div>
|
| 67 |
+
</div>
|
| 68 |
+
<div>
|
| 69 |
+
<h2>Solution(s)</h2>
|
| 70 |
+
<div id="coding-solutions"></div>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
<script>
|
| 74 |
+
const quizData = {"title": "007 Split Words", "hasInstructions": true, "hasTests": true, "hasSolutions": true, "instructions": "<ol><li><p>Implement console program which meet the following requirements:</p><ol><li><p>Program starts and asks user to input any text</p></li><li><p>Program prints array of words entered by user without any spaces or punctuation marks</p></li></ol></li></ol>", "tests": [{"file_name": "Evaluate.java", "content": "import org.junit.Test;\nimport org.junit.Assert;\nimport com.udemy.ucp.*;\n\nimport static org.junit.Assert.assertEquals;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.ByteArrayOutputStream;\nimport java.io.InputStream;\nimport java.io.PrintStream;\n\nimport org.junit.After;\nimport org.junit.Before;\nimport org.junit.Test;\n\npublic class Evaluate {\n\n\tprivate static final String RESULT_SEPARATOR = \"You entered these words: \";\n\t\n\tprivate final ByteArrayOutputStream out = new ByteArrayOutputStream();\n\tprivate final PrintStream originalOut = System.out;\n\n\t@Before\n\tpublic void setStreams() {\n\t System.setOut(new PrintStream(out));\n\t}\n\n\t@After\n\tpublic void restoreInitialStreams() {\n\t System.setOut(originalOut);\n\t}\n\t\n\t@Test\n\tpublic void shouldSplitByAllPunctionaCharacters() {\n\t String input = \"Text with random punctuation marks: Java\\t is a general-purpose \"\n\t \t\t+ \"programming! \\'language\\'?? \\\"that\\\" ;is (class-based) and, \"\n\t \t\t+ \"object-oriented.\";\n\t InputStream in = new ByteArrayInputStream(input.getBytes());\n\t System.setIn(in);\n\n\t SplitWords.main(new String[] {});\n\t \n\t String[] result = out.toString().trim().split(RESULT_SEPARATOR);\n\t System.out.println(result[1]);\n\t\tassertEquals(\"[Text, with, random, punctuation, marks, \"\n\t\t\t\t+ \"Java, is, a, general, purpose, programming, \"\n\t\t\t\t+ \"language, that, is, class, based, and, object, \"\n\t\t\t\t+ \"oriented]\",result[1]);\n\t}\n\t\n}\n"}], "solutions": [{"file_name": "SplitWords.java", "content": "import java.util.Arrays;\r\nimport java.util.Scanner;\r\n\r\npublic class SplitWords {\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner sc = new Scanner(System.in);\r\n\t\tSystem.out.print(\"Please, enter any text: \");\r\n\t\tString userInput = sc.nextLine();\r\n\t\tSystem.out.print(\"You entered these words: \");\r\n\t\tSystem.out.println(Arrays.toString(userInput.split(\"[\\\\p{P}\\\\s]+\"))); // POSIX character classes\r\n\t}\r\n\r\n}\r\n"}]};
|
| 75 |
+
|
| 76 |
+
function renderCodeList(rootElement, codeList, className, titlePrefix) {
|
| 77 |
+
for (var i = 0; i < codeList.length; i++) {
|
| 78 |
+
var elem = codeList[i];
|
| 79 |
+
var jsElem = document.createElement("div");
|
| 80 |
+
jsElem.className = className;
|
| 81 |
+
var jsElemTitle = document.createElement("h3");
|
| 82 |
+
jsElemTitle.innerHTML = titlePrefix + " " + (i + 1);
|
| 83 |
+
var jsElemBody = document.createElement("code");
|
| 84 |
+
jsElemBody.className = "code-block black-block";
|
| 85 |
+
jsElemBody.innerHTML = "<pre>" + elem.content + "</pre>";
|
| 86 |
+
jsElem.appendChild(jsElemTitle);
|
| 87 |
+
jsElem.appendChild(jsElemBody);
|
| 88 |
+
rootElement.appendChild(jsElem);
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
function main() {
|
| 93 |
+
// display the assignment
|
| 94 |
+
var codingTitle = document.getElementById("coding-title");
|
| 95 |
+
codingTitle.innerHTML = quizData.title;
|
| 96 |
+
|
| 97 |
+
var codingInstructions = document.getElementById("coding-instructions");
|
| 98 |
+
if (quizData.hasInstructions) {
|
| 99 |
+
codingInstructions.innerHTML = quizData.instructions;
|
| 100 |
+
} else {
|
| 101 |
+
codingInstructions.innerHTML = '<span class="italic-text">' + quizData.instructions + "</span>";
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// display the test(s)
|
| 105 |
+
var codingTests = document.getElementById("coding-tests");
|
| 106 |
+
if (!quizData.hasTests) {
|
| 107 |
+
codingTests.innerHTML = '<span class="italic-text">' + quizData.tests + "</span>";
|
| 108 |
+
} else {
|
| 109 |
+
renderCodeList(codingTests, quizData.tests, "coding-test", "Test");
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// display the solution(s)
|
| 113 |
+
var codingSolutions = document.getElementById("coding-solutions");
|
| 114 |
+
if (!quizData.hasSolutions) {
|
| 115 |
+
codingSolutions.innerHTML = '<span class="italic-text">' + quizData.solutions + "</span>";
|
| 116 |
+
} else {
|
| 117 |
+
renderCodeList(codingSolutions, quizData.solutions, "coding-solution", "Solution");
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
</script>
|
| 121 |
+
</body>
|
| 122 |
+
</html>
|
06 - Strings in Java/008 Homework review String_en.srt
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:01,000
|
| 3 |
+
Hello team!
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:01,000 --> 00:00:04,000
|
| 7 |
+
Today we will review solution for coding exercises.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:04,000 --> 00:00:07,000
|
| 11 |
+
Let's start from the first one pin number formatting.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:08,000 --> 00:00:09,000
|
| 15 |
+
The solution is pretty simple.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:10,000 --> 00:00:15,000
|
| 19 |
+
Do you remember that in demo for string formatting, I put examples of precision formatting at the bottom.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:17,000 --> 00:00:21,000
|
| 23 |
+
Here also was an example about floating point number formatting.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:21,000 --> 00:00:25,000
|
| 27 |
+
Basically, you can control number of places in your floating point number.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:26,000 --> 00:00:27,000
|
| 31 |
+
And here is the solution.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:27,000 --> 00:00:33,000
|
| 35 |
+
You are using specifiers to indicate that you want to format floating point number with scale of one.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:34,000 --> 00:00:40,000
|
| 39 |
+
After that, you can use newline specifier if you wish, and format pin number again to have floating
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:40,000 --> 00:00:43,000
|
| 43 |
+
point number with scale of two, and so on.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:43,000 --> 00:00:46,000
|
| 47 |
+
Here you can see results in console output.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:47,000 --> 00:00:52,000
|
| 51 |
+
The second task ask user to enter text and split words.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:52,000 --> 00:00:55,000
|
| 55 |
+
Hope you successfully learned regular expressions.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:55,000 --> 00:00:59,000
|
| 59 |
+
Now you understand that you have different ways to implement this task.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:59,000 --> 00:01:03,000
|
| 63 |
+
You can list all punctuation marks in regular expression.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:03,000 --> 00:01:10,000
|
| 67 |
+
And you can use Posix basic regular expression Posix was developed by the Institute of Electrical and
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:10,000 --> 00:01:15,000
|
| 71 |
+
Electronics Engineers, mostly to provide backward compatibility with the traditional simple regular
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:15,000 --> 00:01:19,000
|
| 75 |
+
expressions syntax, providing a common standard.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:19,000 --> 00:01:26,000
|
| 79 |
+
In Posix, we have different character classes and categories here in comments I listed for you Posix
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:26,000 --> 00:01:27,000
|
| 83 |
+
character classes.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:28,000 --> 00:01:34,000
|
| 87 |
+
In our regular expression, we can use punctuation class and special character for all white spaces.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:34,000 --> 00:01:40,000
|
| 91 |
+
Let's split our line in case punctuation marks or spaces will be found in the string one time or more
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:40,000 --> 00:01:41,000
|
| 95 |
+
times in a row.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:42,000 --> 00:01:48,000
|
| 99 |
+
Let me run this program and I will enter any text here with different amount of spaces and punctuation
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:48,000 --> 00:01:49,000
|
| 103 |
+
marks.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:53,000 --> 00:01:56,000
|
| 107 |
+
Pressing enter and here all words that I entered.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:57,000 --> 00:01:58,000
|
| 111 |
+
That's all.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:59,000 --> 00:02:02,000
|
| 115 |
+
Thank you for your attention and see you in the next lesson.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:02,000 --> 00:02:03,000
|
| 119 |
+
Aethes.
|
| 120 |
+
|
06 - Strings in Java/008 Source-code-SOLUTION-Floating-point-number-formatting.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/hw/PINumberFormatting.java
|
06 - Strings in Java/008 Source-code-SOLUTION-Split-words-regular-expression.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/hw/SplitWords.java
|
06 - Strings in Java/009 Quiz Strings 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 Strings 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 Strings in Java - Check yourself</div>
|
| 65 |
+
<div class="article-asset-container"><p><strong>Quiz Link: </strong><a href="https://forms.gle/XcKL4FxK4JLoXcBFA" rel="noopener noreferrer" target="_blank"><strong>https://forms.gle/XcKL4FxK4JLoXcBFA</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>String: object creation and main methods overview</p></li><li><p>String comparison: How to compare Strings and what is String Pool</p></li><li><p>Escape Sequences in Java</p></li><li><p>String Formatting</p></li><li><p>Regular expressions in Java</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>
|
06 - Strings in Java/external-links.txt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
001 Source-code-of-the-example-used-in-the-lesson
|
| 3 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/StringMainMethodsOverview.java
|
| 4 |
+
|
| 5 |
+
002 Source-code-of-the-example-used-in-the-lesson
|
| 6 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/StringComparisonDemo.java
|
| 7 |
+
|
| 8 |
+
003 Source-code-of-the-example-used-in-the-lesson
|
| 9 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/EscapeSequences.java
|
| 10 |
+
|
| 11 |
+
004 Source-code-of-the-example-used-in-the-lesson
|
| 12 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/StringFormattingDemo.java
|
| 13 |
+
|
| 14 |
+
004 Source-code-from-the-lesson-Formatter-Demo
|
| 15 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/FormatterDemo.java
|
| 16 |
+
|
| 17 |
+
005 Source-code-of-the-example-used-in-the-lesson
|
| 18 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/RegularExpressions.java
|
| 19 |
+
|
| 20 |
+
005 Homework
|
| 21 |
+
https://docs.google.com/document/d/12ERxY6dUtcxo5ikfBA13_mB_7yeAByXpliDqEQ0Kjrk/edit?usp=sharing
|
| 22 |
+
|
| 23 |
+
008 Source-code-SOLUTION-Floating-point-number-formatting
|
| 24 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/hw/PINumberFormatting.java
|
| 25 |
+
|
| 26 |
+
008 Source-code-SOLUTION-Split-words-regular-expression
|
| 27 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/string/hw/SplitWords.java
|
07 - Control Statements/001 'if - else' construction_en.srt
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:11,000
|
| 3 |
+
Today, we'll talk with you about if else statement in general, you have if the election statement,
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:11,000 --> 00:00:17,000
|
| 7 |
+
which allows you to control the flow of your program is execution based upon conditions known only during
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:17,000 --> 00:00:18,000
|
| 11 |
+
runtime.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:18,000 --> 00:00:22,000
|
| 15 |
+
Let's take a closer look how you can take control of your program's execution.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:22,000 --> 00:00:24,000
|
| 19 |
+
Imagine we have two variables.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:24,000 --> 00:00:30,000
|
| 23 |
+
In the first one, you're storing the amount of coins which user has, and in the second variable you're
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:30,000 --> 00:00:33,000
|
| 27 |
+
storing item price user wants to purchase in your application.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:34,000 --> 00:00:40,000
|
| 31 |
+
We want program behave differently when a user can and cannot purchase specified item here you can see
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:40,000 --> 00:00:43,000
|
| 35 |
+
if keyword and condition in parentheses.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:43,000 --> 00:00:48,000
|
| 39 |
+
So you need to remember that expression in parenthesis should always return is a true or false.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:49,000 --> 00:00:54,000
|
| 43 |
+
In this particular case, we want to know if amount of money on an account is leathern item price or
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:54,000 --> 00:00:56,000
|
| 47 |
+
no entry.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:56,000 --> 00:00:57,000
|
| 51 |
+
This condition is true.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:57,000 --> 00:01:01,000
|
| 55 |
+
Namely, the amount of money on the account is less than item price.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:01,000 --> 00:01:07,000
|
| 59 |
+
Let's notify users that he or she doesn't have enough money on their account to purchase the item.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:07,000 --> 00:01:13,000
|
| 63 |
+
Otherwise, let's proceed with purchase logic implementation and you see that I used another keyword
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:13,000 --> 00:01:20,000
|
| 67 |
+
else keyword Ellsburg will be executed in case conditions specified next to each statement will be false.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:20,000 --> 00:01:26,000
|
| 71 |
+
From the syntax standpoint, I want to highlight that you not always should put braces for if an X blocks,
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:26,000 --> 00:01:31,000
|
| 75 |
+
for example, if you have only one line in if or else statement you can just keep.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:31,000 --> 00:01:37,000
|
| 79 |
+
Brace's compiler is smart enough to understand that this line is associated with each block and this
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:37,000 --> 00:01:44,000
|
| 83 |
+
line is associated with LS Block, even despite the fact it is possible to write in this way.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:44,000 --> 00:01:50,000
|
| 87 |
+
I don't recommend you to do so y because when you are put in braces, I would say it is more readable
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:50,000 --> 00:01:52,000
|
| 91 |
+
when each book is started and finished.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:53,000 --> 00:01:55,000
|
| 95 |
+
Because for example, let me add line here.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:58,000 --> 00:02:04,000
|
| 99 |
+
At first glance, it looks like this line is part of the El's block, but it isn't to avoid cases like
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:04,000 --> 00:02:10,000
|
| 103 |
+
this and potentially other errors just always use braces for if else blocks.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:10,000 --> 00:02:13,000
|
| 107 |
+
You can use nested if statements, if you wish.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:13,000 --> 00:02:19,000
|
| 111 |
+
Just always remember that alse will be always associated with the closest.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:19,000 --> 00:02:28,000
|
| 115 |
+
If in this example, this else is associated with this if but not with this one, you can build a Fail-Safe.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:28,000 --> 00:02:28,000
|
| 119 |
+
Lawder.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:29,000 --> 00:02:34,000
|
| 123 |
+
Unions are sladen cases when you need to verify condition in specific order one after another.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:35,000 --> 00:02:40,000
|
| 127 |
+
Let's imagine you have order price and you need to identify which discount you want to apply to this
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:40,000 --> 00:02:46,000
|
| 131 |
+
order in case when order price is more than zero but less than one hundred, you apply five percent
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:46,000 --> 00:02:53,000
|
| 135 |
+
discount in case when order price more or equal to one hundred but less than five hundred, you apply
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:53,000 --> 00:02:59,000
|
| 139 |
+
10 percent discount and then case when order price is more or equal to five hundred but less than five
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:59,000 --> 00:03:02,000
|
| 143 |
+
thousand, you apply a 15 percent discount.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:03,000 --> 00:03:07,000
|
| 147 |
+
In this example, we will sequence of checks to show users and most appropriate message.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:08,000 --> 00:03:10,000
|
| 151 |
+
Let's take a look at your homework.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:10,000 --> 00:03:16,000
|
| 155 |
+
I recommend you read book chapter about if statement and share two simple coding exercises for you to
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:16,000 --> 00:03:19,000
|
| 159 |
+
practice your skills in using if statement.
|
| 160 |
+
|
07 - Control Statements/001 Homework.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://docs.google.com/document/d/1HY9UrPLRUNc7Dz3lze26ijLNH9A3eDFkFYApf2nXIGI/edit?usp=sharing
|
07 - Control Statements/001 Source-code-of-the-example-used-in-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/controlstatements/IfElseDemo.java
|
07 - Control Statements/002 Admin and Guest mode for application.html
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>Coding Assignment</title>
|
| 8 |
+
|
| 9 |
+
<style>
|
| 10 |
+
body {
|
| 11 |
+
font-family: sf pro text, -apple-system, BlinkMacSystemFont, Roboto, segoe ui, Helvetica, Arial,
|
| 12 |
+
sans-serif, apple color emoji, segoe ui emoji, segoe ui symbol;
|
| 13 |
+
font-weight: 400;
|
| 14 |
+
line-height: 22.4px;
|
| 15 |
+
font-size: 16px;
|
| 16 |
+
}
|
| 17 |
+
p,
|
| 18 |
+
ul,
|
| 19 |
+
ol {
|
| 20 |
+
font-size: 16px;
|
| 21 |
+
font-weight: 400;
|
| 22 |
+
}
|
| 23 |
+
h1,
|
| 24 |
+
h2,
|
| 25 |
+
h3,
|
| 26 |
+
h4,
|
| 27 |
+
h5,
|
| 28 |
+
h6 {
|
| 29 |
+
font-weight: bold;
|
| 30 |
+
}
|
| 31 |
+
ul {
|
| 32 |
+
list-style: none;
|
| 33 |
+
margin: 0;
|
| 34 |
+
padding: 0;
|
| 35 |
+
max-width: none;
|
| 36 |
+
}
|
| 37 |
+
.code-snippet {
|
| 38 |
+
background-color: #fff;
|
| 39 |
+
border: 1px solid #d1d7dc;
|
| 40 |
+
color: #b4690e;
|
| 41 |
+
font-size: 90%;
|
| 42 |
+
padding: 0.2rem 0.4rem;
|
| 43 |
+
}
|
| 44 |
+
.code-block {
|
| 45 |
+
background-color: #fff;
|
| 46 |
+
color: #b4690e;
|
| 47 |
+
font-size: 90%;
|
| 48 |
+
}
|
| 49 |
+
.black-block {
|
| 50 |
+
color: #000000;
|
| 51 |
+
}
|
| 52 |
+
.italic-text {
|
| 53 |
+
font-style: italic;
|
| 54 |
+
}
|
| 55 |
+
</style>
|
| 56 |
+
</head>
|
| 57 |
+
|
| 58 |
+
<body onload="main()">
|
| 59 |
+
<h1 id="coding-title"></h1>
|
| 60 |
+
<div>
|
| 61 |
+
<h2>Instructions</h2>
|
| 62 |
+
<div id="coding-instructions"></div>
|
| 63 |
+
</div>
|
| 64 |
+
<div>
|
| 65 |
+
<h2>Test(s)</h2>
|
| 66 |
+
<div id="coding-tests"></div>
|
| 67 |
+
</div>
|
| 68 |
+
<div>
|
| 69 |
+
<h2>Solution(s)</h2>
|
| 70 |
+
<div id="coding-solutions"></div>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
<script>
|
| 74 |
+
const quizData = {"title": "002 Admin and Guest mode for application", "hasInstructions": true, "hasTests": true, "hasSolutions": true, "instructions": "<ol><li><p>Implement console program which will meet the following requirements:</p><ol><li><p>Program can be started in \u2018admin\u2019 and \u2018guest\u2019 mode</p></li><li><p>To start program in \u2018admin\u2019 mode any of multiple string arguments should be equal to \u2018--admin\u2019</p></li><li><p>To start program in \u2018guest\u2019 mode any of multiple string arguments should be equal to \u2018--guest\u2019</p></li><li><p>Program cannot be started with \u2018--admin\u2019 and \u2018--guest\u2019 arguments simultaneously</p></li><li><p>If program is started in \u2018admin\u2019 mode then \"Hello, Admin!\" is printed to console</p></li><li><p>If program is started in \u2018guest\u2019 mode then \"Hello, Guest!\" is printed to console</p></li><li><p>If program is started with \u2018--admin\u2019 and \u2018--guest\u2019 arguments then program prints \"Please, select either 'ADMIN' or 'GUEST' mode for this program\" to console</p></li></ol></li></ol><p><br></p>", "tests": [{"file_name": "Evaluate.java", "content": "import org.junit.Test;\nimport org.junit.Assert;\nimport com.udemy.ucp.*;\n\nimport static org.junit.Assert.assertEquals;\n\nimport java.io.ByteArrayOutputStream;\nimport java.io.PrintStream;\n\nimport org.junit.After;\nimport org.junit.Before;\nimport org.junit.Test;\n\npublic class Evaluate {\nprivate final ByteArrayOutputStream out = new ByteArrayOutputStream();\n\tprivate final PrintStream originalOut = System.out;\n\n\t@Before\n\tpublic void setStreams() {\n\t\tSystem.setOut(new PrintStream(out));\n\t}\n\n\t@After\n\tpublic void restoreInitialStreams() {\n\t\tSystem.setOut(originalOut);\n\t}\n\t\n\t@Test\n\tpublic void shouldBeStartedInAdminMode() {\n\t\tAdminGuestMode.main(new String[] {\"asd sdqwd wqdw --admin asdqwk lq\"});\n\t\tString consoleOutput = out.toString().trim();\n\t\tassertEquals(\"Hello, Admin!\", consoleOutput);\n\t}\n\t\n\t@Test\n\tpublic void shouldBeStartedInGuestMode() {\n\t\tAdminGuestMode.main(new String[] {\"asd sdqwd wqdw --guest asdqwk lq\"});\n\t\tString consoleOutput = out.toString().trim();\n\t\tassertEquals(\"Hello, Guest!\", consoleOutput);\n\t}\n\t\n\t@Test\n\tpublic void shouldNotBeStartedInGuestAndAdminMode() {\n\t\tAdminGuestMode.main(new String[] {\"asd --admin wqdw --guest asdqwk lq\"});\n\t\tString consoleOutput = out.toString().trim();\n\t\tassertEquals(\"Please, select either 'ADMIN' or \"\n\t\t\t\t+ \"'GUEST' mode for this program\", consoleOutput);\n\t}\n}\n"}], "solutions": [{"file_name": "AdminGuestMode.java", "content": "public class AdminGuestMode {\r\n\t\r\n\tpublic static final String ADMIN_MODE = \"--admin\";\r\n\tpublic static final String GUEST_MODE = \"--guest\";\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tString inputArguments = String.join(\",\", args);\r\n\t\tif (inputArguments.contains(ADMIN_MODE) && inputArguments.contains(GUEST_MODE)) {\r\n\t\t\tSystem.out.println(\"Please, select either 'ADMIN' or \"\r\n\t\t\t\t\t+ \"'GUEST' mode for this program\");\r\n\t\t} else if (inputArguments.contains(ADMIN_MODE)) {\r\n\t\t\tSystem.out.println(\"Hello, Admin!\");\r\n\t\t} else if (inputArguments.contains(GUEST_MODE)) {\r\n\t\t\tSystem.out.println(\"Hello, Guest!\");\r\n\t\t}\r\n\t\t\r\n\t}\r\n\r\n}"}]};
|
| 75 |
+
|
| 76 |
+
function renderCodeList(rootElement, codeList, className, titlePrefix) {
|
| 77 |
+
for (var i = 0; i < codeList.length; i++) {
|
| 78 |
+
var elem = codeList[i];
|
| 79 |
+
var jsElem = document.createElement("div");
|
| 80 |
+
jsElem.className = className;
|
| 81 |
+
var jsElemTitle = document.createElement("h3");
|
| 82 |
+
jsElemTitle.innerHTML = titlePrefix + " " + (i + 1);
|
| 83 |
+
var jsElemBody = document.createElement("code");
|
| 84 |
+
jsElemBody.className = "code-block black-block";
|
| 85 |
+
jsElemBody.innerHTML = "<pre>" + elem.content + "</pre>";
|
| 86 |
+
jsElem.appendChild(jsElemTitle);
|
| 87 |
+
jsElem.appendChild(jsElemBody);
|
| 88 |
+
rootElement.appendChild(jsElem);
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
function main() {
|
| 93 |
+
// display the assignment
|
| 94 |
+
var codingTitle = document.getElementById("coding-title");
|
| 95 |
+
codingTitle.innerHTML = quizData.title;
|
| 96 |
+
|
| 97 |
+
var codingInstructions = document.getElementById("coding-instructions");
|
| 98 |
+
if (quizData.hasInstructions) {
|
| 99 |
+
codingInstructions.innerHTML = quizData.instructions;
|
| 100 |
+
} else {
|
| 101 |
+
codingInstructions.innerHTML = '<span class="italic-text">' + quizData.instructions + "</span>";
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// display the test(s)
|
| 105 |
+
var codingTests = document.getElementById("coding-tests");
|
| 106 |
+
if (!quizData.hasTests) {
|
| 107 |
+
codingTests.innerHTML = '<span class="italic-text">' + quizData.tests + "</span>";
|
| 108 |
+
} else {
|
| 109 |
+
renderCodeList(codingTests, quizData.tests, "coding-test", "Test");
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// display the solution(s)
|
| 113 |
+
var codingSolutions = document.getElementById("coding-solutions");
|
| 114 |
+
if (!quizData.hasSolutions) {
|
| 115 |
+
codingSolutions.innerHTML = '<span class="italic-text">' + quizData.solutions + "</span>";
|
| 116 |
+
} else {
|
| 117 |
+
renderCodeList(codingSolutions, quizData.solutions, "coding-solution", "Solution");
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
</script>
|
| 121 |
+
</body>
|
| 122 |
+
</html>
|
07 - Control Statements/003 Simple Number Calculator.html
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>Coding Assignment</title>
|
| 8 |
+
|
| 9 |
+
<style>
|
| 10 |
+
body {
|
| 11 |
+
font-family: sf pro text, -apple-system, BlinkMacSystemFont, Roboto, segoe ui, Helvetica, Arial,
|
| 12 |
+
sans-serif, apple color emoji, segoe ui emoji, segoe ui symbol;
|
| 13 |
+
font-weight: 400;
|
| 14 |
+
line-height: 22.4px;
|
| 15 |
+
font-size: 16px;
|
| 16 |
+
}
|
| 17 |
+
p,
|
| 18 |
+
ul,
|
| 19 |
+
ol {
|
| 20 |
+
font-size: 16px;
|
| 21 |
+
font-weight: 400;
|
| 22 |
+
}
|
| 23 |
+
h1,
|
| 24 |
+
h2,
|
| 25 |
+
h3,
|
| 26 |
+
h4,
|
| 27 |
+
h5,
|
| 28 |
+
h6 {
|
| 29 |
+
font-weight: bold;
|
| 30 |
+
}
|
| 31 |
+
ul {
|
| 32 |
+
list-style: none;
|
| 33 |
+
margin: 0;
|
| 34 |
+
padding: 0;
|
| 35 |
+
max-width: none;
|
| 36 |
+
}
|
| 37 |
+
.code-snippet {
|
| 38 |
+
background-color: #fff;
|
| 39 |
+
border: 1px solid #d1d7dc;
|
| 40 |
+
color: #b4690e;
|
| 41 |
+
font-size: 90%;
|
| 42 |
+
padding: 0.2rem 0.4rem;
|
| 43 |
+
}
|
| 44 |
+
.code-block {
|
| 45 |
+
background-color: #fff;
|
| 46 |
+
color: #b4690e;
|
| 47 |
+
font-size: 90%;
|
| 48 |
+
}
|
| 49 |
+
.black-block {
|
| 50 |
+
color: #000000;
|
| 51 |
+
}
|
| 52 |
+
.italic-text {
|
| 53 |
+
font-style: italic;
|
| 54 |
+
}
|
| 55 |
+
</style>
|
| 56 |
+
</head>
|
| 57 |
+
|
| 58 |
+
<body onload="main()">
|
| 59 |
+
<h1 id="coding-title"></h1>
|
| 60 |
+
<div>
|
| 61 |
+
<h2>Instructions</h2>
|
| 62 |
+
<div id="coding-instructions"></div>
|
| 63 |
+
</div>
|
| 64 |
+
<div>
|
| 65 |
+
<h2>Test(s)</h2>
|
| 66 |
+
<div id="coding-tests"></div>
|
| 67 |
+
</div>
|
| 68 |
+
<div>
|
| 69 |
+
<h2>Solution(s)</h2>
|
| 70 |
+
<div id="coding-solutions"></div>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
<script>
|
| 74 |
+
const quizData = {"title": "003 Simple Number Calculator", "hasInstructions": true, "hasTests": true, "hasSolutions": true, "instructions": "<ol><li><p>Implement console program which will meet the following requirements:</p><ol><li><p>Program is started with two arguments (numbers)</p></li><li><p>Program adds these two numbers</p></li><li><p>In case one of the input arguments is floating-point number - the result of addition is floating-point number</p></li><li><p>In case two arguments are integer - the result of addition is integer</p></li></ol></li></ol>", "tests": [{"file_name": "Evaluate.java", "content": "import org.junit.Test;\nimport org.junit.Assert;\nimport com.udemy.ucp.*;\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertFalse;\nimport static org.junit.Assert.assertTrue;\n\nimport java.io.ByteArrayOutputStream;\nimport java.io.PrintStream;\n\nimport org.junit.After;\nimport org.junit.Before;\nimport org.junit.Test;\n\npublic class Evaluate {\n private static final String FLOATING_POINT_NUMBER_PLACES_SEPARATOR = \".\";\n\tprivate final ByteArrayOutputStream out = new ByteArrayOutputStream();\n\tprivate final PrintStream originalOut = System.out;\n\n\t@Before\n\tpublic void setStreams() {\n\t\tSystem.setOut(new PrintStream(out));\n\t}\n\n\t@After\n\tpublic void restoreInitialStreams() {\n\t\tSystem.setOut(originalOut);\n\t}\n\t\n\t@Test\n\tpublic void shouldAddPositiveAndNegativeInteger() {\n\t\tAddNumbers.main(new String[]{\"1\", \"-2\"});\n\t\tString consoleOutput = out.toString().trim();\n\t\tassertFalse(consoleOutput.contains(FLOATING_POINT_NUMBER_PLACES_SEPARATOR));\n\t\tassertEquals(\"-1\", consoleOutput);\n\t}\n\t\n\t@Test\n\tpublic void shouldAddPositiveAndPositiveInteger() {\n\t\tAddNumbers.main(new String[]{\"1\", \"3\"});\n\t\tString consoleOutput = out.toString().trim();\n\t\tassertFalse(consoleOutput.contains(FLOATING_POINT_NUMBER_PLACES_SEPARATOR));\n\t\tassertEquals(\"4\", consoleOutput);\n\t}\n\t\n\t@Test\n\tpublic void shouldAddZeroToZero() {\n\t\tAddNumbers.main(new String[]{\"0\", \"0\"});\n\t\tString consoleOutput = out.toString().trim();\n\t\tassertFalse(consoleOutput.contains(FLOATING_POINT_NUMBER_PLACES_SEPARATOR));\n\t\tassertEquals(\"0\", consoleOutput);\n\t}\n\t\n\t@Test\n\tpublic void shouldAddFloatingPointNumberToInteger() {\n\t\tAddNumbers.main(new String[]{\"1.1\", \"1\"});\n\t\tString consoleOutput = out.toString().trim();\n\t\tassertTrue(consoleOutput.contains(FLOATING_POINT_NUMBER_PLACES_SEPARATOR));\n\t\tassertEquals(\"2.1\", consoleOutput);\n\t}\n\t\n\t@Test\n\tpublic void shouldAddFloatingPointNumberToInteger2() {\n\t\tAddNumbers.main(new String[]{\"1\", \"2.1\"});\n\t\tString consoleOutput = out.toString().trim();\n\t\tassertTrue(consoleOutput.contains(FLOATING_POINT_NUMBER_PLACES_SEPARATOR));\n\t\tassertEquals(\"3.1\", consoleOutput);\n\t}\n\t\n\t@Test\n\tpublic void shouldAddFloatingPointNumbers() {\n\t\tAddNumbers.main(new String[]{\"1.1\", \"2.1\"});\n\t\tString consoleOutput = out.toString().trim();\n\t\tassertTrue(consoleOutput.contains(FLOATING_POINT_NUMBER_PLACES_SEPARATOR));\n\t\tassertEquals(\"3.2\", consoleOutput);\n\t}\n\n}\n"}], "solutions": [{"file_name": "AddNumbers.java", "content": "public class AddNumbers {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tif (args[0].contains(\".\") || args[1].contains(\".\")) {\r\n\t\t\tdouble paramDouble1 = Double.parseDouble(args[0]);\r\n\t\t\tdouble paramDouble2 = Double.parseDouble(args[1]);\r\n\t\t\tSystem.out.println(paramDouble1 + paramDouble2);\r\n\t\t} else {\r\n\t\t\tint paramInt1 = Integer.parseInt(args[0]);\r\n\t\t\tint paramInt2 = Integer.parseInt(args[1]);\r\n\t\t\tSystem.out.println(paramInt1 + paramInt2);\r\n\t\t}\r\n\t}\r\n\r\n}"}]};
|
| 75 |
+
|
| 76 |
+
function renderCodeList(rootElement, codeList, className, titlePrefix) {
|
| 77 |
+
for (var i = 0; i < codeList.length; i++) {
|
| 78 |
+
var elem = codeList[i];
|
| 79 |
+
var jsElem = document.createElement("div");
|
| 80 |
+
jsElem.className = className;
|
| 81 |
+
var jsElemTitle = document.createElement("h3");
|
| 82 |
+
jsElemTitle.innerHTML = titlePrefix + " " + (i + 1);
|
| 83 |
+
var jsElemBody = document.createElement("code");
|
| 84 |
+
jsElemBody.className = "code-block black-block";
|
| 85 |
+
jsElemBody.innerHTML = "<pre>" + elem.content + "</pre>";
|
| 86 |
+
jsElem.appendChild(jsElemTitle);
|
| 87 |
+
jsElem.appendChild(jsElemBody);
|
| 88 |
+
rootElement.appendChild(jsElem);
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
function main() {
|
| 93 |
+
// display the assignment
|
| 94 |
+
var codingTitle = document.getElementById("coding-title");
|
| 95 |
+
codingTitle.innerHTML = quizData.title;
|
| 96 |
+
|
| 97 |
+
var codingInstructions = document.getElementById("coding-instructions");
|
| 98 |
+
if (quizData.hasInstructions) {
|
| 99 |
+
codingInstructions.innerHTML = quizData.instructions;
|
| 100 |
+
} else {
|
| 101 |
+
codingInstructions.innerHTML = '<span class="italic-text">' + quizData.instructions + "</span>";
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// display the test(s)
|
| 105 |
+
var codingTests = document.getElementById("coding-tests");
|
| 106 |
+
if (!quizData.hasTests) {
|
| 107 |
+
codingTests.innerHTML = '<span class="italic-text">' + quizData.tests + "</span>";
|
| 108 |
+
} else {
|
| 109 |
+
renderCodeList(codingTests, quizData.tests, "coding-test", "Test");
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// display the solution(s)
|
| 113 |
+
var codingSolutions = document.getElementById("coding-solutions");
|
| 114 |
+
if (!quizData.hasSolutions) {
|
| 115 |
+
codingSolutions.innerHTML = '<span class="italic-text">' + quizData.solutions + "</span>";
|
| 116 |
+
} else {
|
| 117 |
+
renderCodeList(codingSolutions, quizData.solutions, "coding-solution", "Solution");
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
</script>
|
| 121 |
+
</body>
|
| 122 |
+
</html>
|
07 - Control Statements/004 Homework review 'if' statement_en.srt
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:11,000
|
| 3 |
+
Let's review a solution for holding exercises in the first call, an exercise you need to start program
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:11,000 --> 00:00:15,000
|
| 7 |
+
in admin or guest mode and bring different tacks to consult.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:15,000 --> 00:00:20,000
|
| 11 |
+
One of the possible solutions is to join all arguments in a single string separated by commas.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:20,000 --> 00:00:27,000
|
| 15 |
+
First, to do this, I used joint method from string class ipass separator, an array of arguments to
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:27,000 --> 00:00:33,000
|
| 19 |
+
this method, and after that we can create each statement and check whether String with arguments contains
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:33,000 --> 00:00:36,000
|
| 23 |
+
flogs for admin mode and guest mode.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:36,000 --> 00:00:43,000
|
| 27 |
+
If String contains these two flags simultaneously and I use an operator to check this according to our
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:43,000 --> 00:00:49,000
|
| 31 |
+
requirements, we need to notify users that we need to select mode for our program in case DrinkWise
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:49,000 --> 00:00:52,000
|
| 35 |
+
arguments doesn't have to flag simultaneously.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:52,000 --> 00:00:59,000
|
| 39 |
+
Then we check if string with arguments contains admin FLAC and if not, we check if arguments string
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:59,000 --> 00:01:00,000
|
| 43 |
+
contains guest FLAC.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:01:01,000 --> 00:01:06,000
|
| 47 |
+
As we learn loops and switch statements, he will be able to implement this solution in a different
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:06,000 --> 00:01:12,000
|
| 51 |
+
way to cover also some other use cases, but so far to practice skills in writing if statement.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:12,000 --> 00:01:18,000
|
| 55 |
+
This solution is good enough in the second call, an exercise you need to add no and result in different
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:18,000 --> 00:01:19,000
|
| 59 |
+
formats.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:19,000 --> 00:01:21,000
|
| 63 |
+
Floating point number or integer.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:22,000 --> 00:01:24,000
|
| 67 |
+
You did similar task in the past.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:24,000 --> 00:01:25,000
|
| 71 |
+
What was changed?
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:25,000 --> 00:01:32,000
|
| 75 |
+
So this time let's create if statement at the beginning of our program to check of input arguments contains
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:32,000 --> 00:01:38,000
|
| 79 |
+
points separator which we usually have in floating point numbers and you can see or operator here.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:39,000 --> 00:01:42,000
|
| 83 |
+
So in case first or second argument contains point.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:43,000 --> 00:01:48,000
|
| 87 |
+
Let's try to pass double value from these arguments and bring the result of addition to console.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:49,000 --> 00:01:55,000
|
| 91 |
+
In case both arguments are integers, let's pass integer and print the result to console.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:55,000 --> 00:01:57,000
|
| 95 |
+
Hope you understood the solution.
|
| 96 |
+
|
07 - Control Statements/004 Source-code-SOLUTION-Add-Numbers.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/controlstatements/hw/AddNumbers.java
|
07 - Control Statements/004 Source-code-SOLUTION-Admin-Guest-Mode.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/controlstatements/hw/AdminGuestMode.java
|
07 - Control Statements/005 'switch' construction_en.srt
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:10,000
|
| 3 |
+
They will learn another selection statement I'm talking about, so each statement, I will show you
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:10,000 --> 00:00:14,000
|
| 7 |
+
how you can use it and what the pros and cons of using it.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:14,000 --> 00:00:20,000
|
| 11 |
+
The switch statement is easy way to explain the logic of your program's execution based on the specific
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:20,000 --> 00:00:21,000
|
| 15 |
+
expression.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:21,000 --> 00:00:24,000
|
| 19 |
+
Let's take a look at the next example to understand the topic better.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:25,000 --> 00:00:30,000
|
| 23 |
+
Let's imagine you are writing code to implement logic for online store on the back end as you learn
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:30,000 --> 00:00:33,000
|
| 27 |
+
more will develop our own web application.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:34,000 --> 00:00:38,000
|
| 31 |
+
Right now, imagine that before applying final price for checkout for your customer.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:38,000 --> 00:00:42,000
|
| 35 |
+
You want to apply a personalized discount for this user.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:42,000 --> 00:00:48,000
|
| 39 |
+
To do this, you need to execute a different code based on the customer status, customer status, maybe
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:48,000 --> 00:00:51,000
|
| 43 |
+
be guest, regular customer and premium customer.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:51,000 --> 00:00:53,000
|
| 47 |
+
OK, definitely.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:53,000 --> 00:00:57,000
|
| 51 |
+
It can be different variations in business logic and namin and so on.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:57,000 --> 00:01:01,000
|
| 55 |
+
But for the sake of example, let it be this way here.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:01,000 --> 00:01:04,000
|
| 59 |
+
Next to switch keywords you can specify expression.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:05,000 --> 00:01:11,000
|
| 63 |
+
We passed link to string object, which contains customer status, very specific requirements for expression
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:11,000 --> 00:01:11,000
|
| 67 |
+
type.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:12,000 --> 00:01:18,000
|
| 71 |
+
The expression type should be a bite or short or charr or end or string or enum type.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:19,000 --> 00:01:20,000
|
| 75 |
+
What is enum type.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:20,000 --> 00:01:23,000
|
| 79 |
+
I will explain you in the separate lesson here.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:23,000 --> 00:01:24,000
|
| 83 |
+
Have different cases.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:24,000 --> 00:01:26,000
|
| 87 |
+
Case when expression will be guest.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:26,000 --> 00:01:30,000
|
| 91 |
+
Case when expression will be a regular customer or premium customer.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:31,000 --> 00:01:34,000
|
| 95 |
+
The value of the expression is compared with each value in case statement.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:35,000 --> 00:01:39,000
|
| 99 |
+
If Match is found, the code following that case statement is executed.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:40,000 --> 00:01:46,000
|
| 103 |
+
Default statement is optional, but in case no match was found, the full blog is executed.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:46,000 --> 00:01:50,000
|
| 107 |
+
The brake statement is used to terminate a statement sequence.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:50,000 --> 00:01:53,000
|
| 111 |
+
So it is similar to exit from Swedenborg behavior.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:54,000 --> 00:01:58,000
|
| 115 |
+
In this case, our customer status is premium customer.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:58,000 --> 00:02:00,000
|
| 119 |
+
That's why this blog is executed.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:02,000 --> 00:02:04,000
|
| 123 |
+
Now, let's take a look at the next example.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:06,000 --> 00:02:13,000
|
| 127 |
+
In this example, I Werrimull equals to one in case one doesn't have brake statement, that means that
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:13,000 --> 00:02:19,000
|
| 131 |
+
much will be found here and coach will be executed starting from here until break statement is executed.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:20,000 --> 00:02:26,000
|
| 135 |
+
And here in the next example, you can see how the false statement works, I is equal to 10 right now
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:27,000 --> 00:02:28,000
|
| 139 |
+
and there is no case for 10.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:29,000 --> 00:02:31,000
|
| 143 |
+
That's why the full look is executed.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:33,000 --> 00:02:38,000
|
| 147 |
+
And now when you know what switch statement is, let's compare it with each statement and we'll try
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:38,000 --> 00:02:44,000
|
| 151 |
+
to identify pros and cons, I believe you remember all examples and you'll notice the switch can test
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:44,000 --> 00:02:51,000
|
| 155 |
+
only for equality, whereas if statement can test expressions based on ranges of values, you can not
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:51,000 --> 00:02:54,000
|
| 159 |
+
specify range in case statements inside switch block.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:55,000 --> 00:03:00,000
|
| 163 |
+
But on the other hand, switch statement demonstrates better performance when it comes to multiple parts
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:00,000 --> 00:03:01,000
|
| 167 |
+
of execution.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:02,000 --> 00:03:08,000
|
| 171 |
+
That is because compiler creates so-called jump table for speech statement when during runtime expression
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:08,000 --> 00:03:16,000
|
| 175 |
+
is verified, execution goes directly to the specific case in case was if else if the order verifies
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:16,000 --> 00:03:21,000
|
| 179 |
+
each condition and in case there are a lot of such conditions, obviously it takes more time.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:21,000 --> 00:03:25,000
|
| 183 |
+
Then we switch statement and the last one, but not the least.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:25,000 --> 00:03:29,000
|
| 187 |
+
Some developers consider syntax of speech statement more readable than if statement.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:30,000 --> 00:03:35,000
|
| 191 |
+
Probably that is because clear casebooks which visually separates code blocks better from each other
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:36,000 --> 00:03:36,000
|
| 195 |
+
also.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:36,000 --> 00:03:42,000
|
| 199 |
+
Probably that is because sometimes conditions in EHF statements might be complicated in comparison with
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:42,000 --> 00:03:47,000
|
| 203 |
+
swich block when you don't have one conditions just constants next to case keyword.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:47,000 --> 00:03:50,000
|
| 207 |
+
And that's all what you need to know about which statement.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:03:50,000 --> 00:03:52,000
|
| 211 |
+
Let's take a look at your homework.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:03:53,000 --> 00:03:59,000
|
| 215 |
+
Recommended the Red Book chapter about switch statement and one coding exercise to practice your skills
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:03:59,000 --> 00:04:00,000
|
| 219 |
+
was right and switch statement.
|
| 220 |
+
|
07 - Control Statements/005 Homework.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://docs.google.com/document/d/1foicOJHNEbTvMHJQveg-HvbaWP8JJ7V0pEQ7tAwDSKU/edit?usp=sharing
|
07 - Control Statements/005 Source-code-of-the-example-used-in-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/controlstatements/SwitchDemo.java
|
07 - Control Statements/006 User Activity Selector.html
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>Coding Assignment</title>
|
| 8 |
+
|
| 9 |
+
<style>
|
| 10 |
+
body {
|
| 11 |
+
font-family: sf pro text, -apple-system, BlinkMacSystemFont, Roboto, segoe ui, Helvetica, Arial,
|
| 12 |
+
sans-serif, apple color emoji, segoe ui emoji, segoe ui symbol;
|
| 13 |
+
font-weight: 400;
|
| 14 |
+
line-height: 22.4px;
|
| 15 |
+
font-size: 16px;
|
| 16 |
+
}
|
| 17 |
+
p,
|
| 18 |
+
ul,
|
| 19 |
+
ol {
|
| 20 |
+
font-size: 16px;
|
| 21 |
+
font-weight: 400;
|
| 22 |
+
}
|
| 23 |
+
h1,
|
| 24 |
+
h2,
|
| 25 |
+
h3,
|
| 26 |
+
h4,
|
| 27 |
+
h5,
|
| 28 |
+
h6 {
|
| 29 |
+
font-weight: bold;
|
| 30 |
+
}
|
| 31 |
+
ul {
|
| 32 |
+
list-style: none;
|
| 33 |
+
margin: 0;
|
| 34 |
+
padding: 0;
|
| 35 |
+
max-width: none;
|
| 36 |
+
}
|
| 37 |
+
.code-snippet {
|
| 38 |
+
background-color: #fff;
|
| 39 |
+
border: 1px solid #d1d7dc;
|
| 40 |
+
color: #b4690e;
|
| 41 |
+
font-size: 90%;
|
| 42 |
+
padding: 0.2rem 0.4rem;
|
| 43 |
+
}
|
| 44 |
+
.code-block {
|
| 45 |
+
background-color: #fff;
|
| 46 |
+
color: #b4690e;
|
| 47 |
+
font-size: 90%;
|
| 48 |
+
}
|
| 49 |
+
.black-block {
|
| 50 |
+
color: #000000;
|
| 51 |
+
}
|
| 52 |
+
.italic-text {
|
| 53 |
+
font-style: italic;
|
| 54 |
+
}
|
| 55 |
+
</style>
|
| 56 |
+
</head>
|
| 57 |
+
|
| 58 |
+
<body onload="main()">
|
| 59 |
+
<h1 id="coding-title"></h1>
|
| 60 |
+
<div>
|
| 61 |
+
<h2>Instructions</h2>
|
| 62 |
+
<div id="coding-instructions"></div>
|
| 63 |
+
</div>
|
| 64 |
+
<div>
|
| 65 |
+
<h2>Test(s)</h2>
|
| 66 |
+
<div id="coding-tests"></div>
|
| 67 |
+
</div>
|
| 68 |
+
<div>
|
| 69 |
+
<h2>Solution(s)</h2>
|
| 70 |
+
<div id="coding-solutions"></div>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
<script>
|
| 74 |
+
const quizData = {"title": "006 User Activity Selector", "hasInstructions": true, "hasTests": true, "hasSolutions": true, "instructions": "<ol><li><p>Implement console program which will meet the following requirements:</p><ol><li><p>Program is started and user is asked to enter one of possible events:</p><ol><li><p>login</p></li><li><p>sign_up</p></li><li><p>terminate_program</p></li><li><p>main_menu</p></li><li><p>about_app</p></li></ol></li><li><p>Based on user input program prints to console different text. Mapping is below:<br></p><img src=\"https://img-c.udemycdn.com/redactor/raw/2020-04-14_17-17-07-cd73b16a9c0c505bcb5e301221bf0b31.jpg\"></li></ol></li></ol>", "tests": [{"file_name": "Evaluate.java", "content": "import org.junit.Test;\nimport org.junit.Assert;\nimport com.udemy.ucp.*;\nimport static org.junit.Assert.assertEquals;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.ByteArrayOutputStream;\nimport java.io.InputStream;\nimport java.io.PrintStream;\n\nimport org.junit.After;\nimport org.junit.Before;\nimport org.junit.Test;\n\npublic class Evaluate {\n \tprivate static final String OUTPUT_RESULT_SEPARATOR = \"Please, enter action name:\";\n\tprivate final ByteArrayOutputStream out = new ByteArrayOutputStream();\n\tprivate final PrintStream originalOut = System.out;\n\n\t@Before\n\tpublic void setStreams() {\n\t\tSystem.setOut(new PrintStream(out));\n\t}\n\n\t@After\n\tpublic void restoreInitialStreams() {\n\t\tSystem.setOut(originalOut);\n\t}\n\n\t@Test\n\tpublic void shouldProcessLoginEvent() {\n\t\tString input = \"login\";\n\t\tInputStream in = new ByteArrayInputStream(input.getBytes());\n\t\tSystem.setIn(in);\n\n\t\tUserActivitySelector.main(new String[] {});\n\t\t\n\t\tString consoleOutput = out.toString().split(OUTPUT_RESULT_SEPARATOR)[1].strip();\n\t\tassertEquals(\"Please, enter your username\", consoleOutput);\n\t}\n\n\t@Test\n\tpublic void shouldProcessSignUpEvent() {\n\t\tString input = \"sign_up\";\n\t\tInputStream in = new ByteArrayInputStream(input.getBytes());\n\t\tSystem.setIn(in);\n\n\t\tUserActivitySelector.main(new String[] {});\n\t\t\n\t\tString consoleOutput = out.toString().split(OUTPUT_RESULT_SEPARATOR)[1].strip();\n\t\tassertEquals(\"Welcome!\", consoleOutput);\n\t}\n\n\t@Test\n\tpublic void shouldProcessTerminationEvent() {\n\t\tString input = \"terminate_program\";\n\t\tInputStream in = new ByteArrayInputStream(input.getBytes());\n\t\tSystem.setIn(in);\n\n\t\tUserActivitySelector.main(new String[] {});\n\t\t\n\t\tString consoleOutput = out.toString().split(OUTPUT_RESULT_SEPARATOR)[1].strip();\n\t\tassertEquals(\"Thank you! Good bye!\", \n\t\t\t\tconsoleOutput);\n\t}\n\n\t@Test\n\tpublic void shouldProcessMainMenuEvent() {\n\t\tString input = \"main_menu\";\n\t\tInputStream in = new ByteArrayInputStream(input.getBytes());\n\t\tSystem.setIn(in);\n\n\t\tUserActivitySelector.main(new String[] {});\n\t\t\n\t\tString consoleOutput = out.toString().split(OUTPUT_RESULT_SEPARATOR)[1].strip();\n\t\tassertEquals(\"Main menu\", \n\t\t\t\tconsoleOutput);\n\t}\n\n\t@Test\n\tpublic void shouldProcessAboutAppEvent() {\n\t\tString input = \"about_app\";\n\t\tInputStream in = new ByteArrayInputStream(input.getBytes());\n\t\tSystem.setIn(in);\n\n\t\tUserActivitySelector.main(new String[] {});\n\t\tString consoleOutput = out.toString().split(OUTPUT_RESULT_SEPARATOR)[1].strip();\n\t\tassertEquals(\"This app is created by me with support of \u00aeIT-Bulls.com\", \n\t\t\t\tconsoleOutput);\n\t}\n\n\t@Test\n\tpublic void shouldProcessDefaultEvent() {\n\t\tString input = \"any other input about_app\";\n\t\tInputStream in = new ByteArrayInputStream(input.getBytes());\n\t\tSystem.setIn(in);\n\n\t\tUserActivitySelector.main(new String[] {});\n\t\tString consoleOutput = out.toString().split(OUTPUT_RESULT_SEPARATOR)[1].strip();\n\t\tassertEquals(\"Please, enter one of these values: login, sign_up, terminate_program, main_menu, about_app\", \n\t\t\t\tconsoleOutput);\n\n\t}\n\n}\n"}], "solutions": [{"file_name": "UserActivitySelector.java", "content": "import java.util.Scanner;\r\n\r\npublic class UserActivitySelector {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSystem.out.print(\"Please, enter action name: \");\r\n\t\tScanner sc = new Scanner(System.in);\r\n\t\tString userInput = sc.nextLine();\r\n\r\n\t\tswitch (userInput) {\r\n\t\tcase \"login\":\r\n\t\t\tSystem.out.println(\"Please, enter your username\");\r\n\t\t\tbreak;\r\n\t\tcase \"sign_up\":\r\n\t\t\tSystem.out.println(\"Welcome!\");\r\n\t\t\tbreak;\r\n\t\tcase \"terminate_program\":\r\n\t\t\tSystem.out.println(\"Thank you! Good bye!\");\r\n\t\t\tbreak;\r\n\t\tcase \"main_menu\":\r\n\t\t\tSystem.out.println(\"Main menu\");\r\n\t\t\tbreak;\r\n\t\tcase \"about_app\":\r\n\t\t\tSystem.out.println(\"This app is created by me with \"\r\n\t\t\t\t\t+ \"support of \\u00AEIT-Bulls.com\");\r\n\t\t\tbreak;\r\n\t\tdefault:\r\n\t\t\tSystem.out.println(\"Please, enter one of these values: login, \"\r\n\t\t\t\t\t+ \"sign_up, terminate_program, main_menu, about_app\");\r\n\t\t\tbreak;\r\n\t\t}\r\n\r\n\t}\r\n}\r\n"}]};
|
| 75 |
+
|
| 76 |
+
function renderCodeList(rootElement, codeList, className, titlePrefix) {
|
| 77 |
+
for (var i = 0; i < codeList.length; i++) {
|
| 78 |
+
var elem = codeList[i];
|
| 79 |
+
var jsElem = document.createElement("div");
|
| 80 |
+
jsElem.className = className;
|
| 81 |
+
var jsElemTitle = document.createElement("h3");
|
| 82 |
+
jsElemTitle.innerHTML = titlePrefix + " " + (i + 1);
|
| 83 |
+
var jsElemBody = document.createElement("code");
|
| 84 |
+
jsElemBody.className = "code-block black-block";
|
| 85 |
+
jsElemBody.innerHTML = "<pre>" + elem.content + "</pre>";
|
| 86 |
+
jsElem.appendChild(jsElemTitle);
|
| 87 |
+
jsElem.appendChild(jsElemBody);
|
| 88 |
+
rootElement.appendChild(jsElem);
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
function main() {
|
| 93 |
+
// display the assignment
|
| 94 |
+
var codingTitle = document.getElementById("coding-title");
|
| 95 |
+
codingTitle.innerHTML = quizData.title;
|
| 96 |
+
|
| 97 |
+
var codingInstructions = document.getElementById("coding-instructions");
|
| 98 |
+
if (quizData.hasInstructions) {
|
| 99 |
+
codingInstructions.innerHTML = quizData.instructions;
|
| 100 |
+
} else {
|
| 101 |
+
codingInstructions.innerHTML = '<span class="italic-text">' + quizData.instructions + "</span>";
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// display the test(s)
|
| 105 |
+
var codingTests = document.getElementById("coding-tests");
|
| 106 |
+
if (!quizData.hasTests) {
|
| 107 |
+
codingTests.innerHTML = '<span class="italic-text">' + quizData.tests + "</span>";
|
| 108 |
+
} else {
|
| 109 |
+
renderCodeList(codingTests, quizData.tests, "coding-test", "Test");
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// display the solution(s)
|
| 113 |
+
var codingSolutions = document.getElementById("coding-solutions");
|
| 114 |
+
if (!quizData.hasSolutions) {
|
| 115 |
+
codingSolutions.innerHTML = '<span class="italic-text">' + quizData.solutions + "</span>";
|
| 116 |
+
} else {
|
| 117 |
+
renderCodeList(codingSolutions, quizData.solutions, "coding-solution", "Solution");
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
</script>
|
| 121 |
+
</body>
|
| 122 |
+
</html>
|
07 - Control Statements/007 Homework review 'switch' statement_en.srt
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:11,000
|
| 3 |
+
Let's review together homework first, which statement you had to implement program which will behave
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:11,000 --> 00:00:17,000
|
| 7 |
+
differently based on user input, user can choose different actions and you should bring different texts
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:17,000 --> 00:00:17,000
|
| 11 |
+
to consult.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:18,000 --> 00:00:22,000
|
| 15 |
+
First of all, we ask user what action he or she would like to perform.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:23,000 --> 00:00:26,000
|
| 19 |
+
We use scanner object for that afterwards.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:26,000 --> 00:00:32,000
|
| 23 |
+
We use user input and switch statement as an expression and we have different cases here to address
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:32,000 --> 00:00:39,000
|
| 27 |
+
different user input in case user enters any random value default statement will print to console these
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:39,000 --> 00:00:43,000
|
| 31 |
+
text and will ask you to turn to one of the listed values.
|
| 32 |
+
|
07 - Control Statements/007 Source-code-SOLUTION-User-Activity-Selector.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/controlstatements/hw/UserActivitySelector.java
|
07 - Control Statements/008 Quiz Control Statements - 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 Control Statements - 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 Control Statements - Check yourself</div>
|
| 65 |
+
<div class="article-asset-container"><p><strong>Quiz Link: </strong><a href="https://forms.gle/qpYb2B8MpQo8mUUg6" rel="noopener noreferrer" target="_blank"><strong>https://forms.gle/qpYb2B8MpQo8mUUg6</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>‘if-else’ construction</p></li><li><p>‘switch’ construction</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>
|
07 - Control Statements/external-links.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
001 Homework
|
| 3 |
+
https://docs.google.com/document/d/1HY9UrPLRUNc7Dz3lze26ijLNH9A3eDFkFYApf2nXIGI/edit?usp=sharing
|
| 4 |
+
|
| 5 |
+
001 Source-code-of-the-example-used-in-the-lesson
|
| 6 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/controlstatements/IfElseDemo.java
|
| 7 |
+
|
| 8 |
+
004 Source-code-SOLUTION-Admin-Guest-Mode
|
| 9 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/controlstatements/hw/AdminGuestMode.java
|
| 10 |
+
|
| 11 |
+
004 Source-code-SOLUTION-Add-Numbers
|
| 12 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/controlstatements/hw/AddNumbers.java
|
| 13 |
+
|
| 14 |
+
005 Homework
|
| 15 |
+
https://docs.google.com/document/d/1foicOJHNEbTvMHJQveg-HvbaWP8JJ7V0pEQ7tAwDSKU/edit?usp=sharing
|
| 16 |
+
|
| 17 |
+
005 Source-code-of-the-example-used-in-the-lesson
|
| 18 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/controlstatements/SwitchDemo.java
|
| 19 |
+
|
| 20 |
+
007 Source-code-SOLUTION-User-Activity-Selector
|
| 21 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/controlstatements/hw/UserActivitySelector.java
|
08 - Miscellaneous/001 Random numbers generation_en.srt
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:00,000
|
| 3 |
+
Hello, Tim.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:00,000 --> 00:00:05,000
|
| 7 |
+
Today I will show you how you can generate random numbers from the lesson about math class.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:05,000 --> 00:00:11,000
|
| 11 |
+
You already are aware that you have mass random method, but today I will show you another way to create
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:11,000 --> 00:00:12,000
|
| 15 |
+
random number.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:12,000 --> 00:00:15,000
|
| 19 |
+
It can be that your program needs some random number.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:15,000 --> 00:00:21,000
|
| 23 |
+
For example, you want to implement dice game and when player wants to roll the dice you need to generate
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:21,000 --> 00:00:22,000
|
| 27 |
+
random number.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:22,000 --> 00:00:24,000
|
| 31 |
+
Let's take a look how you can do this.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:25,000 --> 00:00:27,000
|
| 35 |
+
You need to create new object of type.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:27,000 --> 00:00:31,000
|
| 39 |
+
Random eclipse will suggest you to import class Java.util.random.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:32,000 --> 00:00:35,000
|
| 43 |
+
This class is used to generate pseudo random numbers.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:35,000 --> 00:00:40,000
|
| 47 |
+
I don't want to dive into the details of how pseudo random numbers are generated, and why they are
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:40,000 --> 00:00:43,000
|
| 51 |
+
called pseudo random, but not just random.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:43,000 --> 00:00:49,000
|
| 55 |
+
To be honest, this information won't help you in the nearest future, and it is a bit complicated for
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:49,000 --> 00:00:50,000
|
| 59 |
+
understanding right now.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:51,000 --> 00:00:57,000
|
| 63 |
+
In short, it is obvious that absolutely random number is impossible to generate, so usually some algorithm
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:57,000 --> 00:00:59,000
|
| 67 |
+
is used to generate sequence of numbers.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:00,000 --> 00:01:06,000
|
| 71 |
+
That's why these numbers can't be called completely random, because there is predefined algorithm in
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:06,000 --> 00:01:08,000
|
| 75 |
+
place which generates the sequence.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:09,000 --> 00:01:14,000
|
| 79 |
+
After you created instance of random type, you can use its methods to generate either int, float,
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:14,000 --> 00:01:16,000
|
| 83 |
+
double long or boolean.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:16,000 --> 00:01:18,000
|
| 87 |
+
Just type next int.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:18,000 --> 00:01:24,000
|
| 91 |
+
In case when you want to generate pseudorandom int or next double in case when you want to generate
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:24,000 --> 00:01:26,000
|
| 95 |
+
pseudorandom double, and so on.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:26,000 --> 00:01:32,000
|
| 99 |
+
If you want to generate ints within the specific range, just pass integer to the next int method.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:32,000 --> 00:01:36,000
|
| 103 |
+
In this case, we will generate random number from 0 to 99.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:37,000 --> 00:01:42,000
|
| 107 |
+
If you want to generate integers from 1 to 100, just write something like this Ethz.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:42,000 --> 00:01:46,000
|
| 111 |
+
During your homework, you will be asked to generate random numbers for some tasks.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:46,000 --> 00:01:49,000
|
| 115 |
+
And now you know how to do this.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:49,000 --> 00:01:51,000
|
| 119 |
+
Thanks a lot for your attention.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:51,000 --> 00:01:53,000
|
| 123 |
+
See you in the next lesson.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:53,000 --> 00:01:53,000
|
| 127 |
+
Ay ay ay ay ay ay.
|
| 128 |
+
|
08 - Miscellaneous/001 Source-code-of-the-example-used-in-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/misc/RandomDemo.java
|
08 - Miscellaneous/external-links.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
001 Source-code-of-the-example-used-in-the-lesson
|
| 3 |
+
https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/misc/RandomDemo.java
|
09 - Iteration Statements (Loops) in Java/001 'while' loop_en.srt
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:11,000
|
| 3 |
+
We start section about iteration statements in Java, these statements create what we commonly call
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:11,000 --> 00:00:11,000
|
| 7 |
+
loops.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:12,000 --> 00:00:17,000
|
| 11 |
+
We'll discuss all loops which exist in Java and I will show you how you can use them.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:17,000 --> 00:00:20,000
|
| 15 |
+
I will put stress on best practices and when to use which loop.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:21,000 --> 00:00:25,000
|
| 19 |
+
But before we jump to the practical examples, let's discuss when do we need loops?
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:26,000 --> 00:00:29,000
|
| 23 |
+
A lot of times in your program you need to perform repeatable actions.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:30,000 --> 00:00:35,000
|
| 27 |
+
For example, you have multiple items in the cart in the online store and you need to calculate total
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:35,000 --> 00:00:37,000
|
| 31 |
+
price of the card.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:37,000 --> 00:00:43,000
|
| 35 |
+
You can iterate over each item in the cart and get its price to get total price, or you get a request
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:43,000 --> 00:00:48,000
|
| 39 |
+
to the database to fetch data about sellers and you receive multiple rows from database.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:48,000 --> 00:00:55,000
|
| 43 |
+
You need to iterate over each row to create object of seller type, for example, or you have an array
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:55,000 --> 00:01:01,000
|
| 47 |
+
of users and you need to leave only users which have more than one thousand bonus credits on their accounts
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:01,000 --> 00:01:03,000
|
| 51 |
+
and send them a promotional offer.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:03,000 --> 00:01:10,000
|
| 55 |
+
To do this, you need to fetch all users from database, iterate over each one, understand how many
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:10,000 --> 00:01:14,000
|
| 59 |
+
bonus credits has each user, and leave only those who have one thousand and more.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:15,000 --> 00:01:22,000
|
| 63 |
+
There are four types of loops available for us in Java in this lesson we'll discuss while loop while
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:22,000 --> 00:01:24,000
|
| 67 |
+
loop repeats statement or code book.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:24,000 --> 00:01:31,000
|
| 71 |
+
While controlling expression is true, when expression specified here becomes false, then program precede
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:31,000 --> 00:01:34,000
|
| 75 |
+
execution from the next line following after a while loop.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:35,000 --> 00:01:36,000
|
| 79 |
+
The calibrates is not needed.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:36,000 --> 00:01:43,000
|
| 83 |
+
In case you want to repeat a single statement, in case you want to repeat code block, use curly braces.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:43,000 --> 00:01:49,000
|
| 87 |
+
You need to know that the body of the loop won't be executed even once if the condition is false to
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:49,000 --> 00:01:49,000
|
| 91 |
+
begin with.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:50,000 --> 00:01:56,000
|
| 95 |
+
If you want to create infinite loop just plays through boolean literal incontrol an expression like
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:56,000 --> 00:01:56,000
|
| 99 |
+
this.
|
| 100 |
+
|
09 - Iteration Statements (Loops) in Java/001 Source-code-of-the-example-used-in-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/controlstatements/loops/WhileLoopDemo.java
|
09 - Iteration Statements (Loops) in Java/002 'do-while' loop_en.srt
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:11,000
|
| 3 |
+
In this lesson, we'll review with you do while look, there might be cases when you need to repeat
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:11,000 --> 00:00:17,000
|
| 7 |
+
some actions multiple times, but you are sure that you need to repeat look, at least once, I believe
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:17,000 --> 00:00:21,000
|
| 11 |
+
you remember that in a while, loop code will not be executed.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:21,000 --> 00:00:21,000
|
| 15 |
+
Never.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:21,000 --> 00:00:28,000
|
| 19 |
+
If controlling expression is false in the while loop, you can guarantee that body of the loop will
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:28,000 --> 00:00:29,000
|
| 23 |
+
be executed at least once.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:30,000 --> 00:00:35,000
|
| 27 |
+
You need to write the do keyword after that, whatever the loop is described.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:35,000 --> 00:00:39,000
|
| 31 |
+
And after that you have while statement was conditioned inside.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:40,000 --> 00:00:45,000
|
| 35 |
+
To be honest, it's hard to think of real life scenario when we need the while loop and when we use
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:45,000 --> 00:00:53,000
|
| 39 |
+
it or while loop, but the one scenario which pops up in my mind is entering Pincott in the ATM before
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:53,000 --> 00:00:58,000
|
| 43 |
+
dispensing some cash at the end, requested Pincott from you, the Operation of Freedom.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:58,000 --> 00:01:03,000
|
| 47 |
+
Pincott should be performed at least once in the case Billancourt is not valid.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:03,000 --> 00:01:07,000
|
| 51 |
+
Would it be the section one more time and request and Pincott again?
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:08,000 --> 00:01:12,000
|
| 55 |
+
In case Pincott is correct, you need to change condition to break loop.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:12,000 --> 00:01:19,000
|
| 59 |
+
In this example, you can see that I have Contre, which is initialized with zero by default, while
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:19,000 --> 00:01:22,000
|
| 63 |
+
counter is less than five will keep iterating.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:23,000 --> 00:01:27,000
|
| 67 |
+
And in this example you can see that even one counter is already five.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:27,000 --> 00:01:34,000
|
| 71 |
+
The body of the loop is executed after the controlling expression is verified and program is finished
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:35,000 --> 00:01:37,000
|
| 75 |
+
and they see this text in console output.
|
| 76 |
+
|
09 - Iteration Statements (Loops) in Java/002 Source-code-of-the-example-used-in-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/controlstatements/loops/DoWhileLoopDemo.java
|
09 - Iteration Statements (Loops) in Java/003 'for' with condition loop_en.srt
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:11,000
|
| 3 |
+
In this lesson, we'll learn follow up with condition, let's understand how Follow operates on this
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:11,000 --> 00:00:12,000
|
| 7 |
+
example.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:12,000 --> 00:00:14,000
|
| 11 |
+
We need to write for keywords first.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:15,000 --> 00:00:21,000
|
| 15 |
+
After that, we put parentheses and inside we have initialization expression, condition and iteration.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:22,000 --> 00:00:25,000
|
| 19 |
+
Initialization expression is executed only once.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:25,000 --> 00:00:30,000
|
| 23 |
+
The goal is to initialize counter here, which allows us to track the amount of iterations.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:31,000 --> 00:00:38,000
|
| 27 |
+
By the way, what is iteration and iteration is a repetition of loop body, usually iteration, but
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:38,000 --> 00:00:40,000
|
| 31 |
+
it is surrounded with braces.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:40,000 --> 00:00:47,000
|
| 35 |
+
So one execution of this block is one iteration after optimisation part we write condition.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:48,000 --> 00:00:51,000
|
| 39 |
+
This is condition which is verified on each iteration of the loop.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:51,000 --> 00:00:54,000
|
| 43 |
+
If condition is true, Laborie is executed.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:54,000 --> 00:01:01,000
|
| 47 |
+
If condition is false, Laborie is not executed and program to execution from the next line after the
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:01,000 --> 00:01:01,000
|
| 51 |
+
loop.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:01,000 --> 00:01:04,000
|
| 55 |
+
In this case, we limited amount of iterations by five.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:05,000 --> 00:01:08,000
|
| 59 |
+
The next part of the for loop is iteration.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:08,000 --> 00:01:16,000
|
| 63 |
+
This part will be executed after each loop iteration, usually a counter increment or is specified here.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:16,000 --> 00:01:17,000
|
| 67 |
+
So let's recap.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:18,000 --> 00:01:20,000
|
| 71 |
+
Initially I variable is equal to zero.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:21,000 --> 00:01:28,000
|
| 75 |
+
I will be incremented on each iteration and when I will be equal to five will not execute the loop body.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:28,000 --> 00:01:29,000
|
| 79 |
+
I will be zero.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:29,000 --> 00:01:31,000
|
| 83 |
+
One, two, three, four.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:32,000 --> 00:01:37,000
|
| 87 |
+
That is five iterations in total and we will bring the text to console five times.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:38,000 --> 00:01:44,000
|
| 91 |
+
I would like to add a few more things here, first of all, from the syntax standpoint, it is not necessary
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:44,000 --> 00:01:47,000
|
| 95 |
+
to use Brace's if you have only one line in for loop.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:47,000 --> 00:01:52,000
|
| 99 |
+
So if I will remove braces here, everything will work as expected.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:52,000 --> 00:01:56,000
|
| 103 |
+
But personally, I would recommend you keep braces for better readability.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:57,000 --> 00:02:03,000
|
| 107 |
+
Another thing to add here is that you can initialize counter outside of the loop if you wish, or you
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:03,000 --> 00:02:07,000
|
| 111 |
+
can make increment inside the iteration body if you wish.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:08,000 --> 00:02:10,000
|
| 115 |
+
And even look like this is possible.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:11,000 --> 00:02:18,000
|
| 119 |
+
So this is an example of infinite loop, which will never end, you see that there is no condition here.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:19,000 --> 00:02:25,000
|
| 123 |
+
There might be cases when you need to use more than one statement initialization or in iteration part.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:26,000 --> 00:02:33,000
|
| 127 |
+
You can use coma, for example, as you can see here, I'm using coma to declare two counters and one
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:33,000 --> 00:02:38,000
|
| 131 |
+
counter will be implemented after each iteration and another one will be documented.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:38,000 --> 00:02:39,000
|
| 135 |
+
And here how it works.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:41,000 --> 00:02:44,000
|
| 139 |
+
That is all what I wanted to share with you regarding for this condition, look.
|
| 140 |
+
|
09 - Iteration Statements (Loops) in Java/003 Source-code-of-the-example-used-in-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/controlstatements/loops/ForWithConditionLoopDemo.java
|
09 - Iteration Statements (Loops) in Java/004 'for each' loop_en.srt
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:08,000
|
| 3 |
+
In this lesson, we'll review with you for each loop.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:09,000 --> 00:00:11,000
|
| 7 |
+
It's another variation of for loop.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:11,000 --> 00:00:17,000
|
| 11 |
+
This type of loop was created to cycle over collection of elements such as arrays from start to finish.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:18,000 --> 00:00:24,000
|
| 15 |
+
You can't change direction of iteration in for each loop, for each loop is often called as enhanced
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:24,000 --> 00:00:27,000
|
| 19 |
+
for loop to make you understand it better.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:27,000 --> 00:00:29,000
|
| 23 |
+
Let me start from the example.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:30,000 --> 00:00:34,000
|
| 27 |
+
We have an array of INTs and we want to print some of all INTs for Omeri.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:35,000 --> 00:00:37,000
|
| 31 |
+
Let's iterate over this array.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:37,000 --> 00:00:44,000
|
| 35 |
+
Do not declare a counter and condition I can just use for each loop we have for key words here.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:44,000 --> 00:00:48,000
|
| 39 |
+
After that we have iteration, variable and collection of elements.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:48,000 --> 00:00:53,000
|
| 43 |
+
There are various types of collections can be used in foreach loop, such as those which are present
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:53,000 --> 00:00:55,000
|
| 47 |
+
in Java collections framework.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:55,000 --> 00:00:57,000
|
| 51 |
+
We'll discuss them later in this course.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:58,000 --> 00:01:02,000
|
| 55 |
+
But in this lesson we'll use array since you are already familiar with arrays.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:03,000 --> 00:01:09,000
|
| 59 |
+
Iteration variable will receive elements from collection one at a time on each iteration of the loop
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:09,000 --> 00:01:14,000
|
| 63 |
+
element from the array will be assigned to this variable and inside the loop body.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:14,000 --> 00:01:19,000
|
| 67 |
+
You can use this variable to implement your business logic and program output.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:19,000 --> 00:01:23,000
|
| 71 |
+
You can see that we bring to console some of all numbers from the array.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:23,000 --> 00:01:29,000
|
| 75 |
+
This loop is finished when the last element is retrieved from the collection, but you can stop the
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:29,000 --> 00:01:30,000
|
| 79 |
+
loop early if you wish.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:31,000 --> 00:01:35,000
|
| 83 |
+
We are going to have separate lessoned where I will show you how we can break any loop.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:36,000 --> 00:01:44,000
|
| 87 |
+
One more trick to write for each loop faster in eclipse, just type for each breath control space and
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:44,000 --> 00:01:44,000
|
| 91 |
+
press enter.
|
| 92 |
+
|