1 00:00:01,290 --> 00:00:04,000 In this lecture, I would like to introduce you primitives. 2 00:00:04,500 --> 00:00:09,210 First, we will go through the list of the primitives and what values we can store in them. 3 00:00:09,660 --> 00:00:14,760 Next, we will go to the website where I will show you where you can use these primitives. 4 00:00:15,070 --> 00:00:18,360 Then we will do a coding practice based on the website. 5 00:00:18,780 --> 00:00:25,350 And last you will see how to convert one data type into another one and what pitfalls it might have. 6 00:00:25,740 --> 00:00:26,890 OK, let's do it. 7 00:00:26,910 --> 00:00:34,920 So we have four groups of primitives, whole numbers, floating point numbers, boolean and character. 8 00:00:35,580 --> 00:00:45,240 Whole numbers are byte, short end and long byte can store values from minus one hundred and twenty 9 00:00:45,240 --> 00:00:53,130 eight to one hundred and twenty seven short from almost negative thirty three thousand to almost thirty 10 00:00:53,130 --> 00:01:01,110 three thousand and can store a little bit more than two billion in positive and negative and long can 11 00:01:01,110 --> 00:01:03,050 store a massive number. 12 00:01:03,540 --> 00:01:07,860 The most commonly used is Int and the rest of them are barely used. 13 00:01:08,100 --> 00:01:14,400 But if you are restricted on memory, you use byte short if it's necessary and if you need to store 14 00:01:14,400 --> 00:01:16,800 a huge number used long. 15 00:01:17,560 --> 00:01:20,100 OK, let's move on to floating point data types. 16 00:01:20,280 --> 00:01:24,870 There are float and double that you can use as variable data type. 17 00:01:25,290 --> 00:01:32,190 The difference between the two is that float can be precise until six to seven decimal digits and double 18 00:01:32,190 --> 00:01:34,560 until 15 decimal digits. 19 00:01:34,590 --> 00:01:37,050 Here, double is the more commonly used. 20 00:01:37,380 --> 00:01:42,330 There are two other primitive data types, boolean and character here. 21 00:01:42,330 --> 00:01:46,680 Char Boolean is probably the most commonly used data type of all. 22 00:01:47,280 --> 00:01:50,760 It can have two values, true or false. 23 00:01:51,180 --> 00:01:57,520 The other type is char, which can store one single character or an escort character. 24 00:01:57,840 --> 00:02:03,810 Don't worry if you don't know what Askey means, I will tell you what it is and how to use it later. 25 00:02:04,390 --> 00:02:07,320 OK, now let's move on to the website I mentioned before. 26 00:02:09,140 --> 00:02:16,820 OK, so the website we are going to use as an example is Mobileye DC and here are the details of a damaged 27 00:02:17,090 --> 00:02:20,540 2018 Dodge Challenger SRT. 28 00:02:20,930 --> 00:02:25,710 And I'm going to show you what data types can be used to store these values. 29 00:02:26,360 --> 00:02:32,510 I'm going to think universal, so I will choose data types based on the idea that it could be any other 30 00:02:32,510 --> 00:02:32,850 car. 31 00:02:33,200 --> 00:02:34,280 OK, just a side note. 32 00:02:34,280 --> 00:02:41,000 Before we started, price is a whole number and a coma here is just a separator. 33 00:02:41,420 --> 00:02:48,530 While in case of fuel consumption, it is a decimal point and points just separators for thousands. 34 00:02:49,100 --> 00:02:50,890 OK, let's start with numbers. 35 00:02:51,260 --> 00:02:54,290 So the price of this car can be stored in a short. 36 00:02:54,570 --> 00:02:57,890 OK, but what happens if the car is more expensive? 37 00:02:57,890 --> 00:03:02,020 For example, it is a Ferrari, then we need an integer. 38 00:03:02,750 --> 00:03:04,100 Do we need a long for this? 39 00:03:04,460 --> 00:03:11,570 No, I think it's very unlikely that a car can be more expensive than two billion if the prices are 40 00:03:11,570 --> 00:03:12,930 stored in euros. 41 00:03:12,950 --> 00:03:14,800 The next one is the mileage. 42 00:03:15,230 --> 00:03:16,540 Same situation here. 43 00:03:16,790 --> 00:03:20,270 Short is not enough for this, but an integer is good. 44 00:03:20,750 --> 00:03:22,010 The next one is power. 45 00:03:22,190 --> 00:03:26,090 OK, so here is a time for using short byte. 46 00:03:26,090 --> 00:03:28,430 Would be too small for these numbers. 47 00:03:28,700 --> 00:03:37,160 An integer is an overkill because it is pretty unlikely to have a car with more than 32000 horsepower 48 00:03:37,310 --> 00:03:41,930 or kilowatt cubic capacity can be stored in a short ASBA. 49 00:03:42,290 --> 00:03:45,550 OK, moving on to fuel consumption here. 50 00:03:45,560 --> 00:03:48,080 Float is far more than enough to do the job. 51 00:03:48,560 --> 00:03:53,750 Even if you are working in a lab, you don't need to know more than six to seven digits. 52 00:03:54,350 --> 00:04:00,920 If they would need more precision, they would use double for these next kommission. 53 00:04:01,100 --> 00:04:04,730 I think short is enough number of seats. 54 00:04:05,180 --> 00:04:12,140 While it is a tough one for a bus, it may need to be a short, but I think byte is enough. 55 00:04:13,370 --> 00:04:20,450 Count is an absolute by type emissions sticker, and number of vehicle owners can be stored in a bite 56 00:04:20,450 --> 00:04:21,050 as well. 57 00:04:21,680 --> 00:04:27,770 It is very unlikely that the number of owners will be over 100 and 27 here. 58 00:04:27,860 --> 00:04:29,810 First, registration and age. 59 00:04:29,810 --> 00:04:31,040 You are dates. 60 00:04:31,520 --> 00:04:32,890 We don't deal with them now. 61 00:04:33,380 --> 00:04:35,960 So two data types are not used here. 62 00:04:36,140 --> 00:04:44,810 Boolean and Char, as you can see, it is a damaged car and there might be a variable called is damaged 63 00:04:45,080 --> 00:04:48,210 and the value of that variable is true for this car. 64 00:04:48,560 --> 00:04:54,250 And if that is true, the damaged accident damaged vehicle text appears. 65 00:04:54,740 --> 00:04:57,860 But if it's not true, the text doesn't show up. 66 00:04:58,710 --> 00:05:06,510 And last Char, to be honest, we don't really use this the last time I use this, well, it was 10 67 00:05:06,510 --> 00:05:12,320 years ago before this recording, but I think you must know what it can be used for. 68 00:05:12,810 --> 00:05:20,730 So, for example, emissions sticker may have other values like A, B or C, four different emission 69 00:05:20,730 --> 00:05:21,300 levels. 70 00:05:21,660 --> 00:05:24,180 So that can be one option to use char. 71 00:05:24,750 --> 00:05:27,230 The rest of the site is stored in string. 72 00:05:27,720 --> 00:05:29,040 We will cover that later. 73 00:05:29,340 --> 00:05:35,550 Or static HTML text, which is not stored or used, but it is simply displayed. 74 00:05:36,000 --> 00:05:36,680 All right. 75 00:05:36,690 --> 00:05:38,240 That's all about the website. 76 00:05:38,250 --> 00:05:39,690 Let's do some practice.