All language subtitles for Learn-Java-8-Full-Tutorial-for-Beginners_en

af Afrikaans
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam Download
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,130 --> 00:00:16,579 Hi, welcome to my free Java video course.\n 2 00:00:16,579 --> 00:00:23,349 Craftsman with 14 years of experience in Java.\n 3 00:00:23,349 --> 00:00:29,309 possible way. Okay, we will start with a briefing,\n 4 00:00:29,309 --> 00:00:36,090 beginning. Second, we will do a practice session,\n 5 00:00:36,090 --> 00:00:43,400 program. Finally, we will do a short key briefing,\n 6 00:00:43,399 --> 00:00:52,009 and add some more theory were needed. In this\n 7 00:00:52,009 --> 00:00:58,099 the following 15 Java key words or concepts,\n 8 00:00:58,100 --> 00:01:04,859 coding session later on. Please note, especially\n 9 00:01:04,858 --> 00:01:11,879 focus on not using any term before I officially\n 10 00:01:11,879 --> 00:01:17,478 using concepts I don't know, something that\n 11 00:01:17,478 --> 00:01:25,819 do better in this aspect. Therefore, intentionally,\n 12 00:01:25,819 --> 00:01:31,368 correct in the beginning. When necessary,\n 13 00:01:31,368 --> 00:01:40,099 on. As stated earlier, my goal is to teach\n 14 00:01:40,099 --> 00:01:47,509 can achieve this by looking just a bit stupid,\n 15 00:01:47,509 --> 00:01:53,340 is really only a first introduction. It's\n 16 00:01:53,340 --> 00:02:00,670 We will go in more detail and recap the important\n 17 00:02:00,670 --> 00:02:10,189 A package or better package structure is like\n 18 00:02:10,189 --> 00:02:17,520 to organize the different files of your program.\n 19 00:02:17,520 --> 00:02:25,080 is usually the organization's domain name\n 20 00:02:25,080 --> 00:02:32,420 become Marco spiele. For example, if you don't\n 21 00:02:32,419 --> 00:02:39,429 it's okay to invent your own domain name,\n 22 00:02:39,430 --> 00:02:44,629 for this is that the name of a program file\n 23 00:02:44,629 --> 00:02:51,109 plus the full package structure of the package.\n 24 00:02:51,110 --> 00:02:56,730 programs out there, and chances are high that\n 25 00:02:56,729 --> 00:03:04,969 same program file name before you. As Java\n 26 00:03:04,969 --> 00:03:11,740 was needed to come up with a unique name to\n 27 00:03:11,740 --> 00:03:19,980 technically exist only once. Therefore, using\n 28 00:03:19,979 --> 00:03:25,780 name as the default. Think of the package\n 29 00:03:25,780 --> 00:03:35,439 file. Using your package name is optional,\n 30 00:03:35,439 --> 00:03:40,689 the simplest program. When used, the package\n 31 00:03:40,689 --> 00:03:50,949 Java program. The package name is starting\n 32 00:03:50,949 --> 00:03:56,959 before. The reason for this is that the package\n 33 00:03:56,960 --> 00:04:03,710 specific. Using lowercase and singular for\n 34 00:04:03,710 --> 00:04:10,620 Last but not least, the package name also\n 35 00:04:10,620 --> 00:04:16,840 the Program Files related to a certain topic.\n 36 00:04:16,839 --> 00:04:24,079 course would end up in a package called con\n 37 00:04:24,079 --> 00:04:31,459 Please choose package names for fully. It's\n 38 00:04:31,459 --> 00:04:37,969 reflect the internal structure of your entire\n 39 00:04:37,970 --> 00:04:44,560 to choose package names related to your specific\n 40 00:04:44,560 --> 00:04:56,370 terms. Good names are key. To simplify programming.\n 41 00:04:56,370 --> 00:05:03,840 To do so you have to import the code into\n 42 00:05:03,839 --> 00:05:09,679 import statement or import statements will\n 43 00:05:09,680 --> 00:05:15,680 Here you can also see how the package name\n 44 00:05:15,680 --> 00:05:24,439 as it is actually part of the programs falling.\n 45 00:05:24,439 --> 00:05:33,389 of a certain package using the star symbol.\n 46 00:05:33,389 --> 00:05:41,050 also static imports, which we will cover in\n 47 00:05:41,050 --> 00:05:47,639 easily consist of 1000s if not 10s of 1000s\n 48 00:05:47,639 --> 00:05:53,639 in such a big pile of information. Therefore,\n 49 00:05:53,639 --> 00:06:00,590 on the program code besides using packages,\n 50 00:06:00,589 --> 00:06:09,859 code is classified into different units of\n 51 00:06:09,860 --> 00:06:17,009 The programmer is the one who may decide how\n 52 00:06:17,009 --> 00:06:23,000 classes. One aspect of Java is to improve\n 53 00:06:23,000 --> 00:06:30,329 The client is able or should be able to tell\n 54 00:06:30,329 --> 00:06:36,459 be able to know how this can be expressed\n 55 00:06:36,459 --> 00:06:43,209 the business easier, the cooperation between\n 56 00:06:43,209 --> 00:06:48,899 a common language related to the business\n 57 00:06:48,899 --> 00:06:56,319 utmost importance. By convention, the name\n 58 00:06:56,319 --> 00:07:02,250 with a capital letter. opening curly brace\n 59 00:07:02,250 --> 00:07:11,579 the class, where we will later write all our\n 60 00:07:11,579 --> 00:07:18,560 defines the end of the definition of the class,\n 61 00:07:18,560 --> 00:07:24,540 As a recommendation, keep your classes as\n 62 00:07:24,540 --> 00:07:36,530 well as readability. A class usually consists\n 63 00:07:36,529 --> 00:07:44,289 it defines a method of how to achieve a certain\n 64 00:07:44,290 --> 00:07:50,970 to calculate the double amount of an input\n 65 00:07:50,970 --> 00:07:57,730 For now, one at 100%. Academically correct,\n 66 00:07:57,730 --> 00:08:03,050 By convention, the name of a method should\n 67 00:08:03,050 --> 00:08:10,418 of the method. Methods define the actions\n 68 00:08:10,418 --> 00:08:16,359 refine the structure of our program code.\n 69 00:08:16,360 --> 00:08:23,770 us. methods can operate not only in numbers,\n 70 00:08:23,769 --> 00:08:31,589 it. A book would have chapters, every chapter\n 71 00:08:31,589 --> 00:08:38,500 would have sentences structuring your Java\n 72 00:08:38,500 --> 00:08:45,000 be like a chapter, a class would be like a\n 73 00:08:45,000 --> 00:08:51,769 For example, methods internally can call other\n 74 00:08:51,769 --> 00:08:59,120 of methods calling each other. As a programmer.\n 75 00:08:59,120 --> 00:09:06,009 your code, how long you want a method to be,\n 76 00:09:06,009 --> 00:09:11,360 would recommend however, to always think of\n 77 00:09:11,360 --> 00:09:17,740 if you would write a book. For example, a\n 78 00:09:17,740 --> 00:09:25,110 a method prepare appetizer, followed by a\n 79 00:09:25,110 --> 00:09:31,639 again by a method called prepper. Desert.\n 80 00:09:31,639 --> 00:09:39,069 could internally call a method called boil\n 81 00:09:39,070 --> 00:09:44,980 for example mean to have a method prepare\n 82 00:09:44,980 --> 00:09:52,809 appetizer 30 followed by a method called warm\n 83 00:09:52,809 --> 00:10:00,259 method surrounding it. Coming up with clean\n 84 00:10:00,259 --> 00:10:06,950 Code speak to you. Today with problems of\n 85 00:10:06,950 --> 00:10:13,910 part of programming is structure and readability\n 86 00:10:13,909 --> 00:10:18,949 and have difficulties in understanding what\n 87 00:10:18,950 --> 00:10:25,129 misunderstand some concept of the code. And\n 88 00:10:25,129 --> 00:10:32,899 methods as short as possible. As a rule of\n 89 00:10:38,879 --> 00:10:44,830 The definition of a method follows a similar\n 90 00:10:44,830 --> 00:10:51,310 the name of the method. As stated before,\n 91 00:10:51,309 --> 00:10:57,199 The name of a method is followed by an opening\n 92 00:10:57,200 --> 00:11:03,300 we mainly find the names of zero to an unlimited\n 93 00:11:03,299 --> 00:11:09,240 later on, you will need to choose a value\n 94 00:11:09,240 --> 00:11:15,519 method parameters. In order to further improve\n 95 00:11:15,519 --> 00:11:22,829 I recommend you to use as few as possible\n 96 00:11:22,830 --> 00:11:30,980 as a maximum, everything more than that will\n 97 00:11:30,980 --> 00:11:37,431 the beginning of the method definition. closing\n 98 00:11:37,431 --> 00:11:44,360 definition. Later, we will define the actual\n 99 00:11:44,360 --> 00:11:56,300 between the curly braces. As the name implies,\n 100 00:11:56,299 --> 00:12:02,729 for a value that you can set. The value of\n 101 00:12:02,730 --> 00:12:10,350 running. For example, when the third value\n 102 00:12:10,350 --> 00:12:16,730 variables can be used as input or output values\n 103 00:12:16,730 --> 00:12:23,120 of different data types, like numbers or text.\n 104 00:12:23,120 --> 00:12:33,850 time. Just for example, possible variable\n 105 00:12:33,850 --> 00:12:42,040 or mom's car. There are different types of\n 106 00:12:42,039 --> 00:12:48,219 variables, local variables, parameters or\n 107 00:12:54,759 --> 00:13:00,659 Public is an access modifier that defines\n 108 00:13:00,659 --> 00:13:06,199 class or method with public access modifier.\n 109 00:13:06,200 --> 00:13:12,629 modifiers like private default or protected.\n 110 00:13:12,629 --> 00:13:22,120 session we are going to cover access modifiers\n 111 00:13:22,120 --> 00:13:32,360 public in action. The class as well as the\n 112 00:13:32,360 --> 00:13:38,870 For every method, you actually have to define\n 113 00:13:38,870 --> 00:13:44,700 don't want to return any value at all. In\n 114 00:13:44,700 --> 00:13:51,209 of the method to explicitly define that the\n 115 00:13:51,208 --> 00:13:58,289 a method can actually return any kind of data\n 116 00:13:58,289 --> 00:14:05,039 in action or drive method suppose to make\n 117 00:14:05,039 --> 00:14:12,480 an action but not to return any value to us.\n 118 00:14:12,480 --> 00:14:19,220 between query methods, which will return a\n 119 00:14:19,220 --> 00:14:25,800 methods which offer the state but do not return\n 120 00:14:25,799 --> 00:14:37,549 rule. Drive is a command method and therefore\n 121 00:14:37,549 --> 00:14:44,509 indicates an annotation. We will cover annotations\n 122 00:14:44,509 --> 00:14:50,009 I want you to know that with ADD test, we\n 123 00:14:50,009 --> 00:15:00,879 as a test. When a class a variable or method\n 124 00:15:00,879 --> 00:15:07,980 you use an uppercase letter to indicate the\n 125 00:15:07,980 --> 00:15:18,120 case, as the ups and downs of upper and lowercase\n 126 00:15:18,120 --> 00:15:24,389 languages, and underscore is used to separate\n 127 00:15:24,389 --> 00:15:33,309 name. In Java, however, camel case is used\n 128 00:15:33,309 --> 00:15:39,768 we use a thought in English sentences. In\n 129 00:15:39,769 --> 00:15:47,350 meaning. The dot between the variable car\n 130 00:15:47,350 --> 00:15:56,789 to execute or we will alter. Alternatively,\n 131 00:15:56,789 --> 00:16:02,610 already used to indicate a method being called\n 132 00:16:02,610 --> 00:16:10,519 in Java. Here we can see an example of a test\n 133 00:16:10,519 --> 00:16:19,509 drives. The method drive is executed on car\n 134 00:16:19,509 --> 00:16:30,269 to be executed period. I talked about classes\n 135 00:16:30,269 --> 00:16:37,240 code in Java, a unit of code. This is perfectly\n 136 00:16:37,240 --> 00:16:43,549 A class is like a template, like a definition\n 137 00:16:43,549 --> 00:16:49,479 on when the program is running. The class\n 138 00:16:49,480 --> 00:16:56,350 car. However, when your program is running,\n 139 00:16:56,350 --> 00:17:04,390 number of cars, each car may have its own\n 140 00:17:04,390 --> 00:17:10,589 so the value of oil could drop to zero while\n 141 00:17:10,588 --> 00:17:20,750 the human DNA, a definition of how something\n 142 00:17:20,750 --> 00:17:25,599 When a Java program is running, it would usually\n 143 00:17:25,599 --> 00:17:31,589 exist as a set of values in the computer's\n 144 00:17:38,000 --> 00:17:44,580 Each program language for certain concept,\n 145 00:17:44,580 --> 00:17:51,609 is focused around objects in Java. In Java\n 146 00:17:51,609 --> 00:17:57,609 which focuses on necessary aspects to solve\n 147 00:17:57,609 --> 00:18:03,859 of a clever Java programmer to fully understand\n 148 00:18:03,859 --> 00:18:10,699 from it and transfer this model into classes.\n 149 00:18:10,700 --> 00:18:18,169 impact on how precisely a problem is transferred\n 150 00:18:18,169 --> 00:18:23,961 accurate this is done, the less code has to\n 151 00:18:23,961 --> 00:18:30,700 program will run, the less errors it will\n 152 00:18:30,700 --> 00:18:37,419 an execute table model, like a virtual machine\n 153 00:18:37,419 --> 00:18:43,150 taken from the real world, which heavily improves\n 154 00:18:43,150 --> 00:18:49,410 business client, programmer and business client\n 155 00:18:49,410 --> 00:18:56,890 of a real car, and the other of the representation\n 156 00:18:56,890 --> 00:19:07,420 each other. Here we see a simplified definition\n 157 00:19:07,420 --> 00:19:13,730 player creates a car when the game starts.\n 158 00:19:13,730 --> 00:19:23,870 three different cars at runtime. Now I talked\n 159 00:19:23,869 --> 00:19:30,609 from those classes. But how will these objects\n 160 00:19:30,609 --> 00:19:36,640 that will create the objects for us. This\n 161 00:19:36,641 --> 00:19:44,279 a class and we'll create an object each time\n 162 00:19:44,279 --> 00:19:50,259 exists, we cannot call this method anymore.\n 163 00:19:50,259 --> 00:19:58,450 as it is used to construct objects from class\nfiles 164 00:19:58,450 --> 00:20:05,660 to create a new object of time car, you write\n 165 00:20:05,660 --> 00:20:12,250 case, just like a method is given two different\n 166 00:20:12,250 --> 00:20:19,579 for the maximum speed. In our example, when\n 167 00:20:19,579 --> 00:20:27,569 a new object will be created in your computer's\n 168 00:20:27,569 --> 00:20:37,960 already. However, before we can use a variable,\n 169 00:20:37,960 --> 00:20:44,049 Colin is an example of a variable declaration,\n 170 00:20:44,049 --> 00:20:53,319 portion of the type car. Now that we have\n 171 00:20:53,319 --> 00:21:01,710 object we created a variable declaration,\n 172 00:21:01,710 --> 00:21:07,620 done in one single line. So this line reads\n 173 00:21:07,619 --> 00:21:13,918 line of code is executed, create an object\n 174 00:21:13,919 --> 00:21:21,840 a second volume of 320. Then create a variable\n 175 00:21:21,839 --> 00:21:27,990 Last but not least, assign the car object\n 176 00:21:27,990 --> 00:21:35,220 line, whenever we use my portion, we actually\n 177 00:21:35,220 --> 00:21:40,360 you might notice when looking at this line\n 178 00:21:40,359 --> 00:21:46,369 of car. But without looking into the code\n 179 00:21:46,369 --> 00:21:52,288 their meaning actually is. This is one reason\n 180 00:21:52,288 --> 00:21:58,349 variables used in a method as well as in a\n 181 00:21:58,349 --> 00:22:06,918 In session, to have this free Java video course,\n 182 00:22:06,919 --> 00:22:12,500 When we write code, we actually start by writing\n 183 00:22:12,500 --> 00:22:19,849 or class we are going to write. We do this\n 184 00:22:19,849 --> 00:22:27,589 to properly think our idea through which will\n 185 00:22:27,589 --> 00:22:32,470 in the lifecycle of a program is actually\n 186 00:22:32,470 --> 00:22:39,650 code, but to maintain the program, like extending\n 187 00:22:39,650 --> 00:22:46,120 called bugs in your code. Whenever you write\n 188 00:22:46,119 --> 00:22:52,209 defects in your code. When your program is\n 189 00:22:52,210 --> 00:23:00,720 test will ensure that whatever happens, your\n 190 00:23:00,720 --> 00:23:07,579 initially. To recap, in Lesson One of this\n 191 00:23:07,579 --> 00:23:14,079 theory to code our first Java program, which\n 192 00:23:14,079 --> 00:23:20,470 to use these 15 Java keywords and concepts\n 193 00:23:20,470 --> 00:23:26,269 If you haven't done yet, I would recommend\n 194 00:23:26,269 --> 00:23:39,349 this practice session. Okay, so now I'm in\n 195 00:23:39,349 --> 00:23:49,959 folder structure of calm Marcos build Java\n 196 00:23:49,960 --> 00:23:59,370 and also here source main. Java. com Marcos\n 197 00:23:59,369 --> 00:24:07,908 we will write our tests have already created\n 198 00:24:07,909 --> 00:24:18,460 where later we will have our actual program.\n 199 00:24:18,460 --> 00:24:25,769 in Lesson One, we have to start with a package\n 200 00:24:25,769 --> 00:24:33,099 I actually get support by my environment,\n 201 00:24:33,099 --> 00:24:39,548 you later. For now just see that it actually\n 202 00:24:39,548 --> 00:24:47,089 to program, I would recommend you to start\n 203 00:24:47,089 --> 00:24:54,829 to learn all these keywords. And so I guess\n 204 00:24:54,829 --> 00:25:01,990 but it helps you to learn the stuff from scratch.\n 205 00:25:01,990 --> 00:25:08,480 and you don't get assistance. But as soon\n 206 00:25:08,480 --> 00:25:16,329 as you know all them section environment is\n 207 00:25:16,329 --> 00:25:26,289 then I have to define it. COMM macros, we'll\n 208 00:25:26,289 --> 00:25:33,529 the package, because I have here the folder\n 209 00:25:33,529 --> 00:25:39,579 package declaration in my file actually have\n 210 00:25:39,579 --> 00:25:48,399 error. So actually, I don't even have to write\n 211 00:25:48,400 --> 00:25:55,580 is my package. And you see, before we have\n 212 00:25:55,579 --> 00:26:02,990 something is wrong. Now, oh, editor seems\n 213 00:26:02,990 --> 00:26:10,679 here we are. Later, we'll have imports, as\n 214 00:26:10,679 --> 00:26:17,929 later. Normally, you start defining your class\n 215 00:26:17,929 --> 00:26:26,870 how it's underlined red, so something is missing.\n 216 00:26:26,869 --> 00:26:37,099 class name is a person test. So I call my\n 217 00:26:37,099 --> 00:26:46,589 program, which is the class person. Okay,\n 218 00:26:46,589 --> 00:26:53,509 the first one, my editor already adds the\n 219 00:26:53,509 --> 00:26:56,288 you always need a closing bracket. 220 00:26:56,288 --> 00:27:03,429 Okay, so this is the beginning. And this the\n 221 00:27:05,029 --> 00:27:16,379 no at the annotation test. So that I define,\n 222 00:27:16,380 --> 00:27:24,909 the input appeared. Because my environment\n 223 00:27:24,909 --> 00:27:32,419 test also, I mean, it's actually a class.\n 224 00:27:32,419 --> 00:27:41,520 unit test. We'll talk much more about j unit\n 225 00:27:41,519 --> 00:27:46,980 this is a test magically somehow. Okay, and\n 226 00:27:46,980 --> 00:27:55,179 be public. It won't return any value, so it\n 227 00:27:55,179 --> 00:28:04,800 I want it to do should return hello world.\n 228 00:28:04,799 --> 00:28:14,529 of programmers. Someone I don't know who once\n 229 00:28:14,529 --> 00:28:26,668 language should return hello world. So we\n 230 00:28:26,669 --> 00:28:34,940 program, I expect my person to return hello\n 231 00:28:34,940 --> 00:28:43,528 haven't written any actual code for person.\n 232 00:28:43,528 --> 00:28:50,599 with the test, as explained before. So now\n 233 00:28:50,599 --> 00:28:55,639 red, which means we don't have a class person\n 234 00:28:55,640 --> 00:29:01,770 person, I need a variable name. And as my\n 235 00:29:01,769 --> 00:29:11,908 I call the person Marcus. Okay, now I have\n 236 00:29:11,909 --> 00:29:19,799 calling the constructor creating the object.\n 237 00:29:19,798 --> 00:29:28,639 from the type from the class person. And the\n 238 00:29:28,640 --> 00:29:36,450 in the memory of RPC to the variable, the\n 239 00:29:36,450 --> 00:29:44,370 a reference that we can later on use referencing\nthe person. 240 00:29:46,789 --> 00:29:54,750 Now this is read, but we'll take care of this\n 241 00:29:54,750 --> 00:30:03,250 we were done, what do we want? We want to\n 242 00:30:03,250 --> 00:30:11,298 to assert something, we want to assert that\n 243 00:30:11,298 --> 00:30:21,539 the hello world for us. So, we want to compare\n 244 00:30:21,539 --> 00:30:29,658 is going to return. So we say assert equals,\n 245 00:30:29,659 --> 00:30:38,130 have to import more stuff. But for now, we\n 246 00:30:38,130 --> 00:30:47,559 I add one quotation mark, and my environment\n 247 00:30:47,558 --> 00:30:55,720 is what we call a string. And I say hello\n 248 00:30:55,720 --> 00:31:03,259 HelloWorld for me, so, the first part here\n 249 00:31:03,259 --> 00:31:16,908 a comma. And now I have to add what is going\n 250 00:31:16,909 --> 00:31:30,500 Hello, world. So on the object, Marcos of\n 251 00:31:30,500 --> 00:31:44,509 world, with no parameters given and what is\n 252 00:31:44,509 --> 00:31:53,890 to hello world. Now, this is not going to\n 253 00:31:53,890 --> 00:32:01,710 For example, here, we don't have actually\n 254 00:32:01,710 --> 00:32:13,798 environment help us, you see. Now I just have\n 255 00:32:13,798 --> 00:32:22,109 create class person. And here, it already\n 256 00:32:22,109 --> 00:32:30,519 person. COMM walkersville. java course lesson\n 257 00:32:30,519 --> 00:32:37,099 and the actual class of the test will be in\n 258 00:32:37,099 --> 00:32:46,240 lot. But more about this later on. I say,\n 259 00:32:46,240 --> 00:32:54,630 got created. You see the package, and the\n 260 00:32:54,630 --> 00:33:02,090 class possible, just with opening and closing\n 261 00:33:02,089 --> 00:33:11,720 but you see, it's not red anymore. So let's\n 262 00:33:11,720 --> 00:33:19,509 to import something statically. I said before,\n 263 00:33:19,509 --> 00:33:31,819 import. But for now. Just believe me, we have\n 264 00:33:31,819 --> 00:33:42,259 org j unit. But this time, it's an assert.\n 265 00:33:42,259 --> 00:33:49,650 method assert equals. But, um, don't focus\n 266 00:33:49,650 --> 00:33:57,470 later. For now, what is important, we want\n 267 00:33:57,470 --> 00:34:05,289 to define a method. And it also tells us cannot\n 268 00:34:05,289 --> 00:34:12,239 create method HelloWorld. We had enough it\n 269 00:34:12,239 --> 00:34:25,118 fix that. Of course, we need to have it here.\n 270 00:34:25,119 --> 00:34:37,298 start calling our first test. I say run. And\n 271 00:34:37,298 --> 00:34:45,980 again executed our first class that was automatically\n 272 00:34:45,980 --> 00:34:55,748 It tells us a missing return statement. So\n 273 00:34:55,748 --> 00:35:01,848 string. But as you see the method is empty.\n 274 00:35:01,849 --> 00:35:10,789 fix that return. This is how we say it, we\n 275 00:35:10,789 --> 00:35:17,829 Hello, world. exactly as I was expecting it,\n 276 00:35:17,829 --> 00:35:30,480 world. Okay, now we switch over to the test.\n 277 00:35:30,480 --> 00:35:40,240 green, all tests passed. This is our first\n 278 00:35:40,239 --> 00:35:53,669 Tara. Okay. Thank you. That said, lesson three\n 279 00:35:53,670 --> 00:36:02,519 to our development environment, and have a\n 280 00:36:02,518 --> 00:36:09,949 back in our development environment. And now\n 281 00:36:09,949 --> 00:36:21,558 line of our program is the package declaration.\n 282 00:36:21,559 --> 00:36:28,259 of your domain name in reverse order. So in\n 283 00:36:28,259 --> 00:36:38,150 two, and we ended with a color. Actually,\n 284 00:36:38,150 --> 00:36:45,519 I really recommend you to use a package name.\n 285 00:36:45,518 --> 00:36:52,618 need to have some practice. But for now, just\n 286 00:36:52,619 --> 00:36:59,509 And always define a package name. After the\n 287 00:36:59,509 --> 00:37:07,889 import statements. This just for our lesson,\n 288 00:37:07,889 --> 00:37:16,278 name. And this is an A sub package called\n 289 00:37:16,278 --> 00:37:23,798 in the same package. So person has an a package\n 290 00:37:23,798 --> 00:37:30,980 for all classes that are in the exactly same\n 291 00:37:30,980 --> 00:37:39,449 to import them, Java will find them automatically.\n 292 00:37:39,449 --> 00:37:49,399 want to use the name class that I just wrote,\n 293 00:37:49,400 --> 00:37:57,608 class definition public class person. And\n 294 00:37:57,608 --> 00:38:07,028 this says the class ends. Public means all\n 295 00:38:07,028 --> 00:38:16,818 in any package can see the class person. What\n 296 00:38:16,818 --> 00:38:22,818 now, just take it as it is, I don't expect\n 297 00:38:22,818 --> 00:38:33,619 need some practice. And here for now, some\n 298 00:38:33,619 --> 00:38:40,530 name, and I made it private, which is also\n 299 00:38:40,530 --> 00:38:48,660 variable, because it is a reference to later\n 300 00:38:48,659 --> 00:38:56,519 which means other objects that get created\n 301 00:38:56,519 --> 00:39:07,068 See, or access this field here directly. If\n 302 00:39:07,068 --> 00:39:15,480 this method I also just created this one is\n 303 00:39:15,480 --> 00:39:23,329 they call person dot name, the method you\n 304 00:39:23,329 --> 00:39:30,119 but you could also call it I don't know. 305 00:39:30,119 --> 00:39:43,039 Return the name. So this can be anything um,\n 306 00:39:43,039 --> 00:39:50,150 again we see return, which means I want this\n 307 00:39:50,150 --> 00:40:01,440 and the colon which means do it execute it.\n 308 00:40:01,440 --> 00:40:11,009 this stream, and that having a class, returning\n 309 00:40:11,009 --> 00:40:18,190 for the first program that you do. So this\n 310 00:40:18,190 --> 00:40:24,969 I mean, actually, it might not make sense.\n 311 00:40:24,969 --> 00:40:32,539 going to the test, we learned, we actually\n 312 00:40:32,539 --> 00:40:42,358 test, we hadn't defined the class person yet.\n 313 00:40:42,358 --> 00:40:50,119 We did all this on the fly. In our development\n 314 00:40:50,119 --> 00:40:54,910 it was able to create the class as well as\n 315 00:40:54,909 --> 00:41:02,139 of programming. First of all, you define the\n 316 00:41:02,139 --> 00:41:10,889 think about the property sign. And then you\n 317 00:41:10,889 --> 00:41:16,348 actually even write it yourself. And when\n 318 00:41:16,349 --> 00:41:26,930 execute the test. And when it returns, okay,\n 319 00:41:26,929 --> 00:41:38,848 proper job. Okay, see, here, you'll see a\n 320 00:41:38,849 --> 00:41:49,318 So when testing we often speak of green or\n 321 00:41:49,318 --> 00:41:56,389 signal that you understand your test passed\n 322 00:41:56,389 --> 00:42:04,230 speak of green and red bars. Okay, so we learned\n 323 00:42:04,230 --> 00:42:09,409 an annotation. And I told you, you don't need\n 324 00:42:09,409 --> 00:42:20,618 go into details later. Besides on top of input\n 325 00:42:20,619 --> 00:42:30,769 to know that something static exists, but\n 326 00:42:30,768 --> 00:42:38,919 that's it. It's okay, if you don't understand\n 327 00:42:38,920 --> 00:42:48,588 to. Um, so we'll go in more details later.\n 328 00:42:48,588 --> 00:42:54,380 fine. I mean, the start is really tough. I\n 329 00:42:54,380 --> 00:43:04,730 in Java yet. Um, this is just an introduction,\n 330 00:43:04,730 --> 00:43:12,528 we're back in my ID E. Id is actually the\n 331 00:43:12,528 --> 00:43:20,059 And as this is much shorter, usually you just\n 332 00:43:20,059 --> 00:43:30,489 far. And the first one, you have the package.\n 333 00:43:30,489 --> 00:43:38,889 statements, you don't necessarily need something\n 334 00:43:38,889 --> 00:43:47,108 And we use the classes short name, because\n 335 00:43:47,108 --> 00:43:55,018 always the package name, so that the name\n 336 00:43:55,018 --> 00:44:02,548 use its full name, including the package name,\n 337 00:44:02,548 --> 00:44:07,099 But I mean, as you see, this is much more\n 338 00:44:07,099 --> 00:44:13,670 handy. So this is what you normally do. There's\n 339 00:44:13,670 --> 00:44:21,230 So I will just shortly mention it. Sometimes\n 340 00:44:21,230 --> 00:44:26,239 classes of the exact same short name 341 00:44:26,239 --> 00:44:33,579 but have different packages. And so to define\n 342 00:44:33,579 --> 00:44:44,208 use one with the full package name. Okay.\n 343 00:44:44,208 --> 00:44:52,828 with a curly opening brace and ends for the\n 344 00:44:52,829 --> 00:45:00,309 say it's an instance variable actually. And\n 345 00:45:00,309 --> 00:45:05,259 And instance methods could be, of course,\n 346 00:45:05,259 --> 00:45:15,778 members of the class, because they belong\n 347 00:45:15,778 --> 00:45:23,818 object. So of one class, you can create various\n 348 00:45:23,818 --> 00:45:29,539 another person could be, could have the name\n 349 00:45:29,539 --> 00:45:37,639 of class of objects, sorry. And each one of\n 350 00:45:37,639 --> 00:45:47,368 instance variables, this means that each instance\n 351 00:45:47,369 --> 00:45:55,539 each might have a different value does not\n 352 00:45:55,539 --> 00:46:02,770 There's also another thing, which is called\n 353 00:46:02,769 --> 00:46:10,699 we do when we add static to it, we can add\n 354 00:46:10,699 --> 00:46:18,269 case, now when we create different instances,\n 355 00:46:18,268 --> 00:46:25,169 this means that all other instances will also\n 356 00:46:25,170 --> 00:46:32,920 is a bit more advanced and static. We should\n 357 00:46:32,920 --> 00:46:40,009 shortly, just to be complete, wanted to mention\n 358 00:46:40,009 --> 00:46:51,349 this is an instance variable, and this is\n 359 00:46:51,349 --> 00:46:56,890 would want to add a constructor, I think I\n 360 00:46:58,650 --> 00:47:09,699 Opening and closing curly brace. This is what\n 361 00:47:09,699 --> 00:47:15,798 have any parameter here, not any variable.\n 362 00:47:15,798 --> 00:47:22,759 we want to create an object of type person\n 363 00:47:22,760 --> 00:47:30,640 called and everything that we would do in\n 364 00:47:30,639 --> 00:47:38,170 is actually used to initialize an object.\n 365 00:47:38,170 --> 00:47:48,229 Now let's add a parameter, prison name. So\n 366 00:47:48,228 --> 00:47:59,608 because we could try to set the inner person\n 367 00:47:59,608 --> 00:48:06,679 something is wrong. Variable person name is\n 368 00:48:06,679 --> 00:48:13,448 our ID or Java know? What do you mean? Here,\n 369 00:48:13,449 --> 00:48:22,130 Java, what we want is we want to set this\n 370 00:48:22,130 --> 00:48:29,858 person name. One thing we can do to fix that,\n 371 00:48:29,858 --> 00:48:35,808 works. Now we can automatically automatically\n 372 00:48:35,809 --> 00:48:43,069 want that I mean, person name is better name,\n 373 00:48:43,068 --> 00:48:51,469 have to add this to one of them. And as we\n 374 00:48:51,469 --> 00:48:59,858 instance variable person name, we add this\n 375 00:48:59,858 --> 00:49:06,900 mean this one here. And now, when someone\n 376 00:49:06,900 --> 00:49:15,349 of type person, it'll also have to add the\n 377 00:49:15,349 --> 00:49:23,780 directly gets set at the time the object is\n 378 00:49:23,780 --> 00:49:33,059 know is now that we have created our own constructor\n 379 00:49:33,059 --> 00:49:38,700 this class does not does not have a default\n 380 00:49:38,699 --> 00:49:45,558 you before this one has gone. Java will automatically\n 381 00:49:45,559 --> 00:49:53,289 by us. But as soon as we have defined one,\n 382 00:49:53,289 --> 00:50:00,680 our test from the last version, we use the\n 383 00:50:00,679 --> 00:50:09,338 will later on fail, but I want to show you\n 384 00:50:09,338 --> 00:50:17,338 we had that method here HelloWorld, I told\n 385 00:50:17,338 --> 00:50:24,078 language has like a running gag, you return\n 386 00:50:24,079 --> 00:50:31,740 And here we say the method should return a\n 387 00:50:31,739 --> 00:50:39,959 on, I would like to have a method, I can give\n 388 00:50:39,960 --> 00:50:48,880 say hello, the person's name. Um, okay. And\n 389 00:50:48,880 --> 00:50:56,229 with a test. So let's write a test for what\n 390 00:50:56,228 --> 00:51:05,179 test? So we have to first of all at the end\n 391 00:51:05,179 --> 00:51:11,018 it a notation. Much more. We don't know yet.\n 392 00:51:11,018 --> 00:51:18,548 I mean, this is all confusing. So relax. I'll\n 393 00:51:18,548 --> 00:51:28,719 understand that very soon. For now, let's\n 394 00:51:30,259 --> 00:51:39,059 Okay, because this is what I want the method\n 395 00:51:39,059 --> 00:51:47,369 brackets for the method. Okay, so we need\n 396 00:51:47,369 --> 00:51:52,880 I called it, Marcos. This time, I want to\n 397 00:51:52,880 --> 00:52:01,900 So it's called person, new person. So with\n 398 00:52:01,900 --> 00:52:09,599 I call the constructor. And this is like a\n 399 00:52:09,599 --> 00:52:18,189 the time when the object is created in our\n 400 00:52:18,188 --> 00:52:23,528 I told you the default constructor is gone.\n 401 00:52:23,528 --> 00:52:33,548 to our class. And we have to add the default\n 402 00:52:33,548 --> 00:52:45,630 put it here. Okay, and now this is empty,\n 403 00:52:45,630 --> 00:52:51,519 or an empty constructor might be confusing\n 404 00:52:51,518 --> 00:52:56,858 this case, we leave a comment. To mention\n 405 00:52:56,858 --> 00:53:07,328 this on purpose. So let's see how do we do\na comment actually. 406 00:53:07,329 --> 00:53:21,769 So I say empty. On purpose, default constructor.\n 407 00:53:21,768 --> 00:53:33,159 There's also also a single line comment, which\n 408 00:53:33,159 --> 00:53:40,018 But I really recommend you should prefer the\n 409 00:53:40,018 --> 00:53:46,058 will go in detail about comments in a later\n 410 00:53:46,059 --> 00:53:56,440 show you. Okay, so we have fixed the test.\n 411 00:53:56,440 --> 00:54:05,539 created an object of type person, let me copy\n 412 00:54:05,539 --> 00:54:14,900 create various objects one after the other.\n 413 00:54:14,900 --> 00:54:20,838 called person. So this will not work. So we\n 414 00:54:20,838 --> 00:54:27,778 two. And so like this, we could continue.\n 415 00:54:27,778 --> 00:54:35,009 so that you see. We have one class of type\n 416 00:54:35,009 --> 00:54:43,179 the default constructor. And so we have two\n 417 00:54:43,179 --> 00:54:48,198 will delete this again. I mean, this was just\n 418 00:54:48,199 --> 00:54:53,509 what we want to achieve actually is we want\n 419 00:54:53,509 --> 00:55:01,708 I was wrong. I want to say hello, Marcos.\n 420 00:55:01,708 --> 00:55:15,208 I want Hello, Marcos. And I want to say person\n 421 00:55:15,208 --> 00:55:22,028 we use a variable here, we call it an argument.\n 422 00:55:22,028 --> 00:55:28,699 people use this interchangeably. But to be\n 423 00:55:28,699 --> 00:55:35,939 it's all about variables. So we add a string.\n 424 00:55:35,940 --> 00:55:42,400 is missing our ID, he tells us something right\n 425 00:55:42,400 --> 00:55:49,588 So I want on the object of person we created\n 426 00:55:49,588 --> 00:55:55,900 Hello. And you see it's red. And it also our\n 427 00:55:55,900 --> 00:56:05,660 Hello. It doesn't exist. But we are programming\n 428 00:56:05,659 --> 00:56:16,308 to create a method right now. Okay, I'm actually,\n 429 00:56:16,309 --> 00:56:23,729 my array he created for us. Well, there are\n 430 00:56:23,728 --> 00:56:31,219 later on. So for now, I just did this to speed\n 431 00:56:31,219 --> 00:56:38,889 sure you could create that by yourself. Now\n 432 00:56:38,889 --> 00:56:44,208 now this is something special. I don't want\n 433 00:56:44,208 --> 00:56:51,338 I don't want to confuse you. But I also don't\n 434 00:56:51,338 --> 00:57:03,788 other. And now, I would add well Marcus's\n 435 00:57:03,789 --> 00:57:09,440 be any name, not necessarily has to be Marcos,\n 436 00:57:09,440 --> 00:57:17,139 want is I want to add name to Hello. What\n 437 00:57:17,139 --> 00:57:25,078 name. And something is missing. Oh, it doesn't\n 438 00:57:25,079 --> 00:57:32,089 how you concatenate two strings together.\n 439 00:57:32,088 --> 00:57:40,438 can do this any number of time. But for now,\n 440 00:57:40,438 --> 00:57:45,938 the given name. So this should be fine. Actually,\n 441 00:57:45,938 --> 00:57:53,440 see very soon. Which I did on purpose, because\n 442 00:57:53,440 --> 00:58:05,818 Let's execute it. Ah, so you see expected\n 443 00:58:05,818 --> 00:58:11,538 there's a space missing. So see, this is one\n 444 00:58:11,539 --> 00:58:20,140 you to think about the stuff you code. But\n 445 00:58:20,139 --> 00:58:26,588 then you will directly spot it and you're\n 446 00:58:26,588 --> 00:58:35,150 and destroy something. And yeah, this can\n 447 00:58:35,150 --> 00:58:44,630 go down to our method. And here was a space\n 448 00:58:44,630 --> 00:58:58,358 executed again. And now the bar is green.\n 449 00:58:58,358 --> 00:59:07,409 I think that's it for now. Lesson five. So\n 450 00:59:07,409 --> 00:59:15,528 first of all about visibility modifiers. Actually,\n 451 00:59:15,528 --> 00:59:23,059 modifier is private. Another one is public.\n 452 00:59:23,059 --> 00:59:32,048 is visible or usable. From all other classes\n 453 00:59:32,048 --> 00:59:39,288 on the package comm Mako speelde. java course\n 454 00:59:39,289 --> 00:59:45,640 in lesson three. So if we would go in the\n 455 00:59:45,639 --> 00:59:57,389 person as long as it's public. A private class,\n 456 00:59:57,389 --> 01:00:05,139 not allowed here. And of course how That makes\n 457 01:00:05,139 --> 01:00:12,808 But just in this class. This doesn't make\n 458 01:00:12,809 --> 01:00:19,729 we can leave the modifier away. And this will\n 459 01:00:19,728 --> 01:00:27,230 why it's called default modifier, also package\n 460 01:00:27,230 --> 01:00:37,548 be used from other classes within this package.\n 461 01:00:37,548 --> 01:00:46,068 the constructors, we can even have a private\n 462 01:00:46,068 --> 01:00:56,338 could have that method private. And this one\n 463 01:00:56,338 --> 01:01:05,058 one. Let's call HelloWorld. From this method\n 464 01:01:05,059 --> 01:01:11,089 even makes sense. Because especially when\n 465 01:01:11,088 --> 01:01:17,759 say not more than three or 10 lines. Then\n 466 01:01:17,759 --> 01:01:27,858 into smaller private methods, and then calling\n 467 01:01:27,858 --> 01:01:35,058 have only two methods. So to make things up,\n 468 01:01:35,059 --> 01:01:41,199 course, I could define further methods. We\n 469 01:01:41,199 --> 01:01:56,999 any number of methods later on. Okay, so to\n 470 01:01:56,998 --> 01:02:04,409 far is public, private, and default or package\n 471 01:02:04,409 --> 01:02:12,889 modifiers, one, for example, is protected.\n 472 01:02:12,889 --> 01:02:22,960 should be perfectly coming alone, along with\n 473 01:02:22,960 --> 01:02:30,978 let's just concentrate on these few. Let me\n 474 01:02:30,978 --> 01:02:38,678 we are going to need it in our test. And I\n 475 01:02:38,679 --> 01:02:50,608 the code as it was before. Okay, because now\n 476 01:02:50,608 --> 01:02:59,369 idea. I have prepared the test should return\n 477 01:02:59,369 --> 01:03:08,849 of type person, one person, person to 478 01:03:13,338 --> 01:03:18,528 we could also use the other constructor, but\n 479 01:03:18,528 --> 01:03:24,958 as this at the moment is just too much work\n 480 01:03:24,958 --> 01:03:31,428 it a different name, like my person, just\n 481 01:03:31,429 --> 01:03:39,088 variables. So what this means is when the\n 482 01:03:39,088 --> 01:03:45,929 is executed, which is just after the column,\n 483 01:03:45,929 --> 01:03:57,019 in memory. And after this line three objects\n 484 01:03:57,018 --> 01:04:04,288 on a number of objects. Now I should have\n 485 01:04:04,289 --> 01:04:14,179 a method that tells me exactly that. Just\n 486 01:04:14,179 --> 01:04:26,818 Okay, still read, remember, we'll create it.\n 487 01:04:26,818 --> 01:04:34,768 three is a number. And a number in Java is\n 488 01:04:34,768 --> 01:04:41,019 this actually a primitive. And the default\n 489 01:04:41,019 --> 01:04:49,518 zero here. So it's not red anymore. We can\n 490 01:04:49,518 --> 01:04:56,368 course, because it statically returns zero\n 491 01:04:56,369 --> 01:05:09,548 Well of course we could say three statically.\n 492 01:05:09,548 --> 01:05:18,498 of course, greenbar Tada. But, I mean, I want\n 493 01:05:18,498 --> 01:05:26,798 have two persons, I want this to be two. And\n 494 01:05:26,798 --> 01:05:34,668 Let's copy it. And now when I execute it,\n 495 01:05:34,668 --> 01:05:42,879 to, but it's still three. So my first approach\n 496 01:05:42,880 --> 01:05:50,309 gag, but yeah, not what we need. So what we\n 497 01:05:50,309 --> 01:05:58,798 is created, we need to count each object that\n 498 01:05:58,798 --> 01:06:07,059 the object is created, there is one thing,\n 499 01:06:07,059 --> 01:06:15,439 is, you might guess it, the constructor, we\n 500 01:06:15,438 --> 01:06:22,659 So we would have to do something in here.\n 501 01:06:22,659 --> 01:06:35,239 variable, I also call it or let's call it\n 502 01:06:35,239 --> 01:06:42,369 And now I say person counter, because I want\n 503 01:06:42,369 --> 01:06:51,119 add one to the last value of person counter\n 504 01:06:51,119 --> 01:07:00,429 side, is the new value. On the right side\n 505 01:07:00,429 --> 01:07:09,528 And I add one to it. Now, this is a lot of\n 506 01:07:09,528 --> 01:07:17,869 is used so often, that they invented short\n 507 01:07:17,869 --> 01:07:24,108 plus plus, we say take the current value of\n 508 01:07:24,108 --> 01:07:29,380 it again into the value of person counter,\n 509 01:07:29,380 --> 01:07:38,760 it. Let's do that. Make it private, of course,\n 510 01:07:38,760 --> 01:07:47,289 column. Because I don't have to say zero,\n 511 01:07:47,289 --> 01:07:54,589 for end is zero anyway, so what we usually\n 512 01:07:54,588 --> 01:08:01,028 would be it starts with zero. The first time\n 513 01:08:01,028 --> 01:08:10,969 by one, and so on. So that my method now should\n 514 01:08:10,969 --> 01:08:24,988 instead. Okay, let's try that. Execute the\n 515 01:08:24,988 --> 01:08:31,068 It didn't return zero. It didn't return three\n 516 01:08:31,069 --> 01:08:38,500 one anywhere. Maybe you guessed it already.\n 517 01:08:38,500 --> 01:08:47,130 one. Now I told you something in the prior\n 518 01:08:47,130 --> 01:08:56,150 of the instance. So each object has their\n 519 01:08:56,149 --> 01:09:02,979 is called for each of the objects. So in the\n 520 01:09:02,979 --> 01:09:11,358 set to one. So what we need is more like a\n 521 01:09:11,359 --> 01:09:17,298 level. But we say on the class level, because\n 522 01:09:17,298 --> 01:09:31,309 only one class person and this we achieve\n 523 01:09:31,309 --> 01:09:39,099 as a recommendation because this will help\n 524 01:09:39,099 --> 01:09:45,969 just believe me. As we have the variable of\n 525 01:09:45,969 --> 01:09:54,969 method of type static, it would work also\n 526 01:09:54,969 --> 01:10:09,038 so now let's execute it. And this work Great.\n 527 01:10:14,319 --> 01:10:32,488 for for an exit executed and it works, I said\n 528 01:10:32,488 --> 01:10:37,558 And it works? Well as you see this might be\n 529 01:10:37,559 --> 01:10:50,070 on. And also there is a recommendation. Actually\n 530 01:10:50,069 --> 01:10:58,319 persons as a static method, it sees that you\n 531 01:10:58,319 --> 01:11:06,029 And as this is a static method, it doesn't\n 532 01:11:06,029 --> 01:11:11,800 this method is static, it's not part of the\n 533 01:11:11,800 --> 01:11:19,460 of the object. This method now is part of\n 534 01:11:19,460 --> 01:11:29,118 trying to be smart and is smart, and calls\n 535 01:11:29,118 --> 01:11:36,500 doing here is working because Java knows how\n 536 01:11:36,500 --> 01:11:43,149 is better is darkly saying person, so that\n 537 01:11:43,149 --> 01:11:51,449 instance, we're just calling a static static\n 538 01:11:51,449 --> 01:12:02,609 that again. And it's working. Thank you. So\n 539 01:12:02,609 --> 01:12:07,988 to talk about the tools which I'm using. So\n 540 01:12:07,988 --> 01:12:17,829 It's an apple MacBook Pro. This ID that I'm\n 541 01:12:17,829 --> 01:12:24,719 at the moment is my favorite ID. Before I\n 542 01:12:24,719 --> 01:12:31,779 is open source is also very popular at the\n 543 01:12:31,779 --> 01:12:38,099 it's open source and free. However, I think\n 544 01:12:38,099 --> 01:12:43,230 and better every year. So I really like it\n 545 01:12:43,229 --> 01:12:50,689 for saying that. But I mean, this is your\n 546 01:12:50,689 --> 01:12:58,419 So I would say just try it out yourself. There's\n 547 01:12:58,420 --> 01:13:07,550 and it's also for free. I'll just in a second,\n 548 01:13:07,550 --> 01:13:13,570 have a closer look at my tests before. So\n 549 01:13:13,569 --> 01:13:21,130 I'm using j unit, which is a testing framework.\n 550 01:13:21,130 --> 01:13:29,770 a set of tools to set of classes. And it's\n 551 01:13:29,770 --> 01:13:35,820 writing such a framework, it's not really\n 552 01:13:35,819 --> 01:13:42,529 done. So this makes it really easy to start\n 553 01:13:42,529 --> 01:13:48,738 few testing frameworks. The second one I would\n 554 01:13:48,738 --> 01:13:55,589 pretty much the same. And really depends on\n 555 01:13:55,590 --> 01:14:02,010 some use testing G or any other framework,\n 556 01:14:02,010 --> 01:14:08,070 knows not so much big differences. So it doesn't\n 557 01:14:08,069 --> 01:14:14,549 in here. IntelliJ IDEA actually supports both\n 558 01:14:14,550 --> 01:14:22,300 try them. Um, I'm not going in much more details,\n 559 01:14:22,300 --> 01:14:29,949 So I focus really on Java. Just to be complete,\n 560 01:14:29,948 --> 01:14:34,908 I do this in less than six because at the\n 561 01:14:34,908 --> 01:14:42,869 is already quite difficult. So I wanted to\n 562 01:14:42,869 --> 01:14:47,979 the heck is that here? What are you doing?\n 563 01:14:47,979 --> 01:14:55,478 is lots of documentation on the internet.\n 564 01:14:55,479 --> 01:15:04,369 so maybe we just go to the browser now. and\n 565 01:15:04,368 --> 01:15:10,849 intelli j idea for you pops up. 566 01:15:10,850 --> 01:15:18,560 So you can download, I would first of all,\n 567 01:15:18,560 --> 01:15:28,949 you like it or not. Besides, of course, there's\n 568 01:15:28,948 --> 01:15:39,701 then you can choose your operating system,\n 569 01:15:39,701 --> 01:15:55,719 but not least NetBeans. Just press the download\n 570 01:15:55,719 --> 01:16:08,260 system. And then also j unit, let's have a\n 571 01:16:08,260 --> 01:16:13,510 won't have to install it, because it would\n 572 01:16:13,510 --> 01:16:21,110 record, I mean, this also has lots of documentation.\n 573 01:16:21,109 --> 01:16:28,960 version. Let's check documentation. Here.\n 574 01:16:28,960 --> 01:16:35,439 also using so this way, you can define in\n 575 01:16:35,439 --> 01:16:41,719 for 12 of j unit, which I actually did, because\n 576 01:16:41,719 --> 01:16:55,210 in a second. But after j unit, let's also\n 577 01:16:55,210 --> 01:17:02,250 test ng g on this page just provides the false\n 578 01:17:02,250 --> 01:17:08,118 IDEA, it's included anyway. And I checked\n 579 01:17:08,118 --> 01:17:19,339 with NetBeans, I have to admit that beans,\n 580 01:17:19,340 --> 01:17:27,170 download and install. So probably works just\n 581 01:17:27,170 --> 01:17:37,690 Maven, there's what's called a build management\n 582 01:17:37,689 --> 01:17:44,098 build. Now, what's a build? Well, when you\n 583 01:17:44,099 --> 01:17:50,590 of classes, and then you would want to release\n 584 01:17:50,590 --> 01:17:55,569 And then of course, you would not want to\n 585 01:17:55,569 --> 01:18:02,399 usually do a package a single file out of\n 586 01:18:02,399 --> 01:18:08,479 and say in prehistoric times, this was done\n 587 01:18:08,479 --> 01:18:17,618 So people very soon started to program, some\n 588 01:18:17,618 --> 01:18:25,500 first tool that I know of is probably make\n 589 01:18:25,500 --> 01:18:35,939 up with and and Maven again is the successor\n 590 01:18:35,939 --> 01:18:45,658 in version three. Besides Maven, there's also\n 591 01:18:45,658 --> 01:18:53,269 here you see it find that I'm using j unit\n 592 01:18:53,270 --> 01:18:58,639 is UTF eight, because what this bill two also\n 593 01:18:58,639 --> 01:19:07,868 things is environment specific settings. So\n 594 01:19:07,868 --> 01:19:17,488 eight, I can do it here. And so much more.\n 595 01:19:17,488 --> 01:19:26,618 Maven. There, you can download it. They also\n 596 01:19:26,618 --> 01:19:35,139 book. You can download all the files, even\n 597 01:19:35,139 --> 01:19:44,520 check Maven book. I really recommend that.\n 598 01:19:44,520 --> 01:19:53,170 And also there should be a PDF somewhere.\n 599 01:19:53,170 --> 01:20:02,179 there is also a PDF available which you can\n 600 01:20:02,179 --> 01:20:07,730 Last but not least, let's also talk about\n 601 01:20:07,729 --> 01:20:15,408 at least one of the lessons I did so far,\n 602 01:20:15,408 --> 01:20:21,868 But you should start with a text editor instead,\n 603 01:20:21,868 --> 01:20:30,839 first of all testbed for Windows, I really\n 604 01:20:30,840 --> 01:20:40,179 not available. In this, you can write your\n 605 01:20:40,179 --> 01:20:45,739 you have already downloaded the Java JDK,\n 606 01:20:45,738 --> 01:20:55,428 I assume I should be easy, but maybe we could\n 607 01:20:55,429 --> 01:20:59,989 that you can download your code, you can just\n 608 01:20:59,988 --> 01:21:07,968 NetBeans, if it was soiled, and you can choose\n 609 01:21:07,969 --> 01:21:13,179 you have already done that. And so when you\n 610 01:21:13,179 --> 01:21:23,868 pad, or sublime, you're on. Mac, I'm using\n 611 01:21:23,868 --> 01:21:33,420 button. It's also available for Windows and\n 612 01:21:33,420 --> 01:21:40,118 loaded the class person that we saw before.\n 613 01:21:40,118 --> 01:21:45,799 on person's name, it highlights the variable\n 614 01:21:45,800 --> 01:21:51,779 so heavily assist you, like you might have\n 615 01:21:51,779 --> 01:21:59,969 is actually good, I think. Because when your\n 616 01:21:59,969 --> 01:22:07,029 your brain cells too much. I mean, after some\n 617 01:22:07,029 --> 01:22:12,829 really welcome. But for the beginning, I really\n 618 01:22:12,829 --> 01:22:19,538 you get used and familiar with all these keywords,\n 619 01:22:19,538 --> 01:22:25,469 get familiar with that. And so for the beginning,\n 620 01:22:25,469 --> 01:22:32,869 go on the console and called Java arc and\n 621 01:22:32,869 --> 01:22:41,529 you because in this course really I only focus\n 622 01:22:41,529 --> 01:22:45,198 it really short introduction of the tools\nthat I'm using. 623 01:22:45,198 --> 01:22:55,729 If you have any questions, send me an email\n 624 01:22:55,729 --> 01:23:01,339 let's start with the topic of this video,\n 625 01:23:01,340 --> 01:23:10,699 conditional statements, and Boolean. So a\n 626 01:23:10,698 --> 01:23:19,800 a primitive and it can have two values, Boolean,\n 627 01:23:19,801 --> 01:23:30,460 it. So conditional statements, I mean, there\n 628 01:23:30,460 --> 01:23:35,899 And that is something is executed or not.\n 629 01:23:35,899 --> 01:23:41,698 sense, and you might easily understand it.\n 630 01:23:41,698 --> 01:23:47,869 Boolean? I mean, this is a bit weird, I think,\n 631 01:23:47,869 --> 01:23:58,039 just looked it up on the internet. Here on\n 632 01:23:58,039 --> 01:24:04,309 really not a big fan of mathematics. So let's\n 633 01:24:04,309 --> 01:24:11,480 matters to me is Boolean algebra was introduced\n 634 01:24:11,479 --> 01:24:17,558 blah whatsoever. So it turns out that the\n 635 01:24:17,559 --> 01:24:25,750 guy here. Um, I leave this as your homework,\n 636 01:24:25,750 --> 01:24:33,300 algebra, of course, this is again a big topic\n 637 01:24:33,300 --> 01:24:42,670 Java, I just wanted to help you that you get\n 638 01:24:42,670 --> 01:24:49,889 So this thing here is really helpful when\n 639 01:24:49,889 --> 01:24:57,069 exists, some condition, then only execute\n 640 01:24:57,069 --> 01:25:04,849 also say else if this condition does not hold\n 641 01:25:04,849 --> 01:25:11,640 the if statement is probably the most important\n 642 01:25:11,640 --> 01:25:18,309 programming languages, at least the ones I\n 643 01:25:18,309 --> 01:25:24,260 have a different execution flow each time.\n 644 01:25:24,260 --> 01:25:36,820 bit boring. Let's call this Monday. And let's\n 645 01:25:36,819 --> 01:25:45,299 also have Monday. Okay, so in this little\n 646 01:25:45,300 --> 01:25:54,119 nobody could say if it's Monday, and percent\ntwice 647 01:25:55,488 --> 01:26:04,689 So what these two M percent mean is, and so\n 648 01:26:04,689 --> 01:26:13,118 check if it's true, and only if the first\n 649 01:26:13,118 --> 01:26:24,839 like, is it Monday, which would have to return\n 650 01:26:24,840 --> 01:26:30,100 would execute, go here. And check if this\n 651 01:26:30,100 --> 01:26:46,219 be a function if Is it raining or whatever,\n 652 01:26:46,219 --> 01:26:52,719 block here, starting with the curly braces,\n 653 01:26:52,719 --> 01:27:01,189 want to implement the functions. So let's\n 654 01:27:01,189 --> 01:27:10,579 Just to keep it simple, and then drink beer.\n 655 01:27:10,579 --> 01:27:19,550 Um, but now let's make this more easy to drink\n 656 01:27:19,550 --> 01:27:29,250 lover. So on Mac, I mean, as depends which\n 657 01:27:29,250 --> 01:27:38,288 and seven, twice. This is called the pipe\n 658 01:27:38,288 --> 01:27:45,550 um, yeah, I know this is a bit weird. This,\n 659 01:27:45,550 --> 01:27:54,139 or, again, as before with the two ampersands.\n 660 01:27:54,139 --> 01:28:05,000 short circuit operator, which means if the\n 661 01:28:05,000 --> 01:28:13,479 end, at least, then it's not going to execute\n 662 01:28:13,479 --> 01:28:19,189 that a condition will cannot hold true anymore.\n 663 01:28:19,189 --> 01:28:25,589 not execute the rest, which is very handy.\n 664 01:28:25,590 --> 01:28:35,671 here, is it raining. Now imagine this method\n 665 01:28:35,671 --> 01:28:43,230 really save that time if we already see. This\n 666 01:28:43,229 --> 01:28:53,000 why you use the ampersand twice. And the pipe\n 667 01:28:53,000 --> 01:28:58,849 So I want to even spend time to talk about\n 668 01:28:58,849 --> 01:29:08,800 much nicer. If I have an orange here, if it's\n 669 01:29:08,800 --> 01:29:15,750 So this really increases my chance my chance\n 670 01:29:15,750 --> 01:29:26,649 so much more. I'm just kidding. Um, so this\n 671 01:29:26,649 --> 01:29:38,500 you can further combine that led so I don't\n 672 01:29:38,500 --> 01:29:52,658 say Tuesday and sunny. So we have to introduce\n 673 01:29:52,658 --> 01:30:03,500 Well, if it's Monday, it can't be Tuesday.\n 674 01:30:03,500 --> 01:30:11,109 it's raining, it can't be sunny. So sunny\n 675 01:30:11,109 --> 01:30:21,009 this. Now it's not Monday. It's Tuesday. So\n 676 01:30:21,010 --> 01:30:28,139 Okay, now they're not red anymore. So now\n 677 01:30:28,139 --> 01:30:33,539 if Monday is raining, but it's not Monday\n 678 01:30:33,539 --> 01:30:42,590 here is not true. But here we have an or true\n 679 01:30:42,590 --> 01:30:49,139 So this is also false, which means the whole\n 680 01:30:49,139 --> 01:30:57,869 a beer. But let's make this true. And now\n 681 01:30:57,869 --> 01:31:03,889 a beer Ray. Of course, I mean, when it gets\n 682 01:31:03,889 --> 01:31:13,100 more brackets to really tell Java first execute\n 683 01:31:13,100 --> 01:31:20,289 only execute the next statement. I mean, if\n 684 01:31:20,289 --> 01:31:26,969 logic, you will see there are preferences.\n 685 01:31:26,969 --> 01:31:31,939 don't know them, and if you always just add\n 686 01:31:31,939 --> 01:31:42,078 what you want. Okay, now, let's make this\n 687 01:31:42,078 --> 01:31:52,630 something, something else. And this else is\n 688 01:31:52,630 --> 01:32:00,470 we can do something else. And this is the\n 689 01:32:00,470 --> 01:32:12,519 statement. So here, we can say drink, milk.\n 690 01:32:12,519 --> 01:32:18,820 we drink beer. And on all other days, we drink\n 691 01:32:18,819 --> 01:32:24,078 of milk. So if you I mean, milk is really\n 692 01:32:24,078 --> 01:32:33,000 like this. It's much better. But of course,\n 693 01:32:33,000 --> 01:32:46,099 sorry, else if, um, as you introduce a new\n 694 01:32:46,099 --> 01:32:57,670 Friday. At the moment, it's Tuesday, Tuesday.\n 695 01:33:07,800 --> 01:33:18,579 Drink water. Okay, so what do we have now?\n 696 01:33:18,579 --> 01:33:25,309 but usually, you formatted like this, too,\n 697 01:33:25,309 --> 01:33:34,610 belongs together? Because it starts with if\n 698 01:33:34,609 --> 01:33:43,038 check else is it Friday? If so, then call\n 699 01:33:43,038 --> 01:33:58,569 still drink milk. So, okay, and you can have\n 700 01:33:58,569 --> 01:34:09,170 Else if I don't know some other condition,\n 701 01:34:09,170 --> 01:34:23,118 um, what should we do? go swimming, go swimming.\n 702 01:34:23,118 --> 01:34:29,929 can have any number of L's if statements.\n 703 01:34:29,929 --> 01:34:36,850 course, but you don't have to, I mean, this\n 704 01:34:36,850 --> 01:34:44,590 You just you cannot have AIDS if by itself\n 705 01:34:44,590 --> 01:34:54,559 the whole statement has to start with some\n 706 01:34:54,559 --> 01:35:00,489 enough for if else if and else. Now let's\n 707 01:35:00,488 --> 01:35:11,069 that. Because normally, you evaluate some\n 708 01:35:11,069 --> 01:35:17,139 evaluated, this returns a Boolean. Under the,\n 709 01:35:17,139 --> 01:35:31,179 you could say in E equals to four. And then\n 710 01:35:31,179 --> 01:35:39,109 that. Okay, so we have two primitive data\n 711 01:35:39,109 --> 01:35:47,729 a form of video. And then I can compare those\n 712 01:35:47,729 --> 01:35:53,448 as with the Boolean is it's obvious. But I\n 713 01:35:53,448 --> 01:35:59,948 Normally, one function calls the other, and\n 714 01:35:59,948 --> 01:36:05,210 And then you don't know if the user typed\n 715 01:36:05,210 --> 01:36:10,349 example. I think we know that four is bigger\n 716 01:36:10,349 --> 01:36:29,599 know. And then I could say, if i greater than\n 717 01:36:29,599 --> 01:36:47,270 I mean, here, it's again, you can say ELLs,\n 718 01:36:47,270 --> 01:36:59,000 else can we say, oh, if i equal to j, which\n 719 01:36:59,000 --> 01:37:08,300 This, by the way, you see there are two equal\n 720 01:37:08,300 --> 01:37:16,920 here when we assign the value of four to i,\n 721 01:37:16,920 --> 01:37:28,029 in Java, here use two equal symbols to express\n 722 01:37:28,029 --> 01:37:34,519 also can do so so you see the result of this\n 723 01:37:34,520 --> 01:37:45,940 boolean value are equal to a boolean variable.\n 724 01:37:45,939 --> 01:37:53,399 I mean, here, it's very easy to understand.\n 725 01:37:53,399 --> 01:37:59,248 And then if you give it a name, your code\n 726 01:37:59,248 --> 01:38:12,289 you can say are equal. Okay. And then there\n 727 01:38:12,289 --> 01:38:24,779 And then also unequal, which I will usually\n 728 01:38:24,779 --> 01:38:33,090 same. So not equal, you can say with the exclamation\n 729 01:38:33,090 --> 01:38:37,510 this, it's both the same thing. 730 01:38:37,510 --> 01:38:43,429 I really prefer that one. I think it's more\n 731 01:38:43,429 --> 01:38:52,920 mark, really easy to read. And with this,\n 732 01:38:52,920 --> 01:39:00,440 if this no holds true, when you put the exclamation\n 733 01:39:00,439 --> 01:39:10,118 before was holes. Now it's true. Thank you\n 734 01:39:10,118 --> 01:39:16,661 exclamation marks, and every time the value\n 735 01:39:16,661 --> 01:39:23,840 and false again, and so on. I mean, this is\n 736 01:39:23,840 --> 01:39:33,420 Just to be complete. I wanted to mention this\n 737 01:39:33,420 --> 01:39:41,500 much wraps it up. We talked about Boolean.\n 738 01:39:41,500 --> 01:39:47,889 code that is in here. You see it can also\n 739 01:39:47,889 --> 01:39:57,980 I mean, I would really recommend you to write\n 740 01:39:57,980 --> 01:40:02,788 of course, you don't have to have an method\n 741 01:40:02,788 --> 01:40:09,109 because it might be much more readable. But\n 742 01:40:09,109 --> 01:40:25,719 i equals to eight, for example. J equals 299.\n 743 01:40:25,719 --> 01:40:32,498 or plus class, the increment operator that\n 744 01:40:32,498 --> 01:40:44,408 five. So if j with three before, when this\n 745 01:40:44,408 --> 01:40:55,009 it was three before it will be two. Okay,\n 746 01:40:55,010 --> 01:41:02,369 you cannot do is compare a Boolean to another\n 747 01:41:02,369 --> 01:41:12,420 make sense what you can do, but, and this\n 748 01:41:12,420 --> 01:41:24,929 a boolean value let's make this Monday again.\n 749 01:41:24,929 --> 01:41:33,739 equals to true, what does this mean? I mean,\n 750 01:41:33,738 --> 01:41:41,968 this works. And if this was false, if false\n 751 01:41:41,969 --> 01:41:49,130 So the whole thing is false. But I mean, this\n 752 01:41:49,130 --> 01:41:58,050 this is enough. Yeah. But really, comparisons\n 753 01:41:58,050 --> 01:42:06,860 often in code. So if you see that, you're\n 754 01:42:06,859 --> 01:42:12,529 it. If it's true, then just say, if Monday,\n 755 01:42:12,529 --> 01:42:25,819 not Monday. So, see, this is not. Okay. Lesson\n 756 01:42:25,819 --> 01:42:33,299 This is really exciting, because it's a very\n 757 01:42:33,300 --> 01:42:40,519 task much faster than any human could do.\n 758 01:42:40,519 --> 01:42:47,550 powerful. So it's very important to know how\n 759 01:42:47,550 --> 01:42:58,389 types of loops. The first one is a for loop\n 760 01:42:58,389 --> 01:43:06,989 times, execute something. So this is why for\n 761 01:43:06,988 --> 01:43:14,828 a bit cryptic. I'm sorry. The reason is because\n 762 01:43:14,828 --> 01:43:21,929 That was also introduced before Java, actually,\n 763 01:43:21,929 --> 01:43:29,300 c++, which are much older than Java, actually.\n 764 01:43:29,300 --> 01:43:36,800 took over the same style. So this is why it's\na bit cryptic. So 765 01:43:36,800 --> 01:43:48,139 we have three sections here. Let me first\n 766 01:43:48,139 --> 01:43:57,760 the three sections that this first loop usually\n 767 01:43:57,760 --> 01:44:09,789 int, and assign it a value of zero. calling\n 768 01:44:09,788 --> 01:44:18,979 because I just for integer because the guys\n 769 01:44:18,979 --> 01:44:26,419 mathematics, mathematicians. So yeah, they\n 770 01:44:26,420 --> 01:44:34,219 so it's so common. I also used AI, but you\n 771 01:44:34,219 --> 01:44:41,038 people would expect you to call it AI. In\n 772 01:44:41,038 --> 01:44:48,939 AI or just why are some some variables short,\n 773 01:44:48,939 --> 01:44:57,038 our counter variable that defines how many\n 774 01:44:57,038 --> 01:45:02,590 Our statement that we want to execute is actually\n 775 01:45:02,590 --> 01:45:12,400 do this four times. In programming languages,\n 776 01:45:12,399 --> 01:45:19,138 don't start with one, but they start with\n 777 01:45:19,139 --> 01:45:28,239 we have to make sure that we stay that I stay\n 778 01:45:28,238 --> 01:45:35,638 this is four times. And each time when we\n 779 01:45:35,639 --> 01:45:43,130 incremented by one, see, this is the plus\n 780 01:45:43,130 --> 01:45:50,969 and then the next round, it will be one, one\n 781 01:45:50,969 --> 01:45:57,630 two is smaller than four, three is smaller\n 782 01:45:57,630 --> 01:46:09,250 So for the fifth time, the loop will be exited.\n 783 01:46:09,250 --> 01:46:16,729 the cursor kind of, and we will not execute\n 784 01:46:23,369 --> 01:46:32,590 And then this should make sure that four persons\n 785 01:46:32,591 --> 01:46:42,210 this variable is defined within the block,\n 786 01:46:42,210 --> 01:46:52,389 in here, I think I showed you this, see it's\n 787 01:46:52,389 --> 01:47:05,650 could do is we could put the definition of\n 788 01:47:05,649 --> 01:47:12,158 access person one, but actually only the last\n 789 01:47:12,158 --> 01:47:18,479 be overwritten by the next one. I mean, for\n 790 01:47:18,479 --> 01:47:27,788 all we want is we want to calculate the number\n 791 01:47:27,788 --> 01:47:35,429 works, as well as we could also define person\n 792 01:47:35,429 --> 01:47:41,349 case, because this is a static method. We\n 793 01:47:41,349 --> 01:47:59,969 now, let's try that code. And it's green.\n 794 01:47:59,969 --> 01:48:07,880 darkness does not work. Because see we expected\n 795 01:48:07,880 --> 01:48:15,349 constructor was called because this is 10\n 796 01:48:15,349 --> 01:48:22,679 for loop. The regular for loop usually looks\n 797 01:48:22,679 --> 01:48:34,010 name like I, you assign it zero, and then\n 798 01:48:34,010 --> 01:48:43,719 case, 10. Before we head for so that the test\n 799 01:48:43,719 --> 01:48:53,748 these blocks with a colon. And then you increment\n 800 01:48:53,748 --> 01:49:08,498 in here. Like you could say, I equals i plus\n 801 01:49:08,498 --> 01:49:18,189 something. See now we only created two persons,\n 802 01:49:18,189 --> 01:49:26,268 which means the number of times that we were\n 803 01:49:26,269 --> 01:49:34,320 of course. And if we add four or even I don't\n 804 01:49:34,319 --> 01:49:47,599 Let's try that. Yeah, see actual one. Okay,\n 805 01:49:47,599 --> 01:49:58,199 but the default is to just increment a counter\n 806 01:49:58,198 --> 01:50:05,729 with the default and do it like This, I could\n 807 01:50:05,729 --> 01:50:18,439 don't even have to do all this can have this\n 808 01:50:18,439 --> 01:50:24,988 you can try this at home, because this will,\n 809 01:50:31,029 --> 01:50:42,569 but it is valid. Okay. But this is how it\n 810 01:50:42,569 --> 01:50:52,819 the second loop, which is the while loop,\n 811 01:50:52,819 --> 01:51:07,408 And each of these loops have their specific\n 812 01:51:07,408 --> 01:51:13,210 you could use always just the one loop like\n 813 01:51:13,210 --> 01:51:19,210 you want to count something, I mean, this\n 814 01:51:19,210 --> 01:51:26,349 at once, if you want to do exactly the same\n 815 01:51:26,349 --> 01:51:39,239 to zero. Well, I smaller than four. And then\n 816 01:51:39,238 --> 01:51:46,569 So this is exactly the same. And you see,\n 817 01:51:46,569 --> 01:51:52,828 while loop, you would usually do one, for\n 818 01:51:52,828 --> 01:52:06,609 dynamically calculated, like we had the function\n 819 01:52:06,609 --> 01:52:14,799 function here, like should drink beer. This\n 820 01:52:14,800 --> 01:52:20,430 I have not defined those variables here. But\n 821 01:52:20,430 --> 01:52:27,989 function that is always calculated, you will\n 822 01:52:27,988 --> 01:52:39,419 could also create person, and you don't have\n 823 01:52:39,420 --> 01:52:47,609 method sometimes would return false. And when\n 824 01:52:47,609 --> 01:53:02,649 Okay, but let's go back because actually want\n 825 01:53:02,649 --> 01:53:16,609 Because I promise you we can do exactly the\n 826 01:53:16,609 --> 01:53:26,509 this probably will not hold true anymore,\n 827 01:53:26,510 --> 01:53:43,099 So let me remove that code. Okay. Let's check.\n 828 01:53:43,099 --> 01:53:51,639 seems like this is okay. So it's the same\n 829 01:53:51,639 --> 01:53:57,279 also another loop, which is called This is\n 830 01:53:57,279 --> 01:54:04,618 as far as I remember, with Java five, this\n 831 01:54:04,618 --> 01:54:10,578 I'm sorry I cannot show you this one. Because\n 832 01:54:10,578 --> 01:54:23,289 and collection which I will do in one of the\n 833 01:54:23,289 --> 01:54:29,920 another loop the coolest one actually. But\n 834 01:54:29,920 --> 01:54:35,699 to two different loops. Well actually yeah,\n 835 01:54:35,698 --> 01:54:50,329 also do it kind of let's say backwards. So\n 836 01:54:50,329 --> 01:54:57,689 regular while and the for loop I showed you\n 837 01:54:57,689 --> 01:55:05,428 hardly ever see because Again, it's a bit\n 838 01:55:05,429 --> 01:55:12,828 is it executes this statement the first time,\n 839 01:55:12,828 --> 01:55:21,889 So the condition is checked only afterwards.\n 840 01:55:26,090 --> 01:55:37,019 So what we do here is we assert that number\n 841 01:55:37,019 --> 01:55:52,099 is, this won't work, we have to sort it afterwards,\n 842 01:55:52,099 --> 01:55:58,769 even knowing how many times we have created,\n 843 01:55:58,769 --> 01:56:08,360 that I is smaller than four. Let's try this\nand remove that. 844 01:56:08,359 --> 01:56:22,228 See, this also works. Um, this depends on\n 845 01:56:22,229 --> 01:56:29,729 use that. But actually, all the three different\n 846 01:56:29,729 --> 01:56:39,019 you can do everything with each of those loops.\n 847 01:56:39,019 --> 01:56:45,300 depends on what you want to express what's\n 848 01:56:45,300 --> 01:56:52,159 when you're like, did a few months of programming,\n 849 01:56:52,158 --> 01:57:00,710 hang of it. What's like usable in which situation.\n 850 01:57:00,710 --> 01:57:09,609 to arrays. Arrays are also a very cool feature\n 851 01:57:09,609 --> 01:57:19,609 appear in Java. I kind of unofficially introduced\n 852 01:57:19,609 --> 01:57:28,728 talked about loops. And we stopped when I\n 853 01:57:28,729 --> 01:57:35,389 that is specifically designed for arrays and\n 854 01:57:35,389 --> 01:57:42,960 you to areas at least. And so we can also\n 855 01:57:42,960 --> 01:57:51,288 really like container, a box, or let's say\n 856 01:57:51,288 --> 01:58:01,538 is a data construct that can hold a number\n 857 01:58:01,538 --> 01:58:14,788 I already said, box, so far person, the way\n 858 01:58:14,788 --> 01:58:21,809 which symbolizes something like a box, I think,\n 859 01:58:21,809 --> 01:58:29,279 put our persons kind of in in here we could\n 860 01:58:29,279 --> 01:58:41,880 a number of persons, I will call this variable\n 861 01:58:41,880 --> 01:58:48,489 there comes something new again. I don't use\n 862 01:58:48,488 --> 01:58:56,859 brackets. This does not call the person constructor.\n 863 01:58:56,859 --> 01:59:03,698 be working yet there's already a thread on\n 864 01:59:03,698 --> 01:59:15,748 here. This is a specific syntax that says\n 865 01:59:15,748 --> 01:59:22,599 hold a number of persons. And we have to now\n 866 01:59:22,600 --> 01:59:29,869 a red underline now it's gone. So now Java\n 867 01:59:29,868 --> 01:59:40,690 can hold four persons same thing we can do\n 868 01:59:40,690 --> 01:59:54,948 to press out five and six for the square brackets.\n 869 01:59:54,948 --> 02:00:01,419 which is also you know in this primitive but\n 870 02:00:01,420 --> 02:00:12,519 again, I'm not creating an end, I'm creating\n 871 02:00:12,519 --> 02:00:19,619 can also see that it's an object, because\n 872 02:00:19,619 --> 02:00:26,479 button, I see a number of methods that I can\n 873 02:00:26,479 --> 02:00:33,679 this is an attribute, which I can directly\n 874 02:00:33,679 --> 02:00:39,998 said you should have your attributes private,\n 875 02:00:39,998 --> 02:00:47,010 actually violates that rule. And yeah, so\n 876 02:00:47,010 --> 02:00:56,289 us one place where Java itself violates the\n 877 02:00:56,288 --> 02:01:02,969 we just have to live with it anyway. So what\n 878 02:01:08,569 --> 02:01:17,049 like the the length of the array than the\n 879 02:01:17,050 --> 02:01:28,600 year, why intz dot length should return three.\n 880 02:01:28,600 --> 02:01:37,559 it for, let's remove the end. Because I want\n 881 02:01:37,559 --> 02:01:44,538 this error. And the way this is done, again,\n 882 02:01:44,538 --> 02:01:51,349 is I say zero here, oh, I said person, of\n 883 02:01:51,349 --> 02:02:02,719 we have only this one object, persons. And\n 884 02:02:02,719 --> 02:02:12,980 it's a person airy object. Okay, and here\n 885 02:02:12,979 --> 02:02:26,799 does is it creates a new person object in\n 886 02:02:26,800 --> 02:02:36,909 which is like a remote control a way to access\n 887 02:02:36,908 --> 02:02:48,710 which is the first position. Let's copy and\n 888 02:02:48,710 --> 02:03:00,029 one, position two, position three. Okay. If\n 889 02:03:00,029 --> 02:03:07,658 have, I would again, get an error, which we'll\n 890 02:03:07,658 --> 02:03:16,210 which is again, a new big topic. Oh, okay.\n 891 02:03:16,210 --> 02:03:33,359 can also do is, you can do crazy stuff like\n 892 02:03:33,359 --> 02:03:47,288 in the person's array, at position, whatever,\n 893 02:03:47,288 --> 02:03:57,039 you write on every ad position, as it contains\n 894 02:03:57,039 --> 02:04:15,569 would say, person, my person equals to a new\n 895 02:04:15,569 --> 02:04:24,748 object was assigned to this variable to this\n 896 02:04:24,748 --> 02:04:36,408 this. So now, this variable can access that\n 897 02:04:36,408 --> 02:04:43,558 at position three, can also access the same\n 898 02:04:43,559 --> 02:04:53,170 like remote controls to this one object. Yeah,\n 899 02:04:53,170 --> 02:05:06,408 say, my person equals to I don't know something\n 900 02:05:06,408 --> 02:05:15,888 means the object that is at this position,\n 901 02:05:15,889 --> 02:05:23,618 reference variable, my person. So this, my\nperson object now 902 02:05:23,618 --> 02:05:29,069 should still be here, if I'm not wrong, I\n 903 02:05:29,069 --> 02:05:34,420 I'm just explaining this so that you get the\n 904 02:05:34,420 --> 02:05:41,510 too complex, because you see, the more complex\n 905 02:05:41,510 --> 02:05:49,780 so I hope you get the hang of it. Um, one\n 906 02:05:49,779 --> 02:05:57,969 one forces you to, to really define to set\n 907 02:05:57,969 --> 02:06:06,510 out position one, this position is empty.\n 908 02:06:06,510 --> 02:06:14,869 position one, there is now because knowledge\n 909 02:06:14,868 --> 02:06:21,029 there is no reference. If we access it, we\n 910 02:06:21,029 --> 02:06:30,019 what to do. Okay. So that much about now,\n 911 02:06:30,020 --> 02:06:50,639 way, we could also now it, it's called, the\n 912 02:06:50,639 --> 02:06:59,300 also write, so this is like, put nothing here.\n 913 02:06:59,300 --> 02:07:07,420 you have the new person object at position\n 914 02:07:07,420 --> 02:07:16,328 away. And if no reference exists to an object\n 915 02:07:16,328 --> 02:07:21,799 a garbage collector, I will talk specifically\n 916 02:07:21,800 --> 02:07:27,340 a specific lesson only about the garbage collector.\n 917 02:07:27,340 --> 02:07:32,349 that object, we'll clean up the memory. For\n 918 02:07:32,349 --> 02:07:38,779 In other languages like c++, this doesn't\n 919 02:07:38,779 --> 02:07:45,090 up the memory by yourself, which is really\n 920 02:07:45,090 --> 02:07:50,340 features of Java. But anyway, I guess I'm\n 921 02:07:50,340 --> 02:08:00,860 again. Because what I actually want to do\n 922 02:08:00,859 --> 02:08:07,069 that with the arrays and introduce the for\n 923 02:08:07,069 --> 02:08:24,978 of all, go to the regular for loop, take that\n 924 02:08:24,979 --> 02:08:38,420 all that all we have is an object of person\n 925 02:08:38,420 --> 02:08:52,069 loop that may create for whatever in this\n 926 02:08:52,069 --> 02:09:03,708 so because I will change while we go through\n 927 02:09:03,708 --> 02:09:13,979 we can say persons at position I this is really\n 928 02:09:13,979 --> 02:09:26,539 one line Let me clean this up. So we create\n 929 02:09:26,538 --> 02:09:34,719 put it into the array dynamically add position\n 930 02:09:34,719 --> 02:09:45,368 array with persons. And what we can also do\n 931 02:09:45,368 --> 02:09:54,058 same loop. We can access this object by saying\n 932 02:09:54,059 --> 02:10:03,050 on it like hello world that we created in\nan earlier lesson. 933 02:10:03,050 --> 02:10:11,519 Um, okay, I think I have not introduced you\n 934 02:10:11,519 --> 02:10:17,119 maybe I should not do this now, because I\n 935 02:10:17,118 --> 02:10:23,389 stuff with Aries, but would be handy now to\n 936 02:10:23,389 --> 02:10:31,579 of something for each person. But maybe I\n 937 02:10:31,579 --> 02:10:39,859 believe me, if we would print that, we could\n 938 02:10:39,859 --> 02:10:47,670 for each person. Okay, this is already nice,\n 939 02:10:47,670 --> 02:10:56,130 loop. And this is not so much different from\n 940 02:10:56,130 --> 02:11:15,550 in Java five. And this works like that. person,\n 941 02:11:15,550 --> 02:11:28,599 what this does is it automatically under the\n 942 02:11:28,599 --> 02:11:38,369 it does. And now we can also access person\n 943 02:11:38,368 --> 02:11:49,948 now we are using it. So this requires that\n 944 02:11:49,948 --> 02:12:00,158 so this is only for like reading it. I'm fulfilling\n 945 02:12:00,158 --> 02:12:07,509 Because you have to specifically say what\n 946 02:12:07,510 --> 02:12:14,519 this would also be empty. Okay, so but we\n 947 02:12:14,519 --> 02:12:21,449 how much nicer This is really condensed. So\n 948 02:12:21,448 --> 02:12:30,848 loop is like besides areas, there's also other\n 949 02:12:30,849 --> 02:12:39,309 also soon introduce, like collections really\n 950 02:12:39,309 --> 02:12:48,090 than just arrays. And so this for each loop\n 951 02:12:48,090 --> 02:12:57,139 that is. And it does whatever is required.\n 952 02:12:57,139 --> 02:13:03,420 it's really smart to use that for each loop,\n 953 02:13:03,420 --> 02:13:09,489 also because it's a performance and proper\n 954 02:13:09,488 --> 02:13:20,029 you in doing it. Okay, so I think this pretty\n 955 02:13:20,029 --> 02:13:28,469 a not sorry. I didn't know Have I told you.\n 956 02:13:28,469 --> 02:13:36,469 Person start length. This attribute which\n 957 02:13:36,469 --> 02:13:43,618 be public. This gives us dynamically the four.\n 958 02:13:43,618 --> 02:13:51,708 just imagine what can also be yours, you have\n 959 02:13:51,708 --> 02:14:00,170 you don't know its size. So you couldn't say\n 960 02:14:00,170 --> 02:14:07,940 lengths that you need. And as you see in this\n 961 02:14:07,939 --> 02:14:15,219 dynamically calculated by Java for you. Which\n 962 02:14:15,219 --> 02:14:23,590 in the background. At least this is what I\n 963 02:14:23,590 --> 02:14:34,498 you to enums. enums and Java represent an\n 964 02:14:34,498 --> 02:14:43,198 they were introduced in Java five. Now, I\n 965 02:14:43,198 --> 02:14:49,928 arrays because there is one more cool thing\n 966 02:14:49,929 --> 02:14:58,690 We can actually even on the fly out five,\n 967 02:14:58,689 --> 02:15:12,089 already PR Since two equals two, and now I\n 968 02:15:12,090 --> 02:15:21,828 is alt eight and nine on my Mac, by the way,\n 969 02:15:21,828 --> 02:15:29,768 This actually also works. So what does that\n 970 02:15:29,769 --> 02:15:38,599 this says there should be an array. And we\n 971 02:15:38,599 --> 02:15:46,599 the size is automatically calculated, because\n 972 02:15:46,599 --> 02:15:55,279 that would be the same as saying zero, which,\n 973 02:15:55,279 --> 02:16:05,579 technically, it's possible. So and we cannot\n 974 02:16:05,579 --> 02:16:15,748 the size, this gets calculated automatically.\n 975 02:16:15,748 --> 02:16:39,420 if I want to, I can also create a new object.\n 976 02:16:39,420 --> 02:16:49,340 also just to show you what's possible define\n 977 02:16:49,340 --> 02:16:56,478 now to it or talked about now, which is like\n 978 02:16:56,478 --> 02:17:04,058 is the same like that. And I mean, I want\n 979 02:17:04,058 --> 02:17:12,179 does not or what is not is, it does not like\n 980 02:17:12,179 --> 02:17:20,049 it says what you have at position zero of\n 981 02:17:20,049 --> 02:17:32,750 object. Take the reference to add and the\n 982 02:17:32,750 --> 02:17:43,540 position as well as later on, persons, zero.\n 983 02:17:43,540 --> 02:17:54,189 if we say, person to zero, that will be exactly\n 984 02:17:54,189 --> 02:18:01,148 point to this object in memory. All this is\n 985 02:18:01,148 --> 02:18:07,799 follow me. And I will do a specific tutorial\n 986 02:18:07,799 --> 02:18:16,198 things look in the memory. For now, I just\n 987 02:18:16,199 --> 02:18:22,479 I mean, we're talking here about areas and\n 988 02:18:22,478 --> 02:18:29,478 is an array and this is a way of defining\n 989 02:18:29,478 --> 02:18:36,068 Don't worry, we can go in more detail later.\n 990 02:18:36,068 --> 02:18:43,239 soon I'm sure let's do the same trick again\n 991 02:18:43,239 --> 02:18:50,308 even do it twice or any number of times can\n 992 02:18:50,308 --> 02:18:57,948 put this or we can also remove them now put\n 993 02:18:57,949 --> 02:19:03,519 can also do it on the fly you can say new\n 994 02:19:03,519 --> 02:19:09,590 which is this object that defined here. 995 02:19:09,590 --> 02:19:18,349 It sits somewhere in the memory and might\n 996 02:19:18,349 --> 02:19:27,630 outside of my array there is no one who has\n 997 02:19:27,629 --> 02:19:39,068 we have defined it. We could also say I have\n 998 02:19:39,068 --> 02:19:50,119 correctly if not imagined I had counted correctly.\n 999 02:19:50,120 --> 02:20:00,970 cannot copy this reference and I can say my\n 1000 02:20:00,969 --> 02:20:15,059 just VIP. So my VIP, now I have a reference\n 1001 02:20:15,059 --> 02:20:24,778 dirty on the fly in this line together with\n 1002 02:20:24,779 --> 02:20:32,050 just for the sake of it, I assigned it a variable,\n 1003 02:20:32,049 --> 02:20:42,500 like hello world, which you can also do is,\n 1004 02:20:42,500 --> 02:20:50,670 So you can really work with the areas at specific\n 1005 02:20:50,670 --> 02:20:56,219 it's exactly the same thing, even though it\n 1006 02:20:56,219 --> 02:21:02,818 to it. Okay, anyway, I think this is a very\n 1007 02:21:02,818 --> 02:21:10,329 shorter This is here we find just for persons\n 1008 02:21:10,329 --> 02:21:17,409 five lines. Now in just one line, we have\n 1009 02:21:17,409 --> 02:21:23,728 filled it, and this is all in one line. And\n 1010 02:21:23,728 --> 02:21:30,438 is the most important thing. So it's not about\n 1011 02:21:30,439 --> 02:21:38,010 it short, if it keeps being readable, or if\n 1012 02:21:38,010 --> 02:21:46,398 And I might also already introducing new stuff,\n 1013 02:21:46,398 --> 02:21:57,309 is another variable modifier. We already talked\n 1014 02:21:57,309 --> 02:22:05,889 something new final says are like locked in\n 1015 02:22:05,889 --> 02:22:17,100 around with that variable. So if I later after\n 1016 02:22:17,101 --> 02:22:25,529 no cannot assign a value to a final variable\n 1017 02:22:25,529 --> 02:22:33,229 you see, I have to say final. So this is one\n 1018 02:22:33,228 --> 02:22:39,528 to read. This is one more keyword to write.\n 1019 02:22:39,529 --> 02:22:45,930 for a reason. And if you have code that is\n 1020 02:22:45,930 --> 02:22:51,260 that, I would assume you know what you do,\n 1021 02:22:51,260 --> 02:23:00,600 don't want to just one line later. Where this\n 1022 02:23:00,600 --> 02:23:07,850 some constant values, some status values,\n 1023 02:23:07,850 --> 02:23:13,689 that operates on some values. And then you\n 1024 02:23:13,689 --> 02:23:24,130 in Okay, let me give you an example. So for\n 1025 02:23:24,129 --> 02:23:31,948 would do it in the class on the class level,\n 1026 02:23:31,949 --> 02:23:43,050 for all objects of the class. I mean, and\n 1027 02:23:43,049 --> 02:23:51,699 talked about this already means we have just\n 1028 02:23:51,700 --> 02:23:57,010 final. So static and final, they're really\n 1029 02:24:01,809 --> 02:24:07,698 because I want to have a string. But actually\n 1030 02:24:07,699 --> 02:24:17,189 we said the braces right after it so that\n 1031 02:24:17,189 --> 02:24:34,720 and I call it my state values equals and then\n 1032 02:24:34,719 --> 02:24:53,959 like pending, processing and processed. I\n 1033 02:24:53,959 --> 02:25:02,869 many more. Just for now. I have a short example.\n 1034 02:25:02,870 --> 02:25:10,890 wrong here. Yes, comma. Okay. And this means\n 1035 02:25:10,889 --> 02:25:16,849 didn't explain you why I did that. So far,\n 1036 02:25:16,850 --> 02:25:24,109 in lowercase letters here, use the uppercase\n 1037 02:25:24,109 --> 02:25:35,390 again, a best practice, because like, we would\n 1038 02:25:35,389 --> 02:25:42,879 in the code. And you see, now the definition\n 1039 02:25:42,879 --> 02:25:49,679 a programmer working in here and knows what\n 1040 02:25:49,680 --> 02:25:56,738 I don't want you to touch it, I just want\n 1041 02:25:56,738 --> 02:26:02,529 capital letters, and we separate them with\n 1042 02:26:02,529 --> 02:26:11,560 case. And then we could, again, of course,\n 1043 02:26:13,559 --> 02:26:28,000 so let's do the for each loop, say, stream,\n 1044 02:26:28,000 --> 02:26:48,500 braces again, we could say, if we're talking\n 1045 02:26:48,500 --> 02:26:59,978 actually we can't on a stream, say equals,\n 1046 02:26:59,978 --> 02:27:07,849 the equals is working on on on primitive values\n 1047 02:27:07,850 --> 02:27:15,920 is directly in the variable. Oh, no, sorry,\n 1048 02:27:15,920 --> 02:27:21,040 know if I, if I'm making it too complicated.\n 1049 02:27:21,040 --> 02:27:30,149 well continue what we have to say for if we\n 1050 02:27:30,148 --> 02:27:40,148 so we can compare that to some other value.\n 1051 02:27:40,148 --> 02:27:47,719 some other value. So this is some that equals\n 1052 02:27:47,719 --> 02:27:53,978 the string class that we haven't written,\n 1053 02:27:53,978 --> 02:28:04,119 compare this string to some other something,\n 1054 02:28:04,120 --> 02:28:16,140 same, we could do something. And then we could\n 1055 02:28:16,139 --> 02:28:21,020 So we had, as far as I remember, something\nlike pending. 1056 02:28:22,021 --> 02:28:38,439 processing. And, of course, uppercase and\n 1057 02:28:38,439 --> 02:28:41,979 it was processed, but I mean, this is just\n 1058 02:28:41,978 --> 02:28:57,829 much. So, and then we could do some some something,\n 1059 02:28:57,829 --> 02:29:12,529 method and the third method and so on. Okay,\n 1060 02:29:12,529 --> 02:29:18,790 is a faster way of doing that. And this is\n 1061 02:29:18,790 --> 02:29:28,350 to talk about. And second. This string here\n 1062 02:29:28,350 --> 02:29:41,220 it any time. You could say in here, state\n 1063 02:29:41,219 --> 02:29:50,750 few lines. I'm sure no one would ever do that\n 1064 02:29:50,750 --> 02:29:56,020 see a very short examples. We could have like\n 1065 02:29:56,020 --> 02:30:02,479 1000s of lines and we could like call other\n 1066 02:30:02,478 --> 02:30:09,420 then if someone in some other class, like\n 1067 02:30:09,420 --> 02:30:17,850 And you don't want that. You want actually\n 1068 02:30:17,850 --> 02:30:23,149 doesn't work, because final only protects\n 1069 02:30:23,148 --> 02:30:31,948 in here, which you can change any time. And\n 1070 02:30:31,949 --> 02:30:39,609 us to define an enumeration. Oh, okay, oh,\n 1071 02:30:39,609 --> 02:30:46,840 for the time being. But let's jump over I\n 1072 02:30:46,840 --> 02:30:54,000 will be our enum and it will not be a class.\n 1073 02:30:54,000 --> 02:31:02,719 than 10, I have set less than 10. And now,\n 1074 02:31:02,719 --> 02:31:09,170 we would say public class, logging level 1075 02:31:10,170 --> 02:31:17,290 races. But this time we're not doing a class,\n 1076 02:31:17,290 --> 02:31:27,990 is the enum. And now this is obligatory, you\n 1077 02:31:27,989 --> 02:31:35,109 And it's not a string. So we don't need the\n 1078 02:31:35,109 --> 02:31:46,120 Now this is really a value and enumeration\n 1079 02:31:46,120 --> 02:31:55,660 like we like program our own type. And we\n 1080 02:31:55,659 --> 02:32:07,539 had processing. I think we had processed.\nYeah, and then we end 1081 02:32:08,540 --> 02:32:20,470 And now we have defined an email. And we can\n 1082 02:32:20,469 --> 02:32:33,969 say logging level logging level, or let's\ncall it 1083 02:32:36,620 --> 02:32:49,180 state equals to logging level pending. So\n 1084 02:32:49,180 --> 02:32:58,850 is already how it came. Because now we can\n 1085 02:32:58,850 --> 02:33:07,170 over them. But we cannot change this. I mean,\n 1086 02:33:07,170 --> 02:33:14,988 we can only change it to the allowed level\n 1087 02:33:14,988 --> 02:33:22,369 We can set pending, processed and processing,\n 1088 02:33:22,370 --> 02:33:31,710 It can only have one of the three values.\n 1089 02:33:31,709 --> 02:33:37,719 it's not a string, we can only use the values\n 1090 02:33:37,719 --> 02:33:51,728 helpful and makes also our code more readable.\n 1091 02:33:51,728 --> 02:33:58,148 In this case, it's a bit more complicated\n 1092 02:33:58,148 --> 02:34:06,959 which is called values. This method will give\n 1093 02:34:06,959 --> 02:34:13,228 values in here, pending processing processed.\n 1094 02:34:13,228 --> 02:34:29,559 anymore. We say let me also remove that. And\n 1095 02:34:29,559 --> 02:34:36,129 say equals, see this works. Of course, it\n 1096 02:34:36,129 --> 02:34:44,799 never be equal to an enum, but it's perfectly\n 1097 02:34:44,799 --> 02:34:59,250 object. Of course it makes more sense to say\n 1098 02:34:59,250 --> 02:35:14,219 processing and prose So \nlet's put processing. 1099 02:35:17,920 --> 02:35:24,909 Let's put processed. Okay? Um, but this is\n 1100 02:35:24,909 --> 02:35:34,649 here. This is so cool. Actually, for an enum,\n 1101 02:35:34,649 --> 02:35:45,850 equals, again, this does work. Because yada\n 1102 02:35:45,850 --> 02:35:56,220 So for now, just believe me it's working.\n 1103 02:35:56,219 --> 02:36:10,719 value. Okay. Let's just remove this. Okay.\n 1104 02:36:10,719 --> 02:36:17,938 more readable and shorter. That However, there's\n 1105 02:36:17,939 --> 02:36:26,729 statement. However, we will not do this today.\n 1106 02:36:26,728 --> 02:36:31,949 statement, because I think otherwise, it's\n 1107 02:36:31,950 --> 02:36:42,170 about arrays repeated the for each loop. Yeah,\n 1108 02:36:42,170 --> 02:36:50,250 this values method. Actually, there's much\n 1109 02:36:50,250 --> 02:36:59,818 this one. We can also add these brackets here.\n 1110 02:36:59,818 --> 02:37:10,359 put values in here. So what is this going\n 1111 02:37:10,360 --> 02:37:23,590 be private. Let me check if it may be default,\n 1112 02:37:23,590 --> 02:37:29,270 to be working so far, but I'm sure it may\n 1113 02:37:29,270 --> 02:37:36,819 default, visibility seems to be okay. Even\n 1114 02:37:36,818 --> 02:37:46,469 see this. It says the end cannot be applied\n 1115 02:37:46,469 --> 02:38:03,760 is empty. Because what happens is, this is\n 1116 02:38:03,760 --> 02:38:12,000 and now it's working. So having the constructor\n 1117 02:38:12,000 --> 02:38:18,100 to you, of course this is an object. But it's\n 1118 02:38:18,100 --> 02:38:25,359 to go in detail, we can still do the comparison\n 1119 02:38:25,359 --> 02:38:34,390 so we have a constructor. And let's now assign\n 1120 02:38:34,389 --> 02:38:40,108 you see, this doesn't make sense, assigning\n 1121 02:38:40,109 --> 02:38:49,649 thought I know, of course, I have to define\n 1122 02:38:49,649 --> 02:38:56,959 it's working. I don't like it, I want this\n 1123 02:38:56,959 --> 02:39:05,009 And then I mean, this, this depends what this\n 1124 02:39:05,010 --> 02:39:18,689 let's have a method that returns public code.\n 1125 02:39:18,689 --> 02:39:30,399 really powerful, is allows us in dismissing\n 1126 02:39:30,399 --> 02:39:37,270 has these static values that we can iterate\n 1127 02:39:37,270 --> 02:39:44,131 could also think of a traffic like light with\n 1128 02:39:44,130 --> 02:39:48,978 of course have more values here any number. 1129 02:39:48,978 --> 02:39:55,049 I'm actually you don't have to have the enum\n 1130 02:39:55,049 --> 02:40:01,239 fly define it in line in a class, I would\n 1131 02:40:01,239 --> 02:40:06,949 forever, you're all there is an exception\n 1132 02:40:06,950 --> 02:40:17,020 But in 99% of the cases, you would be better\n 1133 02:40:17,020 --> 02:40:24,050 there's much, much more actually that you\n 1134 02:40:24,049 --> 02:40:31,559 this tutorials already a bit long. And I think\n 1135 02:40:31,559 --> 02:40:40,269 further extend this anytime, of course. So\n 1136 02:40:40,270 --> 02:40:49,930 a public method returning the I, you can also\n 1137 02:40:49,930 --> 02:40:56,540 But if you're if one of them has it, and all\n 1138 02:40:56,540 --> 02:41:04,609 appearing here has to appear in the constructor\n 1139 02:41:04,609 --> 02:41:10,510 may use it but you don't have to use it. But\n 1140 02:41:15,389 --> 02:41:25,059 So I think that's enough for now. And the\n 1141 02:41:25,059 --> 02:41:32,019 show you the switch statement. Because this\n 1142 02:41:32,020 --> 02:41:41,310 these enum values, then the code gets much\n 1143 02:41:41,309 --> 02:41:50,239 statement, which is another conditional statement.\n 1144 02:41:50,239 --> 02:41:56,520 first of all, let's recap what I showed you\n 1145 02:41:56,520 --> 02:42:03,050 one, I covered a lot of ground, I think, I\n 1146 02:42:03,049 --> 02:42:12,438 shortly recap. First of all, I showed you\n 1147 02:42:12,439 --> 02:42:18,260 the traditional, let's call it, the traditional\n 1148 02:42:18,260 --> 02:42:26,779 square brackets, persons equals to new person\n 1149 02:42:26,779 --> 02:42:35,439 this can hold four elements starting at zero.\n 1150 02:42:35,439 --> 02:42:43,130 actually is the short form just with the curly\n 1151 02:42:43,129 --> 02:42:50,929 separated list, you can define an array. And\n 1152 02:42:50,930 --> 02:43:02,159 end, so that you can easily extend the array\n 1153 02:43:02,159 --> 02:43:09,750 modifier for variables, a final modifier,\n 1154 02:43:09,750 --> 02:43:23,238 for us. So what it does is when in a later\n 1155 02:43:23,238 --> 02:43:29,969 let's use this area on top here, this is not\n 1156 02:43:29,969 --> 02:43:38,858 variable persons to also we can try to assign\n 1157 02:43:38,859 --> 02:43:48,238 also not work. This is nice ish. However,\n 1158 02:43:48,238 --> 02:43:57,898 in a method. But instead to use it for static\n 1159 02:43:57,898 --> 02:44:08,430 are defined at the top of the class usually\n 1160 02:44:08,430 --> 02:44:16,100 So this at the moment is default visibility.\n 1161 02:44:16,100 --> 02:44:22,809 And if you need other classes accessing it,\n 1162 02:44:22,809 --> 02:44:31,299 So it would be okayish have this public. However,\n 1163 02:44:31,299 --> 02:44:40,478 clean code like I do. You could provide a\n 1164 02:44:40,478 --> 02:44:58,250 I don't know some name. Let's call it states.\n 1165 02:44:58,250 --> 02:45:05,449 we could copy this out Because with a copy\n 1166 02:45:05,449 --> 02:45:12,170 does protect is as I set the variable, what\n 1167 02:45:12,170 --> 02:45:21,398 safer if return a copy of the array. And there's\n 1168 02:45:21,398 --> 02:45:30,930 Java, Java util, which provides some static\n 1169 02:45:30,930 --> 02:45:36,229 going to use the copy. But there's also many,\n 1170 02:45:36,229 --> 02:45:43,809 search and so on. This is really a big toolbox\n 1171 02:45:43,809 --> 02:45:52,329 them. And I might show some of them at a later\n 1172 02:45:52,329 --> 02:46:01,939 then we take the array. And we have to state\n 1173 02:46:01,939 --> 02:46:07,040 array dot length, yeah, we also talked about\n 1174 02:46:07,040 --> 02:46:15,460 length of the array, which in this case is\n 1175 02:46:15,459 --> 02:46:17,409 So this is really a nice way of 1176 02:46:17,409 --> 02:46:26,559 generating clean code and returning this array.\n 1177 02:46:26,559 --> 02:46:35,469 and using the underscore and not written in\n 1178 02:46:35,469 --> 02:46:41,318 a static final. So in short, you just talk\n 1179 02:46:41,318 --> 02:46:54,100 write it. Okay. Let's go back to the bottom.\n 1180 02:46:54,100 --> 02:47:03,130 also very shortly talked about equals, because\n 1181 02:47:03,129 --> 02:47:13,228 And you if you want to compare them, you cannot\n 1182 02:47:13,228 --> 02:47:21,639 going to work, even if it's the same. Because\n 1183 02:47:21,639 --> 02:47:31,029 compare objects. And this is an object, instead,\n 1184 02:47:31,030 --> 02:47:43,020 does work for int three, and then you can\n 1185 02:47:43,020 --> 02:48:03,189 in here. But if you have a string, let's make\n 1186 02:48:03,189 --> 02:48:11,550 or now in here is the reference, which is\n 1187 02:48:11,549 --> 02:48:20,059 a number also will be saved in here. And when\n 1188 02:48:20,059 --> 02:48:29,969 signs, then you compare this variable, which\n 1189 02:48:29,969 --> 02:48:41,778 the same. So what will be true is if you would\n 1190 02:48:41,779 --> 02:48:48,390 usually is not what you want to say. And so\n 1191 02:48:48,389 --> 02:48:55,658 say equals talking about equals usually in\n 1192 02:48:55,658 --> 02:49:02,010 about the hashCode method. This is already\n 1193 02:49:02,010 --> 02:49:11,529 very short for now. It just that if you create\n 1194 02:49:11,529 --> 02:49:19,779 it's often a good idea all depends, but you\n 1195 02:49:19,779 --> 02:49:26,920 in your person object so that you can compare\n 1196 02:49:26,920 --> 02:49:34,270 to implement the hashCode method. What the\n 1197 02:49:34,270 --> 02:49:42,500 explain at a later time. Okay, so that much\n 1198 02:49:42,500 --> 02:49:49,930 thing. I made this now because I also wanted\n 1199 02:49:49,930 --> 02:49:57,760 people that would write equals like this,\n 1200 02:49:57,760 --> 02:50:03,309 This is not so nice, because as you see this\n 1201 02:50:03,309 --> 02:50:11,709 And of course, we don't like arrows. So instead,\n 1202 02:50:11,709 --> 02:50:19,148 never be now, like this string here. I mean,\n 1203 02:50:19,148 --> 02:50:33,629 be now. So ACB equals now, we'll just return\n 1204 02:50:33,629 --> 02:50:47,179 an error. Okay. So let's stop here. Then,\n 1205 02:50:47,180 --> 02:50:54,760 we talked about enums, which I introduced,\n 1206 02:50:54,760 --> 02:51:04,239 go to the class. So public enum logging level,\n 1207 02:51:04,239 --> 02:51:16,219 Because it's not a logging level, I was thinking\n 1208 02:51:16,219 --> 02:51:23,079 But then I decided we haven't talked about\nlogging either. So I 1209 02:51:23,079 --> 02:51:28,969 instead took pending processing process. So\n 1210 02:51:28,969 --> 02:51:34,750 I don't know, let's leave the name for now\n 1211 02:51:34,750 --> 02:51:40,969 that are introduced, which is a bit similar\n 1212 02:51:40,969 --> 02:51:49,019 also has some features a class does not have.\n 1213 02:51:49,020 --> 02:51:56,840 let's call them labels that we can act upon\n 1214 02:51:56,840 --> 02:52:05,520 pending, to this or that, so it's not only\n 1215 02:52:05,520 --> 02:52:13,600 introduced was Java five. And before that,\n 1216 02:52:13,600 --> 02:52:23,439 if something is equal to not to zero, or one.\n 1217 02:52:23,439 --> 02:52:29,979 these values, this really gets nasty and problematic.\n 1218 02:52:29,979 --> 02:52:37,988 you to do it in the proper way. And that is\n 1219 02:52:37,988 --> 02:52:44,478 You can you don't have to also introduce a\n 1220 02:52:44,478 --> 02:52:54,869 for each enum value. And you can provide methods\n 1221 02:52:54,870 --> 02:53:02,500 you want, which are also like to make the\n 1222 02:53:02,500 --> 02:53:11,370 not always. Whenever your code and you design\n 1223 02:53:11,370 --> 02:53:18,470 don't make a decision just because this is\n 1224 02:53:18,469 --> 02:53:25,539 the code you work on, for example, the pending\n 1225 02:53:25,540 --> 02:53:35,771 that it might be nice to add this method is\npending. 1226 02:53:35,771 --> 02:53:42,050 And then you can say return this, which is\n 1227 02:53:42,049 --> 02:53:56,068 the current value of the enum equals equals\n 1228 02:53:56,068 --> 02:54:13,398 let's do this modern level, still I call it\n 1229 02:54:13,398 --> 02:54:21,658 take processing. And then I could say if stayed\n 1230 02:54:21,658 --> 02:54:32,770 Some code would have to be executed. But what\n 1231 02:54:32,770 --> 02:54:39,930 if you really need it. So it would not be\n 1232 02:54:44,109 --> 02:54:53,260 People usually get lazy and when they see\n 1233 02:54:53,260 --> 02:55:01,350 stuff and they just like I might be I might\n 1234 02:55:01,350 --> 02:55:10,640 no, never do that. Never add a method just\n 1235 02:55:10,639 --> 02:55:15,109 code lives. And you can always change your\n 1236 02:55:15,110 --> 02:55:20,890 later. So only edit when you need it. Let's\n 1237 02:55:20,889 --> 02:55:29,099 remove it. Okay, I think this pretty much\n 1238 02:55:29,100 --> 02:55:36,510 much more crazy stuff, like each value could\n 1239 02:55:36,510 --> 02:55:45,898 ever use it. So let's not show this for now.\n 1240 02:55:45,898 --> 02:55:52,760 usually. And now, let's finally actually go\n 1241 02:55:52,760 --> 02:55:58,680 switch statement. So I think I already a bit\n 1242 02:55:58,680 --> 02:56:05,729 we want to shorten this here. So the switch\n 1243 02:56:05,728 --> 02:56:12,099 And that's pretty much exactly the same, like\n 1244 02:56:12,100 --> 02:56:20,380 Okay, I mean, don't think about the exact\n 1245 02:56:20,379 --> 02:56:27,500 explain you something. Okay, this time, I\n 1246 02:56:27,500 --> 02:56:36,439 on this state here. And then we can instead\n 1247 02:56:36,439 --> 02:56:50,229 operating on that value here. And then, instead\n 1248 02:56:50,228 --> 02:57:02,129 that the state has this or that volume, case\n 1249 02:57:02,129 --> 02:57:09,719 equals pending. If you just have one, then\n 1250 02:57:09,719 --> 02:57:18,260 statement is usually used when you iterate\n 1251 02:57:18,260 --> 02:57:25,540 this extra of saying switch, but then the\n 1252 02:57:25,540 --> 02:57:36,110 it will get processing case process. Now I\n 1253 02:57:36,110 --> 02:57:44,949 Let's format this. Now what happens is, I\n 1254 02:57:44,949 --> 02:57:53,399 put a break statement here. So actually, what\n 1255 02:57:53,398 --> 02:57:57,658 method call, I mean, I have not implemented\n 1256 02:57:57,658 --> 02:58:04,039 was a method. So for all these three different\n 1257 02:58:04,040 --> 02:58:12,930 would call this method. If imagine we use\n 1258 02:58:12,930 --> 02:58:21,630 you could also like return a value. So this\n 1259 02:58:21,629 --> 02:58:26,759 you return something from a method, of course,\n 1260 02:58:26,760 --> 02:58:38,500 this out is because normally usually, what\n 1261 02:58:38,500 --> 02:58:45,520 might not even return something like printing\n 1262 02:58:45,520 --> 02:58:55,370 one method. And in here, you would call a\n 1263 02:58:55,370 --> 02:59:04,090 or so. And here a third one. Now it gets problematic\n 1264 02:59:04,090 --> 02:59:11,750 happens is a fall through this will be cold,\n 1265 02:59:11,750 --> 02:59:19,129 a big source of bugs. Very, very dangerous.\n 1266 02:59:19,129 --> 02:59:26,478 if sometimes you'll want to have them together\n 1267 02:59:26,478 --> 02:59:36,750 example or to to call a certain method it's\n 1268 02:59:36,750 --> 02:59:45,799 so that you tell the next program I know what\n 1269 02:59:50,079 --> 02:59:59,140 So that much about follow through. And you\n 1270 02:59:59,140 --> 03:00:04,520 can also leave One out, if nothing is found,\n 1271 03:00:04,520 --> 03:00:13,199 statement, and we'll just not do anything.\n 1272 03:00:13,199 --> 03:00:20,790 possibility to adding a default, which will\n 1273 03:00:20,790 --> 03:00:35,649 apply. And then people sometimes say, I don't\n 1274 03:00:35,648 --> 03:00:41,619 want to warn you. And of course, again, we\n 1275 03:00:41,620 --> 03:00:49,540 This is not so wise. The problem is, I mean,\n 1276 03:00:49,540 --> 03:01:03,040 from extending your enum adding, for example,\n 1277 03:01:03,040 --> 03:01:10,551 would just do this would not know there is\n 1278 03:01:10,550 --> 03:01:17,139 the switch statement, you didn't think of\n 1279 03:01:17,139 --> 03:01:26,420 a specific behavior. But now you would also\n 1280 03:01:26,420 --> 03:01:33,260 So usually, we don't want that. So what I\n 1281 03:01:33,260 --> 03:01:44,700 you don't use it, or even better use it. But\n 1282 03:01:44,700 --> 03:01:51,010 not doing this now, because I haven't talked\n 1283 03:01:51,010 --> 03:01:59,130 time. But this is the place where you would\n 1284 03:01:59,129 --> 03:02:09,469 thing about this is when someone extends your\n 1285 03:02:09,469 --> 03:02:14,079 one or more switch statements, you will see\n 1286 03:02:14,079 --> 03:02:21,270 program crashes. And this is so nasty. Well,\n 1287 03:02:21,270 --> 03:02:28,899 design. And this is called fail early, it's\n 1288 03:02:28,898 --> 03:02:36,318 production even. And to have to fix this within\n 1289 03:02:36,318 --> 03:02:45,180 high severe bug. And no one notices it. Because\n 1290 03:02:45,180 --> 03:02:51,738 something in a wrong way. But a client might\n 1291 03:02:51,738 --> 03:02:58,920 and then the problem will be so so much bigger.\n 1292 03:02:58,920 --> 03:03:05,978 to be brave. I also see people that try to\n 1293 03:03:05,978 --> 03:03:13,398 for example, return now. So this is actually\n 1294 03:03:13,398 --> 03:03:19,148 wrong. And let's fix it. This is just like\n 1295 03:03:19,148 --> 03:03:27,049 it bigger. So I want you to be brave and throw\n 1296 03:03:27,049 --> 03:03:32,869 better. I mean, I'm not saying you should\n 1297 03:03:32,870 --> 03:03:37,439 and concentrate. But sometimes bad things\n 1298 03:03:37,439 --> 03:03:45,479 early. And so you you notice the problem and\n 1299 03:03:45,478 --> 03:03:53,369 hidden bucks. Okay. I hope you got my point. 1300 03:03:54,719 --> 03:04:01,519 so also here. Well, if you have an exception,\n 1301 03:04:01,520 --> 03:04:11,270 always leaves the block. But what is important\n 1302 03:04:11,270 --> 03:04:18,109 don't have to break, leave a comment for through\n 1303 03:04:18,109 --> 03:04:28,109 doing, I want this and Tommy about warnings.\n 1304 03:04:28,109 --> 03:04:33,920 don't overuse the if statements, these conditional\n 1305 03:04:33,920 --> 03:04:42,148 also in combination with for loops and see\n 1306 03:04:42,148 --> 03:04:48,250 have to understand this switch. And then there\n 1307 03:04:48,250 --> 03:04:55,299 then inside of the case statement, there might\n 1308 03:04:55,299 --> 03:05:01,969 complicates the code. Same as with the if\n 1309 03:05:01,969 --> 03:05:08,489 for me to enter this blog, ha, then this method\n 1310 03:05:08,489 --> 03:05:14,850 you might want to check here. So this all\n 1311 03:05:14,850 --> 03:05:20,960 is also like a, let's call it a relic from\n 1312 03:05:20,959 --> 03:05:29,539 code. Because it's like a procedure, it's\n 1313 03:05:29,540 --> 03:05:36,670 a machine, like a machine would switch a state.\n 1314 03:05:36,670 --> 03:05:42,620 that. But humans usually don't, they don't\n 1315 03:05:42,620 --> 03:05:47,890 object oriented programming is that the object\n 1316 03:05:47,889 --> 03:05:54,260 humans think. And this allows you to like\n 1317 03:05:54,260 --> 03:05:56,960 your code nice. And switch is not object oriented.\n 1318 03:05:56,959 --> 03:05:57,959 it might just be easy and fast to use it,\n 1319 03:05:57,959 --> 03:05:58,959 are people that would have maybe hundreds\n 1320 03:05:58,959 --> 03:05:59,959 hard to read. This is also why I had here\n 1321 03:05:59,959 --> 03:06:00,959 better than just having huge switch statements.\n 1322 03:06:00,959 --> 03:06:01,959 you could have an object representing the\n 1323 03:06:01,959 --> 03:06:02,959 the process state and so on. So they are at\n 1324 03:06:02,959 --> 03:06:03,959 statement. And it always depends, like, what's\n 1325 03:06:03,959 --> 03:06:04,959 It might be okay. Just remember, they are\n 1326 03:06:04,959 --> 03:06:05,959 Okay, I hope I have added enough warnings\n 1327 03:06:05,959 --> 03:06:06,959 one reason why I'm only introducing it now.\n 1328 03:06:06,959 --> 03:06:07,959 oriented programmer. I will further continue\n 1329 03:06:07,959 --> 03:06:08,959 you that it's used to iterate over the different\n 1330 03:06:08,959 --> 03:06:09,959 you were introduced with Java five, um, before\n 1331 03:06:09,959 --> 03:06:10,959 you had to emulate enums. And the way this\n 1332 03:06:10,959 --> 03:06:11,959 is not so optimal. And this is also why enums\n 1333 03:06:11,959 --> 03:06:12,959 And I would also not recommend you to show\n 1334 03:06:12,959 --> 03:06:13,959 I already said that in the last episode. I\n 1335 03:06:13,959 --> 03:06:14,959 I think I should still show you. Because you\n 1336 03:06:14,959 --> 03:06:15,959 can understand code of others, I will show\n 1337 03:06:15,959 --> 03:06:16,959 with that warning, I'll show you. And now\n 1338 03:06:17,959 --> 03:06:18,959 And now I give it some number 42. I mean,\n 1339 03:06:18,959 --> 03:06:19,959 And this is already your problem. 42. What\n 1340 03:06:19,959 --> 03:06:20,959 mean processed? How do we know? Well, to make\n 1341 03:06:20,959 --> 03:06:21,959 final values, which I'll do right now also.\n 1342 03:06:21,959 --> 03:06:22,959 Let's introduce now this is a method. Let's\n 1343 03:06:22,959 --> 03:06:23,959 it processed, processed. Forgot to give it\n 1344 03:06:23,959 --> 03:06:24,959 is the 42. And we could also have pending\n 1345 03:06:24,959 --> 03:06:25,959 is also where a normal use case From. So this\n 1346 03:06:25,959 --> 03:06:26,959 letters. Okay, because it's a constant value\n 1347 03:06:26,959 --> 03:06:27,959 this the name of pending cross cutting, let's\n 1348 03:06:27,959 --> 03:06:28,959 course, we need different values, that could\n 1349 03:06:28,959 --> 03:06:29,959 would be a 42. And now I can copy that, go\n 1350 03:06:29,959 --> 03:06:30,959 equals pending. And pending now, I think it\n 1351 03:06:30,959 --> 03:06:31,959 And now this is funny before depending was\n 1352 03:06:31,959 --> 03:06:32,959 to realize, now we're not iterating on the\n 1353 03:06:32,959 --> 03:06:33,959 have processed there, as we have named it,\n 1354 03:06:33,959 --> 03:06:34,959 show you, this is just because we named the\n 1355 03:06:34,959 --> 03:06:35,959 is not used, called is something then of course,\n 1356 03:06:35,959 --> 03:06:36,959 because now you see pending as red, because\n 1357 03:06:36,959 --> 03:06:37,959 not on the interim anymore. We only int something,\n 1358 03:06:37,959 --> 03:06:38,959 one guarantees us that only these three values\n 1359 03:06:38,959 --> 03:06:39,959 time could say my state equals to 300. And\n 1360 03:06:39,959 --> 03:06:40,959 be processed, it will end up in the default.\n 1361 03:06:40,959 --> 03:06:41,959 should not have regular code, but throw an\n 1362 03:06:41,959 --> 03:06:42,959 very soon, I hope. Okay, so anyway, this is\n 1363 03:06:42,959 --> 03:06:43,959 Java seven, I mean, at the time I'm doing\n 1364 03:06:43,959 --> 03:06:44,959 when they introduce Java seven, you now can\n 1365 03:06:44,959 --> 03:06:45,959 called also my string. Okay, not used yet.\n 1366 03:06:45,959 --> 03:06:46,959 strings. Of course, something doesn't work\n 1367 03:06:46,959 --> 03:06:47,959 now, I can of course start to use. Well, for\n 1368 03:06:47,959 --> 03:06:48,959 I can use, again, something in lowercase letters.\n 1369 03:06:48,959 --> 03:06:49,959 labels, which then of course, are private,\n 1370 03:06:49,959 --> 03:06:50,959 don't know. I haven't used pending because\n 1371 03:06:50,959 --> 03:06:51,959 And I will call this pending. But it could\n 1372 03:06:51,959 --> 03:06:52,959 So of course, using that label, I'm only using\n 1373 03:06:52,959 --> 03:06:53,959 Okay, so now, that label I can also use pending\n 1374 03:06:53,959 --> 03:06:54,959 session I talked about the fall through, which\n 1375 03:06:54,959 --> 03:06:55,959 So if it's this case statement will be the\n 1376 03:06:55,959 --> 03:06:56,959 then call this method and then break is called,\n 1377 03:06:56,959 --> 03:06:57,959 the court will continue online 122. The default\n 1378 03:06:57,959 --> 03:06:58,959 anywhere else. For example at the top which\n 1379 03:06:58,959 --> 03:06:59,959 not pending or something, or pending is, I\n 1380 03:06:59,959 --> 03:07:00,959 I think it was 42. So, in this case, all the\n 1381 03:07:00,959 --> 03:07:01,959 which he or we could have some other method.\n 1382 03:07:01,959 --> 03:07:02,959 method. And then we could say break so that\n 1383 03:07:02,959 --> 03:07:03,959 called. And then we would end up here, leaving\n 1384 03:07:03,959 --> 03:07:04,959 see, if I put my cursor at the beginning of\n 1385 03:07:04,959 --> 03:07:05,959 don't really see it ends up here. Because\n 1386 03:07:05,959 --> 03:07:06,959 why you should keep your methods very short.\n 1387 03:07:06,959 --> 03:07:07,959 141. And this method now got so big, that\n 1388 03:07:07,959 --> 03:07:08,959 where it ends. So yeah, I can't say it often\n 1389 03:07:08,959 --> 03:07:09,959 keep them at one to 10 lines at most. I'm,\n 1390 03:07:09,959 --> 03:07:10,959 at one to three lines. Some say I'm really\n 1391 03:07:10,959 --> 03:07:11,959 will very soon see the fruits of your methods\n 1392 03:07:11,959 --> 03:07:12,959 And also, the easier it will be to reuse them.\n 1393 03:07:12,959 --> 03:07:13,959 switch statement. So you can use it with strings.\n 1394 03:07:13,959 --> 03:07:14,959 like I showed you in the last episode, you\n 1395 03:07:14,959 --> 03:07:15,959 So far, I've only showed you int. I'm actually\n 1396 03:07:15,959 --> 03:07:16,959 really talk about the others, because they're\n 1397 03:07:16,959 --> 03:07:17,959 the number ranges just a bit smaller. In 99%\n 1398 03:07:17,959 --> 03:07:18,959 it doesn't really matter these days. how large\n 1399 03:07:18,959 --> 03:07:19,959 not but maybe I still show you. For example,\n 1400 03:07:19,959 --> 03:07:20,959 not working anymore. Why is it because I have\n 1401 03:07:20,959 --> 03:07:21,959 So the bite here. This is just smaller than\n 1402 03:07:21,959 --> 03:07:22,959 it says this is incompatible, because it's\n 1403 03:07:22,959 --> 03:07:23,959 the three works. But I really don't want to\n 1404 03:07:23,959 --> 03:07:24,959 you can also read this on the internet. Because\n 1405 03:07:24,959 --> 03:07:25,959 is the end. So okay, I think this pretty much\n 1406 03:07:25,959 --> 03:07:26,959 So you can use it with a string and an int\n 1407 03:07:26,959 --> 03:07:27,959 you. That's also interesting. And this is\n 1408 03:07:27,959 --> 03:07:28,959 while it's not a string, but it's very similar.\n 1409 03:07:28,959 --> 03:07:29,959 the double quotes. So if I'm using the double\n 1410 03:07:29,959 --> 03:07:30,959 doesn't work anymore. Here it says incompatible\n 1411 03:07:30,959 --> 03:07:31,959 quotes, it's a car. So it's a character of\n 1412 03:07:31,959 --> 03:07:32,959 it could also be a or b. But it cannot be\n 1413 03:07:32,959 --> 03:07:33,959 not a character anymore. Too many characters\n 1414 03:07:33,959 --> 03:07:34,959 iterate over characters. This sometimes might\n 1415 03:07:34,959 --> 03:07:35,959 a string or what is parsing it's have a string\n 1416 03:07:35,959 --> 03:07:36,959 can take each single character, because a\n 1417 03:07:36,959 --> 03:07:37,959 characters. And then you can iterate over\n 1418 03:07:37,959 --> 03:07:38,959 this. Um, yeah. This you might need at a later\n 1419 03:07:38,959 --> 03:07:39,959 told you there are other number types. I would\n 1420 03:07:41,959 --> 03:07:42,959 Well, first of all, let's tell you what my\n 1421 03:07:42,959 --> 03:07:43,959 here. I have prepared a little class car service.\n 1422 03:07:43,959 --> 03:07:44,959 And in the class, this class so far is empty.\n 1423 03:07:44,959 --> 03:07:45,959 like a print out on the console into a file,\n 1424 03:07:45,959 --> 03:07:46,959 So I want to be notified in some way I want\n 1425 03:07:46,959 --> 03:07:47,959 that I, like later on, can go through all\n 1426 03:07:47,959 --> 03:07:48,959 For example, if my system was hacked, I could\n 1427 03:07:48,959 --> 03:07:49,959 And then yeah, analyze it. So that's the idea.\n 1428 03:07:49,959 --> 03:07:50,959 actually, logging for me this word was a bit\n 1429 03:07:50,959 --> 03:07:51,959 friend. So let's do this. So logging is called\n 1430 03:07:51,959 --> 03:07:52,959 this thing here, you know, of ancient times\n 1431 03:07:52,959 --> 03:07:53,959 and was writing down at what time he was at\n 1432 03:07:53,959 --> 03:07:54,959 in that direction. So this is a logbook. So\n 1433 03:07:54,959 --> 03:07:55,959 of the ship. And but still I was asking, why\n 1434 03:07:55,959 --> 03:07:56,959 article here have a read just very fast going\n 1435 03:07:56,959 --> 03:07:57,959 to a book for recording readings from the\n 1436 03:07:57,959 --> 03:07:58,959 and ship block, also called common lock shaped\n 1437 03:07:58,959 --> 03:07:59,959 marinas used to estimate the speed of a vessel\n 1438 03:07:59,959 --> 03:08:00,959 an image. So this thing here is the shape\n 1439 03:08:00,959 --> 03:08:01,959 even a picture they were throwing out the\n 1440 03:08:01,959 --> 03:08:02,959 not in this line in this long line and the\n 1441 03:08:02,959 --> 03:08:03,959 this chip block is taken away. And by measuring\n 1442 03:08:03,959 --> 03:08:04,959 this was done given by knots. So this is still\n 1443 03:08:04,959 --> 03:08:05,959 today. So here it says ship log and associated\n 1444 03:08:05,959 --> 03:08:06,959 So it seems I don't know this, but I just\n 1445 03:08:06,959 --> 03:08:07,959 really looks like a lock, like, like a three\n 1446 03:08:07,959 --> 03:08:08,959 would guess that this is why it's called lock.\n 1447 03:08:08,959 --> 03:08:09,959 lock. And this is why the act of doing like\n 1448 03:08:09,959 --> 03:08:10,959 logging. And as a programmer, you can think\n 1449 03:08:10,959 --> 03:08:11,959 And as such when you want to write on events\n 1450 03:08:11,959 --> 03:08:12,959 you are logging and this is what we are going\n 1451 03:08:12,959 --> 03:08:13,959 and 15 Well, currently you would use SL for\n 1452 03:08:13,959 --> 03:08:14,959 of course, you could write your own logging.\n 1453 03:08:14,959 --> 03:08:15,959 work properly. And this has been done already\n 1454 03:08:15,959 --> 03:08:16,959 Well, actually, this is only for Sade, well,\n 1455 03:08:16,959 --> 03:08:17,959 about. So two, we could say it like, allows\n 1456 03:08:17,959 --> 03:08:18,959 the code, Ork SL for j logger and logger factory.\n 1457 03:08:18,959 --> 03:08:19,959 logger, logger, factory, get logger. give\n 1458 03:08:19,959 --> 03:08:20,959 it with different implementation of logging.\n 1459 03:08:20,959 --> 03:08:21,959 logging framework was log for J. Well, this\n 1460 03:08:21,959 --> 03:08:22,959 better use lockback because it's a more powerful,\n 1461 03:08:22,959 --> 03:08:23,959 it properly. But I try shakey Goku, and this\n 1462 03:08:23,959 --> 03:08:24,959 love for J. So he continued with lockback,\n 1463 03:08:24,959 --> 03:08:25,959 So today, therefore, we use SL for j in combination\n 1464 03:08:25,959 --> 03:08:26,959 visade. will allow us at a later time, if\n 1465 03:08:26,959 --> 03:08:27,959 that is even better than lockback, we can\n 1466 03:08:27,959 --> 03:08:28,959 having to change the code. Because the code\n 1467 03:08:28,959 --> 03:08:29,959 SL for J. So how is this done? Let's jump\n 1468 03:08:29,959 --> 03:08:30,959 you, I'm using Maven for the configuration\n 1469 03:08:30,959 --> 03:08:31,959 to use the dependency org. So for j, and lockback,\n 1470 03:08:31,959 --> 03:08:32,959 of SL for J. And this is the core code of\n 1471 03:08:32,959 --> 03:08:33,959 to get logging in your code. Okay. And then\n 1472 03:08:33,959 --> 03:08:34,959 our file called lockback, dot XML. Here, you\n 1473 03:08:34,959 --> 03:08:35,959 all, you can say, how should you lock where\n 1474 03:08:35,959 --> 03:08:36,959 this class console appender, that will result\n 1475 03:08:36,959 --> 03:08:37,959 There are also other appenders, or other implementations\n 1476 03:08:37,959 --> 03:08:38,959 to the database, to email. And if there's\n 1477 03:08:38,959 --> 03:08:39,959 doesn't exist. You can also implement your\n 1478 03:08:39,959 --> 03:08:40,959 like logging into Twitter in some way, if\n 1479 03:08:40,959 --> 03:08:41,959 the pattern, how, when a message is written,\n 1480 03:08:41,959 --> 03:08:42,959 like so the patterns has, I mean, you have\n 1481 03:08:42,959 --> 03:08:43,959 it's like, give me the time when this event\n 1482 03:08:43,959 --> 03:08:44,959 the logging level is like a mechanism. It's\n 1483 03:08:44,959 --> 03:08:45,959 levels of logging. This is like a signal of\n 1484 03:08:45,959 --> 03:08:46,959 is probably for debugging purposes, use that\nsparsely. 1485 03:08:46,959 --> 03:08:47,959 Then there is a logging level info and error.\n 1486 03:08:47,959 --> 03:08:48,959 in your code, info for general information,\n 1487 03:08:48,959 --> 03:08:49,959 But this really should be used partly because\n 1488 03:08:49,959 --> 03:08:50,959 like in your ID, or we haven't talked about\n 1489 03:08:50,959 --> 03:08:51,959 Now there are different levels. So, in your\n 1490 03:08:51,959 --> 03:08:52,959 on level debug. And here I have defined the\n 1491 03:08:52,959 --> 03:08:53,959 when there's some logging of a class that\n 1492 03:08:53,959 --> 03:08:54,959 if it's debug, I could to also put your error,\n 1493 03:08:54,959 --> 03:08:55,959 it. Or I could put here info, that would mean\n 1494 03:08:55,959 --> 03:08:56,959 also, it would include arrows, because this\n 1495 03:08:56,959 --> 03:08:57,959 debug, info and error, but error would only\n 1496 03:08:57,959 --> 03:08:58,959 So you see, this is really makes it more flexible.\n 1497 03:08:58,959 --> 03:08:59,959 for different packages. So we could also copy\n 1498 03:08:59,959 --> 03:09:00,959 like Java course two, and so on. And we could\n 1499 03:09:00,959 --> 03:09:01,959 other one on error. So this is really flexible\n 1500 03:09:01,959 --> 03:09:02,959 root level. So like, generally lock on info\n 1501 03:09:02,959 --> 03:09:03,959 level, this is what it means. Okay, this was\n 1502 03:09:03,959 --> 03:09:04,959 of course, on the internet. But first of all,\n 1503 03:09:04,959 --> 03:09:05,959 login details here into car service, I put\n 1504 03:09:05,959 --> 03:09:06,959 Like we saw just before in the documentation\n 1505 03:09:06,959 --> 03:09:07,959 for j because I said we want to import only\n 1506 03:09:07,959 --> 03:09:08,959 it should be used, I should use lockback because\n 1507 03:09:08,959 --> 03:09:09,959 This one here. So SL for j is really smart.\n 1508 03:09:09,959 --> 03:09:10,959 SL for j lager and we say import org SL for\n 1509 03:09:10,959 --> 03:09:11,959 factory, by the way, is another design pattern.\n 1510 03:09:11,959 --> 03:09:12,959 course, only on design patterns. design patterns\n 1511 03:09:12,959 --> 03:09:13,959 program code. And when you know what a factory\n 1512 03:09:13,959 --> 03:09:14,959 he does. Okay, more about design patterns\n 1513 03:09:14,959 --> 03:09:15,959 to do. And now in our class, we would probably\n 1514 03:09:15,959 --> 03:09:16,959 because it's all log. And then we say logger\n 1515 03:09:16,959 --> 03:09:17,959 does like a factory. This is why it's called\n 1516 03:09:17,959 --> 03:09:18,959 know how is it created on the fly is a longer\n 1517 03:09:18,959 --> 03:09:19,959 the necessary work for us. Now, we should\n 1518 03:09:19,959 --> 03:09:20,959 this will be used car service class. That\n 1519 03:09:20,959 --> 03:09:21,959 is in source main resources. As I showed you,\n 1520 03:09:21,959 --> 03:09:22,959 even extend that and lock only for specific\nclasses. 1521 03:09:22,959 --> 03:09:23,959 So this is the test and this is the service.\n 1522 03:09:23,959 --> 03:09:24,959 logger. Now, in here, you can now use it log.\n 1523 03:09:24,959 --> 03:09:25,959 as well have this in lowercase log dot and\n 1524 03:09:25,959 --> 03:09:26,959 of you might know it, you would usually say\n 1525 03:09:26,959 --> 03:09:27,959 enabled, only then log something, log dot\n 1526 03:09:27,959 --> 03:09:28,959 plus input. So the input given in our case,\n 1527 03:09:28,959 --> 03:09:29,959 will be concatenated. together. And all this\n 1528 03:09:29,959 --> 03:09:30,959 at the time when the code runs, which at the\n 1529 03:09:30,959 --> 03:09:31,959 can activate and deactivate this. The reason\n 1530 03:09:31,959 --> 03:09:32,959 do it without just like this. But this is\n 1531 03:09:32,959 --> 03:09:33,959 it's not so bad. I mean, all that would happen\n 1532 03:09:33,959 --> 03:09:34,959 together. But you mentioned the string could\n 1533 03:09:34,959 --> 03:09:35,959 So Java in the background for you, this concatenation\n 1534 03:09:35,959 --> 03:09:36,959 have some very big object here, that might\n 1535 03:09:36,959 --> 03:09:37,959 so on. So this creation of a string, as stupid\n 1536 03:09:37,959 --> 03:09:38,959 And, of course, I mean, here, we just have\n 1537 03:09:38,959 --> 03:09:39,959 debug line. But of course, you would log maybe\n 1538 03:09:39,959 --> 03:09:40,959 error, maybe a lot of stuff in your application.\n 1539 03:09:40,959 --> 03:09:41,959 calling this method. And then if this only\n 1540 03:09:41,959 --> 03:09:42,959 200 milliseconds might not seem a lot of time.\n 1541 03:09:42,959 --> 03:09:43,959 can really consume a lot of performance of\n 1542 03:09:43,959 --> 03:09:44,959 to concatenate the string, prepare the string\n 1543 03:09:44,959 --> 03:09:45,959 because if we say log info, but then the logging\n 1544 03:09:45,959 --> 03:09:46,959 to be locked, it would have to throw away\n 1545 03:09:46,959 --> 03:09:47,959 we had done this without any need. And so\n 1546 03:09:47,959 --> 03:09:48,959 why in lock for j, you would do it like is\n 1547 03:09:48,959 --> 03:09:49,959 info enabled is error enabled, and so on,\n 1548 03:09:49,959 --> 03:09:50,959 SL for j However, there's actually even a\n 1549 03:09:50,959 --> 03:09:51,959 lines of code. And this is you can put here,\n 1550 03:09:51,959 --> 03:09:52,959 to say plus, but you say comma. So within\n 1551 03:09:52,959 --> 03:09:53,959 the user in this case, this would be us wants\n 1552 03:09:53,959 --> 03:09:54,959 enabled for this class. And if so, only then\n 1553 03:09:54,959 --> 03:09:55,959 not a string already, and only then concatenate\n 1554 03:09:55,959 --> 03:09:56,959 a smart thing now. Okay, so another enough\n 1555 03:09:56,959 --> 03:09:57,959 check. We have the input given from the process\n 1556 03:09:58,959 --> 03:09:59,959 we put here BMW or Beemer. Okay, so let's\n 1557 03:09:59,959 --> 03:10:00,959 XML. We said comarca spiele. java course,\n 1558 03:10:00,959 --> 03:10:01,959 So if we no log on debug, within this package,\n 1559 03:10:01,959 --> 03:10:02,959 package. This means we should log it. Okay,\nlet's run the test. 1560 03:10:02,959 --> 03:10:03,959 Okay, so something happened. Process finished\n 1561 03:10:03,959 --> 03:10:04,959 at this time, which is now on level debug\n 1562 03:10:04,959 --> 03:10:05,959 we wrote processing car column BMW. So this\n 1563 03:10:05,959 --> 03:10:06,959 it. Let's say we only want to log on error\n 1564 03:10:06,959 --> 03:10:07,959 Run. Process finished. On top, this is all\n 1565 03:10:07,959 --> 03:10:08,959 Well, you see there is no BMW locked. Okay,\n 1566 03:10:08,959 --> 03:10:09,959 is debug. And we could say or, let's have\n 1567 03:10:09,959 --> 03:10:10,959 let's change the package. For example, Java\n 1568 03:10:10,959 --> 03:10:11,959 too. But we are in the package called Marco\n 1569 03:10:11,959 --> 03:10:12,959 log on the root level, which is debug. So\n 1570 03:10:12,959 --> 03:10:13,959 try it run. And there you see it already.\n 1571 03:10:13,959 --> 03:10:14,959 processing car BMW. So this seems to be working.\n 1572 03:10:14,959 --> 03:10:15,959 This is what's compared. Here, we have the\n 1573 03:10:15,959 --> 03:10:16,959 the message, and then this n, I think this\n 1574 03:10:16,959 --> 03:10:17,959 next lowing a new line will be attached. Okay.\n 1575 03:10:17,959 --> 03:10:18,959 is the console that we can see here, in our\n 1576 03:10:18,959 --> 03:10:19,959 with like, for example, a terminal here, you\n 1577 03:10:19,959 --> 03:10:20,959 So let's maybe go back to the documentation,\n 1578 03:10:20,959 --> 03:10:21,959 you see, and you should really use read it.\n 1579 03:10:21,959 --> 03:10:22,959 you can read it typical usage pattern for\n 1580 03:10:22,959 --> 03:10:23,959 with the curly braces, we locked on debug.\n 1581 03:10:23,959 --> 03:10:24,959 the documentation, let's also log on Arrow\n 1582 03:10:24,959 --> 03:10:25,959 here, it's also explained what I showed you\n 1583 03:10:25,959 --> 03:10:26,959 time. So it says here lockback Classic, you\n 1584 03:10:26,959 --> 03:10:27,959 framework, which we used. Yeah, so really\n 1585 03:10:27,959 --> 03:10:28,959 see the dependencies, this is what we did.\n 1586 03:10:28,959 --> 03:10:29,959 lock for J. But lockback, as I showed you\n 1587 03:10:29,959 --> 03:10:30,959 is also documentation of lockback which should\n 1588 03:10:30,959 --> 03:10:31,959 author is chechi Goku, and others. Yeah, so\n 1589 03:10:31,959 --> 03:10:32,959 12 years. I mean, you wouldn't want to work\n 1590 03:10:32,959 --> 03:10:33,959 three guys. So this is a lot of work and brain\n 1591 03:10:33,959 --> 03:10:34,959 which you can use just by configuring it in\n 1592 03:10:34,959 --> 03:10:35,959 also done it import org. So for j logger,\n 1593 03:10:36,959 --> 03:10:37,959 And here they log on info level. Okay. And\n 1594 03:10:37,959 --> 03:10:38,959 also showed you Okay, and there are also other\n 1595 03:10:38,959 --> 03:10:39,959 see, oh, there's also the explanation you\n 1596 03:10:39,959 --> 03:10:40,959 I showed you, or you see better alternative\n 1597 03:10:40,959 --> 03:10:41,959 basically, it's the same thing. But this is\n 1598 03:10:41,959 --> 03:10:42,959 easily. And this is only one line. So it's\n 1599 03:10:42,959 --> 03:10:43,959 that you want to focus on the domain, on the\n 1600 03:10:43,959 --> 03:10:44,959 just not be in the way of your business. The\n 1601 03:10:44,959 --> 03:10:45,959 important. Yes. But it's like not as important\n 1602 03:10:45,959 --> 03:10:46,959 go through all the documentation. It really\n 1603 03:10:46,959 --> 03:10:47,959 I promised you, and then we should finish\n 1604 03:10:47,959 --> 03:10:48,959 like you can see error. Well, as, as far as\n 1605 03:10:48,959 --> 03:10:49,959 error is included within debug, because debug\n 1606 03:10:49,959 --> 03:10:50,959 also look just here, I would expect to see\n 1607 03:10:50,959 --> 03:10:51,959 we would use this in case an error occurred.\n 1608 03:10:51,959 --> 03:10:52,959 some logging event is. Now you see an error.\n 1609 03:10:52,959 --> 03:10:53,959 Well, in our case, this is not an error. So\n 1610 03:10:53,959 --> 03:10:54,959 can we use? Let's see, we should also able\n 1611 03:10:54,959 --> 03:10:55,959 would use a warning for something very close\n 1612 03:10:55,959 --> 03:10:56,959 interfere, then you could use one logging\n 1613 03:10:56,959 --> 03:10:57,959 when your server starts when your program\n 1614 03:10:57,959 --> 03:10:58,959 knows everything is fine. And like here, this\n 1615 03:10:58,959 --> 03:10:59,959 is just starting up. Okay. And here you see\n 1616 03:10:59,959 --> 03:11:00,959 So now that we're using one level, let's put\n 1617 03:11:00,959 --> 03:11:01,959 that we're not using as well as the root level\n 1618 03:11:01,959 --> 03:11:02,959 out, which is this appender the console appender\n 1619 03:11:02,959 --> 03:11:03,959 I would not expect to see any logging. And\n 1620 03:11:03,959 --> 03:11:04,959 logging is gone. Which again, we can change.\n 1621 03:11:04,959 --> 03:11:05,959 Here also we can say worn. So now we should\n 1622 03:11:05,959 --> 03:11:06,959 Okay, well, as I Oh, I think I promised you\n 1623 03:11:06,959 --> 03:11:07,959 So let's finally go back to Firefox. And see\n 1624 03:11:07,959 --> 03:11:08,959 this is not yet. But it's somewhere appenders.\n 1625 03:11:08,959 --> 03:11:09,959 is really a good read. So I'm really fast\n 1626 03:11:09,959 --> 03:11:10,959 appender. This one we used. File append Not\n 1627 03:11:10,959 --> 03:11:11,959 into a file and go through it read it. So\n 1628 03:11:11,959 --> 03:11:12,959 parameters. And there are some really cool\n 1629 03:11:12,959 --> 03:11:13,959 that means that new files are created when\n 1630 03:11:13,959 --> 03:11:14,959 for every day we could have a new file. This\n 1631 03:11:14,959 --> 03:11:15,959 if we're always writing into the same file,\n 1632 03:11:15,959 --> 03:11:16,959 tons of gigabytes. Yeah. And therefore on\n 1633 03:11:16,959 --> 03:11:17,959 a rolling file appender so that thing is really\n 1634 03:11:17,959 --> 03:11:18,959 ODP appender that is supposed to To log into\n 1635 03:11:18,959 --> 03:11:19,959 this is really very easy to be configured.\n 1636 03:11:19,959 --> 03:11:20,959 somewhere somewhere, maybe I've already missed\n 1637 03:11:20,959 --> 03:11:21,959 from the name that is used for logging, sending\n 1638 03:11:21,959 --> 03:11:22,959 that was also the DB appender. I know it is\n 1639 03:11:22,959 --> 03:11:23,959 There it is. So this allows you to directly\n 1640 03:11:23,959 --> 03:11:24,959 databases are supported. So this is really\n 1641 03:11:24,959 --> 03:11:25,959 still goes on. So there are really a lot of\n 1642 03:11:25,959 --> 03:11:26,959 And as I said, you can always extend it and\n 1643 03:11:26,959 --> 03:11:27,959 to lock to any other source. So that pretty\n 1644 03:11:27,959 --> 03:11:28,959 you the main method of Java. The main method,\n 1645 03:11:28,959 --> 03:11:29,959 used to start a program initially. However,\n 1646 03:11:29,959 --> 03:11:30,959 or TDD In short, so far, we actually never\n 1647 03:11:30,959 --> 03:11:31,959 a test. And so far, we use the test to execute\n 1648 03:11:31,959 --> 03:11:32,959 guessed, at some time, when you're done with\n 1649 03:11:32,959 --> 03:11:33,959 And for this, you will need a class that has\n 1650 03:11:33,959 --> 03:11:34,959 look? Well, it's not so different from any\n 1651 03:11:34,959 --> 03:11:35,959 it can be started from outside of the class.\n 1652 03:11:35,959 --> 03:11:36,959 run the method without having an instance\n 1653 03:11:36,959 --> 03:11:37,959 Because the class car selector in this case\n 1654 03:11:37,959 --> 03:11:38,959 frame that we use to start our program. And\n 1655 03:11:38,959 --> 03:11:39,959 need further instances of this class. And\n 1656 03:11:39,959 --> 03:11:40,959 static by definition. The method is void because\n 1657 03:11:40,959 --> 03:11:41,959 be made. So that it can be found by Java.\n 1658 03:11:41,959 --> 03:11:42,959 say noticed by Java. Well, actually, what\n 1659 03:11:42,959 --> 03:11:43,959 the compiler will compile the program to bring\n 1660 03:11:43,959 --> 03:11:44,959 is a big topic, there are huge books, if not\n 1661 03:11:44,959 --> 03:11:45,959 so you could even study compilers. So I tried\n 1662 03:11:45,959 --> 03:11:46,959 But maybe, if I keep talking about Java, executing\n 1663 03:11:46,959 --> 03:11:47,959 and at a later time, I might do a dedicated\n 1664 03:11:47,959 --> 03:11:48,959 that you will know more about compilers. So\nanyway. 1665 03:11:48,959 --> 03:11:49,959 Okay, so back to the public static void Main\n 1666 03:11:49,959 --> 03:11:50,959 they have to contain something, because when\n 1667 03:11:50,959 --> 03:11:51,959 to give it arguments that the program might\n 1668 03:11:51,959 --> 03:11:52,959 are arguments that come as input as strings,\n 1669 03:11:52,959 --> 03:11:53,959 is an area here. So square brackets, and all\n 1670 03:11:53,959 --> 03:11:54,959 any name, people usually would set here arcs.\n 1671 03:11:54,959 --> 03:11:55,959 I usually prefer arguments, because this is\n 1672 03:11:55,959 --> 03:11:56,959 always, for our method, you would have the\n 1673 03:11:56,959 --> 03:11:57,959 curly brace. Um, yeah. And that's already\n 1674 03:11:57,959 --> 03:11:58,959 empty for a moment. And now when you compile\n 1675 03:11:58,959 --> 03:11:59,959 you can execute this Java class. And it will\n 1676 03:11:59,959 --> 03:12:00,959 So this is the place where you like set up\n 1677 03:12:00,959 --> 03:12:01,959 created a car service. So we can use this\n 1678 03:12:01,959 --> 03:12:02,959 technically, it also works to run just the\n 1679 03:12:02,959 --> 03:12:03,959 So let me directly say new car service, no\ntitle car service. 1680 03:12:04,959 --> 03:12:05,959 And then you can call the method, car service\n 1681 03:12:05,959 --> 03:12:06,959 an input. By the way, just to show you what\n 1682 03:12:06,959 --> 03:12:07,959 on the fly, you can say new car service thought\n 1683 03:12:07,959 --> 03:12:08,959 will then just call the method, and you will\n 1684 03:12:08,959 --> 03:12:09,959 If you don't need it, that might be fine.\n 1685 03:12:09,959 --> 03:12:10,959 And I mean, we could use any string here,\n 1686 03:12:10,959 --> 03:12:11,959 interesting, we could no, take the string\n 1687 03:12:11,959 --> 03:12:12,959 Of course, we need a for each loop, which\n 1688 03:12:12,959 --> 03:12:13,959 string argument for one, colon arguments.\n 1689 03:12:13,959 --> 03:12:14,959 will be given to us. When the program runs\n 1690 03:12:16,959 --> 03:12:17,959 That was formatting it. Okay, and now I can\n 1691 03:12:17,959 --> 03:12:18,959 the process method, dynamically creating an\n 1692 03:12:18,959 --> 03:12:19,959 object. So I mean, I wanted to show you that\n 1693 03:12:19,959 --> 03:12:20,959 probably be smarter to just create one object\n 1694 03:12:20,959 --> 03:12:21,959 this would be from the performance perspective,\n 1695 03:12:21,959 --> 03:12:22,959 about performance. Because the compiler these\n 1696 03:12:22,959 --> 03:12:23,959 stuff. And when before a while it compiles\n 1697 03:12:23,959 --> 03:12:24,959 performance is a topic by itself. And you\n 1698 03:12:24,959 --> 03:12:25,959 saying this will be fast or slow. You can\n 1699 03:12:25,959 --> 03:12:26,959 could also do a course only on performance\n 1700 03:12:26,959 --> 03:12:27,959 an instance of car service. And in the main\n 1701 03:12:27,959 --> 03:12:28,959 for each argument that is given to our main\n 1702 03:12:28,959 --> 03:12:29,959 car service. Now let's execute this. Because\n 1703 03:12:29,959 --> 03:12:30,959 Well, I mean, in this episode, I want to show\n 1704 03:12:30,959 --> 03:12:31,959 still holds true, you should always start\n 1705 03:12:31,959 --> 03:12:32,959 see, now I have a run car, see, like the domain.\n 1706 03:12:32,959 --> 03:12:33,959 Here. This shows me the console directly in\n 1707 03:12:33,959 --> 03:12:34,959 printed. This could either be because in the\n 1708 03:12:34,959 --> 03:12:35,959 could be deactivated, but so far, I remember\n 1709 03:12:35,959 --> 03:12:36,959 the moment. Well, the reason this doesn't\n 1710 03:12:36,959 --> 03:12:37,959 the reason is, well, we didn't give our program\n 1711 03:12:37,959 --> 03:12:38,959 this is not throwing any exceptions. By the\n 1712 03:12:38,959 --> 03:12:39,959 But it's empty. So the for loop will actually\n 1713 03:12:39,959 --> 03:12:40,959 When the program is run, so we will directly\n 1714 03:12:40,959 --> 03:12:41,959 the program will directly exit. But we can\n 1715 03:12:41,959 --> 03:12:42,959 on Run, and I say Edit configurations. And\n 1716 03:12:42,959 --> 03:12:43,959 this also contains always the full package\n 1717 03:12:43,959 --> 03:12:44,959 program arguments. So on the console, that\n 1718 03:12:44,959 --> 03:12:45,959 and then the program arguments. So let me\n 1719 03:12:45,959 --> 03:12:46,959 Mercedes. Yeah. And then Okay. And then let\n 1720 03:12:46,959 --> 03:12:47,959 see, we have three warning loggings processing\n 1721 03:12:47,959 --> 03:12:48,959 commerce. seeders. Yeah. So that's the main\nmethod. 1722 03:12:49,959 --> 03:12:50,959 one more thing just really slightly mentioned.\n 1723 03:12:50,959 --> 03:12:51,959 know is you can do this. Now what does that\n 1724 03:12:51,959 --> 03:12:52,959 This thing with the three dots here is called\n 1725 03:12:52,959 --> 03:12:53,959 which means when this is defined like this,\n 1726 03:12:53,959 --> 03:12:54,959 method, while in this case, it's directly\n 1727 03:12:54,959 --> 03:12:55,959 would have the ability to directly put in\n 1728 03:12:55,959 --> 03:12:56,959 by the compiler to an array. So this is very\n 1729 03:12:56,959 --> 03:12:57,959 convenient for whoever calls that method. 1730 03:12:57,959 --> 03:12:58,959 Just so that you have seen this would also\n 1731 03:12:58,959 --> 03:12:59,959 sense because, well, Normally, you would not\n 1732 03:12:59,959 --> 03:13:00,959 So if you don't call the main method directly,\n 1733 03:13:00,959 --> 03:13:01,959 you can write a test and you can call the\n 1734 03:13:01,959 --> 03:13:02,959 make a difference because you could directly\n 1735 03:13:02,959 --> 03:13:03,959 but let me talk about Fox arguments at a later\n 1736 03:13:05,959 --> 03:13:06,959 So now, string array arguments. Okay. So that\n 1737 03:13:06,959 --> 03:13:07,959 of background knowledge for you. So I don't\n 1738 03:13:07,959 --> 03:13:08,959 Java course you ever listened to? I guess\n 1739 03:13:08,959 --> 03:13:09,959 have heard another course or read the book\n 1740 03:13:09,959 --> 03:13:10,959 directly understand why didn't talk about\n 1741 03:13:10,959 --> 03:13:11,959 14 already. So let me give you the reason\n 1742 03:13:11,959 --> 03:13:12,959 specifically. Because this is really a main\n 1743 03:13:12,959 --> 03:13:13,959 is, first of all, I think, in the very first\n 1744 03:13:13,959 --> 03:13:14,959 and its keywords, it's hard to directly be\n 1745 03:13:14,959 --> 03:13:15,959 is just the name of the method would be okay,\n 1746 03:13:15,959 --> 03:13:16,959 All all this stuff for a very first lesson\n 1747 03:13:16,959 --> 03:13:17,959 episode 14, you should by now know what public\n 1748 03:13:17,959 --> 03:13:18,959 we have also talked about arrays. So I hope\n 1749 03:13:18,959 --> 03:13:19,959 and you understand what all this means. Okay?\n 1750 03:13:19,959 --> 03:13:20,959 And I told you, I think various times, Java\n 1751 03:13:20,959 --> 03:13:21,959 usually focus on creating objects, but static,\n 1752 03:13:21,959 --> 03:13:22,959 just one version of this method. I mean, of\n 1753 03:13:22,959 --> 03:13:23,959 you should try to avoid static, wherever possible,\n 1754 03:13:23,959 --> 03:13:24,959 very first Java lesson might lead you to the\n 1755 03:13:24,959 --> 03:13:25,959 reason is, um, even though, I mean, the main\n 1756 03:13:25,959 --> 03:13:26,959 because you use it to actually execute your\n 1757 03:13:26,959 --> 03:13:27,959 For any program at hand, you would have only\n 1758 03:13:27,959 --> 03:13:28,959 consists of hundreds, if not 1000s, of classes.\n 1759 03:13:28,959 --> 03:13:29,959 least, I mean, this counts for Java, se. But\n 1760 03:13:29,959 --> 03:13:30,959 what you usually do is you don't re implement\n 1761 03:13:30,959 --> 03:13:31,959 for example, an open source server implemented\n 1762 03:13:31,959 --> 03:13:32,959 I mean, has already been implemented for you.\n 1763 03:13:32,959 --> 03:13:33,959 even though it's software. And so the Java\n 1764 03:13:33,959 --> 03:13:34,959 infrastructure. And therefore, when you program\n 1765 03:13:34,959 --> 03:13:35,959 a main method at all. So, for example, in\n 1766 03:13:35,959 --> 03:13:36,959 for pretty much 14 years now. But I have maybe,\n 1767 03:13:36,959 --> 03:13:37,959 less than 100 times I have programmed a main\n 1768 03:13:37,959 --> 03:13:38,959 of classes, I'm sure. So the main method is\n 1769 03:13:38,959 --> 03:13:39,959 with writing a test anyway. So you are also\n 1770 03:13:39,959 --> 03:13:40,959 without the main method. Of course, I mean,\n 1771 03:13:40,959 --> 03:13:41,959 one. This one is based on the framework j\n 1772 03:13:41,959 --> 03:13:42,959 So j unit does have a main method. Of course\n 1773 03:13:42,959 --> 03:13:43,959 is the test methods that we write. And his\n 1774 03:13:43,959 --> 03:13:44,959 j unit mechanism, bet so we don't have to\n 1775 03:13:44,959 --> 03:13:45,959 just using a framework, like j unit is so\n 1776 03:13:45,959 --> 03:13:46,959 own main method. Yeah, and I promise you,\n 1777 03:13:46,959 --> 03:13:47,959 method as if it was a regular method. Now\n 1778 03:13:47,959 --> 03:13:48,959 array of string arguments, BMW and Porsche.\n 1779 03:13:48,959 --> 03:13:49,959 arguments as execute the test. And yeah, you\n 1780 03:13:51,959 --> 03:13:52,959 as one last thing, maybe you'll see I could\n 1781 03:13:52,959 --> 03:13:53,959 could say the method returns some end. In\n 1782 03:13:53,959 --> 03:13:54,959 not make it static anymore. I can change it\n 1783 03:13:54,959 --> 03:13:55,959 it just will not be recognized as a regular\n 1784 03:13:55,959 --> 03:13:56,959 to execute it as a Java program, but our test\n 1785 03:13:56,959 --> 03:13:57,959 now this is returning something. So we don't\n 1786 03:13:57,959 --> 03:13:58,959 use equals to Yeah. So you see, it's really,\n 1787 03:13:58,959 --> 03:13:59,959 And we can still call it from the test. But\n 1788 03:13:59,959 --> 03:14:00,959 that will allow us to start a program, then\n 1789 03:14:00,959 --> 03:14:01,959 I think that's pretty much all I can tell\n 1790 03:14:01,959 --> 03:14:02,959 that we were finally able to have a look at\n 1791 03:14:02,959 --> 03:14:03,959 that I've done so far, I think this course\n 1792 03:14:03,959 --> 03:14:04,959 should really know quite a lot about Java,\n 1793 03:14:04,959 --> 03:14:05,959 by now, I will, of course, add a few more\n 1794 03:14:05,959 --> 03:14:06,959 to write your own small programs. I would\n 1795 03:14:06,959 --> 03:14:07,959 So first of all, let's have a look at some\n 1796 03:14:07,959 --> 03:14:08,959 exception handling. And then later on, we\n 1797 03:14:08,959 --> 03:14:09,959 And I'll show you how to do Exception Handling\n 1798 03:14:09,959 --> 03:14:10,959 the Wikipedia article about exception handling.\n 1799 03:14:10,959 --> 03:14:11,959 the definition. So here this article says\n 1800 03:14:11,959 --> 03:14:12,959 to the occurrence during computation of exceptions,\n 1801 03:14:12,959 --> 03:14:13,959 special processing. Okay, let's stop here.\n 1802 03:14:13,959 --> 03:14:14,959 very important is two things. First of all,\n 1803 03:14:14,959 --> 03:14:15,959 in my opinion, this is something that many\n 1804 03:14:15,959 --> 03:14:16,959 is called an exception, because it should\n 1805 03:14:16,959 --> 03:14:17,959 really is what is an exceptional condition.\n 1806 03:14:17,959 --> 03:14:18,959 is something that really, as the name implies,\n 1807 03:14:18,959 --> 03:14:19,959 really rarely, only in very specific situations.\n 1808 03:14:19,959 --> 03:14:20,959 So for example, programming errors, you when\n 1809 03:14:20,959 --> 03:14:21,959 forgot to like you have an array, and you\n 1810 03:14:21,959 --> 03:14:22,959 about that means it has a field that is set\n 1811 03:14:22,959 --> 03:14:23,959 field, that, for example, can throw a so called\n 1812 03:14:23,959 --> 03:14:24,959 really an exceptional case, which you wouldn't\n 1813 03:14:24,959 --> 03:14:25,959 would be one reason for an exception. So exception\n 1814 03:14:25,959 --> 03:14:26,959 of responding to the occurrence of exceptions.\n 1815 03:14:27,959 --> 03:14:28,959 a way to react on that to handle that. Some\n 1816 03:14:28,959 --> 03:14:29,959 program flow. But the cool thing about Yeah,\n 1817 03:14:29,959 --> 03:14:30,959 flow of program execution. because ideally,\n 1818 03:14:30,959 --> 03:14:31,959 the exceptions. And so we want to leave the\n 1819 03:14:31,959 --> 03:14:32,959 take care of this exceptional case. Okay.\n 1820 03:14:32,959 --> 03:14:33,959 programming languages, which gives us a hint,\n 1821 03:14:33,959 --> 03:14:34,959 Well, let's have a look at the history which\n 1822 03:14:34,959 --> 03:14:35,959 developed in Lisp in the 1960s and 1970s.\n 1823 03:14:35,959 --> 03:14:36,959 was invented by Conrad Sousa in, like 1943,\n 1824 03:14:36,959 --> 03:14:37,959 until they finally came up with the idea of\n 1825 03:14:37,959 --> 03:14:38,959 is really necessary. And, well, maybe a bit\n 1826 03:14:38,959 --> 03:14:39,959 with Java, there was some something new introduced,\n 1827 03:14:39,959 --> 03:14:40,959 exceptions were unchecked, which means any\n 1828 03:14:40,959 --> 03:14:41,959 And there is no mechanism that forces you\n 1829 03:14:41,959 --> 03:14:42,959 for example, causes the program to stop. And\n 1830 03:14:42,959 --> 03:14:43,959 like introduced, many times nasty things happened.\n 1831 03:14:43,959 --> 03:14:44,959 or something, they thought, well, maybe we\n 1832 03:14:44,959 --> 03:14:45,959 of all, let's have a look. Check the exceptions\n 1833 03:14:45,959 --> 03:14:46,959 exceptions, which are a special set of exceptions 1834 03:14:47,959 --> 03:14:48,959 Okay, and to make it short, so what's the\n 1835 03:14:48,959 --> 03:14:49,959 also already an example and i o exception,\n 1836 03:14:49,959 --> 03:14:50,959 an IO operation input output operation. The\n 1837 03:14:50,959 --> 03:14:51,959 is they must be declared explicitly in the\n 1838 03:14:51,959 --> 03:14:52,959 do that, you will directly get a compile time\n 1839 03:14:52,959 --> 03:14:53,959 compile your program. I looked at actually\n 1840 03:14:53,959 --> 03:14:54,959 Like how it came with the checked exceptions.\n 1841 03:14:54,959 --> 03:14:55,959 concept of checked exceptions, checked exceptions\n 1842 03:14:55,959 --> 03:14:56,959 must declare the exception in our throws clause.\n 1843 03:14:56,959 --> 03:14:57,959 interesting. According to Anvil wrath, who\n 1844 03:14:57,959 --> 03:14:58,959 the Java exception scheme should mostly go\n 1845 03:14:58,959 --> 03:14:59,959 after some consideration, Java was retooled\n 1846 03:14:59,959 --> 03:15:00,959 for which there was no recovery, or reflect\n 1847 03:15:00,959 --> 03:15:01,959 the world was safe again. Well, so they thought.\n 1848 03:15:01,959 --> 03:15:02,959 like 20 years later, and it turns out, that\n 1849 03:15:02,959 --> 03:15:03,959 and this is also why stated at the beginning,\n 1850 03:15:03,959 --> 03:15:04,959 handling is the process of blah, blah, blah,\n 1851 03:15:04,959 --> 03:15:05,959 And this is the important part. Because they\n 1852 03:15:05,959 --> 03:15:06,959 for something like programmer arrows for something\n 1853 03:15:06,959 --> 03:15:07,959 and to have the checked exceptions for everything\n 1854 03:15:07,959 --> 03:15:08,959 for these cases that can be handled? Why not?\n 1855 03:15:08,959 --> 03:15:09,959 why not that instead validating that situation?\n 1856 03:15:09,959 --> 03:15:10,959 also, and now maybe we should already jump\n 1857 03:15:10,959 --> 03:15:11,959 on too much theory. Let's directly jump into\n 1858 03:15:11,959 --> 03:15:12,959 that I've written car stayed with a different\n 1859 03:15:12,959 --> 03:15:13,959 written this public static from method that\n 1860 03:15:13,959 --> 03:15:14,959 statement. I told you, in a previous episode,\n 1861 03:15:14,959 --> 03:15:15,959 a switch inside air to use a string inside\n 1862 03:15:15,959 --> 03:15:16,959 still applies. But in this case, I assume\n 1863 03:15:16,959 --> 03:15:17,959 And input from the user coming from the console\n 1864 03:15:17,959 --> 03:15:18,959 is all I mean, for every rule, there is an\n 1865 03:15:18,959 --> 03:15:19,959 rule, which is here, we do have a switch,\n 1866 03:15:19,959 --> 03:15:20,959 the default case. And I also told you, I wouldn't,\n 1867 03:15:20,959 --> 03:15:21,959 case, so that it cannot happen, that someone\n 1868 03:15:21,959 --> 03:15:22,959 then be handled by the default case without\n 1869 03:15:22,959 --> 03:15:23,959 And so I told you to throw an exception, but\n 1870 03:15:23,959 --> 03:15:24,959 now, and this is quite easy. You can just\n 1871 03:15:24,959 --> 03:15:25,959 in Java is just an A class. Like almost any\n 1872 03:15:25,959 --> 03:15:26,959 methods and stuff, but at least it's an it's\n 1873 03:15:26,959 --> 03:15:27,959 from it. Now, you know, you already see a\n 1874 03:15:27,959 --> 03:15:28,959 how the compiler already wants me unhandled\n 1875 03:15:28,959 --> 03:15:29,959 also the package java. lang exception. And,\n 1876 03:15:29,959 --> 03:15:30,959 Don't ask me why it's called exception. If\n 1877 03:15:30,959 --> 03:15:31,959 like a checked exception. I mean, the name\n 1878 03:15:31,959 --> 03:15:32,959 have to know that this exception is a checked\n 1879 03:15:32,959 --> 03:15:33,959 exception is an is a runtime exception. This\n 1880 03:15:33,959 --> 03:15:34,959 to know I mean, runtime makes sense, because\n 1881 03:15:34,959 --> 03:15:35,959 so you would normally use a runtime exception\n 1882 03:15:35,959 --> 03:15:36,959 them directly. And the idea was, as I said\n 1883 03:15:36,959 --> 03:15:37,959 where you know how to deal with them. But\n 1884 03:15:37,959 --> 03:15:38,959 why not dealing with them without throwing\n 1885 03:15:38,959 --> 03:15:39,959 But anyway, let's continue. So how can we\n 1886 03:15:39,959 --> 03:15:40,959 at exception to method signature, let's use\n 1887 03:15:40,959 --> 03:15:41,959 exception. Now you see the compile time error\n 1888 03:15:41,959 --> 03:15:42,959 like we fixed the problem. So we told the\n 1889 03:15:42,959 --> 03:15:43,959 exception. We just don't care. The color should\n 1890 03:15:43,959 --> 03:15:44,959 class here. And I made it to use the static\n 1891 03:15:44,959 --> 03:15:45,959 now this class has the problem. Okay, again,\n 1892 03:15:45,959 --> 03:15:46,959 method signature. Okay. And I guess you know,\n 1893 03:15:46,959 --> 03:15:47,959 And again, we have the same problem. Well,\n 1894 03:15:47,959 --> 03:15:48,959 Seems like we're on the wrong line. But yeah,\n 1895 03:15:48,959 --> 03:15:49,959 signature. Okay. Well, sorry, I'm just lazy.\n 1896 03:15:49,959 --> 03:15:50,959 But whenever you write something, you have\n 1897 03:15:50,959 --> 03:15:51,959 So whenever possible, I prefer to have my\n 1898 03:15:51,959 --> 03:15:52,959 by the ID that can save From introducing bugs\n 1899 03:15:52,959 --> 03:15:53,959 will be, like fixed. But now the question\n 1900 03:15:53,959 --> 03:15:54,959 exception, we have here throws exception,\n 1901 03:15:54,959 --> 03:15:55,959 times we had to add this throws exception.\n 1902 03:15:55,959 --> 03:15:56,959 exception. But besides, we didn't handle it,\n 1903 03:15:56,959 --> 03:15:57,959 the code, and the default case is chosen,\n 1904 03:15:57,959 --> 03:15:58,959 it will bubble up to the top to the main method.\n 1905 03:15:58,959 --> 03:15:59,959 the program will stop. And we will see the\n 1906 03:15:59,959 --> 03:16:00,959 could do, for example, with a runtime exception,\n 1907 03:16:00,959 --> 03:16:01,959 cases, you can and you should add some meaningful\n 1908 03:16:01,959 --> 03:16:02,959 So let's say on state, and concatenate that\n 1909 03:16:02,959 --> 03:16:03,959 still keep it. But I don't have to. It's not\n 1910 03:16:04,959 --> 03:16:05,959 Same here, I can remove all these. And this.\n 1911 03:16:05,959 --> 03:16:06,959 differences I mean, I'm not handling the exception,\n 1912 03:16:06,959 --> 03:16:07,959 Because he mentioned again, I'm always bringing\n 1913 03:16:07,959 --> 03:16:08,959 of classes. And as soon as one method has\n 1914 03:16:08,959 --> 03:16:09,959 which means another method, sooner or later,\n 1915 03:16:09,959 --> 03:16:10,959 will then also have to say throws exception,\n 1916 03:16:10,959 --> 03:16:11,959 or later, you will have that throws exception\n 1917 03:16:11,959 --> 03:16:12,959 help us at all. It just makes the code more\n 1918 03:16:12,959 --> 03:16:13,959 meaningful. So anyway, let's first of all\n 1919 03:16:13,959 --> 03:16:14,959 as exception stacktrace looks like for this\n 1920 03:16:14,959 --> 03:16:15,959 And I have to give it some some argument that\n 1921 03:16:15,959 --> 03:16:16,959 I think I have prepared something already.\n 1922 03:16:16,959 --> 03:16:17,959 driving, driving ABCD E, F, G, because also,\n 1923 03:16:17,959 --> 03:16:18,959 the main method only in the prior episode.\n 1924 03:16:18,959 --> 03:16:19,959 as some invalid states. Also in lowercase\n 1925 03:16:19,959 --> 03:16:20,959 we're iterating through the arguments and\n 1926 03:16:20,959 --> 03:16:21,959 just let's just do it. actually still have\n 1927 03:16:21,959 --> 03:16:22,959 Okay, so you see, the exception happened.\n 1928 03:16:22,959 --> 03:16:23,959 reason is that this happened for the very\n 1929 03:16:23,959 --> 03:16:24,959 flying. So this is our program stopped. This\n 1930 03:16:24,959 --> 03:16:25,959 we could also handle it to show you what's\n 1931 03:16:25,959 --> 03:16:26,959 to handle such an exception? Well, always\n 1932 03:16:26,959 --> 03:16:27,959 can do something about the exception. In our\n 1933 03:16:27,959 --> 03:16:28,959 that I get a wrong argument from from when\n 1934 03:16:28,959 --> 03:16:29,959 this to be printed to the console, so that\n 1935 03:16:29,959 --> 03:16:30,959 to be printed here, which means the first\n 1936 03:16:30,959 --> 03:16:31,959 only here on the very top. And so there is\n 1937 03:16:31,959 --> 03:16:32,959 like telling the compiler, I know something\n 1938 03:16:32,959 --> 03:16:33,959 But now I can say catch. And I can catch this\n 1939 03:16:33,959 --> 03:16:34,959 like really short variable names, because\n 1940 03:16:34,959 --> 03:16:35,959 exception, because an exception log is always\n 1941 03:16:35,959 --> 03:16:36,959 exception for with E, for exception. And I\n 1942 03:16:36,959 --> 03:16:37,959 we don't want too much with the exception,\n 1943 03:16:37,959 --> 03:16:38,959 knows the E is for the exception. Okay, so\n 1944 03:16:38,959 --> 03:16:39,959 First of all, we could say e dot print stack\ntrace. 1945 03:16:39,959 --> 03:16:40,959 Well, this is actually exactly what we have\n 1946 03:16:40,959 --> 03:16:41,959 you can think of as a list of all the methods\n 1947 03:16:41,959 --> 03:16:42,959 you see main process from can also jump there.\n 1948 03:16:42,959 --> 03:16:43,959 anymore, because I've no edits code. But at\n 1949 03:16:43,959 --> 03:16:44,959 was thrown. This told us exactly in each class,\n 1950 03:16:44,959 --> 03:16:45,959 true. And he also, but in my car selector,\n 1951 03:16:45,959 --> 03:16:46,959 this. The fact that I've adjusted the code,\n 1952 03:16:46,959 --> 03:16:47,959 and you need to analyze where it came from,\n 1953 03:16:47,959 --> 03:16:48,959 that is running on production is older than\n 1954 03:16:48,959 --> 03:16:49,959 development continues. And then you can only\n 1955 03:16:49,959 --> 03:16:50,959 happened, if you keep the exact same code\n 1956 03:16:50,959 --> 03:16:51,959 but this only really, I don't want to go into\n 1957 03:16:51,959 --> 03:16:52,959 its own, again, about revision control. And\n 1958 03:16:52,959 --> 03:16:53,959 that, you know, the stack trace is really\n 1959 03:16:53,959 --> 03:16:54,959 same code that was implemented at the time\n 1960 03:16:54,959 --> 03:16:55,959 both in sync. Okay, so print sectors here\n 1961 03:16:55,959 --> 03:16:56,959 it's just the default anyway. But this can\n 1962 03:16:56,959 --> 03:16:57,959 in I don't know, was it Episode 13? I think\n 1963 03:16:57,959 --> 03:16:58,959 to log an exception, you can do it like this.\n 1964 03:16:58,959 --> 03:16:59,959 got the log class here. And I don't want to\n 1965 03:16:59,959 --> 03:17:00,959 depends error only when there is something\n 1966 03:17:00,959 --> 03:17:01,959 that has to be restarted. In other cases,\n 1967 03:17:01,959 --> 03:17:02,959 the string that I added into the constructor\nof the exception 1968 03:17:03,959 --> 03:17:04,959 And I have removed the stack trace, because\n 1969 03:17:04,959 --> 03:17:05,959 which I want to add. Now. If you want to know\n 1970 03:17:05,959 --> 03:17:06,959 13 where I explain logging in detail. Okay,\n 1971 03:17:06,959 --> 03:17:07,959 this case, I say I don't want to log it, I\n 1972 03:17:07,959 --> 03:17:08,959 think also in the episode about logging, I\n 1973 03:17:08,959 --> 03:17:09,959 But in this case, let's assume we have just\n 1974 03:17:09,959 --> 03:17:10,959 from the console. And in this case, it can\n 1975 03:17:10,959 --> 03:17:11,959 Which I also wanted to show you once print\n 1976 03:17:11,959 --> 03:17:12,959 dot get message. Or I can also say e dot print\n 1977 03:17:12,959 --> 03:17:13,959 we already have that. So to alter the behavior,\n 1978 03:17:13,959 --> 03:17:14,959 you see something else. You see the program\n 1979 03:17:14,959 --> 03:17:15,959 state flying Unknown, Unknown state driving\n 1980 03:17:15,959 --> 03:17:16,959 invalid states were printed out. Without we\n 1981 03:17:16,959 --> 03:17:17,959 it's red, because I use system error Clinton,\n 1982 03:17:17,959 --> 03:17:18,959 is a special channel, only for errors. And\n 1983 03:17:18,959 --> 03:17:19,959 white. But really, I still warn you don't\n 1984 03:17:19,959 --> 03:17:20,959 Because Yeah, you can't configure it like\n 1985 03:17:20,959 --> 03:17:21,959 cases, using a logger is better. Anyway. So\n 1986 03:17:21,959 --> 03:17:22,959 is this really nice. Now, we have a for loop,\n 1987 03:17:22,959 --> 03:17:23,959 a lot of different hierarchies and a lot of\n 1988 03:17:23,959 --> 03:17:24,959 And this is something I really don't like,\n 1989 03:17:24,959 --> 03:17:25,959 so this is something you should try to prevent.\n 1990 03:17:25,959 --> 03:17:26,959 you, we could do exactly the same. 1991 03:17:26,959 --> 03:17:27,959 If this was throwing an exception. The only\n 1992 03:17:28,959 --> 03:17:29,959 throws throws. So yeah. Maybe also, I should\n 1993 03:17:29,959 --> 03:17:30,959 want to add the method signature, the exception\n 1994 03:17:30,959 --> 03:17:31,959 and then handle it. And then I mean, handling\n 1995 03:17:31,959 --> 03:17:32,959 you have to print it, I mean, printing, it\n 1996 03:17:32,959 --> 03:17:33,959 be even better to really have a method that\n 1997 03:17:33,959 --> 03:17:34,959 I call no handle the exception. The only problem\n 1998 03:17:34,959 --> 03:17:35,959 method now. And this is what I said before,\n 1999 03:17:35,959 --> 03:17:36,959 something about the exception, which in this\n 2000 03:17:36,959 --> 03:17:37,959 typed in something wrong? There's not much\n 2001 03:17:37,959 --> 03:17:38,959 for example, ask the user to type in to fix\n 2002 03:17:38,959 --> 03:17:39,959 handle here. So again, if we want to, like\n 2003 03:17:40,959 --> 03:17:41,959 the state. So let's remove all that. Let's\n 2004 03:17:41,959 --> 03:17:42,959 but I will change it very soon, because now\n 2005 03:17:42,959 --> 03:17:43,959 can be done in the following way. I remove\n 2006 03:17:43,959 --> 03:17:44,959 argument and now I can implement that method.\n 2007 03:17:45,959 --> 03:17:46,959 now well actually I want to say is valid with\n 2008 03:17:46,959 --> 03:17:47,959 is also interesting, by the way about the\n 2009 03:17:47,959 --> 03:17:48,959 Also, this Method automatically esthetic.\n 2010 03:17:48,959 --> 03:17:49,959 method cannot call a method that is not static,\n 2011 03:17:49,959 --> 03:17:50,959 when there is an instance. But for the main\n 2012 03:17:50,959 --> 03:17:51,959 selector. So for this reason this is static,\n 2013 03:17:51,959 --> 03:17:52,959 call it from outside, only the main method\n 2014 03:17:52,959 --> 03:17:53,959 Well, for example, we could use a method directly\n 2015 03:17:53,959 --> 03:17:54,959 is value of this is not implemented by us.\n 2016 03:17:54,959 --> 03:17:55,959 when they implemented when they invented the\n 2017 03:17:55,959 --> 03:17:56,959 get for free. So this will directly try to\n 2018 03:17:56,959 --> 03:17:57,959 can say car stayed. Cars date. So this actually\n 2019 03:17:57,959 --> 03:17:58,959 did. So actually, we won't need it anymore.\n 2020 03:17:58,959 --> 03:17:59,959 I implemented is or bill, I did it actually\n 2021 03:17:59,959 --> 03:18:00,959 work, this will throw a runtime exception,\n 2022 03:18:00,959 --> 03:18:01,959 types of runtime exceptions. And I think it\n 2023 03:18:01,959 --> 03:18:02,959 us the argument that you are giving that you\n 2024 03:18:02,959 --> 03:18:03,959 it's a runtime exception. So and because this\n 2025 03:18:03,959 --> 03:18:04,959 try catch block here, because we want to handle\n 2026 03:18:04,959 --> 03:18:05,959 he or I hope I'm right. I can directly say\nin valid on 2027 03:18:06,959 --> 03:18:07,959 human exemption, there it is. I think that\n 2028 03:18:07,959 --> 03:18:08,959 the exception will not be caught. Okay, and\n 2029 03:18:10,959 --> 03:18:11,959 let's see, this is the wrong one, because\n 2030 03:18:11,959 --> 03:18:12,959 thrown. So invalid. Let's see what the lead\n 2031 03:18:12,959 --> 03:18:13,959 it's an invalid state exception. Yeah, this\n 2032 03:18:13,959 --> 03:18:14,959 value off may throw an invalid state exception\n 2033 03:18:14,959 --> 03:18:15,959 of, for example, flying driving ABC. Okay. 2034 03:18:18,959 --> 03:18:19,959 I think this is also not optimal, that we\n 2035 03:18:19,959 --> 03:18:20,959 would be much, much nicer if the IEM base\n 2036 03:18:20,959 --> 03:18:21,959 just returning true and false. But again,\n 2037 03:18:21,959 --> 03:18:22,959 listen to my opinion, crap, just making a\nstupid joke. 2038 03:18:22,959 --> 03:18:23,959 So for this reason, we do have the exception,\n 2039 03:18:23,959 --> 03:18:24,959 we converting it directly. The exception doesn't\n 2040 03:18:24,959 --> 03:18:25,959 say like this. And we can now say here, return\n 2041 03:18:25,959 --> 03:18:26,959 the method. This is exactly the same. Yeah.\n 2042 03:18:26,959 --> 03:18:27,959 the jump. I mean, imagine you could have lots\n 2043 03:18:27,959 --> 03:18:28,959 just print something. So you could have many,\n 2044 03:18:28,959 --> 03:18:29,959 Let's just copy and paste that to show you\n 2045 03:18:29,959 --> 03:18:30,959 state to something else. Let's just say now.\n 2046 03:18:30,959 --> 03:18:31,959 work out, because the argument is unknown,\n 2047 03:18:31,959 --> 03:18:32,959 the execution will jump from here, directly\n 2048 03:18:32,959 --> 03:18:33,959 program flow, the normal program flow would\n 2049 03:18:33,959 --> 03:18:34,959 here we're jumping from line 21. To line 28.\n 2050 03:18:34,959 --> 03:18:35,959 imagine we have done this several times, for\n 2051 03:18:35,959 --> 03:18:36,959 methods, then we have just one catch, that\n 2052 03:18:36,959 --> 03:18:37,959 an invalid state exception could happen. That's\n 2053 03:18:37,959 --> 03:18:38,959 to give you some more details, actually, I\n 2054 03:18:38,959 --> 03:18:39,959 We're only like, abusing that volume of method\n 2055 03:18:39,959 --> 03:18:40,959 not? Okay, and now I can react on that. I\n 2056 03:18:40,959 --> 03:18:41,959 only process it if it's valid. Yeah, maybe\n 2057 03:18:41,959 --> 03:18:42,959 the invalid states are printed. Now let's\n 2058 03:18:42,959 --> 03:18:43,959 arguments. The question, of course, is, does\n 2059 03:18:43,959 --> 03:18:44,959 we have a problem in our code. So maybe we\n 2060 03:18:44,959 --> 03:18:45,959 system error dot print. ln M. invalid. argument\n 2061 03:18:45,959 --> 03:18:46,959 argument. So this, by the way, whenever you\n 2062 03:18:46,959 --> 03:18:47,959 I already talked about logging, but I can't\n 2063 03:18:47,959 --> 03:18:48,959 as possible, so that whoever is responsible\n 2064 03:18:48,959 --> 03:18:49,959 yeah, it's really hard to understand why something\n 2065 03:18:49,959 --> 03:18:50,959 illegal argument exception. How is that? I\n 2066 03:18:50,959 --> 03:18:51,959 we can now check. Like, this is what I told\n 2067 03:18:51,959 --> 03:18:52,959 have the from it seems like we call it somewhere.\n 2068 03:18:52,959 --> 03:18:53,959 five, so this is not yet. Car state. Illegal\n 2069 03:18:53,959 --> 03:18:54,959 the invalid state exception. And what is actually\n 2070 03:18:54,959 --> 03:18:55,959 So see, this is actually what happens most\n 2071 03:18:55,959 --> 03:18:56,959 this is what Java gives us. It throws an exception.\n 2072 03:18:56,959 --> 03:18:57,959 See, this is how everyone introduces sparks.\n 2073 03:18:57,959 --> 03:18:58,959 not doing a test because I just want to show\nyou exceptions. But 2074 03:18:58,959 --> 03:18:59,959 yeah. We do need tests. Tests are very important.\n 2075 03:18:59,959 --> 03:19:00,959 argument flying ignoring new argument driving,\n 2076 03:19:00,959 --> 03:19:01,959 valid argument was processed. It just didn't\n 2077 03:19:01,959 --> 03:19:02,959 we can change. Here we could say system out\n 2078 03:19:02,959 --> 03:19:03,959 Only use it in very rare situations. Yeah.\n 2079 03:19:03,959 --> 03:19:04,959 again. Yeah, so you see three invalid states\n 2080 03:19:04,959 --> 03:19:05,959 I mean, this was just an issue. Sample Normally,\n 2081 03:19:07,959 --> 03:19:08,959 do something with the car state. I mean, I'm\n 2082 03:19:08,959 --> 03:19:09,959 explain you is exception handling, but I hope\n 2083 03:19:09,959 --> 03:19:10,959 thing. And then actually, I would like to,\n 2084 03:19:10,959 --> 03:19:11,959 exception handling. And the missing thing\n 2085 03:19:11,959 --> 03:19:12,959 because I showed you, we don't actually even\n 2086 03:19:12,959 --> 03:19:13,959 can also do is finally, finally, this is very\n 2087 03:19:13,959 --> 03:19:14,959 making some something up. Finally, as the\n 2088 03:19:14,959 --> 03:19:15,959 end, no matter even exception happened or\n 2089 03:19:15,959 --> 03:19:16,959 this is important. When you have resources,\n 2090 03:19:16,959 --> 03:19:17,959 in short I O, which you have, if you communicate\n 2091 03:19:17,959 --> 03:19:18,959 a file from your hard disk, Yeah, something\n 2092 03:19:18,959 --> 03:19:19,959 especially from external systems, who can\n 2093 03:19:19,959 --> 03:19:20,959 available, or like the hard disk could fail.\n 2094 03:19:20,959 --> 03:19:21,959 nasty stuff that can happen. But there's one\n 2095 03:19:21,959 --> 03:19:22,959 you need resources. And so you have to close\n 2096 03:19:22,959 --> 03:19:23,959 have a problem with more and more resources\n 2097 03:19:23,959 --> 03:19:24,959 explain it in like a second. But all I want\n 2098 03:19:24,959 --> 03:19:25,959 important when you deal with IO operations\n 2099 03:19:25,959 --> 03:19:26,959 close these resources and close resource for\n 2100 03:19:26,959 --> 03:19:27,959 stupid method. You can implement that yourself.\n 2101 03:19:27,959 --> 03:19:28,959 classes found on the internet, open source.\n 2102 03:19:28,959 --> 03:19:29,959 find something. But this is not the one I\n 2103 03:19:29,959 --> 03:19:30,959 think from Apache, and they will have something\n 2104 03:19:30,959 --> 03:19:31,959 And then this will do all the nasty stuff\n 2105 03:19:31,959 --> 03:19:32,959 important is, and this I want to show you\n 2106 03:19:33,959 --> 03:19:34,959 And I will throw the exception again. Which\n 2107 03:19:34,959 --> 03:19:35,959 have to catch it. This also works try and\n 2108 03:19:35,959 --> 03:19:36,959 So, now with the invalid argument, our program\n 2109 03:19:36,959 --> 03:19:37,959 But in any case, let's say I am still running.\n 2110 03:19:37,959 --> 03:19:38,959 be printed after exception. Well, it might\n 2111 03:19:38,959 --> 03:19:39,959 is a valid one. Because with the string airy,\n 2112 03:19:39,959 --> 03:19:40,959 But so that you see, I would whatever happens\n 2113 03:19:40,959 --> 03:19:41,959 This will always be printed. So let's see\n 2114 03:19:41,959 --> 03:19:42,959 wrong. Not Found. Yeah, because we have removed\n 2115 03:19:42,959 --> 03:19:43,959 so let's for now remove that. We at the moment,\n 2116 03:19:44,959 --> 03:19:45,959 I'm really doing some nasty hacking at the\n 2117 03:19:45,959 --> 03:19:46,959 And then the exception comes. So this is what\n 2118 03:19:46,959 --> 03:19:47,959 catch it. So we see the stack trace instead.\n 2119 03:19:47,959 --> 03:19:48,959 And this is the place where we can do some\n 2120 03:19:48,959 --> 03:19:49,959 But you could do anything in here, basically.\n 2121 03:19:49,959 --> 03:19:50,959 exception, runtime exception, because it's\n 2122 03:19:50,959 --> 03:19:51,959 inheritance very soon. So that I can go in\n 2123 03:19:51,959 --> 03:19:52,959 Yeah, we need the closing curly brace, and\n 2124 03:19:52,959 --> 03:19:53,959 I just have I will also show you print stack\n 2125 03:19:53,959 --> 03:19:54,959 And now I will say, system out. print on. 2126 03:19:55,959 --> 03:19:56,959 So you get an idea. In finally block. 2127 03:19:57,959 --> 03:19:58,959 Oh, no, something weird happened. And this\n 2128 03:19:58,959 --> 03:19:59,959 The stack trace was printed. And it's red.\n 2129 03:19:59,959 --> 03:20:00,959 So it's printed on system error. Okay. And\n 2130 03:20:00,959 --> 03:20:01,959 the first one, the second one, and so on.\n 2131 03:20:01,959 --> 03:20:02,959 comes after the whole stack trace. Yeah. And\n 2132 03:20:02,959 --> 03:20:03,959 off to exception. Because it seems like I\n 2133 03:20:03,959 --> 03:20:04,959 So for the valid ones, this line was printed.\n 2134 03:20:04,959 --> 03:20:05,959 a hard time knowing why this happened. So\n 2135 03:20:05,959 --> 03:20:06,959 the argument. So here I can say, our arguement.\n 2136 03:20:06,959 --> 03:20:07,959 after the value of if this is printed, it\n 2137 03:20:07,959 --> 03:20:08,959 call this again. And let me also remove the\n 2138 03:20:08,959 --> 03:20:09,959 readable for us. And let's run the main method\n 2139 03:20:09,959 --> 03:20:10,959 what do we have here? Hello again. So the\n 2140 03:20:10,959 --> 03:20:11,959 did not add the argument. In this case, I\n 2141 03:20:11,959 --> 03:20:12,959 message of the exception. I'm not sure if\n 2142 03:20:13,959 --> 03:20:14,959 Yeah, see, this is the message Hello again.\n 2143 03:20:14,959 --> 03:20:15,959 marktspiegel car stayed flying. So now you\n 2144 03:20:15,959 --> 03:20:16,959 better. And after this we under finally block\n 2145 03:20:16,959 --> 03:20:17,959 this case, we're also ending in the finally\n 2146 03:20:17,959 --> 03:20:18,959 Also in the finally block. Here again comes\nin invalid state 2147 03:20:19,959 --> 03:20:20,959 but we're also in the finally block. And the\n 2148 03:20:20,959 --> 03:20:21,959 So the finally block is always executed all\n 2149 03:20:21,959 --> 03:20:22,959 I wanted to tell you about Exception Handling\n 2150 03:20:22,959 --> 03:20:23,959 go Shortly through the most important gotchas,\n 2151 03:20:23,959 --> 03:20:24,959 which are unchecked exceptions, unchecked\n 2152 03:20:24,959 --> 03:20:25,959 to be handled, you can just throw them, and\n 2153 03:20:25,959 --> 03:20:26,959 a very famous or infamous exception is the\n 2154 03:20:26,959 --> 03:20:27,959 that yourself, Java will throw that for you,\n 2155 03:20:27,959 --> 03:20:28,959 the moment now, just now for the exception\n 2156 03:20:28,959 --> 03:20:29,959 when it happens, you will not be very happy.\n 2157 03:20:29,959 --> 03:20:30,959 exceptions. And they can happen at any line,\n 2158 03:20:30,959 --> 03:20:31,959 don't have to be handled in code. If they're\n 2159 03:20:31,959 --> 03:20:32,959 stop, like we saw before, because the exception\n 2160 03:20:32,959 --> 03:20:33,959 not handled in here, the program will stop.\n 2161 03:20:33,959 --> 03:20:34,959 Then Java was the first and actually also\n 2162 03:20:34,959 --> 03:20:35,959 checked exceptions. Checked exceptions are\n 2163 03:20:35,959 --> 03:20:36,959 that you do something about them, or you add\n 2164 03:20:36,959 --> 03:20:37,959 method signature. There are various checked\n 2165 03:20:37,959 --> 03:20:38,959 probably the i o exception. That will be C,\n 2166 03:20:38,959 --> 03:20:39,959 thrown if you have any problems with i o operations,\n 2167 03:20:39,959 --> 03:20:40,959 and I said Java was also the last programming\n 2168 03:20:40,959 --> 03:20:41,959 So this really shows us indicates us that\n 2169 03:20:41,959 --> 03:20:42,959 you see, all they help us in the end, is they\n 2170 03:20:42,959 --> 03:20:43,959 case that to use them for cases that you can\n 2171 03:20:43,959 --> 03:20:44,959 them, why not taking care of the problem beforehand,\n 2172 03:20:44,959 --> 03:20:45,959 the case, the given argument, and then handling\n 2173 03:20:45,959 --> 03:20:46,959 And then maybe last but not least, for every\n 2174 03:20:46,959 --> 03:20:47,959 that. I've removed it, unfortunately, yeah,\n 2175 03:20:47,959 --> 03:20:48,959 on the string were set in a prior episode.\n 2176 03:20:50,959 --> 03:20:51,959 where I use the value of method of enum, which\n 2177 03:20:51,959 --> 03:20:52,959 trying to validate it. So if we are validating\n 2178 03:20:52,959 --> 03:20:53,959 we can't do anything about it how the method\n 2179 03:20:53,959 --> 03:20:54,959 just have to live with that sometimes an exception\n 2180 03:20:54,959 --> 03:20:55,959 But what we can do is we can catch the exception\n 2181 03:20:55,959 --> 03:20:56,959 so we can convert the exception into a valid\n 2182 03:20:56,959 --> 03:20:57,959 have a library, like an old library that will\n 2183 03:20:57,959 --> 03:20:58,959 exception. What you can always do is you can\n 2184 03:20:58,959 --> 03:20:59,959 our runtime exception. And this is like this.\n 2185 03:20:59,959 --> 03:21:00,959 an ioexception shortly. So see, you can also\n 2186 03:21:00,959 --> 03:21:01,959 now on that exception while it cannot be called\n 2187 03:21:01,959 --> 03:21:02,959 say throw new runtime exception and okay.\n 2188 03:21:02,959 --> 03:21:03,959 we wrap it. Because we put this exception\n 2189 03:21:03,959 --> 03:21:04,959 which means this is the wrapper, it wraps\n 2190 03:21:04,959 --> 03:21:05,959 will be fine. Because we're not throwing an\n 2191 03:21:05,959 --> 03:21:06,959 exception. Well, this is a nasty hack. But\n 2192 03:21:06,959 --> 03:21:07,959 exceptions all over your code. And yeah, I'm\n 2193 03:21:07,959 --> 03:21:08,959 interfaces are probably the most powerful\n 2194 03:21:08,959 --> 03:21:09,959 before I continue, first of all, some organizational\n 2195 03:21:09,959 --> 03:21:10,959 Part One, I will first of all, talk about\n 2196 03:21:10,959 --> 03:21:11,959 interface mean? And tell you a bit about the\n 2197 03:21:11,959 --> 03:21:12,959 into Java. I'll make this part as short as\n 2198 03:21:12,959 --> 03:21:13,959 we'll jump into my ID, he will do a short\n 2199 03:21:13,959 --> 03:21:14,959 use interfaces in Java. And then last but\n 2200 03:21:14,959 --> 03:21:15,959 the pros and cons of interfaces from a clean\n 2201 03:21:15,959 --> 03:21:16,959 jump into the topic interface. So what does\n 2202 03:21:16,959 --> 03:21:17,959 the dictionary page. And the definition is\n 2203 03:21:17,959 --> 03:21:18,959 between entities. And interfaces do not only\n 2204 03:21:18,959 --> 03:21:19,959 kinds of areas, for example, in chemistry\n 2205 03:21:19,959 --> 03:21:20,959 layer or boundary between different substances.\n 2206 03:21:20,959 --> 03:21:21,959 interfaces in object oriented languages and\n 2207 03:21:21,959 --> 03:21:22,959 you will see, there is not much code needed\n 2208 03:21:22,959 --> 03:21:23,959 a boundary. When I say boundary, I think of\n 2209 03:21:23,959 --> 03:21:24,959 a big protection from the hordes that were\n 2210 03:21:24,959 --> 03:21:25,959 And this is also what an interface is, it\n 2211 03:21:25,959 --> 03:21:26,959 more of this later, okay. And then maybe we\n 2212 03:21:26,959 --> 03:21:27,959 of view. So in object oriented programming,\n 2213 03:21:27,959 --> 03:21:28,959 that other code must implement. 2214 03:21:29,959 --> 03:21:30,959 all this holds true for interfaces in Java.\n 2215 03:21:30,959 --> 03:21:31,959 a look at the history. For this, I actually\n 2216 03:21:31,959 --> 03:21:32,959 I found this page here from Oracle, where\n 2217 03:21:32,959 --> 03:21:33,959 the Java language was borrowed from the Objective\n 2218 03:21:33,959 --> 03:21:34,959 everyone says are things that Java was actually\n 2219 03:21:34,959 --> 03:21:35,959 Well, actually, Oracle itself says that this\n 2220 03:21:35,959 --> 03:21:36,959 C. I find this quite interesting. Objective\n 2221 03:21:36,959 --> 03:21:37,959 Objective C, then. So I found this page here\n 2222 03:21:37,959 --> 03:21:38,959 Objective C programming language in the early\n 2223 03:21:38,959 --> 03:21:39,959 was released as far as I know, in 1995. So\n 2224 03:21:39,959 --> 03:21:40,959 to write cleaner, more modular and clearly\n 2225 03:21:40,959 --> 03:21:41,959 quite good. Now, what is interesting is here,\n 2226 03:21:41,959 --> 03:21:42,959 were introduced to Java to enhance Java's\n 2227 03:21:44,959 --> 03:21:45,959 they had introduced the interfaces to get\n 2228 03:21:45,959 --> 03:21:46,959 code. There is a different reason. Well, I\n 2229 03:21:46,959 --> 03:21:47,959 And this for a reason. Because, um, well,\n 2230 03:21:47,959 --> 03:21:48,959 now we have 2015 20 years later, actually,\n 2231 03:21:48,959 --> 03:21:49,959 code community does not believe so much in\n 2232 03:21:49,959 --> 03:21:50,959 has a lot of advantages. But also many disadvantages\n 2233 03:21:50,959 --> 03:21:51,959 next episodes when I'm going to talk about\n 2234 03:21:51,959 --> 03:21:52,959 was introduced, Java is the successor of c++\n 2235 03:21:52,959 --> 03:21:53,959 multiple inheritance. So multiple inheritance\n 2236 03:21:53,959 --> 03:21:54,959 And here they write. multiple inheritance\n 2237 03:21:54,959 --> 03:21:55,959 as well as compiler writers, because it's\n 2238 03:21:55,959 --> 03:21:56,959 inheritance in into a compiler. So it seems,\n 2239 03:21:56,959 --> 03:21:57,959 they added interfaces to Java s, like replacement\n 2240 03:21:57,959 --> 03:21:58,959 Java did not support multiple inheritance.\n 2241 03:21:58,959 --> 03:21:59,959 in different words, I would say, it seems\n 2242 03:21:59,959 --> 03:22:00,959 was introduced into Java by kind of accident,\n 2243 03:22:00,959 --> 03:22:01,959 about cleaner, more modular, clearly separated\n 2244 03:22:01,959 --> 03:22:02,959 something similar to multiple inheritance.\n 2245 03:22:02,959 --> 03:22:03,959 my ID. Cuz I felt you were already feet been\n 2246 03:22:03,959 --> 03:22:04,959 So it was test that I've used in earlier episodes.\n 2247 03:22:04,959 --> 03:22:05,959 method, as the name implies, just for demonstration\n 2248 03:22:05,959 --> 03:22:06,959 that I've implemented, also in one of the\n 2249 03:22:06,959 --> 03:22:07,959 to it. So the idea is to have a service class.\n 2250 03:22:07,959 --> 03:22:08,959 should, like start the engines of several\n 2251 03:22:08,959 --> 03:22:09,959 my car service, I have now a method drive.\n 2252 03:22:09,959 --> 03:22:10,959 I mean, this is just an example you mentioned,\n 2253 03:22:10,959 --> 03:22:11,959 drive method on each of these cars. 2254 03:22:12,959 --> 03:22:13,959 all these classes are in the same package.\n 2255 03:22:13,959 --> 03:22:14,959 But imagine each class would be in a different\n 2256 03:22:14,959 --> 03:22:15,959 separately like BMW and Porsche GE and mercy\n 2257 03:22:15,959 --> 03:22:16,959 this car service at the moment is really Deeply\n 2258 03:22:16,959 --> 03:22:17,959 that we don't want more about this later.\n 2259 03:22:17,959 --> 03:22:18,959 make all the cars drive. And this is something\n 2260 03:22:18,959 --> 03:22:19,959 Now what, again, what is an interface? Well,\n 2261 03:22:19,959 --> 03:22:20,959 definition, what this type should be able\n 2262 03:22:20,959 --> 03:22:21,959 already saying it three different cars. And\n 2263 03:22:21,959 --> 03:22:22,959 I have three different drive methods. I mean,\n 2264 03:22:22,959 --> 03:22:23,959 be different because of course, a BMW has\n 2265 03:22:23,959 --> 03:22:24,959 a different engine than ms cedars. But they\n 2266 03:22:24,959 --> 03:22:25,959 they would all have four wheels, and they\n 2267 03:22:25,959 --> 03:22:26,959 like a contract off. So in this way, let us\n 2268 03:22:26,959 --> 03:22:27,959 here, car dot java. So far, we only have the\n 2269 03:22:27,959 --> 03:22:28,959 So let's start. Let's start as if we would\n 2270 03:22:28,959 --> 03:22:29,959 And then opening and closing curly brace,\n 2271 03:22:30,959 --> 03:22:31,959 And then in here, we could do something. Well,\n 2272 03:22:31,959 --> 03:22:32,959 is not going to work, because then all the\n 2273 03:22:32,959 --> 03:22:33,959 way. But this is not what we want. For example,\n 2274 03:22:33,959 --> 03:22:34,959 drive method. I mean, this is just a stupid\n 2275 03:22:34,959 --> 03:22:35,959 system out print line. But here for our example,\n 2276 03:22:35,959 --> 03:22:36,959 is implemented in a different way. Here it\n 2277 03:22:36,959 --> 03:22:37,959 driving, the BMW actually even has three different\n 2278 03:22:37,959 --> 03:22:38,959 a later time. And it also has the drive method,\n 2279 03:22:41,959 --> 03:22:42,959 continue with doing the interface, we could\n 2280 03:22:42,959 --> 03:22:43,959 do this. Now, just so that you see the code\n 2281 03:22:43,959 --> 03:22:44,959 BMW driving Porsche driving Mercedes driving.\n 2282 03:22:44,959 --> 03:22:45,959 just using interfaces with less and more readable\n 2283 03:22:45,959 --> 03:22:46,959 is fine. If there is a problem, an exception\n 2284 03:22:46,959 --> 03:22:47,959 back to what at the moment is still a class.\n 2285 03:22:47,959 --> 03:22:48,959 an interface. And this is I say interface.\n 2286 03:22:48,959 --> 03:22:49,959 It says interface methods cannot have a body,\n 2287 03:22:49,959 --> 03:22:50,959 here in blue. So the body is actually the\n 2288 03:22:50,959 --> 03:22:51,959 signature. This on top here is called the\n 2289 03:22:51,959 --> 03:22:52,959 of the method is drive. Okay. Sorry. So it\n 2290 03:22:52,959 --> 03:22:53,959 Well, I guess even makes sense. Because we\n 2291 03:22:53,959 --> 03:22:54,959 a contract. But we don't want to actually\n 2292 03:22:54,959 --> 03:22:55,959 by the specific implementations by BMW by\n 2293 03:22:55,959 --> 03:22:56,959 done the implementations. So let me remove\n 2294 03:22:56,959 --> 03:22:57,959 and you see it. Here it even says it It wants\n 2295 03:22:57,959 --> 03:22:58,959 now says, I'm finished. I'm done. This is\n 2296 03:22:58,959 --> 03:22:59,959 definition of a method that other classes\n 2297 03:22:59,959 --> 03:23:00,959 interface car, we can also say they play the\n 2298 03:23:00,959 --> 03:23:01,959 implement more than one interface. A class\n 2299 03:23:01,959 --> 03:23:02,959 remember, before I spoke about multiple inheritance,\n 2300 03:23:02,959 --> 03:23:03,959 because it also allows to have 2301 03:23:04,959 --> 03:23:05,959 multiple implementations in a way, but more\n 2302 03:23:05,959 --> 03:23:06,959 multiple interfaces. Okay. And when I click\n 2303 03:23:06,959 --> 03:23:07,959 Why is it redundant? because by definition,\n 2304 03:23:07,959 --> 03:23:08,959 must be public, they are always public. So\n 2305 03:23:08,959 --> 03:23:09,959 the episode I did on the visibility modifiers,\n 2306 03:23:09,959 --> 03:23:10,959 is no modifier defined, it must be of default,\n 2307 03:23:10,959 --> 03:23:11,959 a public visibility, because it always a method\n 2308 03:23:11,959 --> 03:23:12,959 modifier that is implicitly here is abstract,\n 2309 03:23:12,959 --> 03:23:13,959 here, that the method is not implemented,\n 2310 03:23:13,959 --> 03:23:14,959 and that the body is left away, and that we\n 2311 03:23:14,959 --> 03:23:15,959 we can and we should remove it. Always define\n 2312 03:23:15,959 --> 03:23:16,959 you should just know that implicitly, they're\n 2313 03:23:16,959 --> 03:23:17,959 you can do in an interface. Um, but I warn\n 2314 03:23:17,959 --> 03:23:18,959 pattern. But still just to be complete. I\n 2315 03:23:18,959 --> 03:23:19,959 static, final. So you can add constants, for\n 2316 03:23:19,959 --> 03:23:20,959 And however, you shouldn't do so. And when\n 2317 03:23:20,959 --> 03:23:21,959 find out why. Because for example, the BMW\n 2318 03:23:21,959 --> 03:23:22,959 Yeah, maybe a Porsche can maybe do 320, but\n 2319 03:23:22,959 --> 03:23:23,959 know. So this is actually not part of this\n 2320 03:23:23,959 --> 03:23:24,959 this is an implementation detail. And such\n 2321 03:23:24,959 --> 03:23:25,959 within the class, or even better. In an email\n 2322 03:23:25,959 --> 03:23:26,959 little page I found on the web. And this is\n 2323 03:23:26,959 --> 03:23:27,959 it's called sonar cube sonar cube is really\n 2324 03:23:27,959 --> 03:23:28,959 favorite tools for static code quality analysis.\n 2325 03:23:28,959 --> 03:23:29,959 on sonar cube alone. For now, let me keep\n 2326 03:23:29,959 --> 03:23:30,959 want to talk about interfaces. But in this\n 2327 03:23:30,959 --> 03:23:31,959 that you don't use constants in an interface.\n 2328 03:23:31,959 --> 03:23:32,959 in an interface. And there was also or there\n 2329 03:23:32,959 --> 03:23:33,959 the author of Effective Java, which is, by\n 2330 03:23:33,959 --> 03:23:34,959 that book on my blog, on Marcus minus bo.com,\n 2331 03:23:34,959 --> 03:23:35,959 if you have the time, you can also read all\n 2332 03:23:35,959 --> 03:23:36,959 important parts. Here, we can also look at\n 2333 03:23:36,959 --> 03:23:37,959 variables directly in the interface. And you\n 2334 03:23:37,959 --> 03:23:38,959 final because this is again, every variable\n 2335 03:23:38,959 --> 03:23:39,959 don't even have to say public Static final.\n 2336 03:23:39,959 --> 03:23:40,959 solution is to use an enum we have talked\n 2337 03:23:40,959 --> 03:23:41,959 detail here. Another possibility, which I\n 2338 03:23:41,959 --> 03:23:42,959 called constant classes, which you make final. 2339 03:23:42,959 --> 03:23:43,959 And then in the class, you have the public\n 2340 03:23:43,959 --> 03:23:44,959 but it's always better to have small enums.\n 2341 03:23:44,959 --> 03:23:45,959 classes, they would grow. And they would grow\n 2342 03:23:45,959 --> 03:23:46,959 While this only contains the constants of\n 2343 03:23:46,959 --> 03:23:47,959 about this when I talked about enums is type\n 2344 03:23:47,959 --> 03:23:48,959 Okay, so anyway, so now back to our code.\n 2345 03:23:48,959 --> 03:23:49,959 All this is redundant, and should be removed.\n 2346 03:23:49,959 --> 03:23:50,959 before, because it's an implementation detail,\n 2347 03:23:50,959 --> 03:23:51,959 the car should just define what needs to get\n 2348 03:23:51,959 --> 03:23:52,959 behavior has, like it should drive, but the\n 2349 03:23:52,959 --> 03:23:53,959 or slow. This is part of the class and not\n 2350 03:23:53,959 --> 03:23:54,959 when you want to do clean coding. Okay. So\n 2351 03:23:54,959 --> 03:23:55,959 now, when I say implements car, when you you\n 2352 03:23:55,959 --> 03:23:56,959 so, BMW plays the role of being a car. And\n 2353 03:23:56,959 --> 03:23:57,959 interfaces, which we're going to do very soon.\n 2354 03:23:57,959 --> 03:23:58,959 implements car. And Marie cetus implements\n 2355 03:23:58,959 --> 03:23:59,959 I hadn't got to do anything, or implements\n 2356 03:23:59,959 --> 03:24:00,959 implementing the method will normally let\n 2357 03:24:00,959 --> 03:24:01,959 here, code example. You won't do it like this,\n 2358 03:24:01,959 --> 03:24:02,959 an interface. And then you see I already have\n 2359 03:24:02,959 --> 03:24:03,959 I have to implement the abstract method, Dr.\n 2360 03:24:03,959 --> 03:24:04,959 is happy. It has to be exactly like defined\n 2361 03:24:04,959 --> 03:24:05,959 say int as a return value, because this is\n 2362 03:24:05,959 --> 03:24:06,959 now, let me also show you, oh, there's still\n 2363 03:24:06,959 --> 03:24:07,959 brace missing, somehow. Okay, it seems like\n 2364 03:24:07,959 --> 03:24:08,959 small is is well, actually, by the way, I'm\n 2365 03:24:08,959 --> 03:24:09,959 While this is also not true, there are even\n 2366 03:24:09,959 --> 03:24:10,959 even contain a single method. This is a specialty,\n 2367 03:24:10,959 --> 03:24:11,959 usually they would have at most, at least\n 2368 03:24:11,959 --> 03:24:12,959 But again, I want to warn you, I see often\n 2369 03:24:12,959 --> 03:24:13,959 And sometimes it's just too much. It's better\n 2370 03:24:13,959 --> 03:24:14,959 your classes implement several interfaces\n 2371 03:24:14,959 --> 03:24:15,959 your class is going to play. And lo let's\n 2372 03:24:15,959 --> 03:24:16,959 prepared again, adding these methods, because\n 2373 03:24:16,959 --> 03:24:17,959 is the lockable interface, which I defined.\n 2374 03:24:17,959 --> 03:24:18,959 for example, you want to do logging, you want\n 2375 03:24:18,959 --> 03:24:19,959 could have cars, persons whatsoever, everything\n 2376 03:24:19,959 --> 03:24:20,959 to be likable. Such a class must implement\n 2377 03:24:20,959 --> 03:24:21,959 in my learning framework can call. Because\n 2378 03:24:21,959 --> 03:24:22,959 luggable, it will then have a message method\n 2379 03:24:22,959 --> 03:24:23,959 that should be used for logging purposes.\n 2380 03:24:23,959 --> 03:24:24,959 with examples, because what other roles could\n 2381 03:24:24,959 --> 03:24:25,959 And such a property would have an owner, for\n 2382 03:24:25,959 --> 03:24:26,959 I mean, I want to have a BMW, how cool is\n 2383 03:24:26,959 --> 03:24:27,959 came up with the idea, we could also have\n 2384 03:24:27,959 --> 03:24:28,959 a value. And so my BMW also has a value. So\n 2385 03:24:28,959 --> 03:24:29,959 Think this one I have not implemented yet.\n 2386 03:24:29,959 --> 03:24:30,959 car, comma luggable, comma, asset, comma property,\n 2387 03:24:30,959 --> 03:24:31,959 I've implemented already the value method\n 2388 03:24:31,959 --> 03:24:32,959 I still have to implement. And as I said before,\n 2389 03:24:34,959 --> 03:24:35,959 here, we just return something 2390 03:24:36,959 --> 03:24:37,959 Okay, now, I have a class implementing 1234\n 2391 03:24:37,959 --> 03:24:38,959 classes implementing the interfaces. For this,\n 2392 03:24:38,959 --> 03:24:39,959 already do is now my variable my reference\n 2393 03:24:39,959 --> 03:24:40,959 class so my BMW can do everything that a BMW\n 2394 03:24:40,959 --> 03:24:41,959 owner value, these are methods that we inherit,\n 2395 03:24:41,959 --> 03:24:42,959 object class more of this very soon, but these\n 2396 03:24:42,959 --> 03:24:43,959 in the BMW class, so I can use all of them.\n 2397 03:24:43,959 --> 03:24:44,959 Now, what I can also do is, now that I've\n 2398 03:24:44,959 --> 03:24:45,959 I create an object of type in W, but I put\n 2399 03:24:45,959 --> 03:24:46,959 will change the behavior. Now, I can just\n 2400 03:24:46,959 --> 03:24:47,959 plays the role of a car I can also say luggable\n 2401 03:24:47,959 --> 03:24:48,959 because in the context of logging, I don't\n 2402 03:24:48,959 --> 03:24:49,959 and for logging, I would need such a message\nokay. 2403 03:24:50,959 --> 03:24:51,959 now, let me make all these cars and this is\n 2404 03:24:51,959 --> 03:24:52,959 is the object, but the variable when you have\n 2405 03:24:52,959 --> 03:24:53,959 with the with an interface to the object.\n 2406 03:24:53,959 --> 03:24:54,959 your code like imagine the BMW would come\n 2407 03:24:54,959 --> 03:24:55,959 moment we have these three cars, imagine at\n 2408 03:24:55,959 --> 03:24:56,959 Marquess car, then when the when the method\n 2409 03:24:56,959 --> 03:24:57,959 method will work even with new classes introduced\n 2410 03:24:57,959 --> 03:24:58,959 wrote our car service. So whenever possible,\n 2411 03:24:58,959 --> 03:24:59,959 to have a for each loop. And for this, let\n 2412 03:24:59,959 --> 03:25:00,959 also already talked about array called as\n 2413 03:25:00,959 --> 03:25:01,959 I can even do it on the fly. Make it even\n 2414 03:25:03,959 --> 03:25:04,959 Hello, on this array, I can now easily iterate.\n 2415 03:25:04,959 --> 03:25:05,959 said before, each car will drive differently.\n 2416 03:25:05,959 --> 03:25:06,959 our car service does not know any specific\n 2417 03:25:06,959 --> 03:25:07,959 decoupling the code is not coupled so much\n 2418 03:25:07,959 --> 03:25:08,959 all that it uses, all that it knows is now\n 2419 03:25:08,959 --> 03:25:09,959 lines, I iterate over all the cars and I drive\n 2420 03:25:09,959 --> 03:25:10,959 a look if it works. Yeah, see, this is exactly\n 2421 03:25:10,959 --> 03:25:11,959 Porsche he is driving and marmet cetus is\n 2422 03:25:11,959 --> 03:25:12,959 car reference. As you see, we can only execute\n 2423 03:25:12,959 --> 03:25:13,959 And we do have a BMW as the first element\n 2424 03:25:13,959 --> 03:25:14,959 know. All we know is we have an area of cars.\n 2425 03:25:14,959 --> 03:25:15,959 In here. I can also not say BMW, because this\n 2426 03:25:15,959 --> 03:25:16,959 And we don't need to be in w because this\n 2427 03:25:19,959 --> 03:25:20,959 I think this pretty much wraps up my explanation\n 2428 03:25:20,959 --> 03:25:21,959 And now let's have a discussion about the\n 2429 03:25:21,959 --> 03:25:22,959 of interfaces in Java. Well, first of all,\n 2430 03:25:22,959 --> 03:25:23,959 I can tell you, there are not so many. Well,\n 2431 03:25:23,959 --> 03:25:24,959 I have to type down this code. And, of course,\n 2432 03:25:24,959 --> 03:25:25,959 much more. So, and each class that wants to\n 2433 03:25:25,959 --> 03:25:26,959 So there is some added complexity. Also in\n 2434 03:25:26,959 --> 03:25:27,959 And whenever you introduce complexity, this\n 2435 03:25:27,959 --> 03:25:28,959 sense, if it helps us with something, for\n 2436 03:25:28,959 --> 03:25:29,959 over all the cars. And you mentioned there\n 2437 03:25:29,959 --> 03:25:30,959 my for loop would just be the same. So this\n 2438 03:25:30,959 --> 03:25:31,959 my car service at the moment does not implement\n 2439 03:25:31,959 --> 03:25:32,959 of an exception to the rule. Most services\n 2440 03:25:32,959 --> 03:25:33,959 this makes sense, because it's specifically\n 2441 03:25:33,959 --> 03:25:34,959 implementation just here. In my example, it\n 2442 03:25:34,959 --> 03:25:35,959 explain you interfaces and I want to have\n 2443 03:25:35,959 --> 03:25:36,959 And I know I will only have this one class\n 2444 03:25:36,959 --> 03:25:37,959 I implement an interface here? So at the moment,\n 2445 03:25:37,959 --> 03:25:38,959 implemented interface. Sometimes, of course,\n 2446 03:25:38,959 --> 03:25:39,959 personal point of view there is, if I know\n 2447 03:25:39,959 --> 03:25:40,959 need the interface. My probably leave it away.\n 2448 03:25:40,959 --> 03:25:41,959 you can change it, you can refactor your code.\n 2449 03:25:41,959 --> 03:25:42,959 need to interface then edit at a later time.\n 2450 03:25:42,959 --> 03:25:43,959 people that like they love interfaces. And\n 2451 03:25:43,959 --> 03:25:44,959 call interface readers, like an illness, blindly\n 2452 03:25:44,959 --> 03:25:45,959 always just because, and I think this is not\n 2453 03:25:45,959 --> 03:25:46,959 be a disadvantage, because they just make\n 2454 03:25:46,959 --> 03:25:47,959 already pretty much it. To the advantages,\n 2455 03:25:47,959 --> 03:25:48,959 already mentioned, while explaining the interface.\n 2456 03:25:48,959 --> 03:25:49,959 that it decouples your code, as I explained\n 2457 03:25:49,959 --> 03:25:50,959 the cotton Well, no, I was actually like,\n 2458 03:25:50,959 --> 03:25:51,959 the moment, we still say new BMW new Porsche\n 2459 03:25:51,959 --> 03:25:52,959 it would still be coupled. But normally, of\n 2460 03:25:52,959 --> 03:25:53,959 what he would usually do is you forward an\n 2461 03:25:53,959 --> 03:25:54,959 our core service is not coupled to the specific\n 2462 03:25:54,959 --> 03:25:55,959 your code much better than without interfaces.\n 2463 03:25:55,959 --> 03:25:56,959 things, for example, team cooperation. Imagine\n 2464 03:25:56,959 --> 03:25:57,959 and you have a big project that you have to\n 2465 03:25:57,959 --> 03:25:58,959 And then you would probably form smaller sub\n 2466 03:25:58,959 --> 03:25:59,959 a specific area. For example, one team in\n 2467 03:25:59,959 --> 03:26:00,959 while there would be another team implementing\n 2468 03:26:00,959 --> 03:26:01,959 car service is then or might be dependent\n 2469 03:26:01,959 --> 03:26:02,959 And on the other hand, the team that implements\n 2470 03:26:02,959 --> 03:26:03,959 for testing, and for integrating their code\n 2471 03:26:03,959 --> 03:26:04,959 is dependent on the other team. And so each\n 2472 03:26:04,959 --> 03:26:05,959 be finished. And interfaces can be a solution\n 2473 03:26:05,959 --> 03:26:06,959 an interface here, for example, in this case\n 2474 03:26:06,959 --> 03:26:07,959 the different cars would just do a very stupid\n 2475 03:26:07,959 --> 03:26:08,959 I did here, where you don't have real code,\n 2476 03:26:08,959 --> 03:26:09,959 And then the other team can independently\n 2477 03:26:09,959 --> 03:26:10,959 implementations where needed. And only when\n 2478 03:26:10,959 --> 03:26:11,959 So interfaces really help in team cooperation.\n 2479 03:26:11,959 --> 03:26:12,959 include increase your flexibility, because\n 2480 03:26:12,959 --> 03:26:13,959 the cars array as a parameter to our drive\n 2481 03:26:13,959 --> 03:26:14,959 in our test method, we have this drive method.\n 2482 03:26:14,959 --> 03:26:15,959 some condition if it's sunny, just making\n 2483 03:26:15,959 --> 03:26:16,959 And so I create a pushy here, so I would say\n 2484 03:26:16,959 --> 03:26:17,959 equals to new Porsche else if it's not Sunny,\n 2485 03:26:17,959 --> 03:26:18,959 say I take the BMW instead. Because it's better\n 2486 03:26:18,959 --> 03:26:19,959 I don't want to make an error, let me change\n 2487 03:26:19,959 --> 03:26:20,959 So I just say true here, just to have it simple.\n 2488 03:26:20,959 --> 03:26:21,959 be cold. And in my drive method to make this\n 2489 03:26:21,959 --> 03:26:22,959 I would call drive. So now at runtime, we\n 2490 03:26:22,959 --> 03:26:23,959 really adds a lot of power to our code. 2491 03:26:24,959 --> 03:26:25,959 it might be a pushy, and it might be a BMW\n 2492 03:26:27,959 --> 03:26:28,959 I guess there are many, many more advantages\n 2493 03:26:28,959 --> 03:26:29,959 to add. But I think this is enough for the\n 2494 03:26:29,959 --> 03:26:30,959 are. And all the advantages interfaces have.\n 2495 03:26:30,959 --> 03:26:31,959 our interface, serious illness. This will\n 2496 03:26:31,959 --> 03:26:32,959 much wraps it up. I'm going to talk about\n 2497 03:26:32,959 --> 03:26:33,959 a very powerful feature of object oriented\n 2498 03:26:33,959 --> 03:26:34,959 allows to handle a group of similar objects\n 2499 03:26:34,959 --> 03:26:35,959 it also allows to prevent code duplication,\n 2500 03:26:35,959 --> 03:26:36,959 a parent class to its child classes. I'm the\n 2501 03:26:36,959 --> 03:26:37,959 are the instance variables, and the instance\n 2502 03:26:37,959 --> 03:26:38,959 Okay, well, I guess that sounds very promising.\n 2503 03:26:38,959 --> 03:26:39,959 a bit too powerful actually. Well, if used\n 2504 03:26:39,959 --> 03:26:40,959 your code. So really take here and use inheritance\n 2505 03:26:40,959 --> 03:26:41,959 cases to use inheritance. But whenever in\n 2506 03:26:41,959 --> 03:26:42,959 it actually requires some experience to know\n 2507 03:26:42,959 --> 03:26:43,959 it. To give you a real world example, I'm\n 2508 03:26:43,959 --> 03:26:44,959 about maybe 15,000 lines of code. And there.\n 2509 03:26:44,959 --> 03:26:45,959 are alternatives to using inheritance. I'm\n 2510 03:26:46,959 --> 03:26:47,959 let's stop here for a moment. Because now\n 2511 03:26:47,959 --> 03:26:48,959 in the button right corner talking to you\n 2512 03:26:48,959 --> 03:26:49,959 into the code. And I'll show you how to implement\n 2513 03:26:49,959 --> 03:26:50,959 request. I'm doing this videos for you. So\n 2514 03:26:50,959 --> 03:26:51,959 to you. If so, I would be very happy if you\n 2515 03:26:51,959 --> 03:26:52,959 right corner of this video. And remember,\n 2516 03:26:52,959 --> 03:26:53,959 Okay, well enough of advertisement Now, let's\n 2517 03:26:53,959 --> 03:26:54,959 code. Okay, so here you see I have prepared\n 2518 03:26:54,959 --> 03:26:55,959 not really testing something now. This is\n 2519 03:26:55,959 --> 03:26:56,959 example. Um, this example is actually taken\n 2520 03:26:56,959 --> 03:26:57,959 Sierra, she is really my favorite author of\n 2521 03:26:58,959 --> 03:26:59,959 this and any other offer books. In case you\n 2522 03:26:59,959 --> 03:27:00,959 to her books on my blog on market minus b.com.\n 2523 03:27:00,959 --> 03:27:01,959 find her books. Okay. Now back to the code.\n 2524 03:27:01,959 --> 03:27:02,959 we have here an area of animals, similar to\n 2525 03:27:02,959 --> 03:27:03,959 where I introduced you to interfaces, and\n 2526 03:27:03,959 --> 03:27:04,959 a pushy, now we have an animal array with\na dog, a gorilla 2527 03:27:04,959 --> 03:27:05,959 and a line and a tiger. So you should already\n 2528 03:27:05,959 --> 03:27:06,959 you use them, here, it looks quite similar.\n 2529 03:27:07,959 --> 03:27:08,959 And the idea of polymorphism is that on the\n 2530 03:27:08,959 --> 03:27:09,959 variable of this super type a parent class 2531 03:27:09,959 --> 03:27:10,959 animal. But Polly Morphe. I mean, this also\n 2532 03:27:10,959 --> 03:27:11,959 that you have an interface or a super or parent\nclass. 2533 03:27:11,959 --> 03:27:12,959 And on the right side, an animal can be a\n 2534 03:27:12,959 --> 03:27:13,959 so different things can be assigned to the\n 2535 03:27:13,959 --> 03:27:14,959 like, many sides solve can have different\n 2536 03:27:14,959 --> 03:27:15,959 will all be handled uniformly here, I have\n 2537 03:27:15,959 --> 03:27:16,959 jump here. Okay, so you see I've prepared\n 2538 03:27:16,959 --> 03:27:17,959 we still have to implement, I have only prepared\n 2539 03:27:17,959 --> 03:27:18,959 still have to implement the eat method. And\n 2540 03:27:18,959 --> 03:27:19,959 again, totally stupid, arbitrary example.\n 2541 03:27:19,959 --> 03:27:20,959 to have variation. My idea was, I mean, totally\n 2542 03:27:20,959 --> 03:27:21,959 of your code that like because code is always\n 2543 03:27:21,959 --> 03:27:22,959 totally depends on the example that you're\n 2544 03:27:22,959 --> 03:27:23,959 that I said, Well, every animal, a dog, a\n 2545 03:27:23,959 --> 03:27:24,959 different way. Because for example, a gorilla\n 2546 03:27:24,959 --> 03:27:25,959 grass, or leaves or something will align.\n 2547 03:27:25,959 --> 03:27:26,959 my idea was to have an implementation, a concrete\n 2548 03:27:26,959 --> 03:27:27,959 animal subtype. And further, my idea was to\n 2549 03:27:27,959 --> 03:27:28,959 be of a different age. But the calculation\n 2550 03:27:28,959 --> 03:27:29,959 the age. But I mean, this is just my stupid\n 2551 03:27:29,959 --> 03:27:30,959 would be the same for every animal. So my\n 2552 03:27:30,959 --> 03:27:31,959 an animal and have this as an abstract method,\n 2553 03:27:31,959 --> 03:27:32,959 are different. Sorry, yeah, but interfaces\n 2554 03:27:32,959 --> 03:27:33,959 you only have abstract methods. And because\n 2555 03:27:33,959 --> 03:27:34,959 keyword is not needed. But here we can enhance\n 2556 03:27:34,959 --> 03:27:35,959 already jump now to the animal class. So an\n 2557 03:27:35,959 --> 03:27:36,959 class totally empty. So you can use inheritance\n 2558 03:27:37,959 --> 03:27:38,959 methods, public void, eat Later on, I'll make\n 2559 03:27:38,959 --> 03:27:39,959 public void. Ah, oh, okay. So now maybe we\n 2560 03:27:39,959 --> 03:27:40,959 again, avoid system or print boom, just, if\n 2561 03:27:40,959 --> 03:27:41,959 This is the exception polluter rules and it's\n 2562 03:27:41,959 --> 03:27:42,959 in real code. Okay, so I say, animal is eating.\n 2563 03:27:42,959 --> 03:27:43,959 step one, I said every animal is eating in\n 2564 03:27:43,959 --> 03:27:44,959 Okay, it's here the dots to just for fun.\n 2565 03:27:44,959 --> 03:27:45,959 a regular class, you have seen so many times\n 2566 03:27:45,959 --> 03:27:46,959 want the dog to be an animal. Well, if this\n 2567 03:27:46,959 --> 03:27:47,959 you remember, but it's not it's a class and\n 2568 03:27:47,959 --> 03:27:48,959 is extends really, totally easy. Okay, so\n 2569 03:27:48,959 --> 03:27:49,959 using inheritance. Now it's looks like as\n 2570 03:27:49,959 --> 03:27:50,959 can already use these two methods in dog Okay,\n 2571 03:27:52,959 --> 03:27:53,959 extends animal line extends animal. These\n 2572 03:27:53,959 --> 03:27:54,959 to show you and I might just as well do it\n 2573 03:27:54,959 --> 03:27:55,959 extending classes using inheritance we can\n 2574 03:27:55,959 --> 03:27:56,959 extends or first implements, well, there is\n 2575 03:27:56,959 --> 03:27:57,959 and then implements because in Java, we have\n 2576 03:27:57,959 --> 03:27:58,959 a single class, but we can implement any number\n 2577 03:27:58,959 --> 03:27:59,959 separated list. And therefore, to make it\n 2578 03:27:59,959 --> 03:28:00,959 implements and I can say this interface lockable\n 2579 03:28:00,959 --> 03:28:01,959 a role. So Aline can play the role of being\n 2580 03:28:01,959 --> 03:28:02,959 is running on production at a certain time\n 2581 03:28:02,959 --> 03:28:03,959 to print it and therefore we can implement\n 2582 03:28:03,959 --> 03:28:04,959 that align can be a luggable Okay, so, you\n 2583 03:28:04,959 --> 03:28:05,959 have a lot of methods that we have to implement.\n 2584 03:28:05,959 --> 03:28:06,959 order is arbitrary. We can also start with\n 2585 03:28:06,959 --> 03:28:07,959 was it print I hope method. And then there\n 2586 03:28:07,959 --> 03:28:08,959 This might have Yeah, you see, so the rule\n 2587 03:28:08,959 --> 03:28:09,959 as well as when we, when we implement an abstract\n 2588 03:28:09,959 --> 03:28:10,959 signature must be exactly the same. We can't\n 2589 03:28:10,959 --> 03:28:11,959 must be a string, return something just for\n 2590 03:28:16,959 --> 03:28:17,959 So, now, there is still the eat method missing.\n 2591 03:28:17,959 --> 03:28:18,959 concrete. So we don't have to implement the\n 2592 03:28:18,959 --> 03:28:19,959 So see the red is gone. Everything so far\n 2593 03:28:19,959 --> 03:28:20,959 Sue test. Let's check this are the tiger,\n 2594 03:28:20,959 --> 03:28:21,959 the tiger was not an animal yet. Maybe we\n 2595 03:28:21,959 --> 03:28:22,959 interesting. So see, all those classes are\n 2596 03:28:22,959 --> 03:28:23,959 animal. And so these are already animals,\n 2597 03:28:23,959 --> 03:28:24,959 an animal with found is a tiger. Okay, so\n 2598 03:28:24,959 --> 03:28:25,959 animal, and now it's working, the red is gone. 2599 03:28:25,959 --> 03:28:26,959 Okay, but we still haven't done what we want\n 2600 03:28:26,959 --> 03:28:27,959 Now, you probably remember from when I explained\n 2601 03:28:27,959 --> 03:28:28,959 this method body, the implementation, but\n 2602 03:28:29,959 --> 03:28:30,959 the method signature. So let's remove the\n 2603 03:28:30,959 --> 03:28:31,959 we didn't have to, because in interface, all\nthe methods are 2604 03:28:31,959 --> 03:28:32,959 by definition abstract. But here I mean, how\n 2605 03:28:32,959 --> 03:28:33,959 And this one is supposed to be abstract. So\n 2606 03:28:33,959 --> 03:28:34,959 set abstract. But now there is a difference.\n 2607 03:28:36,959 --> 03:28:37,959 what does this mean? Because actually, this\n 2608 03:28:37,959 --> 03:28:38,959 depends on your personal design of the program\n 2609 03:28:38,959 --> 03:28:39,959 be instantiated. Now, we cannot say the compiler\n 2610 03:28:39,959 --> 03:28:40,959 An abstract class is like just the contract,\n 2611 03:28:40,959 --> 03:28:41,959 an interface is just the raw definition. But\n 2612 03:28:41,959 --> 03:28:42,959 class, we can only do so from concrete classes.\n 2613 03:28:42,959 --> 03:28:43,959 methods. So this is something that you have\n 2614 03:28:43,959 --> 03:28:44,959 another warning, I said that this can be used\n 2615 03:28:44,959 --> 03:28:45,959 think, well, cool, I just create some tool\n 2616 03:28:45,959 --> 03:28:46,959 needed anytime for example, age. And then\n 2617 03:28:46,959 --> 03:28:47,959 the inheritance can have several layers. So\n 2618 03:28:47,959 --> 03:28:48,959 again, could extend some class. So now we\n 2619 03:28:48,959 --> 03:28:49,959 that. But I hope you get the idea. Well, even\n 2620 03:28:49,959 --> 03:28:50,959 Because the rule is you have to apply and\n 2621 03:28:50,959 --> 03:28:51,959 the book of Kathy Sierra had first Java. They\n 2622 03:28:51,959 --> 03:28:52,959 So because it's not a tool, we don't say tool.\n 2623 03:28:52,959 --> 03:28:53,959 And so you shouldn't do that as a recommendation.\n 2624 03:28:53,959 --> 03:28:54,959 So yeah, it still has to be made abstract\n 2625 03:28:54,959 --> 03:28:55,959 have to remove new animal as I said, doesn't\n 2626 03:28:56,959 --> 03:28:57,959 let's go into our classes again. See, now\n 2627 03:28:57,959 --> 03:28:58,959 abstract, we also forced to implement it.\n 2628 03:28:58,959 --> 03:28:59,959 have to implement this method. And again,\n 2629 03:28:59,959 --> 03:29:00,959 is eating dot dot dot Okay, So gorilla is\n 2630 03:29:00,959 --> 03:29:01,959 grass or something reuleaux is eating leaves.\n 2631 03:29:01,959 --> 03:29:02,959 again, and the tiger is eating something.\n 2632 03:29:02,959 --> 03:29:03,959 method in their own unique way. So in reality,\n 2633 03:29:03,959 --> 03:29:04,959 print on but some specific, Tiger related\n 2634 03:29:04,959 --> 03:29:05,959 why we have it here. And all the logic that\n 2635 03:29:05,959 --> 03:29:06,959 by the way, I mean, on the one hand, this\n 2636 03:29:06,959 --> 03:29:07,959 double sided sword. I mean, this is handy\n 2637 03:29:07,959 --> 03:29:08,959 is really complex. Because when you're in\n 2638 03:29:08,959 --> 03:29:09,959 implements eat, and which animal just inherits\n 2639 03:29:09,959 --> 03:29:10,959 because we could of course, again mix that.\n 2640 03:29:10,959 --> 03:29:11,959 example, ah, this one is implemented. But\n 2641 03:29:11,959 --> 03:29:12,959 age by itself are not something. So this is\n 2642 03:29:12,959 --> 03:29:13,959 the rule. You could say, well, my gorilla\n 2643 03:29:13,959 --> 03:29:14,959 H method is replaced by exactly this method. 2644 03:29:14,959 --> 03:29:15,959 And the way this is done is, the signature\n 2645 03:29:15,959 --> 03:29:16,959 pretty much looking the same. You can't like\n 2646 03:29:17,959 --> 03:29:18,959 Well, you see, you can, but it's just not\n 2647 03:29:18,959 --> 03:29:19,959 not yellow, but gray. Um, this is called overloading\n 2648 03:29:19,959 --> 03:29:20,959 a method that has the same name as another\n 2649 03:29:20,959 --> 03:29:21,959 different. So this has nothing to do with\n 2650 03:29:21,959 --> 03:29:22,959 and override me override it, it has to have\n 2651 03:29:22,959 --> 03:29:23,959 And for this, I have to introduce a new visibility\n 2652 03:29:23,959 --> 03:29:24,959 it in an earlier episode, but I didn't really\n 2653 03:29:24,959 --> 03:29:25,959 Now what means protected? protected, means\n 2654 03:29:25,959 --> 03:29:26,959 default, or package level visibility, and\n 2655 03:29:26,959 --> 03:29:27,959 method. In Su. See, this is not read. It also\n 2656 03:29:27,959 --> 03:29:28,959 animal. In our case, now, we have all the\n 2657 03:29:28,959 --> 03:29:29,959 we had a car sitting, extend animal, I mean,\n 2658 03:29:29,959 --> 03:29:30,959 But just technically not from a design perspective.\n 2659 03:29:30,959 --> 03:29:31,959 protected. So the visibility is to any class\n 2660 03:29:31,959 --> 03:29:32,959 that is in the same package. And this again,\n 2661 03:29:32,959 --> 03:29:33,959 to explain? so that you understand, and this\n 2662 03:29:33,959 --> 03:29:34,959 you to passively know when someone else uses\n 2663 03:29:34,959 --> 03:29:35,959 visibility is less visible than public. And\n 2664 03:29:35,959 --> 03:29:36,959 the visibility in a child class. So where\n 2665 03:29:36,959 --> 03:29:37,959 I can say public void. Now this is still not\n 2666 03:29:37,959 --> 03:29:38,959 I can say public And now I can also say protected,\n 2667 03:29:38,959 --> 03:29:39,959 as in parent class animal. But I'm not allowed\n 2668 03:29:39,959 --> 03:29:40,959 error, attempting to assign weaker access\n 2669 03:29:40,959 --> 03:29:41,959 to make it public, but not less than protected.\n 2670 03:29:41,959 --> 03:29:42,959 method defines a contract a protocol. Exactly.\n 2671 03:29:42,959 --> 03:29:43,959 you promise any other class in the Java universe?\n 2672 03:29:43,959 --> 03:29:44,959 is public. And you can call it. And me. You\n 2673 03:29:44,959 --> 03:29:45,959 If there is one class that just does not fulfill\n 2674 03:29:45,959 --> 03:29:46,959 it has to have the same visibility. Oh, okay.\n 2675 03:29:46,959 --> 03:29:47,959 members of a class. And I said, the members\n 2676 03:29:47,959 --> 03:29:48,959 are the instance methods, and the instance\n 2677 03:29:48,959 --> 03:29:49,959 I'm in H. And this will also be inherited.\n 2678 03:29:49,959 --> 03:29:50,959 I mean, this is the H method. Maybe I should\n 2679 03:29:52,959 --> 03:29:53,959 And now I can say this dot age, or just age?\n 2680 03:29:54,959 --> 03:29:55,959 45. So this would now we'll set the age to\n 2681 03:29:55,959 --> 03:29:56,959 this. Because we know what we mean. 2682 03:29:57,959 --> 03:29:58,959 even though this is possible, we inherit the\n 2683 03:29:58,959 --> 03:29:59,959 first of all, because I don't like protected\n 2684 03:29:59,959 --> 03:30:00,959 kind of violates the capsulation because the\n 2685 03:30:00,959 --> 03:30:01,959 its internal variables. Okay. So avoid protected\n 2686 03:30:01,959 --> 03:30:02,959 the the instance members visible. If we have\n 2687 03:30:02,959 --> 03:30:03,959 Well, I have to implement it. Of course, this\n 2688 03:30:03,959 --> 03:30:04,959 animal dot something can also be used now.\n 2689 03:30:04,959 --> 03:30:05,959 dot something. Yeah, you see, it's also formed\n 2690 03:30:06,959 --> 03:30:07,959 But this will not be inherited. So you cannot,\n 2691 03:30:07,959 --> 03:30:08,959 class again, you can say animal dot something 2692 03:30:08,959 --> 03:30:09,959 will actually you can even say and this is\n 2693 03:30:09,959 --> 03:30:10,959 is not inheritance. It's just Java is a bit\n 2694 03:30:10,959 --> 03:30:11,959 It knows gorilla is an animal. So it realizes\n 2695 03:30:12,959 --> 03:30:13,959 But this is still not inheritance. Oh, K.\n 2696 03:30:13,959 --> 03:30:14,959 you too much with that static. 2697 03:30:14,959 --> 03:30:15,959 Just remember, we only inheriting the members\n 2698 03:30:15,959 --> 03:30:16,959 instance variables. All Okay. Well, I think\n 2699 03:30:16,959 --> 03:30:17,959 it again. And now we see dog is eating. He\n 2700 03:30:17,959 --> 03:30:18,959 implementing the H by itself. This was I was\n 2701 03:30:18,959 --> 03:30:19,959 in gorilla lion is eating, he has calculated\n 2702 03:30:19,959 --> 03:30:20,959 really is a complex beast. And in conclusion,\n 2703 03:30:20,959 --> 03:30:21,959 say, when you can apply the is a test. A dog\n 2704 03:30:21,959 --> 03:30:22,959 is an animal, a tiger is an animal, a tool\n 2705 03:30:22,959 --> 03:30:23,959 extends animal never. Um, if you're just looking\n 2706 03:30:23,959 --> 03:30:24,959 to not duplicate code, you can do something\n 2707 03:30:24,959 --> 03:30:25,959 tool object. And then always you can use composition.\n 2708 03:30:25,959 --> 03:30:26,959 don't know, um, has a leg. If that makes sense\n 2709 03:30:26,959 --> 03:30:27,959 And then you if you have a method, for example,\n 2710 03:30:27,959 --> 03:30:28,959 have another animal that also needs up it\n 2711 03:30:28,959 --> 03:30:29,959 now if you have another animal that should\n 2712 03:30:30,959 --> 03:30:31,959 this member. And this by the way can and also\n 2713 03:30:31,959 --> 03:30:32,959 it much more flexible actually, even than\n 2714 03:30:32,959 --> 03:30:33,959 can exchange the behavior at runtime. This\n 2715 03:30:33,959 --> 03:30:34,959 talking about interfaces, where I said you\n 2716 03:30:36,959 --> 03:30:37,959 this implementation and otherwise the other\n 2717 03:30:37,959 --> 03:30:38,959 code. Just very fast. Else. I just hope you\n 2718 03:30:38,959 --> 03:30:39,959 equals to my fast leg, legs, you know. 2719 03:30:40,959 --> 03:30:41,959 the other days, I'm not so fast. I say used\n 2720 03:30:43,959 --> 03:30:44,959 so of course I mean this if else again introduces\n 2721 03:30:44,959 --> 03:30:45,959 there's always pros and cons, you have to\n 2722 03:30:45,959 --> 03:30:46,959 use this, just to give you one example to\n 2723 03:30:46,959 --> 03:30:47,959 your code. Oh, okay. Let me remove that. Don't\n 2724 03:30:47,959 --> 03:30:48,959 Okay, now, let's maybe recap before I finished\n 2725 03:30:48,959 --> 03:30:49,959 We talked about polymorphism. I showed you\n 2726 03:30:49,959 --> 03:30:50,959 actually design principle it's called favor\n 2727 03:30:50,959 --> 03:30:51,959 you you can mix using inheritance with was\n 2728 03:30:51,959 --> 03:30:52,959 I showed you can implement several interfaces,\n 2729 03:30:52,959 --> 03:30:53,959 say it already. When I do the calmer Something\n 2730 03:30:53,959 --> 03:30:54,959 doesn't work. Just believe me for now. Or\n 2731 03:30:54,959 --> 03:30:55,959 is implemented. Yeah. So you see class cannot\n 2732 03:30:55,959 --> 03:30:56,959 class. And it's even more nasty than Single\n 2733 03:30:56,959 --> 03:30:57,959 the deadly diamond of death. But I will not\n 2734 03:30:57,959 --> 03:30:58,959 can google this deadly diamond of death. Because\n 2735 03:30:58,959 --> 03:30:59,959 I'm going to talk about the method finalize\n 2736 03:30:59,959 --> 03:31:00,959 root of the class hierarchy. Every class in\n 2737 03:31:00,959 --> 03:31:01,959 of this class. So this is what makes those\n 2738 03:31:01,959 --> 03:31:02,959 also the reason why those methods are very\n 2739 03:31:02,959 --> 03:31:03,959 questions. So one way or the other, I hope\n 2740 03:31:03,959 --> 03:31:04,959 should now that this episode, as well as the\n 2741 03:31:04,959 --> 03:31:05,959 are based on the really great book, Effective\n 2742 03:31:05,959 --> 03:31:06,959 I mentioned it already earlier. Now I have\n 2743 03:31:06,959 --> 03:31:07,959 better would be if you read it twice. It's\n 2744 03:31:07,959 --> 03:31:08,959 developer must know my episode is supposed\n 2745 03:31:08,959 --> 03:31:09,959 But for more detailed information, it's necessary\n 2746 03:31:09,959 --> 03:31:10,959 start talking about the finalize method. The\n 2747 03:31:10,959 --> 03:31:11,959 What is a hook method? a hook method is a\n 2748 03:31:11,959 --> 03:31:12,959 provided in the class object. And the idea\n 2749 03:31:12,959 --> 03:31:13,959 he would provide an implementation in your\n 2750 03:31:13,959 --> 03:31:14,959 by overwriting this method. And then this\n 2751 03:31:14,959 --> 03:31:15,959 I go in more details, the one the most important\n 2752 03:31:15,959 --> 03:31:16,959 is flawed. So the best you can probably do,\n 2753 03:31:16,959 --> 03:31:17,959 method. So not using it because it has its\n 2754 03:31:17,959 --> 03:31:18,959 mean, there are some few valid users, at least\n 2755 03:31:18,959 --> 03:31:19,959 I can tell you, I'm developing in Java since\n 2756 03:31:19,959 --> 03:31:20,959 never ever overwritten this method. So today\n 2757 03:31:20,959 --> 03:31:21,959 you what it is what it does. Okay. So maybe\n 2758 03:31:21,959 --> 03:31:22,959 because it might be easier to understand for\n 2759 03:31:22,959 --> 03:31:23,959 So the finalize method is called by the garbage\n 2760 03:31:23,959 --> 03:31:24,959 terminate determines that there are no more\n 2761 03:31:24,959 --> 03:31:25,959 was probably what is the garbage collector?\n 2762 03:31:25,959 --> 03:31:26,959 cool thing of the Java language. Other languages\n 2763 03:31:26,959 --> 03:31:27,959 it collects the garbage what's the garbage\n 2764 03:31:27,959 --> 03:31:28,959 worked on them. And after some time, the process\n 2765 03:31:28,959 --> 03:31:29,959 he will not need them anymore. And so it helps\n 2766 03:31:29,959 --> 03:31:30,959 you hopefully never run into out of memory\n 2767 03:31:30,959 --> 03:31:31,959 cover as synchronously by the garbage collector\n 2768 03:31:31,959 --> 03:31:32,959 the finalize method. Because I said it's,\n 2769 03:31:32,959 --> 03:31:33,959 runs. The problem is the garbage collector\n 2770 03:31:33,959 --> 03:31:34,959 when or if the garbage collector is running.\n 2771 03:31:34,959 --> 03:31:35,959 no influence to tell it that it should run.\n 2772 03:31:35,959 --> 03:31:36,959 you have no guarantee that the garbage collector\n 2773 03:31:36,959 --> 03:31:37,959 that the finalized method will ever run. Yeah,\n 2774 03:31:37,959 --> 03:31:38,959 method, the idea was, you will also clean\n 2775 03:31:38,959 --> 03:31:39,959 resources, but not memory real related resources.\n 2776 03:31:39,959 --> 03:31:40,959 i o resource, like a database or a file, those\n 2777 03:31:40,959 --> 03:31:41,959 are limited. So if you don't want to get in\n 2778 03:31:41,959 --> 03:31:42,959 totally, totally freezes. You have to, again,\n 2779 03:31:42,959 --> 03:31:43,959 anymore. So the idea was to do that in a finalized\n 2780 03:31:43,959 --> 03:31:44,959 guarantee that runs. And this already says\n 2781 03:31:44,959 --> 03:31:45,959 Joshua Bloch also gives other reasons. For\n 2782 03:31:45,959 --> 03:31:46,959 an object and destroying it, again, is 430\n 2783 03:31:46,959 --> 03:31:47,959 implemented. So again, don't use it. And now\n 2784 03:31:47,959 --> 03:31:48,959 detail from a practical point of view. Okay.\n 2785 03:31:48,959 --> 03:31:49,959 you might have seen, this method is actually\n 2786 03:31:49,959 --> 03:31:50,959 void finalize, I mean, this Java API is just\n 2787 03:31:50,959 --> 03:31:51,959 see the source code of object dot java. So\n 2788 03:31:51,959 --> 03:31:52,959 And you'll also see this method is empty.\n 2789 03:31:52,959 --> 03:31:53,959 idea is that you override the method and that\n 2790 03:31:54,959 --> 03:31:55,959 And Java, try to prevent that you directly\n 2791 03:31:55,959 --> 03:31:56,959 the idea is that you don't call it but that\n 2792 03:31:56,959 --> 03:31:57,959 method is actually protected. Protected is\n 2793 03:31:57,959 --> 03:31:58,959 use a method that is protected is if you are\n 2794 03:31:58,959 --> 03:31:59,959 isn't a package Java Lang. So I thought being\n 2795 03:31:59,959 --> 03:32:00,959 this package. And this is what I did here,\n 2796 03:32:00,959 --> 03:32:01,959 everything seems fine. I don't have any exception\n 2797 03:32:01,959 --> 03:32:02,959 this method. And you see, this dot finalize,\n 2798 03:32:02,959 --> 03:32:03,959 because this is a static method. So we would\n 2799 03:32:03,959 --> 03:32:04,959 also say, new object. Well, there is an exception,\n 2800 03:32:04,959 --> 03:32:05,959 here at the bottom. I'm not going to handle\n 2801 03:32:05,959 --> 03:32:06,959 from a theoretical point of view, this is\n 2802 03:32:06,959 --> 03:32:07,959 now surrounded with a try catch to get the\n 2803 03:32:07,959 --> 03:32:08,959 directly calling finalize, from a class that\n 2804 03:32:08,959 --> 03:32:09,959 public static void Main method. So I execute\n 2805 03:32:09,959 --> 03:32:10,959 It's prohibited. I cannot use Java Lang as\n 2806 03:32:10,959 --> 03:32:11,959 I just thought I should show you. I think\n 2807 03:32:11,959 --> 03:32:12,959 this again. And let's complete remove this\n 2808 03:32:12,959 --> 03:32:13,959 I mean, I said object is the root class, but\n 2809 03:32:13,959 --> 03:32:14,959 objects of the class object. What I don't\n 2810 03:32:14,959 --> 03:32:15,959 twice, because the class is called object.\n 2811 03:32:15,959 --> 03:32:16,959 you can call all those methods. But here within\n 2812 03:32:16,959 --> 03:32:17,959 finalize method. Okay. So for this, I have\n 2813 03:32:17,959 --> 03:32:18,959 the object class. And now let's override the\n 2814 03:32:18,959 --> 03:32:19,959 any parameter. So to override a method, it\n 2815 03:32:19,959 --> 03:32:20,959 Like in the superclass, the only difference\n 2816 03:32:20,959 --> 03:32:21,959 anymore, I can make it public. Because public\n 2817 03:32:21,959 --> 03:32:22,959 Okay. And now, the idea would be that in here,\n 2818 03:32:22,959 --> 03:32:23,959 I had some i, o reader, i, o reader, reader,\n 2819 03:32:23,959 --> 03:32:24,959 so that you get the idea. So the idea was\n 2820 03:32:24,959 --> 03:32:25,959 close those resources for this, usually I\n 2821 03:32:25,959 --> 03:32:26,959 are several problems for one, I said, you\n 2822 03:32:26,959 --> 03:32:27,959 ever called. This is totally in control by\n 2823 03:32:27,959 --> 03:32:28,959 running out of your control, it's running\n 2824 03:32:28,959 --> 03:32:29,959 really serve our purpose. Second flaw is,\n 2825 03:32:31,959 --> 03:32:32,959 process here will be stopped. And our objects\n 2826 03:32:32,959 --> 03:32:33,959 state. Yeah. Okay, so the question is, what's\n 2827 03:32:33,959 --> 03:32:34,959 method, the alternative would be, if you have\n 2828 03:32:34,959 --> 03:32:35,959 that you want to be closed before it's cleaned\n 2829 03:32:35,959 --> 03:32:36,959 the reader would do. You could and you should\n 2830 03:32:36,959 --> 03:32:37,959 you do clean up i o resources. I'm going to\n 2831 03:32:37,959 --> 03:32:38,959 in car selector. Let's imagine this was a\n 2832 03:32:38,959 --> 03:32:39,959 Porsche, a new Porsche you use a try Finally,\n 2833 03:32:39,959 --> 03:32:40,959 And I think, there in this episode, I told\n 2834 03:32:40,959 --> 03:32:41,959 but you can also use the finally without a\n 2835 03:32:41,959 --> 03:32:42,959 is a different discussion. What is important\n 2836 03:32:42,959 --> 03:32:43,959 the finally the cool thing about the Finally,\n 2837 03:32:43,959 --> 03:32:44,959 it will always be executed. Because this was\n 2838 03:32:44,959 --> 03:32:45,959 non memory resources get cleaned up. Okay,\n 2839 03:32:45,959 --> 03:32:46,959 say Porsche e dot close to clean up the resources.\n 2840 03:32:46,959 --> 03:32:47,959 Also, shortly, let me show you what I think\n 2841 03:32:47,959 --> 03:32:48,959 and the finalize method. What I also want\n 2842 03:32:48,959 --> 03:32:49,959 the method from the class object which is\n 2843 03:32:49,959 --> 03:32:50,959 that is quite helpful here. And this is the\n 2844 03:32:50,959 --> 03:32:51,959 when I put the ad, there is override. So about\n 2845 03:32:51,959 --> 03:32:52,959 yet. So let me explain that. In short, this\n 2846 03:32:52,959 --> 03:32:53,959 compiler, that you say, Well, my intent here\n 2847 03:32:53,959 --> 03:32:54,959 has a different name, some other name. Here,\n 2848 03:32:54,959 --> 03:32:55,959 not override any method from its superclass.\n 2849 03:32:55,959 --> 03:32:56,959 us. So let's, again, call it finalize. Now\n 2850 03:32:56,959 --> 03:32:57,959 the signature is the same as in the superclass.\n 2851 03:32:57,959 --> 03:32:58,959 not overriding anymore, but overloading the\n 2852 03:32:58,959 --> 03:32:59,959 the same name. But as it has a different parameter,\n 2853 03:32:59,959 --> 03:33:00,959 This is not overriding anymore. And now we\n 2854 03:33:00,959 --> 03:33:01,959 notice. So this helps us to have the problem\n 2855 03:33:01,959 --> 03:33:02,959 in our ID. And we will not because otherwise\n 2856 03:33:02,959 --> 03:33:03,959 a method while you have not. And then you're\n 2857 03:33:03,959 --> 03:33:04,959 you will only see when your code runs on production.\n 2858 03:33:04,959 --> 03:33:05,959 at this override, annotation. Okay. So I think\n 2859 03:33:05,959 --> 03:33:06,959 finalize method. In short, again, generally\n 2860 03:33:06,959 --> 03:33:07,959 non memory resources use a try Finally, I'm\n 2861 03:33:08,959 --> 03:33:09,959 a class object I said before, is the superclass\n 2862 03:33:09,959 --> 03:33:10,959 this is why you can use the method clone in\n 2863 03:33:10,959 --> 03:33:11,959 you Really? And the short answer is, you should\n 2864 03:33:11,959 --> 03:33:12,959 is similar to the finalize method that we\n 2865 03:33:12,959 --> 03:33:13,959 again, the reason why I'm talking about clone\n 2866 03:33:13,959 --> 03:33:14,959 quite similar. Okay, but before going in more\n 2867 03:33:14,959 --> 03:33:15,959 what actually does the clone method do. And\n 2868 03:33:15,959 --> 03:33:16,959 copy of the object that you call clone on.\n 2869 03:33:16,959 --> 03:33:17,959 object, you can always assign it a second\n 2870 03:33:17,959 --> 03:33:18,959 The problem is with references, that when\n 2871 03:33:18,959 --> 03:33:19,959 will have will be influenced by your changes.\n 2872 03:33:19,959 --> 03:33:20,959 want an independent copy. And for this reason,\n 2873 03:33:20,959 --> 03:33:21,959 are actually better alternatives, which I'll\n 2874 03:33:21,959 --> 03:33:22,959 Anyway, let's jump into my ad and look at\n 2875 03:33:22,959 --> 03:33:23,959 test, you might remember the pushy and the\n 2876 03:33:23,959 --> 03:33:24,959 I show you the nasty stuff, I wanted to show\n 2877 03:33:24,959 --> 03:33:25,959 clone is actually good. And this is here I\n 2878 03:33:25,959 --> 03:33:26,959 here, I mean array is also an object. So it\n 2879 03:33:26,959 --> 03:33:27,959 for the array, it was already implemented\n 2880 03:33:27,959 --> 03:33:28,959 clone your array. So I can say string copied\n 2881 03:33:28,959 --> 03:33:29,959 I can assert not same, which means this check\n 2882 03:33:29,959 --> 03:33:30,959 In this case, it would be the same 2883 03:33:31,959 --> 03:33:32,959 and copied airy. Which, to show you that their\n 2884 03:33:32,959 --> 03:33:33,959 twice the same reference. So this should be\n 2885 03:33:33,959 --> 03:33:34,959 there are two different instances. 2886 03:33:34,959 --> 03:33:35,959 You see, it finished with a green bar, this\n 2887 03:33:35,959 --> 03:33:36,959 and error compared to itself, it's both the\n 2888 03:33:36,959 --> 03:33:37,959 the same object. But the copy is not the same\n 2889 03:33:37,959 --> 03:33:38,959 a new object. And now, I mean, I want to make\n 2890 03:33:38,959 --> 03:33:39,959 system out, print ln. And then, you know,\n 2891 03:33:39,959 --> 03:33:40,959 element and then I just hope you believe me,\n 2892 03:33:40,959 --> 03:33:41,959 whole elements in in an in a loop. Now I'm\n 2893 03:33:41,959 --> 03:33:42,959 and you see it's one. So the other ones are\n 2894 03:33:42,959 --> 03:33:43,959 telling me copied error. This way, you also\n 2895 03:33:43,959 --> 03:33:44,959 And this is now I can print odd STR and this\n 2896 03:33:46,959 --> 03:33:47,959 So I hope this is working now. 123 C, out.\n 2897 03:33:47,959 --> 03:33:48,959 was just a very short demonstration of a good\n 2898 03:33:48,959 --> 03:33:49,959 and very interesting article Actually, it's\n 2899 03:33:49,959 --> 03:33:50,959 he's really a very cool guy. I love his newsletters.\n 2900 03:33:50,959 --> 03:33:51,959 that clone for very small areas might be a\n 2901 03:33:51,959 --> 03:33:52,959 arrays, it's actually faster than any other\n 2902 03:33:52,959 --> 03:33:53,959 don't have the time. And this is also very,\n 2903 03:33:53,959 --> 03:33:54,959 beginner level, approaching more advanced.\n 2904 03:33:54,959 --> 03:33:55,959 And this is now really test driven style programming.\n 2905 03:33:55,959 --> 03:33:56,959 is not finished, we start with writing a test\n 2906 03:33:56,959 --> 03:33:57,959 we are working our way to get the test screen.\n 2907 03:33:57,959 --> 03:33:58,959 Porsche, actually, this is something you can't\n 2908 03:33:58,959 --> 03:33:59,959 adjusted my class a bit. I mean, you might\n 2909 03:33:59,959 --> 03:34:00,959 because it was empty. Initially, there was\n 2910 03:34:00,959 --> 03:34:01,959 I had to change because I want to show you\n 2911 03:34:01,959 --> 03:34:02,959 And I said, it's the owner, the name of the\n 2912 03:34:02,959 --> 03:34:03,959 Because I always wanted to own a Porsche.\n 2913 03:34:03,959 --> 03:34:04,959 owner of the Porsche. And because you probably\n 2914 03:34:04,959 --> 03:34:05,959 make you the owner of our copy of our clone.\n 2915 03:34:05,959 --> 03:34:06,959 I might just as well copy mine and then give\n 2916 03:34:06,959 --> 03:34:07,959 pretty much impossible. However, here in Java,\n 2917 03:34:07,959 --> 03:34:08,959 is I don't know your name. So for this example,\n 2918 03:34:08,959 --> 03:34:09,959 Peters for xi equals to new pushy. But this\n 2919 03:34:09,959 --> 03:34:10,959 to clone. Yeah, because this is no easy. I\n 2920 03:34:10,959 --> 03:34:11,959 pushy but this is not the original idea. So\n 2921 03:34:11,959 --> 03:34:12,959 dot clone. And interesting enough, really,\n 2922 03:34:12,959 --> 03:34:13,959 covers, because this is done really, by the\n 2923 03:34:13,959 --> 03:34:14,959 it works. But there is never a constructor\n 2924 03:34:14,959 --> 03:34:15,959 copied from the memory. It's just see, we\n 2925 03:34:15,959 --> 03:34:16,959 I mean, I said, we start with a not working\n 2926 03:34:16,959 --> 03:34:17,959 and Java Lang object. And this is something\n 2927 03:34:17,959 --> 03:34:18,959 method is already there. The problem is, it's\n 2928 03:34:18,959 --> 03:34:19,959 Protected would be visible in the same package.\n 2929 03:34:19,959 --> 03:34:20,959 Lang, as I showed you last time. But here\n 2930 03:34:20,959 --> 03:34:21,959 test does not inherit anything from Porsche.\n 2931 03:34:21,959 --> 03:34:22,959 clone in here. Okay, but what I can and what\n 2932 03:34:22,959 --> 03:34:23,959 method. But still, I want the code the implementation\n 2933 03:34:23,959 --> 03:34:24,959 into the Porsche class. So I will override\n 2934 03:34:26,959 --> 03:34:27,959 And then you might still remember from my\n 2935 03:34:27,959 --> 03:34:28,959 override here to have a check from the compiler\n 2936 03:34:28,959 --> 03:34:29,959 Now, let me format that. Okay. And you see,\n 2937 03:34:29,959 --> 03:34:30,959 everything is fine. We'll actually went into\n 2938 03:34:30,959 --> 03:34:31,959 says object, because in object, what could\n 2939 03:34:31,959 --> 03:34:32,959 the method always is exactly copying whatever\n 2940 03:34:32,959 --> 03:34:33,959 a Porsche. So the so it is also fine to directly\n 2941 03:34:33,959 --> 03:34:34,959 empty implementation. And we have to return\n 2942 03:34:34,959 --> 03:34:35,959 But again, this would not be a clone. So this\n 2943 03:34:35,959 --> 03:34:36,959 this is not what we can do. So we have to\n 2944 03:34:36,959 --> 03:34:37,959 from superclass in this case object. And you\n 2945 03:34:37,959 --> 03:34:38,959 the first method, because my ID is already\n 2946 03:34:38,959 --> 03:34:39,959 clone. So it assumes I want to call super\n 2947 03:34:39,959 --> 03:34:40,959 it. So all we did so far is we override the\n 2948 03:34:40,959 --> 03:34:41,959 I don't really want to override it. All I\n 2949 03:34:41,959 --> 03:34:42,959 object. So all we did so far is we made the\n 2950 03:34:42,959 --> 03:34:43,959 it this is all we did so far. But now, you\n 2951 03:34:43,959 --> 03:34:44,959 Java Lang clone, not supported exception.\n 2952 03:34:44,959 --> 03:34:45,959 because, like, why does this Now throw a clone\n 2953 03:34:45,959 --> 03:34:46,959 clone. So, anyway, this is how it is. And\n 2954 03:34:46,959 --> 03:34:47,959 is we say try, because there is an exception\n 2955 03:34:47,959 --> 03:34:48,959 Catch. And there my ID Egan helps me clear\n 2956 03:34:48,959 --> 03:34:49,959 I usually give it the name here. Okay, now,\n 2957 03:34:49,959 --> 03:34:50,959 now. Because we have to return something.\n 2958 03:34:50,959 --> 03:34:51,959 to return something. But this is not so nice.\n 2959 03:34:51,959 --> 03:34:52,959 never happening. But if it for whatever reason\n 2960 03:34:52,959 --> 03:34:53,959 is a problem. So in this case, and I kind\n 2961 03:34:53,959 --> 03:34:54,959 my episode here about clone is based on his\n 2962 03:34:54,959 --> 03:34:55,959 was exactly the same with a finalized episode.\n 2963 03:34:55,959 --> 03:34:56,959 to the topic. Um, Josh block in his book,\n 2964 03:34:56,959 --> 03:34:57,959 clone method. You should really buy the book\n 2965 03:34:57,959 --> 03:34:58,959 minus bu.com, click on mastery, it's, and\n 2966 03:34:58,959 --> 03:34:59,959 it directly. Yeah, also all the books in the\n 2967 03:34:59,959 --> 03:35:00,959 name for a reason. Those are really books.\n 2968 03:35:00,959 --> 03:35:01,959 classics, the best of the best best Java books\n 2969 03:35:01,959 --> 03:35:02,959 if you trust me by that book and read it,\n 2970 03:35:02,959 --> 03:35:03,959 do the same, as he said, throw new assertion\n 2971 03:35:03,959 --> 03:35:04,959 even an exception. Is this really an error?\n 2972 03:35:04,959 --> 03:35:05,959 this clone, not supported exception. Okay,\n 2973 03:35:05,959 --> 03:35:06,959 something wrong. And this is it says I'm calling\n 2974 03:35:06,959 --> 03:35:07,959 the method from object, an object returns\n 2975 03:35:07,959 --> 03:35:08,959 the method. But we are smarter we know actually,\n 2976 03:35:08,959 --> 03:35:09,959 I mean, the super type is object. But the\n 2977 03:35:09,959 --> 03:35:10,959 cast, and we cast it to Porsche. This is safe\n 2978 03:35:10,959 --> 03:35:11,959 a class not support F. Class cast exception.\n 2979 03:35:11,959 --> 03:35:12,959 see. It'll it should work. Okay, well, are\n 2980 03:35:12,959 --> 03:35:13,959 as I said, this method is flawed. So we are\n 2981 03:35:13,959 --> 03:35:14,959 But this I want to see. I mean, my idea was\n 2982 03:35:14,959 --> 03:35:15,959 let's go back to our test, you see, everything\n 2983 03:35:15,959 --> 03:35:16,959 has gone. So I can execute the test. But I\n 2984 03:35:16,959 --> 03:35:17,959 assert that I want to do is I want to assert\n 2985 03:35:17,959 --> 03:35:18,959 of saying not equal. So it won't be the same\n 2986 03:35:18,959 --> 03:35:19,959 pushy, because the idea is that when my clone\n 2987 03:35:19,959 --> 03:35:20,959 it's good to have a method that already from\n 2988 03:35:20,959 --> 03:35:21,959 this one. And I compare not pushy to Peters\n 2989 03:35:21,959 --> 03:35:22,959 that this reference here is not referencing\n 2990 03:35:22,959 --> 03:35:23,959 this isn't our first test all I want to achieve.\n 2991 03:35:24,959 --> 03:35:25,959 You see the assertion error? I said, Well,\n 2992 03:35:25,959 --> 03:35:26,959 And this is why tests are so great. Yes. And\n 2993 03:35:26,959 --> 03:35:27,959 why did this happen? Okay, so by jumping here,\n 2994 03:35:27,959 --> 03:35:28,959 is here in this case, without further knowledge,\n 2995 03:35:28,959 --> 03:35:29,959 So here, sorry, I have to help a bit. Thing\n 2996 03:35:29,959 --> 03:35:30,959 It's not enough to use the power of inheritance\n 2997 03:35:30,959 --> 03:35:31,959 implement an interface here. So we are already\n 2998 03:35:31,959 --> 03:35:32,959 you in the episode about interfaces, we can\n 2999 03:35:32,959 --> 03:35:33,959 now to implement the cloneable interface from\n 3000 03:35:33,959 --> 03:35:34,959 the interface, normally, I would expect that\n 3001 03:35:34,959 --> 03:35:35,959 in this case, it's different. We don't have\n 3002 03:35:35,959 --> 03:35:36,959 case, this interface we call a market interface.\n 3003 03:35:36,959 --> 03:35:37,959 nothing in there. It just tells the JVM. I'm\n 3004 03:35:37,959 --> 03:35:38,959 here, it's a clone here it works. And this\n 3005 03:35:38,959 --> 03:35:39,959 implement an interface, you would on the Reference\n 3006 03:35:39,959 --> 03:35:40,959 I can also make this a cloneable. So that\n 3007 03:35:40,959 --> 03:35:41,959 a cloneable. The problem is, this doesn't\n 3008 03:35:41,959 --> 03:35:42,959 cloneable. Here, all I have is the other methods\n 3009 03:35:42,959 --> 03:35:43,959 now. So because I can also say car, I mean,\n 3010 03:35:43,959 --> 03:35:44,959 And then I can call the methods of car, which\n 3011 03:35:44,959 --> 03:35:45,959 Okay, well about macros interface. That's\n 3012 03:35:45,959 --> 03:35:46,959 haven't talked much about design patterns\n 3013 03:35:46,959 --> 03:35:47,959 So a marker interface, generally speaking\n 3014 03:35:47,959 --> 03:35:48,959 a bit weird that you have to implement a market\n 3015 03:35:48,959 --> 03:35:49,959 the method. Okay, so I make this portion again.\n 3016 03:35:49,959 --> 03:35:50,959 working because otherwise you could not compare\n 3017 03:35:50,959 --> 03:35:51,959 see, now we have the green bar process finished\n 3018 03:35:51,959 --> 03:35:52,959 correct. Peters pushy is not the same instance,\n 3019 03:35:52,959 --> 03:35:53,959 the owner at the moment of Peters, Porsche,\n 3020 03:35:53,959 --> 03:35:54,959 is why before I prepared this method, because\n 3021 03:35:54,959 --> 03:35:55,959 name, because at the moment, we don't have\n 3022 03:35:55,959 --> 03:35:56,959 name. So I wrote this method to see who is\n 3023 03:35:56,959 --> 03:35:57,959 when we're finished is that the name would\n 3024 03:35:57,959 --> 03:35:58,959 partially off, Peter. So let's write a test\n 3025 03:35:58,959 --> 03:35:59,959 you also see it expected. So I'm expecting\n 3026 03:35:59,959 --> 03:36:00,959 comma. And I put here pushy, Dodd as string,\n 3027 03:36:00,959 --> 03:36:01,959 method to return portion of pizza later on.\n 3028 03:36:01,959 --> 03:36:02,959 equals. In an later episode, I'll talk about\n 3029 03:36:02,959 --> 03:36:03,959 that for now. I'm using the S ring method,\n 3030 03:36:03,959 --> 03:36:04,959 method yet. So there's still something missing. 3031 03:36:04,959 --> 03:36:05,959 Okay. I can remove that. So let me also execute\n 3032 03:36:05,959 --> 03:36:06,959 oh, there's an error. I have missed a semicolon.\n 3033 03:36:06,959 --> 03:36:07,959 portion of Peter bar is still mine. Now this\n 3034 03:36:07,959 --> 03:36:08,959 two portions. But okay, I said you get one.\n 3035 03:36:08,959 --> 03:36:09,959 now change the owner. So I will sell on my\n 3036 03:36:09,959 --> 03:36:10,959 Which means I mean, I just made this method\n 3037 03:36:10,959 --> 03:36:11,959 owner. Okay. Also, by the way, I mean, here\n 3038 03:36:11,959 --> 03:36:12,959 possible for our example. Usually, I would\n 3039 03:36:12,959 --> 03:36:13,959 name, for example, and I also already have\n 3040 03:36:13,959 --> 03:36:14,959 string. But more object oriented would be\n 3041 03:36:14,959 --> 03:36:15,959 so I sell it to Peter. And now I expect the\n 3042 03:36:17,959 --> 03:36:18,959 But now I have a fear. What if now my pushy\n 3043 03:36:18,959 --> 03:36:19,959 to assert that the The original pushy is still\n 3044 03:36:19,959 --> 03:36:20,959 K, which also worked. And this tells us now\n 3045 03:36:20,959 --> 03:36:21,959 clone method, it created a new object in memory.\n 3046 03:36:21,959 --> 03:36:22,959 Peters Porsche he inserted that they're not\n 3047 03:36:22,959 --> 03:36:23,959 then I changed the second object. And I gave\n 3048 03:36:23,959 --> 03:36:24,959 now, the owner's name is Peter, by comparing\n 3049 03:36:24,959 --> 03:36:25,959 I was working on the second object, the copy\n 3050 03:36:25,959 --> 03:36:26,959 like proving that our clone operation did\n 3051 03:36:26,959 --> 03:36:27,959 we needed to do for this, I had to say implement\n 3052 03:36:27,959 --> 03:36:28,959 I had to call the super clone method, I had\n 3053 03:36:28,959 --> 03:36:29,959 This is a lot of lines for only this. And\n 3054 03:36:29,959 --> 03:36:30,959 what this does is it creates only a shallow\n 3055 03:36:30,959 --> 03:36:31,959 is a more advanced topic. So I try to keep\n 3056 03:36:31,959 --> 03:36:32,959 between a shallow copy and a deep copy? Okay,\n 3057 03:36:32,959 --> 03:36:33,959 here a more complex object BMW. And here I'm\n 3058 03:36:33,959 --> 03:36:34,959 using a second object color. And let's make\n 3059 03:36:34,959 --> 03:36:35,959 copy would mean that not only BMW is copied,\n 3060 03:36:35,959 --> 03:36:36,959 copied. So that they are also independent,\n 3061 03:36:36,959 --> 03:36:37,959 But a shallow copy will here, only copy the\n 3062 03:36:37,959 --> 03:36:38,959 as the object for color will still be the\n 3063 03:36:38,959 --> 03:36:39,959 is okay. And sometimes it's not, it really\n 3064 03:36:39,959 --> 03:36:40,959 short, if you're using clone want to make\n 3065 03:36:40,959 --> 03:36:41,959 on the internal objects, and this here, I\n 3066 03:36:41,959 --> 03:36:42,959 actually, three times. Now, one more problem\n 3067 03:36:42,959 --> 03:36:43,959 here is, first of all, I cloned BMW, and then\n 3068 03:36:43,959 --> 03:36:44,959 already fully functional, I assign a new value,\n 3069 03:36:44,959 --> 03:36:45,959 it turns out not to in order to make a deep\n 3070 03:36:45,959 --> 03:36:46,959 not final, and sometimes you want them to\n 3071 03:36:46,959 --> 03:36:47,959 the clone method. And also, I mean, how complicated\n 3072 03:36:47,959 --> 03:36:48,959 there are alternatives I told you. I've written\n 3073 03:36:48,959 --> 03:36:49,959 so I could show you what to think. Yeah, I\n 3074 03:36:49,959 --> 03:36:50,959 because I noticed many of you are only watching\n 3075 03:36:50,959 --> 03:36:51,959 be asleep anyway. So let's keep this short.\n 3076 03:36:51,959 --> 03:36:52,959 to using the clone method. There are two alternatives.\n 3077 03:36:52,959 --> 03:36:53,959 constructor, and this is this thing here.\n 3078 03:36:53,959 --> 03:36:54,959 this is the same object. And then you see\n 3079 03:36:54,959 --> 03:36:55,959 color on BMW dot color. So I'm taking the\n 3080 03:36:56,959 --> 03:36:57,959 And so in the end, I will have a new object\n 3081 03:36:57,959 --> 03:36:58,959 This is One alternative. The other alternative\n 3082 03:36:58,959 --> 03:36:59,959 one to use a so called static factory method. 3083 03:36:59,959 --> 03:37:00,959 And this is this here, it's a static method.\n 3084 03:37:00,959 --> 03:37:01,959 dot new instance, you can give it the BMW\n 3085 03:37:01,959 --> 03:37:02,959 probably Marquess BMW. And then you You see,\n 3086 03:37:02,959 --> 03:37:03,959 here, this is a more complex object. So I\n 3087 03:37:03,959 --> 03:37:04,959 Because again, I say new instance. And he\n 3088 03:37:04,959 --> 03:37:05,959 those methods to also cop copy the owner's\n 3089 03:37:05,959 --> 03:37:06,959 copy, I could have also just assigned the\n 3090 03:37:06,959 --> 03:37:07,959 it's safer to have deep copies. Okay, so And\n 3091 03:37:07,959 --> 03:37:08,959 name and color. Because there again, I do\n 3092 03:37:08,959 --> 03:37:09,959 method. So this is taking a parameter of name,\n 3093 03:37:09,959 --> 03:37:10,959 name. Now, first name and last name are both\n 3094 03:37:10,959 --> 03:37:11,959 why do I not need to copy down? Okay, now\n 3095 03:37:11,959 --> 03:37:12,959 um, thing is a string as an object, but it's\n 3096 03:37:12,959 --> 03:37:13,959 means whenever you change the object, like\n 3097 03:37:13,959 --> 03:37:14,959 say, Peter, you will not influence the other\n 3098 03:37:14,959 --> 03:37:15,959 this, Peter will get a new object. So this\n 3099 03:37:15,959 --> 03:37:16,959 done for you. Actually, you can do this for\n 3100 03:37:16,959 --> 03:37:17,959 this, you just have the limitation that you\n 3101 03:37:17,959 --> 03:37:18,959 allows the client to change the values in\n 3102 03:37:18,959 --> 03:37:19,959 change, return a new instance. And then you\n 3103 03:37:19,959 --> 03:37:20,959 an immutable test. Because there's another\n 3104 03:37:20,959 --> 03:37:21,959 integer. Big integer is similar to an int,\n 3105 03:37:21,959 --> 03:37:22,959 First of all, because it can work on ends\n 3106 03:37:22,959 --> 03:37:23,959 until your memory is full. And there you have\n 3107 03:37:23,959 --> 03:37:24,959 Now, when you say one, add one, this is returning\n 3108 03:37:24,959 --> 03:37:25,959 not be influenced by this operation, you can\n 3109 03:37:25,959 --> 03:37:26,959 every method that you call will never influence\n 3110 03:37:26,959 --> 03:37:27,959 it's created once with the constructor, this\n 3111 03:37:27,959 --> 03:37:28,959 you can never ever changed it again, which\n 3112 03:37:28,959 --> 03:37:29,959 a good design principle to use immutables\n 3113 03:37:29,959 --> 03:37:30,959 very good to use multiples when you do code\n 3114 03:37:30,959 --> 03:37:31,959 about multi threading yet, we will at a later\n 3115 03:37:31,959 --> 03:37:32,959 they will make everything more easy. So, maybe\n 3116 03:37:32,959 --> 03:37:33,959 episode. And this is favor immutables try\n 3117 03:37:33,959 --> 03:37:34,959 that they are not mutable, that they cannot\n 3118 03:37:34,959 --> 03:37:35,959 here at the same thing with string. Maybe\n 3119 03:37:35,959 --> 03:37:36,959 Hello, which in memory is actually the same\n 3120 03:37:36,959 --> 03:37:37,959 This will influence the string one, and not\n 3121 03:37:37,959 --> 03:37:38,959 So you see, like the speaker so we can see\n 3122 03:37:38,959 --> 03:37:39,959 string here printed Hi, the second string\n 3123 03:37:39,959 --> 03:37:40,959 first one has high, and the second one has\n 3124 03:37:40,959 --> 03:37:41,959 had commented it out. Let's execute it again.\n 3125 03:37:41,959 --> 03:37:42,959 the difference. And this is one example of\n 3126 03:37:42,959 --> 03:37:43,959 Maybe we could also call this here. So I print\n 3127 03:37:43,959 --> 03:37:44,959 to do a few things. So the input value of\n 3128 03:37:44,959 --> 03:37:45,959 and the end value of zero is zero. Well, I'm\n 3129 03:37:45,959 --> 03:37:46,959 return a new object, return a new object,\n 3130 03:37:46,959 --> 03:37:47,959 this is an immutable, this is something that\n 3131 03:37:47,959 --> 03:37:48,959 go back to Chrome. Let's recap. So in order\n 3132 03:37:48,959 --> 03:37:49,959 all, override the clone method so that it\n 3133 03:37:49,959 --> 03:37:50,959 it's recommended. Use not object here, but\n 3134 03:37:50,959 --> 03:37:51,959 then you will have to do an explicit cast\n 3135 03:37:51,959 --> 03:37:52,959 exception, thrown your assertion error, which\n 3136 03:37:52,959 --> 03:37:53,959 cloneable, which you will also have to do.\n 3137 03:37:53,959 --> 03:37:54,959 will create a shallow clone for you. Which\n 3138 03:37:54,959 --> 03:37:55,959 and you then operate on those objects, this\n 3139 03:37:55,959 --> 03:37:56,959 not totally independent, you're only potentially\n 3140 03:37:56,959 --> 03:37:57,959 independent. But if here you have name, this\n 3141 03:37:57,959 --> 03:37:58,959 here would still be the same. If you also\n 3142 03:37:58,959 --> 03:37:59,959 a more complex clone method, you have to also\n 3143 03:37:59,959 --> 03:38:00,959 assign the new clone values to your internal\n 3144 03:38:00,959 --> 03:38:01,959 not final. So this already limits the way\n 3145 03:38:01,959 --> 03:38:02,959 not working now. So and this is one of the\n 3146 03:38:02,959 --> 03:38:03,959 why you should not use clone, other than to\n 3147 03:38:03,959 --> 03:38:04,959 One is use a static factory method. I call\n 3148 03:38:04,959 --> 03:38:05,959 Effective Java that you should buy. And here,\n 3149 03:38:05,959 --> 03:38:06,959 I call again, a factory method on name. And\n 3150 03:38:06,959 --> 03:38:07,959 creates a deep copy. Or I can do the same\n 3151 03:38:07,959 --> 03:38:08,959 is actually shorter. So this is why I would\n 3152 03:38:08,959 --> 03:38:09,959 works. Okay, so here, I call twice a new constructor,\n 3153 03:38:09,959 --> 03:38:10,959 new color object. Okay, and then in name,\n 3154 03:38:10,959 --> 03:38:11,959 And this now is strings and I said strings.\n 3155 03:38:11,959 --> 03:38:12,959 string is immutable. So you have to do this\n 3156 03:38:12,959 --> 03:38:13,959 object or a primitive. If this were again,\n 3157 03:38:13,959 --> 03:38:14,959 with cloning, or copying, like calling the\n 3158 03:38:14,959 --> 03:38:15,959 or a primitive value or another immutable\n 3159 03:38:15,959 --> 03:38:16,959 And then we can also look at color one last\n 3160 03:38:16,959 --> 03:38:17,959 different implementations here with a static\n 3161 03:38:17,959 --> 03:38:18,959 And last but not least, here with a copy constructor,\n 3162 03:38:18,959 --> 03:38:19,959 the string from the original object, which\n 3163 03:38:19,959 --> 03:38:20,959 any further. I'm actually going to talk a\n 3164 03:38:20,959 --> 03:38:21,959 on track, talking about the class object,\n 3165 03:38:21,959 --> 03:38:22,959 I need to tell you about are hashCode. And\n 3166 03:38:22,959 --> 03:38:23,959 important methods in Java, I think. However,\n 3167 03:38:23,959 --> 03:38:24,959 to explain. So before I can tackle them, I\n 3168 03:38:24,959 --> 03:38:25,959 things up. And to talk a bit about the missing\n 3169 03:38:25,959 --> 03:38:26,959 As you see, I have prepared this demo test\n 3170 03:38:26,959 --> 03:38:27,959 testing something today. This is really only\n 3171 03:38:27,959 --> 03:38:28,959 things. So let's do one by one. And the first\n 3172 03:38:28,959 --> 03:38:29,959 You might remember, I think I talked about\n 3173 03:38:29,959 --> 03:38:30,959 and I kind of promised you to later on give\n 3174 03:38:30,959 --> 03:38:31,959 this time was we hadn't talked about static.\n 3175 03:38:31,959 --> 03:38:32,959 have any better opportunity to talk about\n 3176 03:38:32,959 --> 03:38:33,959 I should really finally tell you what exactly\n 3177 03:38:33,959 --> 03:38:34,959 what it helps you. So actually, we used it\n 3178 03:38:34,959 --> 03:38:35,959 Here on top, I have this import static org\n 3179 03:38:35,959 --> 03:38:36,959 because at the moment, I'm not using it. This\n 3180 03:38:36,959 --> 03:38:37,959 Now you can see it. And you can also see here,\n 3181 03:38:37,959 --> 03:38:38,959 is, what's the difference between the two\n 3182 03:38:38,959 --> 03:38:39,959 whole test class? Well, this one here, a static\n 3183 03:38:39,959 --> 03:38:40,959 Because in j unit, you know, when we want\n 3184 03:38:41,959 --> 03:38:42,959 Let's do that now. Like assert. True, you\n 3185 03:38:42,959 --> 03:38:43,959 true is always true. There's a stupid, but\n 3186 03:38:43,959 --> 03:38:44,959 thing is, this is only not working because\n 3187 03:38:44,959 --> 03:38:45,959 great anymore, it turns white, because now\n 3188 03:38:45,959 --> 03:38:46,959 at this class, I can jump there, you see even\n 3189 03:38:46,959 --> 03:38:47,959 the classes extend object anyway. So here\n 3190 03:38:47,959 --> 03:38:48,959 what my ID he can also do to show me the code.\n 3191 03:38:48,959 --> 03:38:49,959 what happens behind the cover. So you Here\n 3192 03:38:49,959 --> 03:38:50,959 actually like groups them and makes them usable\n 3193 03:38:50,959 --> 03:38:51,959 when I talked about static, the way you would\n 3194 03:38:51,959 --> 03:38:52,959 say class name, dot assert true. Now you can\n 3195 03:38:52,959 --> 03:38:53,959 is org dot j unit dot assert, and then assert\n 3196 03:38:53,959 --> 03:38:54,959 you would import the class and then you can\n 3197 03:38:54,959 --> 03:38:55,959 there are also other methods, you can have\n 3198 03:38:55,959 --> 03:38:56,959 complicated ones like you can even compare\n 3199 03:38:56,959 --> 03:38:57,959 equals, with message without is equals, and\n 3200 03:38:57,959 --> 03:38:58,959 this means I can also say, assert dot assert\n 3201 03:38:58,959 --> 03:38:59,959 because I have not normally imported the assert\n 3202 03:38:59,959 --> 03:39:00,959 have to say org, J unit dot assert, and then\n 3203 03:39:00,959 --> 03:39:01,959 used anymore, because now I'm not statically\n 3204 03:39:01,959 --> 03:39:02,959 the class name to use the method. But I mean,\n 3205 03:39:02,959 --> 03:39:03,959 with Java five. The reason to introduce this\n 3206 03:39:03,959 --> 03:39:04,959 shorter, because you don't always want to\n 3207 03:39:05,959 --> 03:39:06,959 and you could also do it as said before, without\n 3208 03:39:06,959 --> 03:39:07,959 than you could go without the import. Now,\n 3209 03:39:07,959 --> 03:39:08,959 That's the difference, because now I don't\n 3210 03:39:08,959 --> 03:39:09,959 we can go with or without. And if you wanted\n 3211 03:39:09,959 --> 03:39:10,959 the static import and not the regular import.\n 3212 03:39:10,959 --> 03:39:11,959 means just input all the static members or\n 3213 03:39:11,959 --> 03:39:12,959 functions and also the static variables of\n 3214 03:39:12,959 --> 03:39:13,959 to import that are static. This also works\n 3215 03:39:13,959 --> 03:39:14,959 say you import only specific functions or\n 3216 03:39:14,959 --> 03:39:15,959 that's all I can tell you about static imports,\n 3217 03:39:15,959 --> 03:39:16,959 it actually happens, then you would think\n 3218 03:39:16,959 --> 03:39:17,959 that are the same in different classes. If\n 3219 03:39:17,959 --> 03:39:18,959 I told you about the imports, you can only\n 3220 03:39:18,959 --> 03:39:19,959 import. If you're not have a second class\n 3221 03:39:19,959 --> 03:39:20,959 to use the full fledged, or at least a class\n 3222 03:39:20,959 --> 03:39:21,959 in this case, I want the assert true method\n 3223 03:39:21,959 --> 03:39:22,959 want the assert true from another class. Okay,\n 3224 03:39:22,959 --> 03:39:23,959 the compiler understands what you're trying\n 3225 03:39:23,959 --> 03:39:24,959 I mean, then it's just obvious the assert\n 3226 03:39:24,959 --> 03:39:25,959 okay. So that much about static imports. The\n 3227 03:39:25,959 --> 03:39:26,959 open this up is default values for different\n 3228 03:39:26,959 --> 03:39:27,959 And also interesting. Because I see many people\n 3229 03:39:27,959 --> 03:39:28,959 And then they would say something like, here,\n 3230 03:39:28,959 --> 03:39:29,959 Boolean, they would say false. Or for the\n 3231 03:39:29,959 --> 03:39:30,959 have to do that. Because now for object, as\n 3232 03:39:30,959 --> 03:39:31,959 So this is in my eyes, this is just clutter,\n 3233 03:39:31,959 --> 03:39:32,959 for every rule, there's always an exception.\n 3234 03:39:32,959 --> 03:39:33,959 this is set to false. And this is really a\n 3235 03:39:33,959 --> 03:39:34,959 with it. It might make sense to sometimes\n 3236 03:39:34,959 --> 03:39:35,959 maybe you should name your variable a bit\n 3237 03:39:35,959 --> 03:39:36,959 And because my Boolean now I mean, this might\n 3238 03:39:36,959 --> 03:39:37,959 always false. Okay, so And now let's have\n 3239 03:39:37,959 --> 03:39:38,959 when I say default, this really only applies\n 3240 03:39:38,959 --> 03:39:39,959 for example, have a local variable Like Boolean,\n 3241 03:39:39,959 --> 03:39:40,959 use it, this is not going to work. If b, this\n 3242 03:39:40,959 --> 03:39:41,959 have been initialized, but it does work with\n 3243 03:39:41,959 --> 03:39:42,959 see, and now it will count as false. So the\n 3244 03:39:42,959 --> 03:39:43,959 but now enough of talking, blah, blah, blah.\n 3245 03:39:43,959 --> 03:39:44,959 so let's make this a bit bigger, so we can\n 3246 03:39:44,959 --> 03:39:45,959 default value, short default value, those\nare all zero. 3247 03:39:45,959 --> 03:39:46,959 Actually, there are many number types that\n 3248 03:39:46,959 --> 03:39:47,959 what I'm just going to introduce right now.\n 3249 03:39:47,959 --> 03:39:48,959 this is actually the one that is most times\n 3250 03:39:48,959 --> 03:39:49,959 others. I think I shortly once showed you\n 3251 03:39:49,959 --> 03:39:50,959 but there are also others. In my opinion,\n 3252 03:39:50,959 --> 03:39:51,959 see the ranges very soon are only here because\n 3253 03:39:51,959 --> 03:39:52,959 in other programming languages before Java,\n 3254 03:39:52,959 --> 03:39:53,959 The reason is probably because like something\n 3255 03:39:53,959 --> 03:39:54,959 And that was really the memory space was so\n 3256 03:39:54,959 --> 03:39:55,959 I don't know, a few kilobytes. Now with gigabytes\n 3257 03:39:55,959 --> 03:39:56,959 So the space end users actually a bit more\n 3258 03:39:56,959 --> 03:39:57,959 these days, in 99, and probably 99.9% of the\n 3259 03:39:57,959 --> 03:39:58,959 in my personal opinion on something like deprecated.\n 3260 03:39:58,959 --> 03:39:59,959 I'm sure someone can tell me there is a specific\n 3261 03:39:59,959 --> 03:40:00,959 on average, generally speaking, you should\n 3262 03:40:00,959 --> 03:40:01,959 the sizes of these types in a second. So yeah,\n 3263 03:40:01,959 --> 03:40:02,959 numbers than end. This sometimes might be\n 3264 03:40:02,959 --> 03:40:03,959 now float and double, as the name implies,\n 3265 03:40:03,959 --> 03:40:04,959 numbers. And double, I think the name comes\n 3266 03:40:04,959 --> 03:40:05,959 then that of a float. Actually, also these\n 3267 03:40:05,959 --> 03:40:06,959 did not worry too much with these kinds of\n 3268 03:40:06,959 --> 03:40:07,959 case I did, for example, calculating on money\n 3269 03:40:07,959 --> 03:40:08,959 are quite problematic, actually, because they\n 3270 03:40:08,959 --> 03:40:09,959 can happen that when you have something like\n 3271 03:40:09,959 --> 03:40:10,959 by a number of people that in the end, you\n 3272 03:40:10,959 --> 03:40:11,959 in the financial industry, this is just not\n 3273 03:40:11,959 --> 03:40:12,959 use be used there. The reason I can't perfectly\n 3274 03:40:12,959 --> 03:40:13,959 these numbers of course stored in a binary\n 3275 03:40:13,959 --> 03:40:14,959 and one. And then when, from this format,\n 3276 03:40:14,959 --> 03:40:15,959 those floating point numbers, then there are\n 3277 03:40:15,959 --> 03:40:16,959 need to have a correct floating point result,\n 3278 03:40:16,959 --> 03:40:17,959 to store the number without the floating point,\n 3279 03:40:17,959 --> 03:40:18,959 even as a string. And then you do your calculation,\n 3280 03:40:18,959 --> 03:40:19,959 point visually at the place in the UI where\n 3281 03:40:19,959 --> 03:40:20,959 local settings, like numbers are formatted\n 3282 03:40:20,959 --> 03:40:21,959 this is usually the way you would go, at least\n 3283 03:40:21,959 --> 03:40:22,959 industry. Okay, so anyway, float and double\n 3284 03:40:22,959 --> 03:40:23,959 by the way, is like, when you have a constant\nvalue 3285 03:40:23,959 --> 03:40:24,959 like 34 43.31, this here, I mean, this is\n 3286 03:40:24,959 --> 03:40:25,959 this down like it is at the moment, this is\n 3287 03:40:25,959 --> 03:40:26,959 If I want to have this as a float, I have\n 3288 03:40:26,959 --> 03:40:27,959 end, which makes it up float. So, if I have\n 3289 03:40:27,959 --> 03:40:28,959 he really have to say f at the end, because\n 3290 03:40:28,959 --> 03:40:29,959 it says it found a double, but float is required.\n 3291 03:40:29,959 --> 03:40:30,959 bite, there is just the other way around,\n 3292 03:40:30,959 --> 03:40:31,959 want to use a short short as equals to 43.\n 3293 03:40:31,959 --> 03:40:32,959 the space is fitting. And then it will just\n 3294 03:40:32,959 --> 03:40:33,959 really an end to a short. Ever. Let's try\n 3295 03:40:33,959 --> 03:40:34,959 also works because now you try to store the\n 3296 03:40:34,959 --> 03:40:35,959 should always fit. Okay. So what else, so\n 3297 03:40:35,959 --> 03:40:36,959 I said before, Boolean, the default value\n 3298 03:40:36,959 --> 03:40:37,959 depends on if you safe if you display this\n 3299 03:40:37,959 --> 03:40:38,959 it's called the null character. And I think\n 3300 03:40:38,959 --> 03:40:39,959 see there is something it just can't be displayed\n 3301 03:40:39,959 --> 03:40:40,959 blue. But here when I go over it, it's displayed\n 3302 03:40:40,959 --> 03:40:41,959 it just not visible. And I can convert this\n 3303 03:40:41,959 --> 03:40:42,959 And then it's a zero. Okay? Now, so these\n 3304 03:40:42,959 --> 03:40:43,959 data types as primitives. Okay, and now, as\n 3305 03:40:43,959 --> 03:40:44,959 told you so far, all these number types, they\n 3306 03:40:44,959 --> 03:40:45,959 a look, and then see and discuss why that\n 3307 03:40:45,959 --> 03:40:46,959 is used already on top. So let's call, let's\njust call it b 3308 03:40:46,959 --> 03:40:47,959 equals to bite dot value of now, this is a\n 3309 03:40:47,959 --> 03:40:48,959 be used to convert convert, sorry 3310 03:40:48,959 --> 03:40:49,959 a byte primitive to a byte object. You can\n 3311 03:40:49,959 --> 03:40:50,959 because this might use more space. So, I don't\n 3312 03:40:50,959 --> 03:40:51,959 talk forever for performance optimization.\n 3313 03:40:51,959 --> 03:40:52,959 while the other one might reuse an existing\n 3314 03:40:52,959 --> 03:40:53,959 is good enough. Okay, there's also other methods,\n 3315 03:40:53,959 --> 03:40:54,959 this works not on a string as far as I know,\n 3316 03:40:54,959 --> 03:40:55,959 See, I can Also see it here. And this converts\n 3317 03:40:55,959 --> 03:40:56,959 This is the value of it converts it to abide.\n 3318 03:40:56,959 --> 03:40:57,959 of 10, or eight or 16, or whatever. This usually,\n 3319 03:40:57,959 --> 03:40:58,959 a lot of lot of functions. What is also interesting\n 3320 03:40:58,959 --> 03:40:59,959 abstract type number, abstract class, we talked\n 3321 03:40:59,959 --> 03:41:00,959 you can see all these different functions\n 3322 03:41:00,959 --> 03:41:01,959 So each of them, you can convert to an int,\n 3323 03:41:01,959 --> 03:41:02,959 The green stuff is, by the way, the Java API\n 3324 03:41:02,959 --> 03:41:03,959 short. So this, all these types automatically\n 3325 03:41:03,959 --> 03:41:04,959 these cool methods, that might be helpful.\n 3326 03:41:04,959 --> 03:41:05,959 as objects. The reason is, I think, mainly\n 3327 03:41:05,959 --> 03:41:06,959 that we will talk about very soon. I think\n 3328 03:41:06,959 --> 03:41:07,959 similar to an array, it's like an array on\n 3329 03:41:07,959 --> 03:41:08,959 throw in objects. And that's really it, you\n 3330 03:41:08,959 --> 03:41:09,959 not throw in any primitive. And therefore,\n 3331 03:41:09,959 --> 03:41:10,959 this object then will wrap around this primitive\n 3332 03:41:10,959 --> 03:41:11,959 by the way, in the past, when working with\n 3333 03:41:11,959 --> 03:41:12,959 before putting it into the collection, you\n 3334 03:41:12,959 --> 03:41:13,959 like the CMI byte, input, the object would\n 3335 03:41:13,959 --> 03:41:14,959 just say add, I mean, in reality, it looks\n 3336 03:41:14,959 --> 03:41:15,959 an abstract idea, you would have added this\n 3337 03:41:15,959 --> 03:41:16,959 to retrieve it again, you could then say,\n 3338 03:41:16,959 --> 03:41:17,959 there were people saying all this is just\n 3339 03:41:17,959 --> 03:41:18,959 five, there was an auto conversion introduced,\n 3340 03:41:18,959 --> 03:41:19,959 an object, and will automatically behind the\n 3341 03:41:19,959 --> 03:41:20,959 an object to a primitive, whatever is needed\n 3342 03:41:20,959 --> 03:41:21,959 in used by almost every developer, I really\n 3343 03:41:21,959 --> 03:41:22,959 ID, that I get displayed these conversions.\n 3344 03:41:22,959 --> 03:41:23,959 with performance, because I see functions\n 3345 03:41:23,959 --> 03:41:24,959 an object, and to a primitive and so on back\n 3346 03:41:24,959 --> 03:41:25,959 Second, for a primitive, you have the default\n 3347 03:41:25,959 --> 03:41:26,959 throw a null pointer exception. Ever for an\n 3348 03:41:26,959 --> 03:41:27,959 the value will be now and then when you on\n 3349 03:41:27,959 --> 03:41:28,959 actually throw a null pointer exception. The\n 3350 03:41:28,959 --> 03:41:29,959 be automatically be inserted by the compiler\n 3351 03:41:29,959 --> 03:41:30,959 you get a nullpointerexception. So really\n 3352 03:41:30,959 --> 03:41:31,959 I personally hardly ever use them. 3353 03:41:31,959 --> 03:41:32,959 Okay, but so, so that you know of each of\n 3354 03:41:32,959 --> 03:41:33,959 the same type as an object. The names are\n 3355 03:41:33,959 --> 03:41:34,959 a short object. For int, it is integer. So\n 3356 03:41:34,959 --> 03:41:35,959 float is float and double, it's double. And\n 3357 03:41:35,959 --> 03:41:36,959 the way, also has static Boolean object values.\n 3358 03:41:36,959 --> 03:41:37,959 the bite. Because this is also B, Boolean\n 3359 03:41:37,959 --> 03:41:38,959 now this is an object. I can also show, you\n 3360 03:41:38,959 --> 03:41:39,959 though this is an object, the aesthetic value\n 3361 03:41:39,959 --> 03:41:40,959 final Boolean false equals to new Boolean\n 3362 03:41:40,959 --> 03:41:41,959 is there's only one object that is always\n 3363 03:41:41,959 --> 03:41:42,959 to save some space. Okay. And now you see,\n 3364 03:41:42,959 --> 03:41:43,959 type, because internally, the compiler will\n 3365 03:41:43,959 --> 03:41:44,959 so that's, I think, all I can tell you about\n 3366 03:41:44,959 --> 03:41:45,959 variants. Now let's have a look at their ranges.\n 3367 03:41:45,959 --> 03:41:46,959 smaller ranges. But enough of talking, I think\n 3368 03:41:46,959 --> 03:41:47,959 test. And we see, let me scroll this down.\n 3369 03:41:47,959 --> 03:41:48,959 we can see the test and the code in parallel.\n 3370 03:41:48,959 --> 03:41:49,959 Remember, don't use it avoided. Just try test,\n 3371 03:41:49,959 --> 03:41:50,959 to show you the results. Otherwise, in productive\n 3372 03:41:50,959 --> 03:41:51,959 and would probably lead generally speaking\n 3373 03:41:51,959 --> 03:41:52,959 here you see. So there are signed types and\n 3374 03:41:52,959 --> 03:41:53,959 is a minus, so it goes from minus 128 to plus\n 3375 03:41:53,959 --> 03:41:54,959 127. While he is 128. This actually is for\n 3376 03:41:54,959 --> 03:41:55,959 in your memory of your computer will actually\n 3377 03:41:55,959 --> 03:41:56,959 if it's a minus or a plus. And this is why\n 3378 03:41:56,959 --> 03:41:57,959 just decided that minus has one, one more\n 3379 03:41:57,959 --> 03:41:58,959 also done it the other way. But this is how\n 3380 03:41:58,959 --> 03:41:59,959 is only for very small numbers. 120 minus\n 3381 03:41:59,959 --> 03:42:00,959 much bigger. It can store 32,000 something\n 3382 03:42:00,959 --> 03:42:01,959 right side in again is much bigger. I think\n 3383 03:42:01,959 --> 03:42:02,959 much bigger. I don't even know how long this\n 3384 03:42:02,959 --> 03:42:03,959 fine with int can in some rare cases you need\n 3385 03:42:03,959 --> 03:42:04,959 a long Okay. And then there's his float floating\n 3386 03:42:04,959 --> 03:42:05,959 and the double see here even is much bigger\n 3387 03:42:05,959 --> 03:42:06,959 is unsigned. So, this is why there is no minus\n 3388 03:42:06,959 --> 03:42:07,959 something is the double size down to the short\n 3389 03:42:07,959 --> 03:42:08,959 it needs to have it in a signed form with\n 3390 03:42:09,959 --> 03:42:10,959 Okay, and car as you have seen before, usually\n 3391 03:42:10,959 --> 03:42:11,959 But if you convert it to an end, you can also\n 3392 03:42:11,959 --> 03:42:12,959 to 65,000 something okay. I think this is\n 3393 03:42:12,959 --> 03:42:13,959 Okay, so these were the ranges let's go to\n 3394 03:42:13,959 --> 03:42:14,959 way to show you see here I converted this\n 3395 03:42:14,959 --> 03:42:15,959 you see here I used actually the object, the\n 3396 03:42:15,959 --> 03:42:16,959 gives me the min and max value. This is really\n 3397 03:42:16,959 --> 03:42:17,959 just use them out of the box and say min value\n 3398 03:42:17,959 --> 03:42:18,959 directly, I can just look them up. And Java\n 3399 03:42:18,959 --> 03:42:19,959 now. And go to our next test. Because now,\n 3400 03:42:19,959 --> 03:42:20,959 also save your numbers, not only on the base\n 3401 03:42:20,959 --> 03:42:21,959 base 16. So now it depends. I don't know,\n 3402 03:42:21,959 --> 03:42:22,959 I'm assuming you had, they should be really\n 3403 03:42:22,959 --> 03:42:23,959 with the base two, you would store you would\n 3404 03:42:23,959 --> 03:42:24,959 then with the base 10. If you never heard\n 3405 03:42:24,959 --> 03:42:25,959 is not so important. I think I never needed\n 3406 03:42:25,959 --> 03:42:26,959 decimal was always fine to me. I mean, this\n 3407 03:42:26,959 --> 03:42:27,959 on the left side is always the same, no matter\n 3408 03:42:27,959 --> 03:42:28,959 used, because you are in a certain domain\n 3409 03:42:28,959 --> 03:42:29,959 for example, the hex. And so you would, for\n 3410 03:42:29,959 --> 03:42:30,959 a hex value. And so you could have the same\n 3411 03:42:30,959 --> 03:42:31,959 here in your code, which would make it easier\n 3412 03:42:31,959 --> 03:42:32,959 has nothing to do with how they're stored.\n 3413 03:42:32,959 --> 03:42:33,959 in your memory. And your computer can always\n 3414 03:42:33,959 --> 03:42:34,959 no matter what format, you use them internally,\n 3415 03:42:34,959 --> 03:42:35,959 by default, they're also when I print them\n 3416 03:42:35,959 --> 03:42:36,959 also always be printed out on the base of\n 3417 03:42:36,959 --> 03:42:37,959 them. So this is only a displaying issue in\n 3418 03:42:37,959 --> 03:42:38,959 binary format, you need specific formatting\n 3419 03:42:38,959 --> 03:42:39,959 So I will not go in detail on this. Now. Also,\n 3420 03:42:39,959 --> 03:42:40,959 What is also interesting, by the way, I mean,\n 3421 03:42:40,959 --> 03:42:41,959 only. So this only recently got added. Speaking\n 3422 03:42:41,959 --> 03:42:42,959 to store, base 10, base eight and base 16.\n 3423 03:42:42,959 --> 03:42:43,959 stuff more readable. I mean, especially with\n 3424 03:42:43,959 --> 03:42:44,959 here of zeros and ones. So that you could\n 3425 03:42:44,959 --> 03:42:45,959 credit card numbers, you can add these underscores\n 3426 03:42:45,959 --> 03:42:46,959 You're just not allowed to do it at the beginning\n 3427 03:42:46,959 --> 03:42:47,959 But I mean, I don't see how this would make\n 3428 03:42:47,959 --> 03:42:48,959 it. So this is why you put them here in between,\n 3429 03:42:48,959 --> 03:42:49,959 is, is that more readable? In this case? Of\n 3430 03:42:49,959 --> 03:42:50,959 especially for something like credit card\n 3431 03:42:50,959 --> 03:42:51,959 them more easily, like on the phone talking\n 3432 03:42:51,959 --> 03:42:52,959 number nine you can talk about the blogs makes\n 3433 03:42:52,959 --> 03:42:53,959 is just the displaying issue in the code.\n 3434 03:42:53,959 --> 03:42:54,959 like before. So now let's execute the test.\n 3435 03:42:54,959 --> 03:42:55,959 and we can have a look at it. Okay, so here\n 3436 03:42:55,959 --> 03:42:56,959 I'm storing the number in binary. The number\n 3437 03:42:56,959 --> 03:42:57,959 the zero. You can use the capital and a lowercase\n 3438 03:42:57,959 --> 03:42:58,959 On this long thing here, so ob four is binary\n 3439 03:42:58,959 --> 03:42:59,959 you can use your calculator and calculate\n 3440 03:43:01,959 --> 03:43:02,959 By the way, of course, just shortly, binary\n 3441 03:43:02,959 --> 03:43:03,959 three, this will give you an error, integer\n 3442 03:43:03,959 --> 03:43:04,959 format, indicated by the B and zero here with\n 3443 03:43:04,959 --> 03:43:05,959 with a zero only. So zero and seven means\n 3444 03:43:05,959 --> 03:43:06,959 eight in the on the base of eight. As I said,\n 3445 03:43:06,959 --> 03:43:07,959 you will understand what I'm talking about.\n 3446 03:43:07,959 --> 03:43:08,959 you will hardly ever need it. Let's have a\n 3447 03:43:08,959 --> 03:43:09,959 this is the eight. And this is some large\n 3448 03:43:09,959 --> 03:43:10,959 in here. This is just to help so that it's\n 3449 03:43:10,959 --> 03:43:11,959 hex code is started with zero and x. And then\n 3450 03:43:11,959 --> 03:43:12,959 no, I think our numbers are not Latin, their\n 3451 03:43:12,959 --> 03:43:13,959 they are based on the base 10. So nine is\n 3452 03:43:13,959 --> 03:43:14,959 10 you need one zero, while on the hex, you\n 3453 03:43:14,959 --> 03:43:15,959 they used ABCDE, F for 10 to 16. So the F\n 3454 03:43:15,959 --> 03:43:16,959 I was lying to you. It's the 15 in this case,\n 3455 03:43:16,959 --> 03:43:17,959 it's the 15. Because the 16 again, would be\n 3456 03:43:19,959 --> 03:43:20,959 I think it's not so important. It's just interesting\n 3457 03:43:20,959 --> 03:43:21,959 I think you really should know, Java inside\n 3458 03:43:21,959 --> 03:43:22,959 is possible. The question if you personally\n 3459 03:43:22,959 --> 03:43:23,959 project will need it. I don't know, depends,\n 3460 03:43:23,959 --> 03:43:24,959 here to be used. Okay. So now, I think really\n 3461 03:43:24,959 --> 03:43:25,959 And I think this is really now a good base\n 3462 03:43:25,959 --> 03:43:26,959 talk about the two methods equals, and hashCode.\n 3463 03:43:26,959 --> 03:43:27,959 of all the methods of the Java Lang object\n 3464 03:43:27,959 --> 03:43:28,959 that ties them closely together, which is\n 3465 03:43:28,959 --> 03:43:29,959 just one episode. Knowing all the details\n 3466 03:43:29,959 --> 03:43:30,959 programmer today. So get yourself some popcorn,\n 3467 03:43:30,959 --> 03:43:31,959 the equals method. What does it do? What's\n 3468 03:43:31,959 --> 03:43:32,959 is used to compare two objects for equality,\n 3469 03:43:32,959 --> 03:43:33,959 for primitive values. But before I'm going\n 3470 03:43:33,959 --> 03:43:34,959 my ID and see this in action. Now in my ID,\n 3471 03:43:34,959 --> 03:43:35,959 equals method for anyway, because so far,\n 3472 03:43:35,959 --> 03:43:36,959 and this was working. Let's see this again,\n 3473 03:43:36,959 --> 03:43:37,959 and J equals four. So now I assert, with the\n 3474 03:43:37,959 --> 03:43:38,959 we get the green bar. Old tests passed, everything\n 3475 03:43:38,959 --> 03:43:39,959 same thing with strings. Here we have a constant\n 3476 03:43:39,959 --> 03:43:40,959 Hello. And each has assigned to its own string,\n 3477 03:43:40,959 --> 03:43:41,959 these two strings with the equal operator?\n 3478 03:43:41,959 --> 03:43:42,959 And I told you a string is an object. So as\n 3479 03:43:42,959 --> 03:43:43,959 equals method at all. Well, with a string,\n 3480 03:43:43,959 --> 03:43:44,959 a string, there is some optimization going\n 3481 03:43:44,959 --> 03:43:45,959 because for this constant value, there's actually\n 3482 03:43:45,959 --> 03:43:46,959 to the same object in memory. The variable\n 3483 03:43:46,959 --> 03:43:47,959 object is stored in a memory area called heap.\n 3484 03:43:47,959 --> 03:43:48,959 differently. As soon as I add a new string\n 3485 03:43:48,959 --> 03:43:49,959 is only age. And then I say at runtime, hello,\n 3486 03:43:49,959 --> 03:43:50,959 ello to it, which will be Hello, at runtime.\n 3487 03:43:50,959 --> 03:43:51,959 that we can see there is really Hello. In\n 3488 03:43:51,959 --> 03:43:52,959 assert, hello, one, equal operator Hello,\n 3489 03:43:52,959 --> 03:43:53,959 red bar, nasty, nasty. So now they're not\n 3490 03:43:53,959 --> 03:43:54,959 Hello. So from our expectation it should have\n 3491 03:43:55,959 --> 03:43:56,959 And ensured you should not use equal operator\n 3492 03:43:56,959 --> 03:43:57,959 for strings, there is the equals method. Let's\n 3493 03:43:57,959 --> 03:43:58,959 This works, it seems like using that method,\n 3494 03:43:58,959 --> 03:43:59,959 actually at the method. Here we are clustering.\n 3495 03:43:59,959 --> 03:44:00,959 an object. It says things like if this equals\n 3496 03:44:00,959 --> 03:44:01,959 the same reference, if it's the same object,\n 3497 03:44:01,959 --> 03:44:02,959 Now it checks that the object is actually\n 3498 03:44:02,959 --> 03:44:03,959 of operator so that we can safely cast the\n 3499 03:44:03,959 --> 03:44:04,959 both strings. Interesting thing about instance,\n 3500 03:44:04,959 --> 03:44:05,959 developers know, or at least not all, yet.\n 3501 03:44:05,959 --> 03:44:06,959 object is now this will never be a string\n 3502 03:44:06,959 --> 03:44:07,959 So anyway, without going into further details,\n 3503 03:44:07,959 --> 03:44:08,959 character by character of both strings. And\n 3504 03:44:08,959 --> 03:44:09,959 return true. So this is how equals was implemented\n 3505 03:44:09,959 --> 03:44:10,959 you, the equals method is a method from the\n 3506 03:44:10,959 --> 03:44:11,959 out string is also a subclass of object and\n 3507 03:44:11,959 --> 03:44:12,959 here. So then it works on strings as expected.\n 3508 03:44:12,959 --> 03:44:13,959 happily use equals, so that we know that a\n 3509 03:44:13,959 --> 03:44:14,959 Now, how are things with classes that we implement\n 3510 03:44:14,959 --> 03:44:15,959 car with owner Marcos. It is a Porsche and\n 3511 03:44:15,959 --> 03:44:16,959 like it has both instances have exactly the\n 3512 03:44:16,959 --> 03:44:17,959 be the same car. Now let's first of all, try\n 3513 03:44:17,959 --> 03:44:18,959 this is false. It's not working test failed.\n 3514 03:44:18,959 --> 03:44:19,959 instances here. Let's try the positive case.\n 3515 03:44:19,959 --> 03:44:20,959 again, comparing it to itself. So yes, this\n 3516 03:44:20,959 --> 03:44:21,959 to be able to compare Porsche one and Porsche\n 3517 03:44:21,959 --> 03:44:22,959 Let's do this now. For sheet one. Oh, let's\n 3518 03:44:22,959 --> 03:44:23,959 let's also do this, my portion one equals\nmy portion one 3519 03:44:23,959 --> 03:44:24,959 I would expect that to be true. And yes, it\n 3520 03:44:24,959 --> 03:44:25,959 itself. Now, let's compare my Porsche one\n 3521 03:44:26,959 --> 03:44:27,959 it's not working. We have the nasty red bar.\n 3522 03:44:27,959 --> 03:44:28,959 why is it not working with our car? Let's\n 3523 03:44:28,959 --> 03:44:29,959 in the class object. Because in our car class,\n 3524 03:44:29,959 --> 03:44:30,959 So what happens is, the original method of\n 3525 03:44:30,959 --> 03:44:31,959 here, internally, what happens is, we compare\n 3526 03:44:31,959 --> 03:44:32,959 my pushy one, we compare it using the equal\n 3527 03:44:32,959 --> 03:44:33,959 the method, which was pushy to. And this compares\n 3528 03:44:33,959 --> 03:44:34,959 So this is false, because we have two different\n 3529 03:44:34,959 --> 03:44:35,959 What by the way, is also possible. To make\n 3530 03:44:35,959 --> 03:44:36,959 to the reference variable of my portion one,\n 3531 03:44:36,959 --> 03:44:37,959 in memory, no variable is assigned to it.\n 3532 03:44:37,959 --> 03:44:38,959 here in this line, and both variables, point\n 3533 03:44:38,959 --> 03:44:39,959 Because now actually, we only compare the\n 3534 03:44:39,959 --> 03:44:40,959 compares the reference variables, which now\n 3535 03:44:40,959 --> 03:44:41,959 But this is not what we want. So let's remove\n 3536 03:44:41,959 --> 03:44:42,959 We want to compare this one with that one.\n 3537 03:44:42,959 --> 03:44:43,959 This is a small class I wrote. And it just\n 3538 03:44:43,959 --> 03:44:44,959 now. And there is no equals method overwritten.\n 3539 03:44:44,959 --> 03:44:45,959 equals now, I want to compare a car car. No,\n 3540 03:44:45,959 --> 03:44:46,959 is object. So we have to say object here.\n 3541 03:44:46,959 --> 03:44:47,959 car, like we saw on the class string. 3542 03:44:47,959 --> 03:44:48,959 And then it's always good to add the override\n 3543 03:44:48,959 --> 03:44:49,959 overwritten the method. Now, I mean, this\n 3544 03:44:49,959 --> 03:44:50,959 false, just to see that when I'm in my car\n 3545 03:44:50,959 --> 03:44:51,959 I overridden method. Now, of course, when\n 3546 03:44:51,959 --> 03:44:52,959 not work. So we will have to implement it.\n 3547 03:44:52,959 --> 03:44:53,959 is not so easy. And we need some more theory\n 3548 03:44:53,959 --> 03:44:54,959 first of all, jump back to my slides. Before\n 3549 03:44:54,959 --> 03:44:55,959 we need to come up with a proper design first.\n 3550 03:44:55,959 --> 03:44:56,959 phase, and simply click on autogenerate. But\n 3551 03:44:56,959 --> 03:44:57,959 two sub optimal performance. Let me show you\n 3552 03:44:57,959 --> 03:44:58,959 you have to define what it is in your specific\n 3553 03:44:58,959 --> 03:44:59,959 or unequal. In your program, are two cars\n 3554 03:44:59,959 --> 03:45:00,959 maybe when they have the same manufacturer\n 3555 03:45:00,959 --> 03:45:01,959 of wheels, the same top speed, the same vehicle\n 3556 03:45:01,959 --> 03:45:02,959 on a knowledge of the business you are working\n 3557 03:45:02,959 --> 03:45:03,959 and which fields are redundant, and not helpful\n 3558 03:45:03,959 --> 03:45:04,959 performance, you need to define in which order\n 3559 03:45:04,959 --> 03:45:05,959 any fields that have a high chance to be unequal?\n 3560 03:45:05,959 --> 03:45:06,959 than others? To implement a meaningful equals\n 3561 03:45:06,959 --> 03:45:07,959 in great detail. Let's go through this process.\n 3562 03:45:07,959 --> 03:45:08,959 top speed relates to the type of engine and\n 3563 03:45:08,959 --> 03:45:09,959 field, that will not be helpful for the equals\n 3564 03:45:09,959 --> 03:45:10,959 just say the number of wheels is always for\n 3565 03:45:10,959 --> 03:45:11,959 would also not help us to differentiate the\n 3566 03:45:12,959 --> 03:45:13,959 this again depends on the type of program\n 3567 03:45:13,959 --> 03:45:14,959 like the police, this one is probably the\n 3568 03:45:14,959 --> 03:45:15,959 about a program used by the manufacturer itself.\n 3569 03:45:15,959 --> 03:45:16,959 sold yet, I would assume the witness of less\n 3570 03:45:16,959 --> 03:45:17,959 that in detail. This is what you will have\n 3571 03:45:17,959 --> 03:45:18,959 company or your department. Based on their\n 3572 03:45:18,959 --> 03:45:19,959 to compare in which order. In my artificial\n 3573 03:45:19,959 --> 03:45:20,959 the business analyst. So for my example, I\n 3574 03:45:20,959 --> 03:45:21,959 different wind numbers can be seen as equal.\n 3575 03:45:21,959 --> 03:45:22,959 my equals comparison later on. Now, before\n 3576 03:45:22,959 --> 03:45:23,959 some more theory to cover. In the introduction,\n 3577 03:45:23,959 --> 03:45:24,959 of equals and hashCode we have to fulfill.\n 3578 03:45:24,959 --> 03:45:25,959 equals implementation has to comply with,\n 3579 03:45:25,959 --> 03:45:26,959 it actually is. Let's go through each of them\n 3580 03:45:26,959 --> 03:45:27,959 to itself, so that when I call my old car\n 3581 03:45:27,959 --> 03:45:28,959 this makes sense and should be easy to understand.\n 3582 03:45:28,959 --> 03:45:29,959 not they are equal. If my old car equals some\n 3583 03:45:29,959 --> 03:45:30,959 car must also return true This sounds obvious\n 3584 03:45:30,959 --> 03:45:31,959 a simple condition when it comes to inheritance.\n 3585 03:45:31,959 --> 03:45:32,959 is extending the car class, it could happen\n 3586 03:45:32,959 --> 03:45:33,959 car is not equal to the BMW is every BMW is\n 3587 03:45:33,959 --> 03:45:34,959 see, the symmetry rule can actually lead to\n 3588 03:45:34,959 --> 03:45:35,959 interesting articles online discussing potential\n 3589 03:45:35,959 --> 03:45:36,959 each contract condition with a dedicated unit\n 3590 03:45:36,959 --> 03:45:37,959 with a contract. Our next condition is transitivity.\n 3591 03:45:37,959 --> 03:45:38,959 a second is equal to a third, then the first\n 3592 03:45:38,959 --> 03:45:39,959 sounds much more complicated than it actually\n 3593 03:45:39,959 --> 03:45:40,959 object b is equal to object C, they should\n 3594 03:45:40,959 --> 03:45:41,959 equal to a consistency. If two objects are\n 3595 03:45:41,959 --> 03:45:42,959 unless one of them is changed. So when you\n 3596 03:45:42,959 --> 03:45:43,959 a equals method, it should always return the\n 3597 03:45:43,959 --> 03:45:44,959 method should not alter the object in any\n 3598 03:45:44,959 --> 03:45:45,959 what Josh Bloch calls nonlocality. When knowledge\n 3599 03:45:45,959 --> 03:45:46,959 they should always return false and never\n 3600 03:45:46,959 --> 03:45:47,959 know quite a bit about the equals method.\n 3601 03:45:47,959 --> 03:45:48,959 for? For processing similar objects are usually\n 3602 03:45:48,959 --> 03:45:49,959 Java is like a more powerful array, or an\n 3603 03:45:49,959 --> 03:45:50,959 Besides other things, it allows you to look\n 3604 03:45:50,959 --> 03:45:51,959 but also based on their specific values. This\n 3605 03:45:51,959 --> 03:45:52,959 To speed up this lookup process, the Java\n 3606 03:45:52,959 --> 03:45:53,959 that will use the hash value as a grouping\n 3607 03:45:53,959 --> 03:45:54,959 needed. In the optimal case, each object that\n 3608 03:45:54,959 --> 03:45:55,959 will also return a different hash code. This\n 3609 03:45:55,959 --> 03:45:56,959 so called buckets. Now, in this optimal case,\n 3610 03:45:56,959 --> 03:45:57,959 by a lookup based on its hash value. However,\n 3611 03:45:57,959 --> 03:45:58,959 where two unequal objects will share the same\n 3612 03:45:58,959 --> 03:45:59,959 same bucket. Now, if I'm looking for that\n 3613 03:45:59,959 --> 03:46:00,959 based on the hash code minus 391. That car\n 3614 03:46:00,959 --> 03:46:01,959 I will on top have to do an equals comparison\n 3615 03:46:01,959 --> 03:46:02,959 but inadmissible bad performing hash code\n 3616 03:46:02,959 --> 03:46:03,959 for all objects. In this case, however, the\n 3617 03:46:03,959 --> 03:46:04,959 In the end, you would have to do an equals\n 3618 03:46:04,959 --> 03:46:05,959 as if the hashing logic had never existed.\n 3619 03:46:05,959 --> 03:46:06,959 idea of the hashCode method, I have to further\n 3620 03:46:06,959 --> 03:46:07,959 method has to fulfill. The first condition\n 3621 03:46:07,959 --> 03:46:08,959 is for any two objects return same hash codes\n 3622 03:46:08,959 --> 03:46:09,959 use the same idea Define attributes for both\n 3623 03:46:09,959 --> 03:46:10,959 much. Now, if you don't fully understand what\n 3624 03:46:10,959 --> 03:46:11,959 you to the hashCode contract, I will jump\n 3625 03:46:11,959 --> 03:46:12,959 When hashCode is invoked more than once on\n 3626 03:46:12,959 --> 03:46:13,959 the same int value as long as the object is\n 3627 03:46:13,959 --> 03:46:14,959 consistency rule, I introduced to before both\n 3628 03:46:14,959 --> 03:46:15,959 results. To fulfill this contract, you should\n 3629 03:46:15,959 --> 03:46:16,959 and vice versa. Also, when you add or remove\n 3630 03:46:16,959 --> 03:46:17,959 probably also have to adjust your equals and\n 3631 03:46:17,959 --> 03:46:18,959 to return different hash codes when equals\n 3632 03:46:18,959 --> 03:46:19,959 rule, but it will improve the performance\n 3633 03:46:19,959 --> 03:46:20,959 hash collisions. to the extreme, the hash\n 3634 03:46:20,959 --> 03:46:21,959 42 for all objects, as Josh block states in\n 3635 03:46:21,959 --> 03:46:22,959 result in quadratic rather than linear execution\n 3636 03:46:22,959 --> 03:46:23,959 between working and not working. Actually,\n 3637 03:46:23,959 --> 03:46:24,959 beast, I couldn't practically fit in all the\n 3638 03:46:24,959 --> 03:46:25,959 asleep. Therefore, I have done a follow up\n 3639 03:46:25,959 --> 03:46:26,959 on the hashCode method, which you will need\n 3640 03:46:26,959 --> 03:46:27,959 programming. Below this video, there's a link,\n 3641 03:46:27,959 --> 03:46:28,959 for the hashCode method. For now, that's all\n 3642 03:46:28,959 --> 03:46:29,959 your own hashCode and equals methods. to round\n 3643 03:46:29,959 --> 03:46:30,959 to show you some practical examples of hashCode\n 3644 03:46:30,959 --> 03:46:31,959 can see I've implemented both equals, and\n 3645 03:46:31,959 --> 03:46:32,959 engine, and color, also here and hashCode,\n 3646 03:46:32,959 --> 03:46:33,959 them based on the decisions I made during\n 3647 03:46:33,959 --> 03:46:34,959 the theory session. So the car clause has\n 3648 03:46:34,959 --> 03:46:35,959 Manufacturer, engine, color, and number of\n 3649 03:46:35,959 --> 03:46:36,959 that number of wheels and Vehicle Identification\n 3650 03:46:36,959 --> 03:46:37,959 to compare a car. Of course, this is totally\n 3651 03:46:37,959 --> 03:46:38,959 it. I really can't stress that enough. In\n 3652 03:46:38,959 --> 03:46:39,959 the business people and find out what is important\n 3653 03:46:39,959 --> 03:46:40,959 the order that I've chosen. I just thought\n 3654 03:46:40,959 --> 03:46:41,959 millions, or however many colors that for\n 3655 03:46:41,959 --> 03:46:42,959 I think most cars are either black or white,\n 3656 03:46:42,959 --> 03:46:43,959 or yellow. But that's probably it. So I thought\n 3657 03:46:43,959 --> 03:46:44,959 and also more different engines. And I want\n 3658 03:46:44,959 --> 03:46:45,959 which are not equal, I want to leave the method\n 3659 03:46:45,959 --> 03:46:46,959 I leave the method, the faster the entire\n 3660 03:46:46,959 --> 03:46:47,959 then usually it has to go till the very end.\n 3661 03:46:47,959 --> 03:46:48,959 But it does make a difference if it's not\n 3662 03:46:48,959 --> 03:46:49,959 for perform performance optimization I have\nchosen this order 3663 03:46:50,959 --> 03:46:51,959 So this is what I would also ask you to do,\n 3664 03:46:51,959 --> 03:46:52,959 And if the performance is important, then\n 3665 03:46:52,959 --> 03:46:53,959 for sure until you test for the performance.\n 3666 03:46:53,959 --> 03:46:54,959 hashCode and equals. And now, we should also\n 3667 03:46:54,959 --> 03:46:55,959 mostly is also a performance optimization,\n 3668 03:46:55,959 --> 03:46:56,959 I compare the object to itself, I want to\n 3669 03:46:56,959 --> 03:46:57,959 variable references the same object in memory.\n 3670 03:46:57,959 --> 03:46:58,959 I don't have to compare all these things.\n 3671 03:46:58,959 --> 03:46:59,959 a specific case, where you know that you will\n 3672 03:46:59,959 --> 03:47:00,959 might even leave this if a way. Yeah, this\n 3673 03:47:00,959 --> 03:47:01,959 because such a check doesn't also cost a lot,\n 3674 03:47:01,959 --> 03:47:02,959 is actually very important here. This is the\n 3675 03:47:02,959 --> 03:47:03,959 an object that we compare is now that we always\n 3676 03:47:03,959 --> 03:47:04,959 otherwise object dot get class would throw\n 3677 03:47:04,959 --> 03:47:05,959 happen, because now we are already, we have\n 3678 03:47:05,959 --> 03:47:06,959 Okay. And then the third, if check compares\n 3679 03:47:06,959 --> 03:47:07,959 object that is coming in to all equals method\n 3680 03:47:07,959 --> 03:47:08,959 bikes and cars, for example, or cars and apples\n 3681 03:47:08,959 --> 03:47:09,959 this explicit cast to car would also throw\n 3682 03:47:09,959 --> 03:47:10,959 made sure that they both have the car class,\n 3683 03:47:10,959 --> 03:47:11,959 And now I think this is quite interesting.\n 3684 03:47:11,959 --> 03:47:12,959 equals other dot manufacturer. This field\n 3685 03:47:12,959 --> 03:47:13,959 car, even though that this is another instance,\n 3686 03:47:13,959 --> 03:47:14,959 access this private field. So I don't have\n 3687 03:47:14,959 --> 03:47:15,959 field. This works and makes the code I think,\n 3688 03:47:15,959 --> 03:47:16,959 not equal, then I can directly leave the method\n 3689 03:47:16,959 --> 03:47:17,959 fields. And if I'm here, that I'm sure that\n 3690 03:47:17,959 --> 03:47:18,959 compare number of wheels as well as we equal\n 3691 03:47:18,959 --> 03:47:19,959 about them, I don't care because number of\n 3692 03:47:19,959 --> 03:47:20,959 be four. So would be the same anyway. And\n 3693 03:47:20,959 --> 03:47:21,959 be two different cars. But just like, if I'm\n 3694 03:47:21,959 --> 03:47:22,959 example, or the look, then I wouldn't care\n 3695 03:47:22,959 --> 03:47:23,959 cars. I would just say well, this is a BMW\n 3696 03:47:23,959 --> 03:47:24,959 Lou. So for me, this is the same car. Period.\n 3697 03:47:24,959 --> 03:47:25,959 Now the hashCode method. This is actually\n 3698 03:47:25,959 --> 03:47:26,959 that I've decided to do a follow up tutorial,\n 3699 03:47:26,959 --> 03:47:27,959 to watch. There is a link below this video,\n 3700 03:47:27,959 --> 03:47:28,959 only in short about the hashCode method. The\n 3701 03:47:28,959 --> 03:47:29,959 he is multiplied with always the result. So\n 3702 03:47:29,959 --> 03:47:30,959 field, which will return some in number 3703 03:47:30,959 --> 03:47:31,959 will edit, starting with one, and then multiply\n 3704 03:47:31,959 --> 03:47:32,959 reason is this is an optimization to have\n 3705 03:47:32,959 --> 03:47:33,959 the collisions, that this can decrease the\n 3706 03:47:33,959 --> 03:47:34,959 really doing something here, I'm just calling\n 3707 03:47:34,959 --> 03:47:35,959 is why now we should jump in the other classes,\n 3708 03:47:35,959 --> 03:47:36,959 but I've chosen engine here in this case,\n 3709 03:47:36,959 --> 03:47:37,959 in one example. So let's jump to engine. Okay,\n 3710 03:47:37,959 --> 03:47:38,959 or at least similar. Then in car, the only\n 3711 03:47:38,959 --> 03:47:39,959 I called optional field, because I defined\n 3712 03:47:39,959 --> 03:47:40,959 So therefore, my check here for equals has\n 3713 03:47:40,959 --> 03:47:41,959 to save it's now then I check if the other\n 3714 03:47:41,959 --> 03:47:42,959 field is now the other is not so it's not\n 3715 03:47:42,959 --> 03:47:43,959 both fields. So I'm doing all this again to\n 3716 03:47:43,959 --> 03:47:44,959 other case, when I don't check for now, my\n 3717 03:47:44,959 --> 03:47:45,959 field, so it can't be null anyway, but for\n 3718 03:47:45,959 --> 03:47:46,959 a manufacturer, engine and a color. So my\n 3719 03:47:46,959 --> 03:47:47,959 now, if someone would introduce a bug. And\n 3720 03:47:47,959 --> 03:47:48,959 course, this could produce a nullpointerexception.\n 3721 03:47:48,959 --> 03:47:49,959 This is what I call rocket code. Because it's\n 3722 03:47:49,959 --> 03:47:50,959 your code, you have to have certain assumptions,\n 3723 03:47:50,959 --> 03:47:51,959 fields, these fields can never be now. And\n 3724 03:47:51,959 --> 03:47:52,959 will crash, okay, we have to fix it. But then\n 3725 03:47:52,959 --> 03:47:53,959 stays clean. And this is important, because\n 3726 03:47:53,959 --> 03:47:54,959 Okay, so only four fields where you know,\n 3727 03:47:54,959 --> 03:47:55,959 Okay. So that much for the equals method,\n 3728 03:47:55,959 --> 03:47:56,959 in car. Now for the hashCode method. Here,\n 3729 03:47:56,959 --> 03:47:57,959 Because here, I cannot forward to a hash code\n 3730 03:47:57,959 --> 03:47:58,959 long. And for that, because the primitive\n 3731 03:47:58,959 --> 03:47:59,959 some hash code. And this is a long, and so\n 3732 03:47:59,959 --> 03:48:00,959 A long has that has like 64 bits, while an\n 3733 03:48:00,959 --> 03:48:01,959 make the long to half its size, and you want\n 3734 03:48:01,959 --> 03:48:02,959 least possible number of collisions. And therefore,\n 3735 03:48:02,959 --> 03:48:03,959 is actually based on again, Josh blocks book\n 3736 03:48:03,959 --> 03:48:04,959 actually, he doesn't explain it too much.\n 3737 03:48:04,959 --> 03:48:05,959 watch my follow up tutorial about hash code\n 3738 03:48:05,959 --> 03:48:06,959 This is a shift by 32 bits. And then this\n 3739 03:48:06,959 --> 03:48:07,959 combine this field. And last but not least,\n 3740 03:48:07,959 --> 03:48:08,959 where you throw away Half of the long, but\n 3741 03:48:08,959 --> 03:48:09,959 one minute, you have to watch really the extended\n 3742 03:48:09,959 --> 03:48:10,959 good way to create an end hash code from alarm.\n 3743 03:48:11,959 --> 03:48:12,959 And the second field here is a string as it\n 3744 03:48:12,959 --> 03:48:13,959 And I'm not sure if I have shown you this\n 3745 03:48:13,959 --> 03:48:14,959 because otherwise the code would even be longer.\n 3746 03:48:14,959 --> 03:48:15,959 now. If true, then return zero, else return\n 3747 03:48:15,959 --> 03:48:16,959 calls the hashCode method of string. This\n 3748 03:48:16,959 --> 03:48:17,959 where the code was like in a while loop, going\n 3749 03:48:17,959 --> 03:48:18,959 calculating an int value for the string. So\n 3750 03:48:18,959 --> 03:48:19,959 call the hashCode method. Okay. So, again,\n 3751 03:48:19,959 --> 03:48:20,959 And in this case, I decided to use both to\n 3752 03:48:20,959 --> 03:48:21,959 And so as I use type an optional field and\n 3753 03:48:21,959 --> 03:48:22,959 and hashCode in the same order and same fields.\n 3754 03:48:22,959 --> 03:48:23,959 is this doesn't mean anything, this is really\n 3755 03:48:23,959 --> 03:48:24,959 short, show you all the different primitive\n 3756 03:48:24,959 --> 03:48:25,959 that you see like how the different cases\n 3757 03:48:25,959 --> 03:48:26,959 So let's first of all look at hash code. So\n 3758 03:48:26,959 --> 03:48:27,959 one here, float, well float has the same size\n 3759 03:48:27,959 --> 03:48:28,959 function, which will convert the float to\n 3760 03:48:28,959 --> 03:48:29,959 A has the same length as a long. So this is\n 3761 03:48:29,959 --> 03:48:30,959 again, with a native function too long. A\n 3762 03:48:30,959 --> 03:48:31,959 implemented in Java, but in machine dependent\n 3763 03:48:31,959 --> 03:48:32,959 details, watch my follow up tutorial. But\n 3764 03:48:32,959 --> 03:48:33,959 weird line here to convert it to an end. Next\n 3765 03:48:33,959 --> 03:48:34,959 here. If it's true, question mark, then 1231.\n 3766 03:48:34,959 --> 03:48:35,959 All this stuff is really technical might be\n 3767 03:48:35,959 --> 03:48:36,959 just really important for performance optimization\n 3768 03:48:36,959 --> 03:48:37,959 car is just taken as it is because it can\n 3769 03:48:37,959 --> 03:48:38,959 we call this hashCode method. And for the\n 3770 03:48:38,959 --> 03:48:39,959 an end or smaller than an end, that's relatively\n 3771 03:48:39,959 --> 03:48:40,959 it is because a byte will always fit into\n 3772 03:48:40,959 --> 03:48:41,959 And an end of course, should also fit into\n 3773 03:48:41,959 --> 03:48:42,959 really short. I'm just not enough time to\n 3774 03:48:42,959 --> 03:48:43,959 I have done the follow up tutorial you can\n 3775 03:48:43,959 --> 03:48:44,959 understand. Now last but not least, let's\n 3776 03:48:44,959 --> 03:48:45,959 the primitive values here, it's pretty easy\n 3777 03:48:45,959 --> 03:48:46,959 can just use the not equal operator. 3778 03:48:46,959 --> 03:48:47,959 So if it's if the bytes are not equal, just\n 3779 03:48:47,959 --> 03:48:48,959 involved, false is returned. And also see\n 3780 03:48:48,959 --> 03:48:49,959 the smallest possible values, because here\n 3781 03:48:49,959 --> 03:48:50,959 all this crazy stuff down here. And this is\n 3782 03:48:50,959 --> 03:48:51,959 end, long, this is all easy. With float, it's\n 3783 03:48:51,959 --> 03:48:52,959 first to an end, that will has to be converted\n 3784 03:48:52,959 --> 03:48:53,959 actually, if this was a real whoops, if this\n 3785 03:48:53,959 --> 03:48:54,959 it differently, I would have put it to the\n 3786 03:48:54,959 --> 03:48:55,959 you the different types. So in reality, I\n 3787 03:48:55,959 --> 03:48:56,959 based on what the business tells you what\n 3788 03:48:56,959 --> 03:48:57,959 you have to think, like, from the performance,\n 3789 03:48:57,959 --> 03:48:58,959 it depends if you really need the performance.\n 3790 03:48:58,959 --> 03:48:59,959 because you might think something is fast.\n 3791 03:48:59,959 --> 03:49:00,959 as fast as he would have thought, okay, because\n 3792 03:49:00,959 --> 03:49:01,959 thumb, but I might be totally wrong in a specific\n 3793 03:49:01,959 --> 03:49:02,959 need a certain performance, I test for it.\n 3794 03:49:02,959 --> 03:49:03,959 it. Or I just use my gut feeling to sort the\n 3795 03:49:03,959 --> 03:49:04,959 so I hope you liked this episode about hashCode.\n 3796 03:49:04,959 --> 03:49:05,959 and so long. I just wanted to put in everything\n 3797 03:49:05,959 --> 03:49:06,959 topic that he should really understand in\n 3798 03:49:06,959 --> 03:49:07,959 So I would also ask you go to my blog, www\n 3799 03:49:07,959 --> 03:49:08,959 some links to some extended articles on the\n 3800 03:49:08,959 --> 03:49:09,959 Effective Java from Drush blog, he also talks\n 3801 03:49:10,959 --> 03:49:11,959 I will give you a high level introduction\n 3802 03:49:11,959 --> 03:49:12,959 there are several overloaded uses of the word\n 3803 03:49:12,959 --> 03:49:13,959 up front. The different use cases are a collection\n 3804 03:49:13,959 --> 03:49:14,959 or group of things. Second, the Java collections\n 3805 03:49:14,959 --> 03:49:15,959 and classes. Third, a collection as a data\n 3806 03:49:15,959 --> 03:49:16,959 can hold a group of objects, like an array,\n 3807 03:49:16,959 --> 03:49:17,959 interface, one of the two main interfaces\n 3808 03:49:17,959 --> 03:49:18,959 Java util collections, or utility class that\n 3809 03:49:18,959 --> 03:49:19,959 collections. This episode is based on chapter\n 3810 03:49:19,959 --> 03:49:20,959 packed with knowledge. As a great fan of the\n 3811 03:49:20,959 --> 03:49:21,959 you to read this book, even when you don't\n 3812 03:49:21,959 --> 03:49:22,959 is the Java collections framework? from a\n 3813 03:49:22,959 --> 03:49:23,959 more like a library a toolbox of generic interfaces\n 3814 03:49:23,959 --> 03:49:24,959 collection interfaces and classes that serve\n 3815 03:49:24,959 --> 03:49:25,959 to arrays, collection related utility interfaces\n 3816 03:49:25,959 --> 03:49:26,959 I'm going to describe both parts in detail\n 3817 03:49:26,959 --> 03:49:27,959 interface and class hierarchy for collections.\n 3818 03:49:27,959 --> 03:49:28,959 grow or shrink in size. Except before a collection\n 3819 03:49:28,959 --> 03:49:29,959 pairs of objects that have some kind of relation,\n 3820 03:49:30,959 --> 03:49:31,959 does not have a specific position in this\n 3821 03:49:31,959 --> 03:49:32,959 is related to relax if you don't get it now.\n 3822 03:49:32,959 --> 03:49:33,959 So here you see the hierarchy of classes and\n 3823 03:49:33,959 --> 03:49:34,959 collections interface. Just try to remember\n 3824 03:49:34,959 --> 03:49:35,959 an overview so far. As you can see, the collection\n 3825 03:49:35,959 --> 03:49:36,959 and implementing classes. A collection can\n 3826 03:49:36,959 --> 03:49:37,959 is extended by the interface of set list and\n 3827 03:49:37,959 --> 03:49:38,959 objects. What is considered as unique is defined\n 3828 03:49:38,959 --> 03:49:39,959 set holds. So in other words, a set cannot\n 3829 03:49:39,959 --> 03:49:40,959 a sequence of objects. So unlike a set, a\n 3830 03:49:40,959 --> 03:49:41,959 a list keeps its elements in the order, they\n 3831 03:49:41,959 --> 03:49:42,959 sides, entries are added to the end and removed\n 3832 03:49:42,959 --> 03:49:43,959 as first in first out, which is pretty much\n 3833 03:49:43,959 --> 03:49:44,959 first person queueing up will also be the\n 3834 03:49:44,959 --> 03:49:45,959 have a closer look at the interfaces and classes\n 3835 03:49:45,959 --> 03:49:46,959 Hash set linked hash set and three set are\n 3836 03:49:46,959 --> 03:49:47,959 is the default implementation that is used\n 3837 03:49:47,959 --> 03:49:48,959 is like a mix of a hash set and the list as\n 3838 03:49:48,959 --> 03:49:49,959 set. But it returns its elements in the order\n 3839 03:49:49,959 --> 03:49:50,959 would do. Chrisette will constantly keep all\n 3840 03:49:50,959 --> 03:49:51,959 mind, there is no free lunch. So every edit\n 3841 03:49:51,959 --> 03:49:52,959 After looking at the classes implementing\n 3842 03:49:52,959 --> 03:49:53,959 at the two extending interfaces we haven't\n 3843 03:49:53,959 --> 03:49:54,959 set is a set that is constantly sorted. The\n 3844 03:49:54,959 --> 03:49:55,959 Java six, it allows to navigate through the\n 3845 03:49:55,959 --> 03:49:56,959 to retrieve the next element greater or smaller\n 3846 03:49:56,959 --> 03:49:57,959 have a closer look at the classes that implement\n 3847 03:49:57,959 --> 03:49:58,959 implementation of the list interface. Like\n 3848 03:49:58,959 --> 03:49:59,959 elements and it does allow to iterate the\n 3849 03:49:59,959 --> 03:50:00,959 on arrays, it is very fast to iterate and\n 3850 03:50:00,959 --> 03:50:01,959 an element at a random position is very slow,\n 3851 03:50:01,959 --> 03:50:02,959 array structure. vector is a class that exists\n 3852 03:50:02,959 --> 03:50:03,959 framework, which was added with Java two.\n 3853 03:50:03,959 --> 03:50:04,959 So So please never use it. Use ArrayList or\n 3854 03:50:04,959 --> 03:50:05,959 it and forget about it. The next list implementation\n 3855 03:50:05,959 --> 03:50:06,959 is based on a linked list, which makes it\n 3856 03:50:06,959 --> 03:50:07,959 in the list. Last but not least, let's have\n 3857 03:50:07,959 --> 03:50:08,959 interface. We already talked about link list,\n 3858 03:50:08,959 --> 03:50:09,959 However, the fact that it's based on a double\n 3859 03:50:09,959 --> 03:50:10,959 also implement the queue interface. linked\n 3860 03:50:10,959 --> 03:50:11,959 priority queue is a queue implementation that\n 3861 03:50:11,959 --> 03:50:12,959 It has similar functionality like a tree set,\n 3862 03:50:12,959 --> 03:50:13,959 look at the map interface. This interface\n 3863 03:50:13,959 --> 03:50:14,959 A collection operates on one entity, while\n 3864 03:50:14,959 --> 03:50:15,959 for example, a vehicle identification number,\n 3865 03:50:15,959 --> 03:50:16,959 for example, a car object with the help of\n 3866 03:50:16,959 --> 03:50:17,959 to. The interface map is the root of a lot\n 3867 03:50:17,959 --> 03:50:18,959 at now. The class hash table was the first\n 3868 03:50:18,959 --> 03:50:19,959 on a data structure hash table. So the Java\n 3869 03:50:19,959 --> 03:50:20,959 this makes it a bit hard to differentiate\n 3870 03:50:20,959 --> 03:50:21,959 deprecated, because of its sub optimal performance,\n 3871 03:50:21,959 --> 03:50:22,959 Instead, use one of the other classes that\n 3872 03:50:22,959 --> 03:50:23,959 default implementation that you should use\n 3873 03:50:23,959 --> 03:50:24,959 not make any guarantees on how it internally\n 3874 03:50:24,959 --> 03:50:25,959 rule is linked hash map, which allows to iterate\n 3875 03:50:25,959 --> 03:50:26,959 not least, tree map is a constantly sorted\n 3876 03:50:26,959 --> 03:50:27,959 extend the map interface. As the name implies,\n 3877 03:50:27,959 --> 03:50:28,959 and defines the contract of a constantly sorted\n 3878 03:50:28,959 --> 03:50:29,959 map interface, and adds methods to navigate\n 3879 03:50:29,959 --> 03:50:30,959 all entries smaller or bigger than a given\n 3880 03:50:30,959 --> 03:50:31,959 similarities between the map and the set hierarchy.\n 3881 03:50:31,959 --> 03:50:32,959 are actually internally backed by a map implementation.\n 3882 03:50:32,959 --> 03:50:33,959 the Java collection classes often contain\n 3883 03:50:33,959 --> 03:50:34,959 name. To choose the best collection for a\n 3884 03:50:34,959 --> 03:50:35,959 characteristics of data structures like array,\n 3885 03:50:35,959 --> 03:50:36,959 short, there is no single best option. Each\n 3886 03:50:36,959 --> 03:50:37,959 I promise to talk about this very exciting\n 3887 03:50:37,959 --> 03:50:38,959 overview of the collection and map classes\n 3888 03:50:38,959 --> 03:50:39,959 In a later episode, I will introduce you to\n 3889 03:50:39,959 --> 03:50:40,959 framework. generics is a topic at least as\n 3890 03:50:40,959 --> 03:50:41,959 the context of this episode, I will therefore\n 3891 03:50:41,959 --> 03:50:42,959 to understand the collections framework. It's\n 3892 03:50:42,959 --> 03:50:43,959 my brief overview. Give both of us some time.\n 3893 03:50:43,959 --> 03:50:44,959 the other I would recommend you to subscribe\n 3894 03:50:44,959 --> 03:50:45,959 as I upload the next episodes of the Java\n 3895 03:50:45,959 --> 03:50:46,959 belts. Here, it's going to be a bumpy ride,\n 3896 03:50:46,959 --> 03:50:47,959 brackets. Just relax. Actually, it's much\n 3897 03:50:47,959 --> 03:50:48,959 line, you see I have defined a list variable\n 3898 03:50:48,959 --> 03:50:49,959 brackets, I tell the compiler that my main\n 3899 03:50:50,959 --> 03:50:51,959 Then I create an object of type ArrayList.\n 3900 03:50:51,959 --> 03:50:52,959 is only supposed to be used with strings,\n 3901 03:50:52,959 --> 03:50:53,959 tries to put anything else than a string into\n 3902 03:50:53,959 --> 03:50:54,959 the container type safe. Also, note that I\n 3903 03:50:54,959 --> 03:50:55,959 not ArrayList. This makes your code more flexible.\n 3904 03:50:55,959 --> 03:50:56,959 at various places in your code, he will use\n 3905 03:50:56,959 --> 03:50:57,959 for the reference variable. You could later\n 3906 03:50:58,959 --> 03:50:59,959 you had to adjust was this one line of code.\n 3907 03:51:00,959 --> 03:51:01,959 you could also use the collection interface\n 3908 03:51:01,959 --> 03:51:02,959 for the reference variable. Oh, by the way,\n 3909 03:51:02,959 --> 03:51:03,959 use as a constructor argument. This I have\n 3910 03:51:03,959 --> 03:51:04,959 before, the collection classes can dynamically\n 3911 03:51:04,959 --> 03:51:05,959 and all hash table based collections are internally\n 3912 03:51:05,959 --> 03:51:06,959 grows in size, it will internally on the fly,\n 3913 03:51:06,959 --> 03:51:07,959 from the old to the new array. This of course\n 3914 03:51:07,959 --> 03:51:08,959 so fast, that is usually should not be a problem.\n 3915 03:51:08,959 --> 03:51:09,959 the exact, or at least the approximate size\n 3916 03:51:09,959 --> 03:51:10,959 better than trusting on the collections default\n 3917 03:51:10,959 --> 03:51:11,959 the data structures that the Java collections\n 3918 03:51:11,959 --> 03:51:12,959 understand performance considerations like\n 3919 03:51:12,959 --> 03:51:13,959 small little details, makes the difference\n 3920 03:51:13,959 --> 03:51:14,959 So I wanted to let you know as early as possible.\n 3921 03:51:14,959 --> 03:51:15,959 Let's get back to the topic of generics. Now\n 3922 03:51:15,959 --> 03:51:16,959 is instantiated accordingly. As said before,\n 3923 03:51:16,959 --> 03:51:17,959 key to one value element. Both these elements\n 3924 03:51:17,959 --> 03:51:18,959 example, I use Vin, the vehicle identification\n 3925 03:51:18,959 --> 03:51:19,959 value. This has to be added as a comma separated\n 3926 03:51:19,959 --> 03:51:20,959 will check that this holds true. If you create\n 3927 03:51:20,959 --> 03:51:21,959 both in one line, you can also leave the second\n 3928 03:51:21,959 --> 03:51:22,959 inferred from the generic type of the reference\n 3929 03:51:22,959 --> 03:51:23,959 and is called the diamond operator. Because\n 3930 03:51:23,959 --> 03:51:24,959 a diamond. Actually, I'm sorry. That's not\n 3931 03:51:24,959 --> 03:51:25,959 what I just showed you. This was actually\n 3932 03:51:25,959 --> 03:51:26,959 class when you lock in the contract parameter\n 3933 03:51:26,959 --> 03:51:27,959 method, the interface or the class was defined\n 3934 03:51:27,959 --> 03:51:28,959 you see a generically defined interface. In\n 3935 03:51:28,959 --> 03:51:29,959 an interface operating on two separate generic\n 3936 03:51:29,959 --> 03:51:30,959 time. However, when these types are locked\n 3937 03:51:30,959 --> 03:51:31,959 type, the types, interface methods we'll use.\n 3938 03:51:31,959 --> 03:51:32,959 in one of the next slides, just remember it\n 3939 03:51:32,959 --> 03:51:33,959 a generic way. Okay, now we are ready to look\n 3940 03:51:33,959 --> 03:51:34,959 Java collections framework. They are implemented\n 3941 03:51:34,959 --> 03:51:35,959 the JDK in general, but they can also be implemented\n 3942 03:51:35,959 --> 03:51:36,959 of the collections framework. Well, strictly\n 3943 03:51:36,959 --> 03:51:37,959 is not part of the framework. But more precisely,\n 3944 03:51:37,959 --> 03:51:38,959 of Java util collection. So every class that\n 3945 03:51:38,959 --> 03:51:39,959 implement the Java Lang iterable interface.\n 3946 03:51:39,959 --> 03:51:40,959 in detail. an iterator is an object that acts\n 3947 03:51:40,959 --> 03:51:41,959 collection. Let's look at its methods. Boolean\n 3948 03:51:41,959 --> 03:51:42,959 more elements. ie next returns the next element\n 3949 03:51:42,959 --> 03:51:43,959 the last element returned by this iterator\n 3950 03:51:43,959 --> 03:51:44,959 provides only one method, which will return\n 3951 03:51:44,959 --> 03:51:45,959 this interface can be used on the for each\n 3952 03:51:45,959 --> 03:51:46,959 your homemade collection. In order to plug\n 3953 03:51:46,959 --> 03:51:47,959 you will have to execute two simple steps.\n 3954 03:51:47,959 --> 03:51:48,959 over your collection with methods like hasnext.\n 3955 03:51:48,959 --> 03:51:49,959 you need to implement the iterable interface\n 3956 03:51:49,959 --> 03:51:50,959 an instance of this iterator implementing\n 3957 03:51:50,959 --> 03:51:51,959 a sort order for your entities. The interface\n 3958 03:51:51,959 --> 03:51:52,959 which is int compared to if you want to define\n 3959 03:51:52,959 --> 03:51:53,959 make it implement this interface. return a\n 3960 03:51:53,959 --> 03:51:54,959 a given method argument, zero if the object\n 3961 03:51:54,959 --> 03:51:55,959 a positive integer if the object is greater\n 3962 03:51:55,959 --> 03:51:56,959 smaller or greater is for you to define. For\n 3963 03:51:56,959 --> 03:51:57,959 is smaller than five, for example. But for\n 3964 03:51:57,959 --> 03:51:58,959 sort your entities. When you put objects of\n 3965 03:51:58,959 --> 03:51:59,959 into a tree set or tree map, it will use your\n 3966 03:51:59,959 --> 03:52:00,959 elements you put into the collection. As you\n 3967 03:52:00,959 --> 03:52:01,959 been greatly designed for extension. It offers\n 3968 03:52:01,959 --> 03:52:02,959 classes. This interface is very similar to\n 3969 03:52:02,959 --> 03:52:03,959 define additional sorting orders like a reverse\n 3970 03:52:03,959 --> 03:52:04,959 implemented in your entity, but in an external\n 3971 03:52:04,959 --> 03:52:05,959 be added to a collection or sorting method\n 3972 03:52:05,959 --> 03:52:06,959 your collection of entities. The rules of\n 3973 03:52:06,959 --> 03:52:07,959 same as for comparable. return a negative\n 3974 03:52:07,959 --> 03:52:08,959 the second argument, zero if both arguments\n 3975 03:52:08,959 --> 03:52:09,959 argument is greater than the second. Last\n 3976 03:52:09,959 --> 03:52:10,959 classes, collections and arrays, like a Swiss\n 3977 03:52:10,959 --> 03:52:11,959 that greatly enhance the general usefulness\n 3978 03:52:11,959 --> 03:52:12,959 offers methods like sword shuffle, reverse\n 3979 03:52:12,959 --> 03:52:13,959 on areas and not on collections actually,\n 3980 03:52:13,959 --> 03:52:14,959 us to swap areas or to search through areas\n 3981 03:52:14,959 --> 03:52:15,959 look at ArrayList. And the second half, I'll\n 3982 03:52:15,959 --> 03:52:16,959 get started. Error list is the default implementation\n 3983 03:52:16,959 --> 03:52:17,959 of list, you can have duplicate elements in\n 3984 03:52:17,959 --> 03:52:18,959 to element in the same order as the elements\n 3985 03:52:18,959 --> 03:52:19,959 provides fast access, but inserting or removing\n 3986 03:52:19,959 --> 03:52:20,959 time, as this will require to reorganize the\n 3987 03:52:20,959 --> 03:52:21,959 most applications, which is why ArrayList\n 3988 03:52:21,959 --> 03:52:22,959 data that changes frequently. However, consider\n 3989 03:52:22,959 --> 03:52:23,959 linked list. I will talk about this as well\n 3990 03:52:23,959 --> 03:52:24,959 of my free Java video course. Okay, before\n 3991 03:52:24,959 --> 03:52:25,959 terms, which are important to understand in\n 3992 03:52:25,959 --> 03:52:26,959 Size is the number of elements the ArrayList\n 3993 03:52:26,959 --> 03:52:27,959 to the list, the size will grow by one capacity\n 3994 03:52:27,959 --> 03:52:28,959 underlying array can hold. The capacity of\n 3995 03:52:28,959 --> 03:52:29,959 list starts with an initial capacity. Every\n 3996 03:52:29,959 --> 03:52:30,959 the ArrayList copies the data over to a new\n 3997 03:52:30,959 --> 03:52:31,959 one. Let's say you want to add 100 elements\n 3998 03:52:31,959 --> 03:52:32,959 10. As the list grows, the system will create\nsix more areas 3999 03:52:32,959 --> 03:52:33,959 to take the place of the first. First one\n 4000 03:52:33,959 --> 03:52:34,959 a maximum of 22 elements. Then areas with\n 4001 03:52:34,959 --> 03:52:35,959 to hold the growing list. These restructuring\n 4002 03:52:35,959 --> 03:52:36,959 you can instantly create an array of the correct\n 4003 03:52:36,959 --> 03:52:37,959 by defining the correct capacity at creation\n 4004 03:52:37,959 --> 03:52:38,959 of the ArrayList at creation time, estimated\n 4005 03:52:38,959 --> 03:52:39,959 capacity however, can also negatively impact\n 4006 03:52:39,959 --> 03:52:40,959 I advise you to always explicitly set the\n 4007 03:52:40,959 --> 03:52:41,959 intentions. For most projects, you won't have\n 4008 03:52:41,959 --> 03:52:42,959 powerful hardware. But this is no excuse for\n 4009 03:52:42,959 --> 03:52:43,959 you can see a simplified extract of the class\n 4010 03:52:43,959 --> 03:52:44,959 a bit more complicated. This is just meant\n 4011 03:52:44,959 --> 03:52:45,959 class ArrayList looks like. As you can see,\n 4012 03:52:45,959 --> 03:52:46,959 written. Given enough time and knowledge,\n 4013 03:52:46,959 --> 03:52:47,959 actual source code online. However, don't\n 4014 03:52:47,959 --> 03:52:48,959 the source code as they may change any time\n 4015 03:52:48,959 --> 03:52:49,959 specification. Default capacity is the initial\n 4016 03:52:49,959 --> 03:52:50,959 it as I recommended before element data is\n 4017 03:52:50,959 --> 03:52:51,959 ArrayList in size is the number of elements\n 4018 03:52:51,959 --> 03:52:52,959 remove are some of the many functions ArrayList\n 4019 03:52:52,959 --> 03:52:53,959 So, let me give you a short overview of the\n 4020 03:52:53,959 --> 03:52:54,959 easy for you, I have broken up the overview\n 4021 03:52:54,959 --> 03:52:55,959 interface, and methods belonging to the Java\n 4022 03:52:55,959 --> 03:52:56,959 containers in later episodes, implementing\n 4023 03:52:56,959 --> 03:52:57,959 refer back to this episode. Instead of repeating\n 4024 03:52:57,959 --> 03:52:58,959 are subscribed to my YouTube channel. So you\n 4025 03:52:58,959 --> 03:52:59,959 these classes also. Okay, so let's start with\n 4026 03:52:59,959 --> 03:53:00,959 interface. The contract of the collection\n 4027 03:53:00,959 --> 03:53:01,959 order, and therefore does not provide any\n 4028 03:53:01,959 --> 03:53:02,959 can see the first set of methods that implement\n 4029 03:53:02,959 --> 03:53:03,959 these methods does not only apply to ArrayList,\n 4030 03:53:03,959 --> 03:53:04,959 collection interface. The method Boolean ad\n 4031 03:53:04,959 --> 03:53:05,959 to the next empty cell of the underlying array.\n 4032 03:53:05,959 --> 03:53:06,959 to the end of the collection. The stuff in\n 4033 03:53:06,959 --> 03:53:07,959 short, it ensures that no one can call such\n 4034 03:53:07,959 --> 03:53:08,959 relax. I will tell you more in my upcoming\n 4035 03:53:08,959 --> 03:53:09,959 the first occurrence of the element you specify\n 4036 03:53:09,959 --> 03:53:10,959 the given elements from the collection. The\n 4037 03:53:10,959 --> 03:53:11,959 use an a loop to move from one element to\n 4038 03:53:11,959 --> 03:53:12,959 step you say I iterate over the collection.\n 4039 03:53:12,959 --> 03:53:13,959 number of elements of the collection. Boolean\n 4040 03:53:13,959 --> 03:53:14,959 at least one instance of the element you specify. 4041 03:53:14,959 --> 03:53:15,959 Wide clear removes all elements from the collection.\n 4042 03:53:15,959 --> 03:53:16,959 collection contains no elements. And to array\n 4043 03:53:17,959 --> 03:53:18,959 Alright, let's move on to the methods of the\n 4044 03:53:18,959 --> 03:53:19,959 similar in part to the methods we just looked\n 4045 03:53:19,959 --> 03:53:20,959 order on the elements of the list. So here\n 4046 03:53:20,959 --> 03:53:21,959 about these methods does not only apply to\n 4047 03:53:21,959 --> 03:53:22,959 the list interface. This add method with an\n 4048 03:53:22,959 --> 03:53:23,959 insert method. It allows you to insert an\n 4049 03:53:23,959 --> 03:53:24,959 Instead of just adding the element to the\n 4050 03:53:24,959 --> 03:53:25,959 of the underlying array will be shifted to\n 4051 03:53:25,959 --> 03:53:26,959 necessary. The remove index method allows\n 4052 03:53:26,959 --> 03:53:27,959 of the Similar to the Add method we just looked\n 4053 03:53:27,959 --> 03:53:28,959 elements of the underlying array to the left.\n 4054 03:53:28,959 --> 03:53:29,959 from any given position of the list. The index\n 4055 03:53:29,959 --> 03:53:30,959 index of the first occurrence of the element\n 4056 03:53:30,959 --> 03:53:31,959 not found. In last index of returns the index\n 4057 03:53:31,959 --> 03:53:32,959 list, and SP four minus one if the element\n 4058 03:53:32,959 --> 03:53:33,959 of the list starting with the position you\n 4059 03:53:33,959 --> 03:53:34,959 before the one you specify as to index. Last\n 4060 03:53:34,959 --> 03:53:35,959 list following the order of the given comparator.\n 4061 03:53:35,959 --> 03:53:36,959 time to move on to some practical coding.\n 4062 03:53:36,959 --> 03:53:37,959 prepared a little test method. So we can do\n 4063 03:53:37,959 --> 03:53:38,959 already created an instance of ArrayList.\n 4064 03:53:38,959 --> 03:53:39,959 of type collection. Now, this might be a bit\n 4065 03:53:39,959 --> 03:53:40,959 that not ArrayList? Or at least list. While\n 4066 03:53:40,959 --> 03:53:41,959 C. Martin, he says, a good architecture is\n 4067 03:53:41,959 --> 03:53:42,959 not made, or the number of decisions D fared.\n 4068 03:53:43,959 --> 03:53:44,959 I mean, you would create this instance for\n 4069 03:53:44,959 --> 03:53:45,959 forward it to either other methods and or\n 4070 03:53:45,959 --> 03:53:46,959 ArrayList, this will really limit all your\n 4071 03:53:46,959 --> 03:53:47,959 to work on an ArrayList. But now, the requirements\n 4072 03:53:47,959 --> 03:53:48,959 they change very fast as you know. And if\n 4073 03:53:48,959 --> 03:53:49,959 can hold duplicate elements. But now there\n 4074 03:53:49,959 --> 03:53:50,959 you cannot have duplicate elements, you have\n 4075 03:53:50,959 --> 03:53:51,959 So you might want to use hash set here. Now,\n 4076 03:53:51,959 --> 03:53:52,959 the code, it will be very tough to change\n 4077 03:53:52,959 --> 03:53:53,959 code, which is very dangerous. But if this\n 4078 03:53:53,959 --> 03:53:54,959 many things. And so it will be much easier\n 4079 03:53:54,959 --> 03:53:55,959 have to do is change the instantiation of\n 4080 03:53:55,959 --> 03:53:56,959 if you can, like of course, this limits the\n 4081 03:53:56,959 --> 03:53:57,959 the collection interface is less powerful\n 4082 03:53:57,959 --> 03:53:58,959 But if you can, like if you only need the\n 4083 03:53:58,959 --> 03:53:59,959 then do it like this. later on. We will switch\n 4084 03:53:59,959 --> 03:54:00,959 show you methods that only appear in the list\n 4085 03:54:00,959 --> 03:54:01,959 variable of type collection. And then you'll\n 4086 03:54:01,959 --> 03:54:02,959 you see in the single line? Besides you might\n 4087 03:54:02,959 --> 03:54:03,959 brackets, so we have created a collection\n 4088 03:54:03,959 --> 03:54:04,959 so called diamond operator that was introduced\n 4089 03:54:04,959 --> 03:54:05,959 in one line, we do the object instantiation.\n 4090 03:54:05,959 --> 03:54:06,959 line. The compiler directly sees this must\n 4091 03:54:06,959 --> 03:54:07,959 the diamond operator. But we could also do\n 4092 03:54:07,959 --> 03:54:08,959 is just a bit shorter. Okay, and last but\n 4093 03:54:08,959 --> 03:54:09,959 initial capacity, which is a constant, which\n 4094 03:54:09,959 --> 03:54:10,959 initial capacity five. Now you might say well,\n 4095 03:54:10,959 --> 03:54:11,959 this is faster. Well, at first, it might seem\n 4096 03:54:11,959 --> 03:54:12,959 this is evil, because it makes it so much\n 4097 03:54:12,959 --> 03:54:13,959 this five actually means. Like not everyone\n 4098 03:54:13,959 --> 03:54:14,959 But if you use the constant value here, you\n 4099 03:54:14,959 --> 03:54:15,959 is actually quite good. And I recommend you\n 4100 03:54:15,959 --> 03:54:16,959 start using some methods. I mean, we're not\n 4101 03:54:16,959 --> 03:54:17,959 but we're just playing around with the methods,\n 4102 03:54:17,959 --> 03:54:18,959 is all about. And as this is now, a collection\n 4103 03:54:18,959 --> 03:54:19,959 see all the methods of the collection interface.\n 4104 03:54:19,959 --> 03:54:20,959 like one limitation that we have now is we\n 4105 03:54:20,959 --> 03:54:21,959 also the reason why before in my slides, I\n 4106 03:54:21,959 --> 03:54:22,959 related to the collection interface, and methods\n 4107 03:54:22,959 --> 03:54:23,959 now I can also go back to the slides and compare,\n 4108 03:54:23,959 --> 03:54:24,959 collection interface. So this is a collection\n 4109 03:54:24,959 --> 03:54:25,959 let's add B, capital B. Let's add some more. 4110 03:54:26,959 --> 03:54:27,959 later on, I'm also planning to sort the error\n 4111 03:54:27,959 --> 03:54:28,959 with the collection reference variable, we\n 4112 03:54:28,959 --> 03:54:29,959 I'll do it soon. Oh, okay. And I mean, even\n 4113 03:54:29,959 --> 03:54:30,959 collection, still, the fact that we have an\n 4114 03:54:30,959 --> 03:54:31,959 elements. So let's do that. Maybe I should\n 4115 03:54:31,959 --> 03:54:32,959 count how many numbers elements I added 123456,\n 4116 03:54:32,959 --> 03:54:33,959 means when you add the sixth element, internally,\n 4117 03:54:33,959 --> 03:54:34,959 list will realize, well, the capacity is insufficient,\n 4118 03:54:34,959 --> 03:54:35,959 and will then migrate all the existing data\n 4119 03:54:35,959 --> 03:54:36,959 the second he is added, which costs some extra\n 4120 03:54:36,959 --> 03:54:37,959 regular situation like this five, six elements,\n 4121 03:54:37,959 --> 03:54:38,959 Low. So never, I'm never worry, in such situations,\n 4122 03:54:38,959 --> 03:54:39,959 about this when it gets a problem. And usually,\n 4123 03:54:39,959 --> 03:54:40,959 1000s or 10s of 1000s, if not a million of\n 4124 03:54:40,959 --> 03:54:41,959 of elements, you have the amount of iterations\n 4125 03:54:41,959 --> 03:54:42,959 print the error list as it is now, there are\n 4126 03:54:42,959 --> 03:54:43,959 string method. So I could directly say system,\n 4127 03:54:43,959 --> 03:54:44,959 bit more complicated, because I want to show\n 4128 03:54:44,959 --> 03:54:45,959 And this is because every list, and every\n 4129 03:54:45,959 --> 03:54:46,959 which is used in this new for each loop. And\n 4130 03:54:46,959 --> 03:54:47,959 string string, and then column and then elements.\n 4131 03:54:47,959 --> 03:54:48,959 list will be done here inside and you don't\n 4132 03:54:48,959 --> 03:54:49,959 us internally. In short, I can tell you, there\n 4133 03:54:49,959 --> 03:54:50,959 Before, which will then be used. You might\n 4134 03:54:50,959 --> 03:54:51,959 you to the iterable. And the iterator interface,\n 4135 03:54:51,959 --> 03:54:52,959 enough, if you see, you can use the ArrayList\n 4136 03:54:52,959 --> 03:54:53,959 out each element separately, which of course\n 4137 03:54:53,959 --> 03:54:54,959 print something else here also. Okay. So this\n 4138 03:54:54,959 --> 03:54:55,959 element by element. And I also want to show\n 4139 03:54:55,959 --> 03:54:56,959 this out. I also want to show you that which\n 4140 03:54:56,959 --> 03:54:57,959 the elements, AB AC E, will be also exactly\n 4141 03:54:57,959 --> 03:54:58,959 out, which would be different if we had a\n 4142 03:54:58,959 --> 03:54:59,959 execute it and see it in action. 4143 03:54:59,959 --> 03:55:00,959 Okay, so here you see a B, A, C, E, exactly\n 4144 03:55:00,959 --> 03:55:01,959 list. Okay, now that we added elements, we\n 4145 03:55:01,959 --> 03:55:02,959 also just as easy we move. And now on the\n 4146 03:55:02,959 --> 03:55:03,959 But I can remove by stating the object that\n 4147 03:55:03,959 --> 03:55:04,959 uses the equals method. If you don't know\n 4148 03:55:04,959 --> 03:55:05,959 about the equals method. So it goes over each\n 4149 03:55:05,959 --> 03:55:06,959 is implemented in the string class. If there's\n 4150 03:55:06,959 --> 03:55:07,959 and will then remove it. You might also notice\n 4151 03:55:07,959 --> 03:55:08,959 know, like will the first a be removed will\n 4152 03:55:08,959 --> 03:55:09,959 And there is another tip I have for you. Like\n 4153 03:55:09,959 --> 03:55:10,959 a book for video tutorial, you can look in\n 4154 03:55:10,959 --> 03:55:11,959 never be as Sure. And probably also never\n 4155 03:55:11,959 --> 03:55:12,959 like this. And you just try it out for yourself.\n 4156 03:55:12,959 --> 03:55:13,959 the code doesn't lie. If you see it, he will\n 4157 03:55:13,959 --> 03:55:14,959 So let's do this and check which element is\n 4158 03:55:14,959 --> 03:55:15,959 first a is missing? So the answer is the first\n 4159 03:55:15,959 --> 03:55:16,959 Okay, so what else can we do? Let's check.\n 4160 03:55:16,959 --> 03:55:17,959 a bit simpler now. To have it as short as\n 4161 03:55:17,959 --> 03:55:18,959 copy that copying some code that you will\n 4162 03:55:18,959 --> 03:55:19,959 or K. And as long as you're just copying the\n 4163 03:55:19,959 --> 03:55:20,959 fine. So this supposed to give us the number\n 4164 03:55:20,959 --> 03:55:21,959 we just see the number of elements. Let's\n 4165 03:55:21,959 --> 03:55:22,959 the object. So I expect here to see a zero,\n 4166 03:55:22,959 --> 03:55:23,959 be another alternative possibility that this\n 4167 03:55:23,959 --> 03:55:24,959 So let's check that execute the test was actually\n 4168 03:55:24,959 --> 03:55:25,959 but here. So you see it return zero and the\n 4169 03:55:25,959 --> 03:55:26,959 method. You can even ask, Are you empty? Which\n 4170 03:55:26,959 --> 03:55:27,959 probably false. And there is true and false.\n 4171 03:55:27,959 --> 03:55:28,959 interface. And let's also play a bit around\n 4172 03:55:28,959 --> 03:55:29,959 variable of type list. And I can use all the\n 4173 03:55:30,959 --> 03:55:31,959 extends the collection interface. So it includes\n 4174 03:55:31,959 --> 03:55:32,959 has. But on top of that, we now have more\nmethods 4175 03:55:32,959 --> 03:55:33,959 than just the methods of the collection interface.\n 4176 03:55:33,959 --> 03:55:34,959 an index position. So I could for example,\n 4177 03:55:34,959 --> 03:55:35,959 know T and S at index position two. And then\n 4178 03:55:35,959 --> 03:55:36,959 Let's remove this because it'll format the\n 4179 03:55:36,959 --> 03:55:37,959 you what I mean. Okay, we still have the true\n 4180 03:55:37,959 --> 03:55:38,959 it's fine. So we have T, because we added\n 4181 03:55:38,959 --> 03:55:39,959 will be inserted where a was before. Before\n 4182 03:55:39,959 --> 03:55:40,959 zero. So this, put it to where a was before\n 4183 03:55:40,959 --> 03:55:41,959 And this is why now this is nice to see it\n 4184 03:55:41,959 --> 03:55:42,959 is all shifted to the right, which when I\n 4185 03:55:42,959 --> 03:55:43,959 if I remove the s, everything will be shifted\n 4186 03:55:43,959 --> 03:55:44,959 and we added the S at index two. So now this\n 4187 03:55:44,959 --> 03:55:45,959 rest to the right. Okay, so let's also remove\n 4188 03:55:45,959 --> 03:55:46,959 remove index. And now let's see, I remove\n 4189 03:55:46,959 --> 03:55:47,959 Okay. And there, it seems I am wrong because\n 4190 03:55:47,959 --> 03:55:48,959 Let us see. Well, of course, because it's\n 4191 03:55:48,959 --> 03:55:49,959 position zero, a is now index position one,\n 4192 03:55:49,959 --> 03:55:50,959 is always not so easy. Really, I have to tell\n 4193 03:55:50,959 --> 03:55:51,959 use them. Normally, you're fine, actually\n 4194 03:55:51,959 --> 03:55:52,959 interface, which again tells you like, often\n 4195 03:55:52,959 --> 03:55:53,959 so this actually inserts an element. Okay.\n 4196 03:55:53,959 --> 03:55:54,959 for demonstration purposes. I mean, this is\n 4197 03:55:54,959 --> 03:55:55,959 in my slides, you should really think carefully\n 4198 03:55:55,959 --> 03:55:56,959 here, it's different because we're playing\n 4199 03:55:56,959 --> 03:55:57,959 again in the example between the capacity\n 4200 03:55:57,959 --> 03:55:58,959 is the number of elements. Let's do this here,\n 4201 03:55:58,959 --> 03:55:59,959 a capacity of 100 the area will be 100 elements\n 4202 03:55:59,959 --> 03:56:00,959 however, will be much smaller. And here you\n 4203 03:56:00,959 --> 03:56:01,959 is a difference. Okay. Now we can also ask\n 4204 03:56:01,959 --> 03:56:02,959 do this here. Index off and there is also\n 4205 03:56:02,959 --> 03:56:03,959 we should also use. So index off. Let's use\n 4206 03:56:03,959 --> 03:56:04,959 that. to not make it too confusing to keep\n 4207 03:56:04,959 --> 03:56:05,959 the first index of an element. So I would\n 4208 03:56:05,959 --> 03:56:06,959 And they receive zero. And we can also say\n 4209 03:56:07,959 --> 03:56:08,959 Check that. And you might ask, Well, what\n 4210 03:56:08,959 --> 03:56:09,959 to more flexible, like combine the methods\n 4211 03:56:09,959 --> 03:56:10,959 say like, like, remove this index or so on,\n 4212 03:56:10,959 --> 03:56:11,959 I can also show you the clear method. And\n 4213 03:56:11,959 --> 03:56:12,959 method we already saw. But now let's use rim 4214 03:56:12,959 --> 03:56:13,959 clear. This method is void, so I cannot cannot\n 4215 03:56:13,959 --> 03:56:14,959 empty the list. And then we'll ask 4216 03:56:14,959 --> 03:56:15,959 is it empty now. And we can also print out\n 4217 03:56:15,959 --> 03:56:16,959 because this would be another question. Can\n 4218 03:56:16,959 --> 03:56:17,959 throw an exception maybe? Let's test it. And\n 4219 03:56:17,959 --> 03:56:18,959 it. It's just the square brackets and there's\n 4220 03:56:18,959 --> 03:56:19,959 Okay. So I think that's already it. A really\n 4221 03:56:19,959 --> 03:56:20,959 I really recommend you to do the same fire\n 4222 03:56:20,959 --> 03:56:21,959 with the methods of earliest. I know there\n 4223 03:56:21,959 --> 03:56:22,959 just that in this video i don't have all the\n 4224 03:56:22,959 --> 03:56:23,959 motivation to play around with it by yourself.\n 4225 03:56:23,959 --> 03:56:24,959 any questions, leave them as a comment below\n 4226 03:56:24,959 --> 03:56:24,973 a thumbs up before you go. Thanks for watching,\n 348319

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.