1 00:00:00,210 --> 00:00:01,110 ‫Instructor: Hi. 2 00:00:01,110 --> 00:00:03,720 ‫Within this lecture we are going to continue 3 00:00:03,720 --> 00:00:07,500 ‫with the variables and most popular data types 4 00:00:07,500 --> 00:00:11,070 ‫like we have seen double, float, and integer, and long. 5 00:00:11,070 --> 00:00:15,480 ‫We are going to see strings and some other types as well. 6 00:00:15,480 --> 00:00:20,480 ‫So for example, we have seen what happens when 7 00:00:20,550 --> 00:00:24,720 ‫we divide double by double or integer by integer. 8 00:00:24,720 --> 00:00:27,180 ‫Let's create a double called pi, 9 00:00:27,180 --> 00:00:31,230 ‫and this will be equal to 3.14 of course 10 00:00:31,230 --> 00:00:34,500 ‫and let's create an integer for example 11 00:00:34,500 --> 00:00:39,500 ‫for our radius and calculate a circumference of a circle. 12 00:00:40,770 --> 00:00:44,100 ‫Okay? So for example, I have my pi, 3.14 13 00:00:44,100 --> 00:00:47,070 ‫I have my radius as five. 14 00:00:47,070 --> 00:00:50,460 ‫So do you know the equation of circumference? 15 00:00:50,460 --> 00:00:55,460 ‫It's two multiplied by pi multiplied by radius, right? 16 00:00:56,520 --> 00:01:01,520 ‫So what happens when we multiply an integer with a double? 17 00:01:01,620 --> 00:01:04,650 ‫Now we're gonna find out about that, aren't we? 18 00:01:04,650 --> 00:01:08,400 ‫Let's call System.out.println one more time 19 00:01:08,400 --> 00:01:13,400 ‫and try to multiply 2 by pi by r. 20 00:01:13,440 --> 00:01:15,510 ‫And I suggest you pause the video 21 00:01:15,510 --> 00:01:17,370 ‫and try to do it on your own 22 00:01:17,370 --> 00:01:21,450 ‫with these kind of little exercises okay? 23 00:01:21,450 --> 00:01:24,870 ‫So let me do it and let me run it. 24 00:01:24,870 --> 00:01:29,870 ‫And you will see it's 31.4, 25 00:01:29,880 --> 00:01:34,740 ‫so don't worry about this 000002 things 26 00:01:34,740 --> 00:01:38,550 ‫like if it's a very small decimal 27 00:01:38,550 --> 00:01:42,360 ‫it's not your fault, it's just how actually 28 00:01:42,360 --> 00:01:47,360 ‫Android handles how Java handles the decimals. 29 00:01:47,370 --> 00:01:48,600 ‫So it's not very important. 30 00:01:48,600 --> 00:01:53,040 ‫It won't mess with your calculations in real life examples 31 00:01:53,040 --> 00:01:56,460 ‫but as you can see we got a double out of this. 32 00:01:56,460 --> 00:02:01,440 ‫So we got 31.4 as we expect. 33 00:02:01,440 --> 00:02:06,197 ‫So if we just multiply a double by an integer as 34 00:02:06,197 --> 00:02:11,197 ‫as we would expect, it gives out the result as a double 35 00:02:11,700 --> 00:02:14,790 ‫and it's actually better for us because we can 36 00:02:14,790 --> 00:02:16,830 ‫see the decimals at this point. 37 00:02:16,830 --> 00:02:20,610 ‫So if you need decimals, make sure you are working 38 00:02:20,610 --> 00:02:25,470 ‫with doubles, at least in a single parameter 39 00:02:25,470 --> 00:02:28,860 ‫of an equation like this so that you can get 40 00:02:28,860 --> 00:02:31,173 ‫specific results out of that. 41 00:02:32,310 --> 00:02:37,310 ‫So let me move on to some other examples from here. 42 00:02:37,890 --> 00:02:41,880 ‫I believe this is sufficient for us right now at least 43 00:02:41,880 --> 00:02:45,870 ‫about numbers because we have so many data types 44 00:02:45,870 --> 00:02:50,310 ‫and we are going to do a lot of examples with numbers later 45 00:02:50,310 --> 00:02:51,690 ‫on as well. 46 00:02:51,690 --> 00:02:54,210 ‫So let me talk about strings. 47 00:02:54,210 --> 00:02:56,640 ‫We have briefly talked about that before 48 00:02:56,640 --> 00:02:59,490 ‫right? We have talked about that 49 00:02:59,490 --> 00:03:01,800 ‫this is a text. 50 00:03:01,800 --> 00:03:03,600 ‫So let me do an example. 51 00:03:03,600 --> 00:03:07,080 ‫Just write String with an upper case S 52 00:03:07,080 --> 00:03:09,480 ‫and give some name afterwards. 53 00:03:09,480 --> 00:03:12,900 ‫Like this is an object name like, "name", 54 00:03:12,900 --> 00:03:17,640 ‫or, "myString", or "myName", or anything you want. 55 00:03:17,640 --> 00:03:19,590 ‫Okay let's go with name 56 00:03:19,590 --> 00:03:23,910 ‫for example and open this quotation marks 57 00:03:23,910 --> 00:03:27,750 ‫and between the quotation marks, write your text. 58 00:03:27,750 --> 00:03:30,000 ‫So you can do it with your own name. 59 00:03:30,000 --> 00:03:32,550 ‫I'm gonna do it with James Hatfield. 60 00:03:32,550 --> 00:03:35,580 ‫So I'm going to call this name, I'm going to 61 00:03:35,580 --> 00:03:39,480 ‫create another string, which is surname, which is Hatfield. 62 00:03:39,480 --> 00:03:43,860 ‫Okay? And don't forget with semi-colons at the end 63 00:03:43,860 --> 00:03:46,830 ‫and now I'm going to print name 64 00:03:46,830 --> 00:03:50,364 ‫and now I'm going to print surname. 65 00:03:50,364 --> 00:03:53,970 ‫Just beware that I'm not putting 66 00:03:53,970 --> 00:03:57,720 ‫any double quotations, quotation marks 67 00:03:57,720 --> 00:04:01,320 ‫in the System.out.println over here. 68 00:04:01,320 --> 00:04:04,350 ‫I'm just writing surname or name 69 00:04:04,350 --> 00:04:07,863 ‫because I can refer to that variable right now. 70 00:04:08,700 --> 00:04:10,740 ‫So this is good. 71 00:04:10,740 --> 00:04:13,080 ‫So if I run this, of course it will print 72 00:04:13,080 --> 00:04:17,430 ‫out James Hatfield one by one over here. 73 00:04:17,430 --> 00:04:19,380 ‫So now I have these variables 74 00:04:19,380 --> 00:04:22,233 ‫I can do whatever I want to do with them. 75 00:04:23,160 --> 00:04:27,390 ‫For example, I can create a new string out of those. 76 00:04:27,390 --> 00:04:30,330 ‫Like I can just create a full name 77 00:04:30,330 --> 00:04:35,330 ‫and some name and surname together like this. 78 00:04:35,490 --> 00:04:39,633 ‫So what happens when I add one string to another? 79 00:04:40,530 --> 00:04:43,770 ‫So let me try to print line 80 00:04:43,770 --> 00:04:48,000 ‫that as well so that we can see the results in the logs. 81 00:04:48,000 --> 00:04:48,833 ‫Here you go. 82 00:04:48,833 --> 00:04:51,150 ‫As you can see, it added them side by side. 83 00:04:51,150 --> 00:04:56,150 ‫So we can see the name and surname together like this. 84 00:04:56,760 --> 00:05:01,500 ‫So of course you're thinking about how to put a space 85 00:05:01,500 --> 00:05:05,100 ‫between name and surname right now it's very easy. 86 00:05:05,100 --> 00:05:07,320 ‫You can do like this. 87 00:05:07,320 --> 00:05:12,320 ‫So, name plus a space over here and plus surname. 88 00:05:13,680 --> 00:05:18,680 ‫So if I run this, then I will see, "James Hatfield". 89 00:05:19,560 --> 00:05:23,250 ‫Now I can use those variables in wherever I want 90 00:05:23,250 --> 00:05:25,680 ‫at this point on, right? 91 00:05:25,680 --> 00:05:27,990 ‫So this is strings, this is very basic. 92 00:05:27,990 --> 00:05:30,060 ‫This is just a text. 93 00:05:30,060 --> 00:05:34,860 ‫So before we have learned about numbers, they were integers 94 00:05:34,860 --> 00:05:37,260 ‫and floats and doubles and longs. 95 00:05:37,260 --> 00:05:39,240 ‫Now we have learned about strings. 96 00:05:39,240 --> 00:05:42,660 ‫Now we wanna move on to booleans. 97 00:05:42,660 --> 00:05:44,910 ‫So this is a type as well. 98 00:05:44,910 --> 00:05:47,700 ‫So what kind of a data type is this? 99 00:05:47,700 --> 00:05:52,260 ‫So boolean is a true or is a false. 100 00:05:52,260 --> 00:05:54,720 ‫So they have only two values 101 00:05:54,720 --> 00:05:57,900 ‫actually it's either true or false. 102 00:05:57,900 --> 00:06:00,900 ‫So how do we use them? 103 00:06:00,900 --> 00:06:02,670 ‫So let's create a boolean 104 00:06:02,670 --> 00:06:07,440 ‫and create it like this boolean with small b. 105 00:06:07,440 --> 00:06:10,830 ‫And then you can give it a name. 106 00:06:10,830 --> 00:06:14,580 ‫For example, in a real life example would be a game 107 00:06:14,580 --> 00:06:18,720 ‫like for tracking if character is alive. 108 00:06:18,720 --> 00:06:22,440 ‫So if it's true, then my character is alive 109 00:06:22,440 --> 00:06:26,040 ‫and if it's false, then my character is dead. 110 00:06:26,040 --> 00:06:27,960 ‫So maybe I can keep track 111 00:06:27,960 --> 00:06:31,920 ‫whether my character is alive or not with a variable. 112 00:06:31,920 --> 00:06:33,960 ‫I can change it anytime I want. 113 00:06:33,960 --> 00:06:35,430 ‫Like this: 114 00:06:35,430 --> 00:06:38,940 ‫Let's print those out and let's see 115 00:06:38,940 --> 00:06:40,890 ‫if we can see the false over here. 116 00:06:40,890 --> 00:06:42,060 ‫Here we go. 117 00:06:42,060 --> 00:06:45,510 ‫As you can see, it's the most basic data type of all. 118 00:06:45,510 --> 00:06:47,850 ‫So it's either true or false. 119 00:06:47,850 --> 00:06:52,020 ‫There isn't many thing to talk about it right now 120 00:06:52,020 --> 00:06:54,330 ‫but later on we are going to see a lot 121 00:06:54,330 --> 00:06:57,240 ‫of usages of booleans as well. 122 00:06:57,240 --> 00:06:59,520 ‫So once I create a string 123 00:06:59,520 --> 00:07:03,000 ‫or once I create a variable, I can change it, right? 124 00:07:03,000 --> 00:07:08,000 ‫For example, I have changed name to be Lars 125 00:07:08,070 --> 00:07:13,070 ‫and now if I print name, I will see Lars as you can see. 126 00:07:13,290 --> 00:07:15,030 ‫But I cannot do that. 127 00:07:15,030 --> 00:07:18,840 ‫I cannot change name to be 40 like this, 128 00:07:18,840 --> 00:07:23,840 ‫because I have defined name as a string, not an integer. 129 00:07:24,600 --> 00:07:26,370 ‫As you can see it gives me an error. 130 00:07:26,370 --> 00:07:29,760 ‫I'm expecting a string and you are giving me an integer 131 00:07:29,760 --> 00:07:34,760 ‫it says. So whatever you have specified first 132 00:07:34,980 --> 00:07:38,370 ‫you have to do that later on as well. 133 00:07:38,370 --> 00:07:42,180 ‫So let me comment this out and go up and over here. 134 00:07:42,180 --> 00:07:45,210 ‫For example, we have double z. 135 00:07:45,210 --> 00:07:47,400 ‫Now can I do that? 136 00:07:47,400 --> 00:07:49,290 ‫Can I say this is a four? 137 00:07:49,290 --> 00:07:52,260 ‫Yep, I can do that actually. 138 00:07:52,260 --> 00:07:54,540 ‫It doesn't mean it's necessarily an 139 00:07:54,540 --> 00:07:59,540 ‫integer right now because it's perceived as a double. 140 00:07:59,580 --> 00:08:00,540 ‫But if I do that 141 00:08:00,540 --> 00:08:04,650 ‫as you can see right now, it's giving me an error. 142 00:08:04,650 --> 00:08:06,570 ‫It's not exactly a double. 143 00:08:06,570 --> 00:08:08,790 ‫It's a string it says. 144 00:08:08,790 --> 00:08:13,790 ‫Whenever you do 4 it, it just thinks it as 4.0. 145 00:08:13,950 --> 00:08:15,720 ‫Okay? So it's okay 146 00:08:15,720 --> 00:08:18,723 ‫but turning it into a string, it's not okay. 147 00:08:19,980 --> 00:08:23,190 ‫So that's it for the most basic ones. 148 00:08:23,190 --> 00:08:25,410 ‫These are the data types that you're going to 149 00:08:25,410 --> 00:08:30,390 ‫need when you try to learn the other concepts 150 00:08:30,390 --> 00:08:33,720 ‫of Java in the following lectures. 151 00:08:33,720 --> 00:08:36,420 ‫So make sure you follow along with the next lectures 152 00:08:36,420 --> 00:08:39,603 ‫in order to comprehend all of those things in a better way.