1 00:00:00,510 --> 00:00:03,840 ‫Instructor: Hi, within this lecture we are going to learn 2 00:00:03,840 --> 00:00:07,200 ‫about a concept called classes. 3 00:00:07,200 --> 00:00:11,700 ‫So far we have been working with classes anyway, right? 4 00:00:11,700 --> 00:00:16,700 ‫So we have all these methods inside of our main activity. 5 00:00:16,860 --> 00:00:19,770 ‫And if you look closely in your main activity, 6 00:00:19,770 --> 00:00:22,833 ‫main activity is actually a class itself as well. 7 00:00:23,790 --> 00:00:28,350 ‫So we have all these methods and we have all 8 00:00:28,350 --> 00:00:33,350 ‫this class surrounding all these methods as well. 9 00:00:33,750 --> 00:00:36,480 ‫So class is the bigger part, over here, 10 00:00:36,480 --> 00:00:40,740 ‫class is like a blueprint of programming. 11 00:00:40,740 --> 00:00:43,080 ‫So you get to choose your structure, 12 00:00:43,080 --> 00:00:44,820 ‫you get to choose your methods, 13 00:00:44,820 --> 00:00:49,820 ‫you get to choose your variables, properties, like options 14 00:00:50,010 --> 00:00:54,543 ‫that you're gonna get or you are gonna provide in your code. 15 00:00:55,500 --> 00:00:59,640 ‫For example, let us think that we're going to have 16 00:00:59,640 --> 00:01:02,610 ‫some musicians, okay? 17 00:01:02,610 --> 00:01:06,300 ‫We can create some musician names, for example, 18 00:01:06,300 --> 00:01:11,300 ‫like string musician one and string musician two, right? 19 00:01:12,840 --> 00:01:17,520 ‫And assume that we' re going to have the age 20 00:01:17,520 --> 00:01:22,520 ‫of those musicians as well, like age one and age two. 21 00:01:23,490 --> 00:01:28,490 ‫And suppose that you also have instrument of that musicians, 22 00:01:28,770 --> 00:01:33,000 ‫like string instrument one, string instrument two. 23 00:01:33,000 --> 00:01:37,020 ‫So suppose that you're gonna have like a hundred musicians 24 00:01:37,020 --> 00:01:40,920 ‫and it would be a little bit difficult for you 25 00:01:40,920 --> 00:01:42,000 ‫to do it like this. 26 00:01:42,000 --> 00:01:46,710 ‫Like musician one is James, age one is 50, 27 00:01:46,710 --> 00:01:49,320 ‫instrument one is guitar. 28 00:01:49,320 --> 00:01:52,740 ‫So after one point you will lose track 29 00:01:52,740 --> 00:01:57,090 ‫and it will get complicated for you, right? 30 00:01:57,090 --> 00:02:02,090 ‫So rather than doing this, you can create a class or model 31 00:02:02,760 --> 00:02:07,760 ‫of a musician and you can give it any property you want, 32 00:02:07,950 --> 00:02:12,950 ‫and you can have a more structural way of dealing with data. 33 00:02:15,060 --> 00:02:18,150 ‫So this is where class comes in. 34 00:02:18,150 --> 00:02:21,150 ‫Like you can create your own class, 35 00:02:21,150 --> 00:02:24,780 ‫you can create your own structure, your own blueprint, 36 00:02:24,780 --> 00:02:26,880 ‫and you can have your own way 37 00:02:26,880 --> 00:02:31,170 ‫of having properties, having methods. 38 00:02:31,170 --> 00:02:33,540 ‫Over here we have this main activity 39 00:02:33,540 --> 00:02:36,300 ‫and it's a class itself as well. 40 00:02:36,300 --> 00:02:40,140 ‫So this extends to something called a compact activity. 41 00:02:40,140 --> 00:02:42,840 ‫And we're gonna see what extending means later. 42 00:02:42,840 --> 00:02:47,840 ‫Oh, but this is actually a class and we are working inside 43 00:02:48,570 --> 00:02:52,200 ‫of a class anyway, so you should have a class. 44 00:02:52,200 --> 00:02:55,680 ‫And we have created class over here before, right? 45 00:02:55,680 --> 00:02:57,840 ‫We said new Java. 46 00:02:57,840 --> 00:02:59,670 ‫So that's what we're going to do, now. 47 00:02:59,670 --> 00:03:02,730 ‫I'm gonna create a musician's class 48 00:03:02,730 --> 00:03:07,440 ‫and be aware that I'm making this M upper case 49 00:03:07,440 --> 00:03:10,830 ‫because that's how we write class names. 50 00:03:10,830 --> 00:03:12,270 ‫So all we had to do 51 00:03:12,270 --> 00:03:15,270 ‫is just write public class musicians actually, 52 00:03:15,270 --> 00:03:17,520 ‫inside of a Java document. 53 00:03:17,520 --> 00:03:19,890 ‫So this is our class. 54 00:03:19,890 --> 00:03:21,480 ‫Now I get to choose 55 00:03:21,480 --> 00:03:25,860 ‫what kind of properties that I will have 56 00:03:25,860 --> 00:03:28,503 ‫inside of a musician object. 57 00:03:29,520 --> 00:03:32,850 ‫So for example, I can say string name, 58 00:03:32,850 --> 00:03:35,970 ‫and then I can say string instrument. 59 00:03:35,970 --> 00:03:37,530 ‫And if I want to add an age, 60 00:03:37,530 --> 00:03:41,970 ‫I can edit, it's age and that's it. 61 00:03:41,970 --> 00:03:46,500 ‫Now I get to create a musician object 62 00:03:46,500 --> 00:03:48,813 ‫out of a musician class. 63 00:03:49,680 --> 00:03:54,210 ‫It's the same thing like creating a string object 64 00:03:54,210 --> 00:03:57,600 ‫from a string class like this. 65 00:03:57,600 --> 00:04:00,120 ‫So let me come over here 66 00:04:00,120 --> 00:04:05,040 ‫maybe under on create or let me create my own new method, 67 00:04:05,040 --> 00:04:08,160 ‫so that it would be a separate method, 68 00:04:08,160 --> 00:04:12,570 ‫so you can keep track of things in a better way, okay. 69 00:04:12,570 --> 00:04:14,490 ‫You don't have to create methods right now. 70 00:04:14,490 --> 00:04:16,920 ‫All we have to say public void. 71 00:04:16,920 --> 00:04:21,240 ‫And over here, let me call this, make musicians. 72 00:04:21,240 --> 00:04:25,650 ‫So it would be explicit as much as possible, okay? 73 00:04:25,650 --> 00:04:28,950 ‫And under this make musicians method, 74 00:04:28,950 --> 00:04:32,013 ‫I'm going to create a musician object. 75 00:04:32,850 --> 00:04:35,400 ‫So if you come over here and take a look, 76 00:04:35,400 --> 00:04:37,770 ‫we already did something like that. 77 00:04:37,770 --> 00:04:40,380 ‫So it's the, it's basically the same thing 78 00:04:40,380 --> 00:04:43,170 ‫like saying string, my string, okay, 79 00:04:43,170 --> 00:04:45,990 ‫we are gonna say musicians like this. 80 00:04:45,990 --> 00:04:48,570 ‫And as you can see now it's appearing 81 00:04:48,570 --> 00:04:50,400 ‫in the results as well. 82 00:04:50,400 --> 00:04:53,340 ‫So musicians is our class 83 00:04:53,340 --> 00:04:58,340 ‫and we are going to create an object out of that class. 84 00:04:58,470 --> 00:05:01,500 ‫And we can name it anything we want. 85 00:05:01,500 --> 00:05:03,930 ‫Like James for example. 86 00:05:03,930 --> 00:05:08,220 ‫So James is a musician's object right now. 87 00:05:08,220 --> 00:05:13,170 ‫James is not a integer, is not a string, is not a bullion. 88 00:05:13,170 --> 00:05:18,170 ‫James is musicians and I can just say new musicians. 89 00:05:18,420 --> 00:05:23,420 ‫And I can actually give the property values afterwards 90 00:05:23,730 --> 00:05:24,690 ‫if I want to. 91 00:05:24,690 --> 00:05:27,237 ‫Like I can say James dot, 92 00:05:27,237 --> 00:05:32,070 ‫and I can reach all the properties that I have defined 93 00:05:32,070 --> 00:05:35,940 ‫inside of my musicians class. 94 00:05:35,940 --> 00:05:37,770 ‫Now what do I have over there? 95 00:05:37,770 --> 00:05:42,210 ‫I have the name, I have these instrument, I have the age. 96 00:05:42,210 --> 00:05:45,540 ‫Now if I say James dot, I can reach all of those 97 00:05:45,540 --> 00:05:48,840 ‫as you can see, age, instrument, name. 98 00:05:48,840 --> 00:05:51,570 ‫If I had another method or something, 99 00:05:51,570 --> 00:05:54,960 ‫some kind of property over there, 100 00:05:54,960 --> 00:05:57,450 ‫I could have reached those as well. 101 00:05:57,450 --> 00:06:00,540 ‫So I can just say James dot age is 50, 102 00:06:00,540 --> 00:06:03,303 ‫James dot instrument is guitar. 103 00:06:04,860 --> 00:06:07,620 ‫And I can just say James dot name is 104 00:06:07,620 --> 00:06:10,383 ‫of course James itself. 105 00:06:11,460 --> 00:06:14,280 ‫So this is how you deal with classes. 106 00:06:14,280 --> 00:06:18,160 ‫This is how you create models for your own objects. 107 00:06:20,130 --> 00:06:24,600 ‫Now I get to create whatever I want, 108 00:06:24,600 --> 00:06:28,170 ‫like an object inside of my, 109 00:06:28,170 --> 00:06:31,290 ‫under a development environment. 110 00:06:31,290 --> 00:06:34,590 ‫Of course, there are a lot of other things to consider 111 00:06:34,590 --> 00:06:36,600 ‫when you deal with classes 112 00:06:36,600 --> 00:06:39,870 ‫and we're gonna see a lot of those 113 00:06:39,870 --> 00:06:42,093 ‫in the next lecture as well.