1 00:00:00,510 --> 00:00:01,440 ‫Instructor: Hi. 2 00:00:01,440 --> 00:00:03,120 ‫Within this lecture we are going 3 00:00:03,120 --> 00:00:06,240 ‫to start working on variables. 4 00:00:06,240 --> 00:00:10,530 ‫So, if you haven't heard the term variables before, 5 00:00:10,530 --> 00:00:13,260 ‫you're gonna learn it because you are going to need it 6 00:00:13,260 --> 00:00:16,290 ‫in every kind of programming language that you 7 00:00:16,290 --> 00:00:19,050 ‫will ever learn from this point on. 8 00:00:19,050 --> 00:00:22,170 ‫Okay? So, why do we need variables 9 00:00:22,170 --> 00:00:25,320 ‫and what are variables anyhow? 10 00:00:25,320 --> 00:00:27,840 ‫So, it's spelled like this, variables, 11 00:00:27,840 --> 00:00:31,380 ‫and beware of the two slashes that I have put over here 12 00:00:31,380 --> 00:00:33,180 ‫in order to take a note. 13 00:00:33,180 --> 00:00:35,610 ‫You can do the same thing as well. 14 00:00:35,610 --> 00:00:38,430 ‫And as you can see, I cannot write like this. 15 00:00:38,430 --> 00:00:41,070 ‫I'll get an error because it's not a word. 16 00:00:41,070 --> 00:00:43,350 ‫It's not a comment. It's not a code. 17 00:00:43,350 --> 00:00:48,350 ‫It's just a comment when you put two slashes in front of it. 18 00:00:49,080 --> 00:00:52,380 ‫Okay? So, what is a variable? 19 00:00:52,380 --> 00:00:57,380 ‫It's kind of an object to save values. 20 00:00:57,450 --> 00:01:02,100 ‫For example, remember, we have done something like this. 21 00:01:02,100 --> 00:01:05,970 ‫We have done five minus applied by two, I believe. 22 00:01:05,970 --> 00:01:10,970 ‫Now, I'm doing 10 plus 20, or 10 multiplied by 20, 23 00:01:11,700 --> 00:01:15,273 ‫and we get 200 out of it, right? 24 00:01:16,200 --> 00:01:18,690 ‫So, maybe I want to store those values 25 00:01:18,690 --> 00:01:21,870 ‫in variables, in some objects. 26 00:01:21,870 --> 00:01:25,020 ‫So, why do we want that? 27 00:01:25,020 --> 00:01:27,180 ‫For example, we may want to use it more 28 00:01:27,180 --> 00:01:32,180 ‫than once or maybe we don't even know what the number 29 00:01:33,270 --> 00:01:36,510 ‫that we are going to be multiplying is going to be, 30 00:01:36,510 --> 00:01:41,430 ‫like, for example, the age of the user. 31 00:01:41,430 --> 00:01:43,827 ‫So, suppose that age of the user is 20 32 00:01:43,827 --> 00:01:48,600 ‫and I'm going to multiply the age of the user by 10. 33 00:01:48,600 --> 00:01:52,290 ‫So, I can create a variable like this. 34 00:01:52,290 --> 00:01:56,070 ‫So, this variable is an integer type. 35 00:01:56,070 --> 00:01:58,650 ‫So, of course, there are multiple types 36 00:01:58,650 --> 00:02:02,100 ‫of variables and this is an integer. 37 00:02:02,100 --> 00:02:05,550 ‫Integer means a whole number. It's a number, okay? 38 00:02:05,550 --> 00:02:07,110 ‫It doesn't have a decimal. 39 00:02:07,110 --> 00:02:12,060 ‫It's just a number like one or two or five or 20. 40 00:02:12,060 --> 00:02:14,550 ‫So, in order to create a variable, 41 00:02:14,550 --> 00:02:18,570 ‫all you have to do is just write "int" or the type 42 00:02:18,570 --> 00:02:23,430 ‫of the variable and the name of the variable, okay? 43 00:02:23,430 --> 00:02:26,370 ‫I could have called this anything, not only age, 44 00:02:26,370 --> 00:02:29,070 ‫but I could have changed that if I wanted 45 00:02:29,070 --> 00:02:31,560 ‫to create an in integer. 46 00:02:31,560 --> 00:02:36,180 ‫And then, with an equal sign, you just give the value. 47 00:02:36,180 --> 00:02:39,420 ‫For example, once I do that, I can just delete the 20 48 00:02:39,420 --> 00:02:42,990 ‫and I can write "age" over here, 49 00:02:42,990 --> 00:02:46,920 ‫and Android Studio will know to multiply 10 by 20 50 00:02:46,920 --> 00:02:48,060 ‫when I run this. 51 00:02:48,060 --> 00:02:52,440 ‫As you can see, we still get the 200 out of this equation 52 00:02:52,440 --> 00:02:56,160 ‫because age now represents 20. 53 00:02:56,160 --> 00:03:00,930 ‫Now, I can use age in any other line as well. 54 00:03:00,930 --> 00:03:05,930 ‫Like, I can divide the age by five. I will get four. 55 00:03:07,530 --> 00:03:11,100 ‫So, as you can see, once I define a variable, 56 00:03:11,100 --> 00:03:15,360 ‫I can use it in multiple places, so it's an advantage, 57 00:03:15,360 --> 00:03:18,720 ‫and maybe I'm getting this value from internet. 58 00:03:18,720 --> 00:03:20,310 ‫Maybe I'm getting this value 59 00:03:20,310 --> 00:03:23,703 ‫from user via text field or something. 60 00:03:24,720 --> 00:03:29,720 ‫So, let me create something like X is five, Y is 10, okay? 61 00:03:31,740 --> 00:03:36,740 ‫And let's try to do Y divided by X. 62 00:03:36,990 --> 00:03:39,810 ‫So, can I do that? Of course I can. 63 00:03:39,810 --> 00:03:40,643 ‫As you can see, 64 00:03:40,643 --> 00:03:44,430 ‫we still have the result of two 'cause I'm dividing 10 65 00:03:44,430 --> 00:03:47,130 ‫by five over here. 66 00:03:47,130 --> 00:03:51,930 ‫So, let me try to do that, 11 divided by five. 67 00:03:51,930 --> 00:03:55,410 ‫What will I get? I still get two. 68 00:03:55,410 --> 00:03:58,920 ‫So, it's a little bit odd, do you think? 69 00:03:58,920 --> 00:04:03,210 ‫Because 11 divided by five is not a whole number. 70 00:04:03,210 --> 00:04:06,390 ‫So, let me do this with calculator. 71 00:04:06,390 --> 00:04:11,390 ‫If I divide 11 by five, I will get 2.2. 72 00:04:11,850 --> 00:04:15,090 ‫I should get that in here as well, right? 73 00:04:15,090 --> 00:04:18,180 ‫But, remember what I said about integer. 74 00:04:18,180 --> 00:04:23,180 ‫Integer is a whole number. It doesn't have any decimals. 75 00:04:23,940 --> 00:04:27,420 ‫So, when I divide an integer by integer, 76 00:04:27,420 --> 00:04:29,430 ‫exactly what's gonna happen 77 00:04:29,430 --> 00:04:33,060 ‫is to create another integer, right? 78 00:04:33,060 --> 00:04:37,290 ‫So, if I want to get something with decimals, 79 00:04:37,290 --> 00:04:40,983 ‫then I would work with double, or float. 80 00:04:42,120 --> 00:04:44,880 ‫So, these are variables as well. 81 00:04:44,880 --> 00:04:48,720 ‫Like, I can just say something like double Z 82 00:04:48,720 --> 00:04:52,050 ‫is equal to 5.0. 83 00:04:52,050 --> 00:04:57,050 ‫So, this is still five, but with 0.0. Okay? 84 00:04:57,060 --> 00:05:01,650 ‫So, let me create another, like, 11.0. 85 00:05:01,650 --> 00:05:05,280 ‫So, these are numbers as well and these are 11 86 00:05:05,280 --> 00:05:06,660 ‫and five as well, 87 00:05:06,660 --> 00:05:11,460 ‫but rather than just creating them, like integers, 88 00:05:11,460 --> 00:05:15,330 ‫I have created them as doubles. 89 00:05:15,330 --> 00:05:20,330 ‫So now, if I divide A by zet, what will I get as a result? 90 00:05:23,220 --> 00:05:25,290 ‫So, let me try it and see. 91 00:05:25,290 --> 00:05:29,910 ‫Let me run it from here, or right-clicking to domain, 92 00:05:29,910 --> 00:05:32,360 ‫and as you can see, we have 2.2. 93 00:05:33,570 --> 00:05:38,570 ‫Because the result of this equation is also a double, 94 00:05:38,790 --> 00:05:41,910 ‫I'm actually dividing a double by a double 95 00:05:41,910 --> 00:05:45,750 ‫and I'm getting the decimals like this. 96 00:05:45,750 --> 00:05:49,500 ‫So, you will come across in situations where you will need 97 00:05:49,500 --> 00:05:52,440 ‫to work on doubles because you will have, 98 00:05:52,440 --> 00:05:54,930 ‫you will need some kind of decimals, 99 00:05:54,930 --> 00:05:57,750 ‫but also, you will come across with situations 100 00:05:57,750 --> 00:06:00,450 ‫where you will need to work with integers 101 00:06:00,450 --> 00:06:03,690 ‫because the result, or the number itself, 102 00:06:03,690 --> 00:06:07,890 ‫would have to be integers or longs. 103 00:06:07,890 --> 00:06:12,890 ‫Okay? And these are all just numbers, right? 104 00:06:13,470 --> 00:06:16,110 ‫So, maybe you get confused at this. 105 00:06:16,110 --> 00:06:19,440 ‫What is a long? What is a float? 106 00:06:19,440 --> 00:06:21,360 ‫So, let me show you. 107 00:06:21,360 --> 00:06:22,830 ‫As you can see, 108 00:06:22,830 --> 00:06:27,000 ‫if you can just search for "int, float, double Java," 109 00:06:27,000 --> 00:06:30,210 ‫you will come across with a table like this. 110 00:06:30,210 --> 00:06:34,080 ‫So, we have this number types in Java, like integers, 111 00:06:34,080 --> 00:06:36,630 ‫long, float, doubles, okay? 112 00:06:36,630 --> 00:06:39,330 ‫And these are all just numbers, 113 00:06:39,330 --> 00:06:43,110 ‫but they have different capacities like sizes, 114 00:06:43,110 --> 00:06:45,270 ‫32 bits, 64 bits. 115 00:06:45,270 --> 00:06:48,810 ‫As you can see, you can store much larger values 116 00:06:48,810 --> 00:06:52,770 ‫with doubles rather than floats and much larger values 117 00:06:52,770 --> 00:06:56,070 ‫with longs rather than integers, 118 00:06:56,070 --> 00:07:01,070 ‫and if you are looking for a very big number to work with, 119 00:07:01,200 --> 00:07:04,650 ‫then go for long and double and if you're working 120 00:07:04,650 --> 00:07:08,520 ‫with small numbers, you can go for float and integers. 121 00:07:08,520 --> 00:07:11,280 ‫Don't be confused by them. 122 00:07:11,280 --> 00:07:12,930 ‫We're going to do a lot 123 00:07:12,930 --> 00:07:16,710 ‫of examples during the lectures, okay? 124 00:07:16,710 --> 00:07:19,590 ‫I'm just showing you this as an example 125 00:07:19,590 --> 00:07:21,450 ‫so that you won't get confused 126 00:07:21,450 --> 00:07:25,824 ‫about integers or floats or longs or doubles. 127 00:07:25,824 --> 00:07:27,840 ‫These are just numbers 128 00:07:27,840 --> 00:07:31,113 ‫and we have different number types, that's all. 129 00:07:32,040 --> 00:07:36,120 ‫So let's, for example, try to do something like this. 130 00:07:36,120 --> 00:07:40,860 ‫Let's create a long and call this "My Long," 131 00:07:40,860 --> 00:07:42,900 ‫with camel keys of course, 132 00:07:42,900 --> 00:07:46,890 ‫and I'm going to give 10 as a value. 133 00:07:46,890 --> 00:07:49,800 ‫Of course, you can print this out. 134 00:07:49,800 --> 00:07:52,170 ‫You can do whatever you may want to do with it, 135 00:07:52,170 --> 00:07:54,360 ‫like dividing it by five, 136 00:07:54,360 --> 00:07:57,360 ‫and you will still get two as a result. 137 00:07:57,360 --> 00:08:02,360 ‫Over here, it won't change the outcome of the situation. 138 00:08:03,540 --> 00:08:08,340 ‫Of course, we can do this with float as well, like 10.0, 139 00:08:08,340 --> 00:08:11,820 ‫but in case you get an error like this over here, 140 00:08:11,820 --> 00:08:16,820 ‫it means that looking for float, but you gave me doubled. 141 00:08:16,920 --> 00:08:21,090 ‫So, you have to be as explicit as possible over here, 142 00:08:21,090 --> 00:08:24,240 ‫which is why they invented something like this. 143 00:08:24,240 --> 00:08:27,780 ‫If you put F at the end of the value, 144 00:08:27,780 --> 00:08:29,520 ‫it means that it's a float. 145 00:08:29,520 --> 00:08:32,700 ‫If you don't put it, it's a double. Okay? 146 00:08:32,700 --> 00:08:35,430 ‫So now, under Android Studio actually understand 147 00:08:35,430 --> 00:08:36,573 ‫this is a double. 148 00:08:37,410 --> 00:08:40,980 ‫So, we're not going to spend so much time over here. 149 00:08:40,980 --> 00:08:42,570 ‫All you have to understand, 150 00:08:42,570 --> 00:08:44,370 ‫these are just numbers and there are some, 151 00:08:44,370 --> 00:08:46,860 ‫several types in Java. 152 00:08:46,860 --> 00:08:49,083 ‫Let's continue within the next lecture.