1 00:00:08,929 --> 00:00:11,708 2 00:00:11,708 --> 00:00:14,968 This presentation is delivered by the Stanford Center for Professional 3 00:00:14,968 --> 00:00:21,969 Development. 4 00:00:22,920 --> 00:00:26,320 So let's go ahead and get started with the actual content. And so today 5 00:00:26,320 --> 00:00:29,310 is the day where we make a little bit of a transition. It's like one of our 6 00:00:29,309 --> 00:00:31,629 transition points in life. It's kind of like coming to college. 7 00:00:31,629 --> 00:00:35,369 And the transition point we make is you now come into the Java world, and you're like, 8 00:00:35,369 --> 00:00:39,058 "But I'm still doing Karel." Yeah, in lectures, we're going to start to wave bye bye 9 00:00:39,058 --> 00:00:41,119 to Karel and Karel's like, "Yeah, 10 00:00:41,119 --> 00:00:44,399 I'll be there in your dreams when you're actually programming, right." So Karel's not 11 00:00:44,399 --> 00:00:48,009 really gone until you're done with the Assignment No. 1. But now, we 12 00:00:48,009 --> 00:00:51,500 take we sort of graduate into the world of Java and you'll actually see that a lot of things 13 00:00:51,500 --> 00:00:54,159 that exists in Karel's world will come back because 14 00:00:54,159 --> 00:00:58,000 we give them to in a gentle form in Karel's world and 15 00:00:58,000 --> 00:01:01,100 then the Java world, they come full steam. So 16 00:01:01,100 --> 00:01:02,300 before we dive into that, 17 00:01:02,299 --> 00:01:05,879 I want you to get a little notion of the history of computing. Okay, and we'll go over this very 18 00:01:05,879 --> 00:01:10,099 briefly, but computing actually has a very long history and it dates back about 19 00:01:10,099 --> 00:01:12,049 4,000 years, okay. 20 00:01:12,049 --> 00:01:15,579 So roughly 4,000 years ago, the first one we think of is computing 21 00:01:15,579 --> 00:01:19,039 device was made available, but then you want to know what that was? 22 00:01:19,040 --> 00:01:19,859 Advocates. 23 00:01:19,859 --> 00:01:23,390 The first computing device allowed you to do some fairly 24 00:01:23,390 --> 00:01:24,769 rudimentary arithmetic on it, 25 00:01:24,769 --> 00:01:27,589 but it actually was something that allowed people to compute a lot faster 26 00:01:27,590 --> 00:01:30,510 than they could by keeping track of stuff in their head. 27 00:01:30,510 --> 00:01:34,320 The real sort of advances in what we think of as computing actually came 28 00:01:34,319 --> 00:01:37,169 around in the 1800's. That was 29 00:01:37,170 --> 00:01:39,760 someone by the name Charles Babbage. 30 00:01:39,760 --> 00:01:41,760 Anyone heard of Charles Babbage, by the way, a just 31 00:01:41,760 --> 00:01:43,230 quick show of hands. 32 00:01:43,230 --> 00:01:45,680 We can just call him Chuck. He 33 00:01:45,680 --> 00:01:47,820 was actually 34 00:01:47,819 --> 00:01:51,798 a very well learned and well-known person in his day. He had the Lucasian 35 00:01:51,799 --> 00:01:53,270 chair, 36 00:01:53,269 --> 00:01:56,769 which is the same chair at university that actually Steven Hawking has now 37 00:01:56,769 --> 00:01:58,899 that Sir Isaac Newton had at one point. So, 38 00:01:58,900 --> 00:02:00,340 pretty smart dude, 39 00:02:00,340 --> 00:02:03,390 and he came up with this notion of something called the Difference Engine, 40 00:02:03,390 --> 00:02:06,649 which is a way of being able to automatically. And in those days, right, they didn't 41 00:02:06,649 --> 00:02:10,109 have silicon. Well, they had silicon, but it was in the form of sand, 42 00:02:10,109 --> 00:02:13,769 and they didn't have computers in the way we think of computers, so he wanted to 43 00:02:13,769 --> 00:02:17,468 build a mechanical device like with real, actual, you know, mechanics and pieces of 44 00:02:17,468 --> 00:02:18,979 woods that's been around, 45 00:02:18,979 --> 00:02:23,219 and in his time, he thought is would be powered by steam, right, because this is sort of pre 46 00:02:23,219 --> 00:02:25,289 thinking about electronic computers 47 00:02:25,289 --> 00:02:28,188 that would do automated calculation. And he designed something 48 00:02:28,188 --> 00:02:31,128 called the Difference Engine and then he designed something called the Analytic 49 00:02:31,128 --> 00:02:33,319 Engine, which was supposed to be even more powerful, 50 00:02:33,319 --> 00:02:35,979 and interestingly enough neither one of them was actually built during his 51 00:02:35,979 --> 00:02:36,768 lifetime. 52 00:02:36,769 --> 00:02:40,278 It turns out that years later, the difference engine was actually 53 00:02:40,278 --> 00:02:42,069 built from a bunch 54 00:02:42,069 --> 00:02:43,750 of wheels and rotors and stuff and now 55 00:02:43,750 --> 00:02:46,739 the things, you know, that he would have liked to think of as the Analytic Engine 56 00:02:46,739 --> 00:02:49,259 is actually these puppies. It actually turned in the 1800's; he had a lot of 57 00:02:49,259 --> 00:02:50,298 the same ideas 58 00:02:50,299 --> 00:02:54,079 that are in our laptops or in our computers today strangely enough. 59 00:02:54,079 --> 00:02:57,409 But, so that's kind of where our computing we think of the notion of computing is 60 00:02:57,408 --> 00:02:58,469 really coming from, 61 00:02:58,469 --> 00:03:01,679 and it turns out the first programmer 62 00:03:01,679 --> 00:03:05,368 was a woman by the name of Ada 63 00:03:05,368 --> 00:03:08,908 Byron, actually Augusta Ada Byron and if the Byron looks familiar, too, is 64 00:03:08,908 --> 00:03:12,138 because she was the daughter of Lord Byron, the English poet 65 00:03:12,139 --> 00:03:15,808 and she was actually very taken by the designs of Charles Babbage's machines 66 00:03:15,808 --> 00:03:19,188 and actually wrote programs. The machines were actually written to have sort of 67 00:03:19,188 --> 00:03:19,889 cards, sort of 68 00:03:19,889 --> 00:03:22,449 like the Jacard Loom if you've ever heard of the Jacard Loom, if you haven't, 69 00:03:22,449 --> 00:03:23,769 it's not important, 70 00:03:23,770 --> 00:03:27,049 that actually would have programs for the kind of computations that it would do 71 00:03:27,049 --> 00:03:30,379 and see, she actually devised various programs 72 00:03:30,378 --> 00:03:33,209 for Charles Babbage's Analytical Engine. And 73 00:03:33,209 --> 00:03:34,840 you might be sitting there and you might think, 74 00:03:34,840 --> 00:03:37,960 "But Marion, you've just told me that the Analytical Engine was never actually 75 00:03:37,960 --> 00:03:39,540 built in their lifetime, 76 00:03:39,539 --> 00:03:43,248 so what's she doing writing programs for a computer that doesn't exist," 77 00:03:43,248 --> 00:03:46,538 and that's actually something that happens today. People write programs for 78 00:03:46,538 --> 00:03:48,418 computers that don't exist and you might wonder 79 00:03:48,419 --> 00:03:51,340 why. That's not a very good use of your time. 80 00:03:51,340 --> 00:03:52,348 Well, guess what, 81 00:03:52,348 --> 00:03:55,539 if the next generation of computers is going to come out while it's still being 82 00:03:55,539 --> 00:03:58,449 designed before it's actually manufactured and built, 83 00:03:58,449 --> 00:04:01,289 someone needs to figure out what kind of programs you want to run on that 84 00:04:01,289 --> 00:04:04,060 machine, so there are actually programmers today who actually write programs for machines 85 00:04:04,060 --> 00:04:07,420 that aren't built. And they simulate them by hand and they go through and try to 86 00:04:07,419 --> 00:04:10,289 figure out what they would do and it's perfectly reasonably thing to do. 87 00:04:10,289 --> 00:04:16,639 But as a result, Ada Byron is in some sense, the first programmer, 88 00:04:16,639 --> 00:04:19,340 right, because she was actually writing programs for in some sense, a 89 00:04:19,339 --> 00:04:21,478 general purpose computational device 90 00:04:21,478 --> 00:04:24,199 over 100 years ago, which is kind of an astounding thing if you think 91 00:04:24,199 --> 00:04:25,069 about it. 92 00:04:25,069 --> 00:04:28,939 Now it turns out computing actually got its first real, you know, what we think 93 00:04:28,939 --> 00:04:31,669 more closely of as computing devices 94 00:04:31,668 --> 00:04:35,668 in the 1930's. I should put 19 here just so we're clear 1930's 95 00:04:35,668 --> 00:04:36,599 and 40's, 96 00:04:36,600 --> 00:04:40,610 they were sort of the first prototypes of electro mechanical computers that 97 00:04:40,610 --> 00:04:44,160 were actually built at the time. There was a computer that was built at Iowa 98 00:04:44,160 --> 00:04:47,300 State by Atanasoff and Berry. Their names are actually not well, they're 99 00:04:47,300 --> 00:04:48,920 important if you're a lawyer because it turned 100 00:04:48,920 --> 00:04:51,770 out there were actually lawsuits at the time by who patented it in the computer, 101 00:04:51,769 --> 00:04:53,918 but we won't talk about that. 102 00:04:53,918 --> 00:04:59,158 Started sort of in this era with sort of prototypes and then the 103 00:04:59,158 --> 00:05:03,178 one machine you may have actually heard of by 1946, there was a 104 00:05:03,178 --> 00:05:06,308 machine called ENIAC, 105 00:05:06,309 --> 00:05:09,050 which was actually built by Elkhart and McCauley at U Penn 106 00:05:09,050 --> 00:05:13,538 which was standard for, if I can remember this, for electronic, numerical integrator and 107 00:05:13,538 --> 00:05:14,379 calculator. 108 00:05:14,379 --> 00:05:17,509 And basically with one of these big things, you know, sat in a 109 00:05:17,509 --> 00:05:19,400 big warehouse, a few tons, 110 00:05:19,399 --> 00:05:21,019 but it actually did computational, 111 00:05:21,019 --> 00:05:23,740 you know, the kinds of things we would think of as computation and it was 112 00:05:23,740 --> 00:05:27,408 really in some sense the first large-scale electro magnetic computer 113 00:05:27,408 --> 00:05:30,259 that we think about, again, you know, modular lawyers. 114 00:05:30,259 --> 00:05:33,810 And then really it was in 1971, that the first 115 00:05:33,810 --> 00:05:37,158 microprocessor came around, so we come to a fairly modern time, right, so it's not 116 00:05:37,158 --> 00:05:39,829 all that long ago, like we're talking 36 years, 117 00:05:39,829 --> 00:05:46,209 the microprocessors have actually been around. And so the first microprocessor 118 00:05:46,209 --> 00:05:49,538 and one of the folks who was on that team who built the first microprocessor, Ted Hawk, is 119 00:05:49,538 --> 00:05:52,909 actually Stanford alum, interestingly enough, it was built at Intel. The 120 00:05:52,910 --> 00:05:56,160 Intel 4004 was the name of that microprocessor and at the time, no 121 00:05:56,160 --> 00:05:57,590 one actually thought that 122 00:05:57,589 --> 00:06:00,699 having a single chip microprocessor was going to be that interesting. He sort of designed 123 00:06:00,699 --> 00:06:01,899 this thing and it was 124 00:06:01,899 --> 00:06:05,449 originally going to be going over for use in some machine in Japan 125 00:06:05,449 --> 00:06:08,610 and they were just going to give them some design and the patent for it and the 126 00:06:08,610 --> 00:06:11,610 folks were getting like, "Well, we're not really interested. Yeah, sure it's an interesting 127 00:06:11,610 --> 00:06:13,220 chip, but we're not really interested 128 00:06:13,220 --> 00:06:16,300 in, you know, owning the patent. We don't think there's anything interesting 129 00:06:16,300 --> 00:06:17,189 necessarily here," 130 00:06:17,189 --> 00:06:21,019 and so they kind of ran with it and the rest is history, as they say. And as 131 00:06:21,019 --> 00:06:24,668 you can imagine in the last 35 years or so, there's just been an astounding 132 00:06:24,668 --> 00:06:27,258 amount of development in computing and computer science, right, 133 00:06:27,259 --> 00:06:30,060 so really this field is like hundreds or thousands years old, if you think 134 00:06:30,060 --> 00:06:30,860 about it, 135 00:06:30,860 --> 00:06:33,410 but really it's kind of in your lifetime 136 00:06:33,410 --> 00:06:35,629 that all the interesting stuff is really happening, 137 00:06:35,629 --> 00:06:39,050 which is also why it's exciting to be alive now and be a computer scientist 138 00:06:39,050 --> 00:06:41,408 because you're in this acceleration phase, right. 139 00:06:41,408 --> 00:06:44,269 Think about what's going to happen, like all the stuff that happened in the last 36 140 00:06:44,269 --> 00:06:44,789 years, 141 00:06:44,790 --> 00:06:46,930 you're gonna be around to see the next 36 years and you're gonna be 142 00:06:46,930 --> 00:06:49,970 doing the next 36 years, so that's just an exciting thing 143 00:06:49,970 --> 00:06:51,899 that I think about. But 144 00:06:51,899 --> 00:06:54,649 another thing that comes up when you think about this, what is computer science, 145 00:06:54,649 --> 00:06:58,119 right, like why do we we've been talking about Karel programming and a lot of this 146 00:06:58,119 --> 00:07:00,930 class we're gonna learn about software development and Java programming 147 00:07:00,930 --> 00:07:04,309 and so a lot of people tend to equate computer science with programming and 148 00:07:04,309 --> 00:07:05,090 they think, 149 00:07:05,089 --> 00:07:08,409 "Well, why isn't a major just called, you know, computer programming and why is 150 00:07:08,410 --> 00:07:10,370 there really a science to it in some sense." 151 00:07:10,370 --> 00:07:13,209 That's something that people actually would use to debate. They don't really debate it 152 00:07:13,209 --> 00:07:15,870 so much anymore. Is there a real science to computing 153 00:07:15,870 --> 00:07:17,540 or is it just programming and in fact, 154 00:07:17,540 --> 00:07:22,210 the difference between the two is that computer science or CS as we'll just 155 00:07:22,209 --> 00:07:23,288 affectionately refer to it, 156 00:07:23,288 --> 00:07:28,860 really is the science or in some sense, the study 157 00:07:28,860 --> 00:07:32,900 of problem solving with computers, 158 00:07:32,899 --> 00:07:36,489 and you don't need to write his all down; it's just for your edification, with 159 00:07:36,490 --> 00:07:41,668 computers or I should say, computational devices. 160 00:07:41,668 --> 00:07:45,959 Computational I'll even say methods because some people actually look at, you know, 161 00:07:45,959 --> 00:07:48,848 theoretically what's possible without even necessarily thinking that 162 00:07:48,848 --> 00:07:50,759 it's real life in hardware, right. Turns 163 00:07:50,759 --> 00:07:53,288 out it actually surprises people there are some functions that you can prove 164 00:07:53,288 --> 00:07:55,259 are not computable. I'm 165 00:07:55,259 --> 00:07:58,069 like, "Really, you can?" Yeah, and it's good to know about them before you go and try to 166 00:07:58,069 --> 00:07:59,850 write a program to actually compute them 167 00:07:59,850 --> 00:08:02,910 because in theory they're not computable and you can prove that, and if you're 168 00:08:02,910 --> 00:08:07,189 actually interested in that, take CS 103 or CS 154 and we'll talk about it all the time. 169 00:08:07,189 --> 00:08:09,689 But that's really what the science is, 170 00:08:09,689 --> 00:08:13,439 is thinking about problem-solving and the approaches to problem-solving, how you 171 00:08:13,439 --> 00:08:16,939 analyze how efficient a solution is to a problem, how solvable it actually is, the 172 00:08:16,939 --> 00:08:18,329 different approaches you take to it. 173 00:08:18,329 --> 00:08:20,348 So, notice the word programming 174 00:08:20,348 --> 00:08:21,810 doesn't show up here. 175 00:08:21,810 --> 00:08:25,819 Programming is an artifact. It's something we do to realize that 176 00:08:25,819 --> 00:08:28,909 particular problem-solving technique in a computer or some 177 00:08:28,910 --> 00:08:30,019 computational method. 178 00:08:30,019 --> 00:08:33,528 It's just something we do as part of the process, right. It's not what the whole 179 00:08:33,528 --> 00:08:35,799 thing is really about. In some sense, 180 00:08:35,799 --> 00:08:37,798 there is actually this famous quote that 181 00:08:37,798 --> 00:08:41,608 computer science is just as much about programming as astronomy is 182 00:08:41,609 --> 00:08:43,310 about building telescopes. 183 00:08:43,309 --> 00:08:46,529 Right, astronomy is about far more than building telescopes. It's really sort of a science 184 00:08:46,529 --> 00:08:48,159 of celestial bodies. 185 00:08:48,159 --> 00:08:50,649 Telescopes is the mechanism by which you actually look at them. 186 00:08:50,649 --> 00:08:57,649 Uh-huh, question in the back? 187 00:08:59,669 --> 00:09:03,309 [Inaudible]. Well, if you think about computer engineering, part of it is just kind of a 188 00:09:03,309 --> 00:09:05,699 definition that a particular school wants to have for it, right. 189 00:09:05,700 --> 00:09:08,940 And some places actually our computer science program is in the School of Engineering. 190 00:09:08,940 --> 00:09:11,260 Some places it's actually in humanities and sciences. 191 00:09:11,259 --> 00:09:14,370 It depends on the view and it also depends on the particular program that's there, 192 00:09:14,370 --> 00:09:16,679 so some places may actually 193 00:09:16,679 --> 00:09:20,419 there's no way I'm gonna hit you in the back may just be training programmers, 194 00:09:20,419 --> 00:09:23,449 right. And the science of computing is not what they're actually interested in, 195 00:09:23,450 --> 00:09:27,870 and so it depends on the program, but we really think of the computer science as a science, and it's 196 00:09:27,870 --> 00:09:30,528 an interesting philosophical argument. We can certainly talk about it more in class, 197 00:09:30,528 --> 00:09:33,240 but I just wanted to kind of push on. All right, 198 00:09:33,240 --> 00:09:36,330 so with that said, that's kind of the quick tour of a couple hundred years of 199 00:09:36,330 --> 00:09:37,990 computer science history, 200 00:09:37,990 --> 00:09:42,039 it turns out when we get into modern day, when we actually think about 201 00:09:42,039 --> 00:09:44,579 computing, what does a computer really understand 202 00:09:44,580 --> 00:09:48,400 and what are the programs that you write on it and how do they turn into something that 203 00:09:48,399 --> 00:09:51,559 the computer understands. So it turns out that the computer actually understands zeros 204 00:09:51,559 --> 00:09:52,758 and ones. 205 00:09:52,759 --> 00:09:56,959 And so we like to think of that as binary, right. Binary is just a number system that 206 00:09:56,958 --> 00:10:01,628 only has zeros and ones. It's base two numbers basically and that's all that computers 207 00:10:01,629 --> 00:10:03,590 understands, zeros and ones on and off. 208 00:10:03,590 --> 00:10:07,540 So how do we take these things like move or turn left and turn them into ones 209 00:10:07,539 --> 00:10:09,569 and zeros, and so 210 00:10:09,570 --> 00:10:12,810 there's something called machine language 211 00:10:12,809 --> 00:10:17,269 that is what a computer understands or in some sense what the microprocessor 212 00:10:17,269 --> 00:10:20,600 understands, right. The machine languages is defined by what chip you have inside 213 00:10:20,600 --> 00:10:21,980 your computer. 214 00:10:21,980 --> 00:10:25,269 That's eventually going to boil down into a bunch of ones and zeros. 215 00:10:25,269 --> 00:10:28,620 People are real bad at writing ones and zeros in a form that computers can 216 00:10:28,620 --> 00:10:28,980 understand. 217 00:10:28,980 --> 00:10:32,590 So we program what's known as a high-level language, 218 00:10:32,590 --> 00:10:36,759 okay. And there's all kinds of high-level languages, so one of the ones that you're gonna 219 00:10:36,759 --> 00:10:40,360 learn in this class is Java and there's some other ones you may have heard like C 220 00:10:40,360 --> 00:10:44,339 or C++ or Basic or Fortran or whatever the case may be. 221 00:10:44,339 --> 00:10:47,110 These are all high-level languages, because they're at a higher level than what the 222 00:10:47,110 --> 00:10:48,430 machine understands, 223 00:10:48,429 --> 00:10:51,809 and so there's this question that's actually part of the science of computing is 224 00:10:51,809 --> 00:10:54,388 how do you go from this high-level language 225 00:10:54,389 --> 00:10:57,799 into something the machine understands, right. What is this translation process because there actually is some translation that needs to 226 00:10:57,799 --> 00:11:00,308 happen 227 00:11:00,308 --> 00:11:04,149 and this process going form the high-level language to the machine language 228 00:11:04,149 --> 00:11:07,070 is something we refer to as compilation, 229 00:11:07,070 --> 00:11:11,360 right. So compilation is something, strangely enough, that's done by a 230 00:11:11,360 --> 00:11:15,350 compiler and Eclipse which you've been using this whole time is in fact a 231 00:11:15,350 --> 00:11:18,700 compiler. It takes the instructions that you write in some high-level language 232 00:11:18,700 --> 00:11:21,840 and converts them into some form that the machine understands. 233 00:11:21,840 --> 00:11:25,019 Now it turns out that the process for doing this in some languages is actually 234 00:11:25,019 --> 00:11:27,359 slightly different than other languages, so I want to show you 235 00:11:27,359 --> 00:11:31,319 a quick little overview of how that looks in Java just so you can get a real 236 00:11:31,318 --> 00:11:35,058 sense of what's going on between the time you write a program and the time the 237 00:11:35,058 --> 00:11:38,620 machine executes it so you sort of understand it at a low level. 238 00:11:38,620 --> 00:11:43,200 As programmers, you write what's called source code. 239 00:11:43,200 --> 00:11:46,580 Know it, learn it, live it, love it. Source code that's what you're gonna write. When you 240 00:11:46,580 --> 00:11:49,740 were writing Karel programs, you were writing source code. When you write Java, 241 00:11:49,740 --> 00:11:51,549 you're going to write source code. 242 00:11:51,549 --> 00:11:54,889 What the machine understands, these zeros and ones here, it's something that's called 243 00:11:54,889 --> 00:11:57,799 objects code. 244 00:11:57,799 --> 00:12:02,379 An object code is essentially just the low-level instructions, the machine 245 00:12:02,379 --> 00:12:02,828 instructions 246 00:12:02,828 --> 00:12:04,598 that the computer understands 247 00:12:04,599 --> 00:12:05,730 and so 248 00:12:05,730 --> 00:12:09,560 going from source code to object code is basically what the compiler does. It's the 249 00:12:09,559 --> 00:12:10,708 translation from this to 250 00:12:10,708 --> 00:12:11,889 this. 251 00:12:11,889 --> 00:12:15,600 Now in regular languages, that might look, if we got the overhead. 252 00:12:15,600 --> 00:12:18,360 Is shouldn't say regular language. In some classical languages, 253 00:12:18,360 --> 00:12:22,070 it might look something like this, you write some source code in what we refer to 254 00:12:22,070 --> 00:12:24,649 as the source file. The source file is just a file 255 00:12:24,649 --> 00:12:26,340 that contains source code. 256 00:12:26,340 --> 00:12:30,070 So you write your program that goes into some compiler, say Eclipse, which is 257 00:12:30,070 --> 00:12:31,409 the compiler you're using 258 00:12:31,408 --> 00:12:34,158 and what might come out of it is an object file because what is contained 259 00:12:34,158 --> 00:12:37,539 in that file is just essentially object code 260 00:12:37,539 --> 00:12:40,990 or in this case a bunch of zeros and ones that the computer understands. 261 00:12:40,990 --> 00:12:44,070 And there might have been other programs that someone wrote along the way like 262 00:12:44,070 --> 00:12:47,129 some libraries you might make use of like you did with Karel, right, all the 263 00:12:47,129 --> 00:12:49,730 basic Karel functionality might be in some other 264 00:12:49,730 --> 00:12:53,089 library and so there's other files that contain object code 265 00:12:53,089 --> 00:12:56,909 and all of this stuff gets linked together into one big set of object code 266 00:12:56,908 --> 00:13:00,019 which we refer to as the executable or the application. 267 00:13:00,019 --> 00:13:03,048 That's the thing that, say, when you double click on your word processor on your 268 00:13:03,048 --> 00:13:04,568 computer and it runs, 269 00:13:04,568 --> 00:13:08,128 you're running some executable file, which is just basically a file of a bunch of 270 00:13:08,129 --> 00:13:09,750 ones and zeros that eventually 271 00:13:09,750 --> 00:13:13,600 or as some time ago, someone wrote and source code and it got compiled down in this executable 272 00:13:13,600 --> 00:13:14,149 file. 273 00:13:14,149 --> 00:13:17,028 And for a lot of languages like C or C++, 274 00:13:17,028 --> 00:13:19,370 this is the process that actually happens. 275 00:13:19,370 --> 00:13:21,289 Now the people who did Java 276 00:13:21,289 --> 00:13:24,469 thought of things slightly differently and here is kind of where things get funky 277 00:13:24,470 --> 00:13:26,800 in Java, okay? 278 00:13:26,799 --> 00:13:29,169 In Java's world, 279 00:13:29,169 --> 00:13:31,599 part of what's going on is actually 280 00:13:31,600 --> 00:13:35,450 run on a virtual machine. What does that mean; it means you write some source file 281 00:13:35,450 --> 00:13:37,430 in Java, okay, 282 00:13:37,429 --> 00:13:41,229 that goes through some compiler and what comes out of it is not an object file, 283 00:13:41,230 --> 00:13:43,220 but something called a class file. 284 00:13:43,220 --> 00:13:46,730 It takes all of the high-level stuff that you write in Java or in this case, 285 00:13:46,730 --> 00:13:49,360 you could say Karel because it's the same thing, 286 00:13:49,360 --> 00:13:50,938 and turns it into 287 00:13:50,938 --> 00:13:55,740 some set of numerical instructions that are not yet ones and zeros that the computer 288 00:13:55,740 --> 00:13:59,430 understands but are some intermediate language, which is just a numerical language. 289 00:13:59,429 --> 00:14:01,998 And sometimes you refer to this as Java bite code, 290 00:14:01,999 --> 00:14:04,879 but the name is actually not important. It's some intermediate language, 291 00:14:04,879 --> 00:14:08,889 and guess what, there's other classes just like there were before that contain 292 00:14:08,889 --> 00:14:11,429 instructions in this intermediate language and those all get linked 293 00:14:11,429 --> 00:14:16,159 together in some big file that we call a jar archive which just stands for jar just 294 00:14:16,159 --> 00:14:18,480 means Java archive, strangely enough. 295 00:14:18,480 --> 00:14:22,379 So it's actually redundant to say jar archive. People just do, but it means Java archive. All 296 00:14:22,379 --> 00:14:23,960 right, 297 00:14:23,960 --> 00:14:27,580 and then this whole thing is now instead of this intermediate language, it's 298 00:14:27,580 --> 00:14:30,470 something that neither the human really understands okay, there's a few humans in 299 00:14:30,470 --> 00:14:33,490 the world that might and they're a little weird and we won't talk about them. 300 00:14:33,490 --> 00:14:36,649 Most people don't understand this and the computer doesn't understand it 301 00:14:36,649 --> 00:14:40,299 directly either. So you say, "Well, that's the most useless thing ever. Why would I ever 302 00:14:40,299 --> 00:14:41,699 do that?" 303 00:14:41,700 --> 00:14:45,310 These instructions go to something called the Java Virtual Machine, the 304 00:14:45,309 --> 00:14:46,299 JVM, 305 00:14:46,299 --> 00:14:49,879 and what the Java Virtual Machine says, it says, "Hey, guess what? 306 00:14:49,879 --> 00:14:55,289 I'm going to be pretending like I'm a machine that understands this as my 307 00:14:55,289 --> 00:14:59,259 object code. I understand this stuff as the basic language I speak, 308 00:14:59,259 --> 00:15:02,950 and I take that and when I run it, I do something on your computer." 309 00:15:02,950 --> 00:15:06,520 And you might say, "Why would you want to have this extra process?" 310 00:15:06,519 --> 00:15:10,039 And the reason why you want to have this extra process is the fact that guess what, 311 00:15:10,039 --> 00:15:13,939 in the world there's things like Macs and there's PCs and there's Linux 312 00:15:13,940 --> 00:15:16,290 computers and there's all kinds of machines out there, 313 00:15:16,289 --> 00:15:19,759 which means if you sort of do things in either the good old way or the bad old 314 00:15:19,759 --> 00:15:20,929 way, 315 00:15:20,929 --> 00:15:24,569 the compiler needs to understand what are the ones and zeros that your 316 00:15:24,570 --> 00:15:28,080 computer speaks and the ones and zeros that a Macintosh speaks are different than 317 00:15:28,080 --> 00:15:29,920 the ones and zeros that a PC speaks. 318 00:15:29,919 --> 00:15:33,079 And they're different than the ones and zeros that the Linux machine speaks. 319 00:15:33,080 --> 00:15:36,460 So the compiler needs to know all that if it's actually gonna generate this kind 320 00:15:36,460 --> 00:15:40,019 of code for all of those different sorts of machines and most compilers don't. Most of the 321 00:15:40,019 --> 00:15:41,230 time you've got a compiler that says, 322 00:15:41,230 --> 00:15:44,490 "Hey I'm a PC compiler. I'm just gonna generate stuff for the PC and that's 323 00:15:44,490 --> 00:15:45,830 all I do." 324 00:15:45,830 --> 00:15:49,020 In Java's world, things are a little bit more interesting because 325 00:15:49,019 --> 00:15:52,000 the compiler doesn't need to know what kind of computer you're running on. It says, 326 00:15:52,000 --> 00:15:55,220 "Hey, I'm producing this intermediate language and the intermediate language is 327 00:15:55,220 --> 00:15:57,139 the same for all computers." 328 00:15:57,139 --> 00:16:00,379 The only thing that has to be different on your computer is you need to have 329 00:16:00,379 --> 00:16:02,480 this little thing called the JVM 330 00:16:02,480 --> 00:16:05,509 that knows how to translate this intermediate language 331 00:16:05,509 --> 00:16:09,298 into what's going on on your computer. So if you have a JVM for your Mac 332 00:16:09,298 --> 00:16:12,720 or a JVM for your PC or a JVM for your Linux machine, 333 00:16:12,720 --> 00:16:17,110 they can all run this same low-level intermediate code and do the right thing 334 00:16:17,110 --> 00:16:18,990 on those computers. Okay, 335 00:16:18,990 --> 00:16:21,830 and so remember when you set up Eclipse or if you haven't set up Eclipse yet, 336 00:16:21,830 --> 00:16:25,540 you'll get there soon enough, but when you're wetting up Eclipse, we asked you to 337 00:16:25,539 --> 00:16:28,389 download and install something called the Java run-time environment and how many 338 00:16:28,389 --> 00:16:31,620 people remember that? Raise your hand if you remember that? You folks 339 00:16:31,620 --> 00:16:34,089 guess what the Java runtime environment provided? 340 00:16:34,089 --> 00:16:37,350 It provided this thing for your computer, okay. 341 00:16:37,350 --> 00:16:39,459 So you write the program once; 342 00:16:39,458 --> 00:16:44,149 you compile it once and now that class information that you have, that class file 343 00:16:44,149 --> 00:16:47,619 can be run on any computer that has this Java Virtual Machine and Java Virtual 344 00:16:47,619 --> 00:16:51,480 Machines are sort of ubiquitous. They exist for a lot of different computing platforms, okay. 345 00:16:51,480 --> 00:16:53,879 So that's why they actually do it that way, and it's kind of funky, but it's a 346 00:16:53,879 --> 00:16:55,549 little bit different. 347 00:16:55,549 --> 00:16:56,649 Now, 348 00:16:56,649 --> 00:16:59,590 with that kind of said, that's the low-level stuff. That's kind of what's happening at 349 00:16:59,590 --> 00:17:02,600 the low level and you don't really need to know that low level intimately. I just 350 00:17:02,600 --> 00:17:05,500 want you to understand what's happening from the programs you write 351 00:17:05,500 --> 00:17:08,339 to what happens when they get executed on the computer. 352 00:17:08,339 --> 00:17:14,079 Now what you do need to know, is how do we begin to write programs in Java. 353 00:17:14,079 --> 00:17:15,418 In Java, 354 00:17:15,419 --> 00:17:17,870 you'll see some examples of it today, 355 00:17:17,869 --> 00:17:21,119 is what we refer to as an object-oriented language, 356 00:17:21,119 --> 00:17:24,899 okay. So Java is object 357 00:17:24,900 --> 00:17:25,528 oriented 358 00:17:25,528 --> 00:17:29,169 and not all languages are object oriented. What is this whole object oriented 359 00:17:29,169 --> 00:17:32,379 thing about, so you should know what this whole notion is about before you 360 00:17:32,378 --> 00:17:35,789 start programming in the language that's kind of seeped in the idea. 361 00:17:35,789 --> 00:17:37,200 The idea 362 00:17:37,200 --> 00:17:40,680 basically is that a program is written as a bunch of classes, right, so if you 363 00:17:40,680 --> 00:17:44,630 think about, let's back up for a second, if you think about Karel, right. 364 00:17:44,630 --> 00:17:47,980 When you are writing Karel programs, of you saw Karel programs, 365 00:17:47,980 --> 00:17:51,360 you would actually create some Karel program by saying, 366 00:17:51,359 --> 00:17:52,859 "Public, 367 00:17:52,859 --> 00:17:54,129 class 368 00:17:54,130 --> 00:17:56,250 Karel program 369 00:17:56,250 --> 00:17:57,690 extends 370 00:17:57,690 --> 00:18:01,100 Super Karel." Let's just say we are Karel model. 371 00:18:01,099 --> 00:18:05,529 And then you put some stuff in here and you have like your run method in here, maybe 372 00:18:05,529 --> 00:18:06,519 some other methods 373 00:18:06,519 --> 00:18:09,519 and what you did was you were creating a class 374 00:18:09,519 --> 00:18:13,118 that was basically the information for your program, what instructions you 375 00:18:13,118 --> 00:18:16,599 were actually going to execute as part of that program. So 376 00:18:16,599 --> 00:18:22,019 what a Java program is is just a set of classes. You may have more than one 377 00:18:22,019 --> 00:18:25,319 class. Like in Karel right now you always just have one class and inside that 378 00:18:25,319 --> 00:18:26,898 class you may have a bunch of different methods, but 379 00:18:26,898 --> 00:18:31,359 you always have one class. A Java program can actually have multiple classes associated 380 00:18:31,359 --> 00:18:33,788 with it. And when we start in this class, we'll start with some simple ones that are all 381 00:18:33,788 --> 00:18:34,960 just one class. 382 00:18:34,960 --> 00:18:36,299 What you have to think about is 383 00:18:36,299 --> 00:18:39,539 that you can have more than one class, okay? 384 00:18:39,539 --> 00:18:41,288 And what these classes are, 385 00:18:41,288 --> 00:18:44,079 what you can think of a class as, 386 00:18:44,079 --> 00:18:44,769 okay, 387 00:18:44,769 --> 00:18:46,400 a class 388 00:18:46,400 --> 00:18:50,970 is just basically an encapsulation 389 00:18:50,970 --> 00:18:55,839 of some behavior that the program does, just like in Karel's 390 00:18:55,839 --> 00:18:59,789 world, you had some behavior of a bunch of different methods you define for Karel to 391 00:18:59,789 --> 00:19:01,430 actually to be able to execute, right, 392 00:19:01,430 --> 00:19:02,788 those are just different behaviors. 393 00:19:02,788 --> 00:19:06,858 But you also have some data, so it's behavior and data, 394 00:19:06,858 --> 00:19:10,470 because in the Java world you are now actually gonna keep around a track of information 395 00:19:10,470 --> 00:19:13,650 that are not just beepers in some world, but they're actually just 396 00:19:13,650 --> 00:19:16,380 numbers that you're actually gonna store somewhere and that's your data. 397 00:19:16,380 --> 00:19:19,930 And so what we do is we think of having the behaviors, all the kind of 398 00:19:19,930 --> 00:19:21,840 manipulations you might want to do with data, 399 00:19:21,839 --> 00:19:22,879 along with the data 400 00:19:22,880 --> 00:19:25,929 and put that all into this thing called the class. 401 00:19:25,929 --> 00:19:28,690 So just like in Karel where you had a class an you had behaviors, you can just 402 00:19:28,690 --> 00:19:31,538 imagine, yeah, we're gonna have some behaviors, which means in Java we're gonna 403 00:19:31,538 --> 00:19:34,319 have some class and define a bunch of methods in that class, 404 00:19:34,319 --> 00:19:36,918 but we're also gonna have some data associated with it and that whole think 405 00:19:36,919 --> 00:19:38,929 together is gonna be a class. 406 00:19:38,929 --> 00:19:41,940 Now, it turns out, the thing that's interesting about classes. Is there any questions 407 00:19:41,940 --> 00:19:45,870 about the notion of a class? It's just kind of this abstract concept right now. 408 00:19:45,869 --> 00:19:49,229 The thing that makes classes really powerful is the classes actually get 409 00:19:49,230 --> 00:19:50,529 organized into hierarchies, 410 00:19:50,529 --> 00:19:51,450 I mean, just 411 00:19:51,450 --> 00:19:52,960 draw it here, 412 00:19:52,960 --> 00:19:53,779 okay. 413 00:19:53,779 --> 00:19:57,660 And you've actually already seen this in a very small way with Karel, so all the 414 00:19:57,660 --> 00:20:00,390 things that you've seen in Karel are gonna translate over. 415 00:20:00,390 --> 00:20:03,600 Remember we talked about the basic Karel model and when you are writing a 416 00:20:03,599 --> 00:20:06,939 program you could say extends Karel and when you did the basic Karel model, 417 00:20:06,940 --> 00:20:07,910 you got like 418 00:20:07,910 --> 00:20:09,540 move and turn left 419 00:20:09,539 --> 00:20:12,308 and pick beeper and put beeper and that's all you got. 420 00:20:12,308 --> 00:20:14,889 And then we said, "Hey, you really want to turn right and turn 421 00:20:14,890 --> 00:20:20,059 around, well there's this thing called Super Karel and Super Karel is just a souped 422 00:20:20,058 --> 00:20:22,028 up version of Karel." 423 00:20:22,028 --> 00:20:25,490 Well, guess what, Karel was just a class, 424 00:20:25,490 --> 00:20:31,108 and Super Karel was also a class, but Super Karel is a class that extends 425 00:20:31,108 --> 00:20:34,029 the functionality of the basic Karel class, okay. 426 00:20:34,029 --> 00:20:37,119 So we say that Super Karel, the way we would draw things, 427 00:20:37,119 --> 00:20:39,859 if we were gonna put boxes around them and draw like the book 428 00:20:39,859 --> 00:20:42,788 is say that Super Karel is a sub class 429 00:20:42,788 --> 00:20:46,970 of Karel and Karel is the super class, this is where it's gonna get confusing, but 430 00:20:46,970 --> 00:20:50,400 super class are the things in some sense that are more general 431 00:20:50,400 --> 00:20:51,739 and the sub class 432 00:20:51,739 --> 00:20:56,149 are the things that take the basic idea of some class and extend it. So Super 433 00:20:56,148 --> 00:20:57,949 Karel does everything that Karel does, 434 00:20:57,950 --> 00:20:59,319 but it also does 435 00:20:59,319 --> 00:21:02,918 turn right and turn around, okay. So 436 00:21:02,919 --> 00:21:07,890 Super Karel is a sub class of Karel or alternatively Karel is a super class 437 00:21:07,890 --> 00:21:11,230 of Super Karel, which sounds a little bit backward, but the super here and the 438 00:21:11,230 --> 00:21:15,048 super here mean two different things. Super here means sort of above, 439 00:21:15,048 --> 00:21:18,980 and super here means cooler than, okay. So don't want to think of them as they mean 440 00:21:18,980 --> 00:21:22,240 the same thing, it's just an overloaded term, all right? 441 00:21:22,240 --> 00:21:25,630 So you might say, "Okay, Marion, this is getting a whole little abstract for me." Well, 442 00:21:25,630 --> 00:21:28,040 let me put it in terms that you understand. 443 00:21:28,039 --> 00:21:30,549 You're a human being, right? 444 00:21:30,549 --> 00:21:34,359 At this point, you should say right. And if you're not, come talk to me. All right, 445 00:21:34,359 --> 00:21:38,229 it wouldn't be the first time. 446 00:21:38,230 --> 00:21:43,079 So we have humans, okay. Humans are just a class, okay, 447 00:21:43,079 --> 00:21:46,480 and all humans are 448 00:21:46,480 --> 00:21:47,640 primates. 449 00:21:47,640 --> 00:21:50,759 Primates are a super 450 00:21:50,759 --> 00:21:54,769 class of humans, because all humans are primates, 451 00:21:54,769 --> 00:21:59,650 all primates are mammals, 452 00:21:59,650 --> 00:22:01,840 and all mammals are animals. 453 00:22:01,839 --> 00:22:06,639 So there's actually a much deeper and richer hierarchy say in biology then 454 00:22:06,640 --> 00:22:08,259 there is with Karel 455 00:22:08,259 --> 00:22:12,099 and when you actually see Java, Java will eventually have sort of a richer hierarchy 456 00:22:12,099 --> 00:22:12,939 associated with it. 457 00:22:12,940 --> 00:22:15,299 Now, the interesting thing about this, this is 458 00:22:15,299 --> 00:22:21,919 not only humans primates, but monkeys are also primates, okay. 459 00:22:21,920 --> 00:22:24,950 Humans are not monkeys and monkeys are not humans, so there's not a strict you 460 00:22:24,950 --> 00:22:27,269 might say, "Well, we don't know about that." But there isn't 461 00:22:27,269 --> 00:22:30,319 a strict relationship between humans and monkeys other than they're 462 00:22:30,319 --> 00:22:31,408 both primates, 463 00:22:31,409 --> 00:22:34,080 and that makes them mammals, and that makes them animals, 464 00:22:34,079 --> 00:22:36,529 and the whole notion of having this hierarchy 465 00:22:36,529 --> 00:22:40,490 of classes, right, so you could think of being animal as just a class and it has some 466 00:22:40,490 --> 00:22:42,058 behaviors. What does it mean to be an animal? 467 00:22:42,058 --> 00:22:45,700 Well, to be an animal means you digest food, right, 468 00:22:45,700 --> 00:22:49,039 it's not something like something like [Inaudible] actually, and one of the technical terms I'm 469 00:22:49,039 --> 00:22:52,509 not a biologist, but just what my friends tell me, embryos pass 470 00:22:52,509 --> 00:22:53,679 through the 471 00:22:53,679 --> 00:22:56,540 blastula stage. Any biologists in here? 472 00:22:56,539 --> 00:22:57,869 Is that right? Yeah. 473 00:22:57,869 --> 00:23:01,259 Okay, good, good because I was like asking a friend of mine, like, "What differentiates animals 474 00:23:01,259 --> 00:23:04,369 form plants," and he was like, "Oh, of course, the embryo was passed through the blastula stage and I was 475 00:23:04,369 --> 00:23:05,048 like, 476 00:23:05,048 --> 00:23:06,589 477 00:23:06,589 --> 00:23:10,049 "Oh, right on." I had no idea, and I was like, "How do you spell blastula?" 478 00:23:10,049 --> 00:23:14,480 So I'll just put blastula down here, right. 479 00:23:14,480 --> 00:23:18,220 So that means, guess what, all mammals 480 00:23:18,220 --> 00:23:20,239 inherit those same properties. 481 00:23:20,239 --> 00:23:23,440 Mammals also have some internal digestion of food and also pass 482 00:23:23,440 --> 00:23:24,840 through this blastula stage, 483 00:23:24,839 --> 00:23:30,009 but mammals additionally we know are warm blooded 484 00:23:30,009 --> 00:23:33,960 in general and they have mammary glands which is where the 485 00:23:33,960 --> 00:23:38,329 name mammal comes from. So mammary glands or just kind of a 486 00:23:38,329 --> 00:23:40,589 generalization of sweat glands, 487 00:23:40,589 --> 00:23:44,199 but that's what mammals have, and then all primates are mammals, which means all 488 00:23:44,200 --> 00:23:45,410 primates 489 00:23:45,410 --> 00:23:49,149 have all of these same properties plus they have more and so primates 490 00:23:49,148 --> 00:23:52,548 interestingly enough have five fingers. I didn't know all primates have all five fingers, but evidently 491 00:23:52,548 --> 00:23:53,848 I'm told that they do. 492 00:23:53,848 --> 00:23:57,589 They have opposable thumbs. 493 00:23:57,589 --> 00:24:00,709 And they also have fingernails, but fingernails we just won't put up there. It's 494 00:24:00,710 --> 00:24:02,390 not a big deal, okay? 495 00:24:02,390 --> 00:24:05,720 And then we get down to humans and monkey, right, and humans it turns out in 496 00:24:05,720 --> 00:24:09,460 theory anyway were supposed to have highly developed brains. 497 00:24:09,460 --> 00:24:11,710 I'll just put 498 00:24:11,710 --> 00:24:15,829 brains in quotes here because other animals have brains, too, but we're supposed to have highly developed 499 00:24:15,829 --> 00:24:16,228 brains 500 00:24:16,229 --> 00:24:21,730 and we have an erect body carriage. 501 00:24:21,730 --> 00:24:24,679 That's just what we are. We're wrecked brains. 502 00:24:24,679 --> 00:24:28,240 And monkeys have mother things that are going on, so evidently their brains are 503 00:24:28,240 --> 00:24:31,140 not as highly developed and they're sort of like their knuckles drag on the 504 00:24:31,140 --> 00:24:34,370 ground. Sometimes I do that in the morning, but that's not important. 505 00:24:34,369 --> 00:24:38,449 But that's the whole point. This is the class hierarchy. These are all 506 00:24:38,450 --> 00:24:42,950 classes and things that are sub classes of some other class means they inherit 507 00:24:42,950 --> 00:24:45,650 all of the behaviors of the things above them, 508 00:24:45,650 --> 00:24:47,180 all the way up the chain 509 00:24:47,180 --> 00:24:50,539 plus they may have their own additional behaviors and that's the key concept here 510 00:24:50,539 --> 00:24:53,128 of organizing things in classes and you'll see that 511 00:24:53,128 --> 00:24:56,648 in more specific instance when you get into Java. You saw it already with Karel in 512 00:24:56,648 --> 00:25:00,449 just really simple example, right. There was four commands for Karel. Super Karel gave 513 00:25:00,450 --> 00:25:04,940 you those four plus an additional two; that was it; okay? Now, 514 00:25:04,940 --> 00:25:08,980 besides this idea, there's another key idea that comes up besides this notion of 515 00:25:08,980 --> 00:25:09,568 classes, 516 00:25:09,568 --> 00:25:14,230 okay? And that's the notion of the instance of a class, okay. 517 00:25:14,230 --> 00:25:17,640 And what the instance of a class is, is 518 00:25:17,640 --> 00:25:22,559 humans are a class. There is no one person that is, "Oh, you are humanity, right?" 519 00:25:22,558 --> 00:25:24,168 You are a person, right, so [Inaudible] 520 00:25:24,169 --> 00:25:28,090 what's your name? Eduardo. Huh? Eduardo. 521 00:25:28,089 --> 00:25:29,569 Eduardo, all right. 522 00:25:29,569 --> 00:25:32,210 So I hope I'm spelling this right, 523 00:25:32,210 --> 00:25:34,200 Eduardo; is that right? 524 00:25:34,200 --> 00:25:38,009 Is an instance of human, I would hope, right. So 525 00:25:38,009 --> 00:25:39,690 what that means is 526 00:25:39,690 --> 00:25:43,720 you're going to have things in your Java programs that you create 527 00:25:43,720 --> 00:25:49,058 which are objects and what an object is to differentiate it from a class, so 528 00:25:49,058 --> 00:25:50,660 Eduardo is an object. 529 00:25:50,660 --> 00:25:52,500 I'm sorry; sorry to break it to you. That's 530 00:25:52,500 --> 00:25:53,380 just 531 00:25:53,380 --> 00:25:55,440 you're an object. 532 00:25:55,440 --> 00:26:00,440 An object is an instance of a class; it is a particular example of a class. There 533 00:26:00,440 --> 00:26:05,179 will be multiple objects or multiple instances potentially of some class, 534 00:26:05,179 --> 00:26:09,249 and that instance of a class has all of the characteristics of the class 535 00:26:09,249 --> 00:26:12,630 and all of the other classes above it in the class hierarchy. 536 00:26:12,630 --> 00:26:16,850 So by looking at this, I could say, "Hey, Eduardo, guess what, you went through the blastula 537 00:26:16,849 --> 00:26:20,519 phase when you were an embryo." Good times; because you're an animal, right and I know that 538 00:26:20,519 --> 00:26:22,970 and this is inherited all the way up. 539 00:26:22,970 --> 00:26:26,190 So that's the important thing to keep in mind is you're going to be writing 540 00:26:26,190 --> 00:26:29,298 classes; you're going to be writing things that define some set of behavior 541 00:26:29,298 --> 00:26:36,190 and along with that, you'll be creating instances so that this is an instance of the class 542 00:26:36,190 --> 00:26:40,230 and the instances are what we refer to as objects so all of your instances in 543 00:26:40,230 --> 00:26:43,440 the world are just things that we think of as objects and your classes are in 544 00:26:43,440 --> 00:26:44,219 some sense 545 00:26:44,219 --> 00:26:46,269 the templates 546 00:26:46,269 --> 00:26:49,230 for those objects, okay. 547 00:26:49,230 --> 00:26:51,680 So any questions about the general concepts; I know they're a little bit 548 00:26:51,680 --> 00:26:56,200 high level, but it's important for you to kind of understand. Okay. 549 00:26:56,200 --> 00:26:57,610 So with that said, 550 00:26:57,609 --> 00:26:59,558 let's actually 551 00:26:59,558 --> 00:27:00,769 begin to look at 552 00:27:00,769 --> 00:27:03,629 this notion in Java, okay? 553 00:27:03,630 --> 00:27:10,630 And so the way that this is gonna work uh-huh? [Inaudible] in Karel, what was the object? 554 00:27:10,990 --> 00:27:16,079 So in Karel, it turned out what you're actually just creating was 555 00:27:16,079 --> 00:27:20,548 a single Karel object was being created that contained your program 556 00:27:20,548 --> 00:27:22,170 and that's what was actually run. 557 00:27:22,170 --> 00:27:26,230 So you created the class Karel, and when that puppy actually sort of fired up and 558 00:27:26,230 --> 00:27:28,298 you saw little Karel running around in the world, 559 00:27:28,298 --> 00:27:31,470 that was a Karel object; that was an instance of your class. 560 00:27:31,470 --> 00:27:34,779 Now, you actually didn't see multiple objects or multiple instances there. 561 00:27:34,779 --> 00:27:37,720 There was only one Karel instance. So there it's very it's a good question because it's 562 00:27:37,720 --> 00:27:40,319 easy to get confused between the instance 563 00:27:40,319 --> 00:27:42,569 and the class in that case because it was only one. 564 00:27:42,569 --> 00:27:46,220 But in here you'll actually see we'll actually create classes and we'll have multiple instances of 565 00:27:46,220 --> 00:27:53,220 them, which are running Karel with basically the instance of that object. Okay, question? 566 00:27:55,529 --> 00:27:59,579 So, basically like you can have, like several 567 00:27:59,579 --> 00:28:00,319 Karels 568 00:28:00,319 --> 00:28:02,819 running around in like one program? 569 00:28:02,819 --> 00:28:06,458 You could if we sort of set it up that way. In the Karel, 570 00:28:06,459 --> 00:28:09,440 the way it's kind of set up is it only allows you, it only sort of behind 571 00:28:09,440 --> 00:28:12,169 the scenes creates for you this one instance of Karel, 572 00:28:12,169 --> 00:28:15,989 but in some, you know, alternative Karel universe, we could have actually have just taken her 573 00:28:15,989 --> 00:28:16,730 class and said, 574 00:28:16,730 --> 00:28:19,849 "Hey, guess what, we're gonna just create multiple Karel instances from 575 00:28:19,849 --> 00:28:23,159 your class and have them all run around in the same room." We could have, 576 00:28:23,160 --> 00:28:24,199 and guess what, 577 00:28:24,199 --> 00:28:26,798 that's what seemed to have happened in this room, right. Somewhere along the way, there 578 00:28:26,798 --> 00:28:28,119 was this class human 579 00:28:28,119 --> 00:28:31,559 and someone came along and created multiple instances of you. Well, I wouldn't 580 00:28:31,559 --> 00:28:32,599 just say just one person, 581 00:28:32,599 --> 00:28:34,649 but now there's multiple instances of you, 582 00:28:34,650 --> 00:28:37,030 right, and you're all running around in the world doing your thing and you interact 583 00:28:37,029 --> 00:28:39,599 with each other and guess what 584 00:28:39,599 --> 00:28:43,519 objects actually do; they interact with each other, okay? 585 00:28:43,519 --> 00:28:45,089 So with that said, 586 00:28:45,089 --> 00:28:47,558 there is gonna be some functionality we're gonna use that was written by 587 00:28:47,558 --> 00:28:50,548 someone else. So just like Karel, the basic version of Karel was written by 588 00:28:50,548 --> 00:28:53,500 someone else. When we start with Java, we're gonna start with some set of 589 00:28:53,500 --> 00:28:56,069 scaffolding or libraries that were written by someone else 590 00:28:56,069 --> 00:29:01,139 that are gonna allow us to do a bunch of powerful things in Java very early on, okay? 591 00:29:01,140 --> 00:29:04,900 And this is something that is called the ACM program hierarchy. So it sounds 592 00:29:04,900 --> 00:29:06,250 all complicated. 593 00:29:06,250 --> 00:29:09,609 But all this is, right, and much the same way that I drew that picture over there 594 00:29:09,609 --> 00:29:12,659 with animals, mammals, primates, humans and monkeys, 595 00:29:12,660 --> 00:29:14,090 this is a hierarchy 596 00:29:14,089 --> 00:29:19,319 of classes that exist in Java's world or at least are provided by the ACM and you 597 00:29:19,319 --> 00:29:22,970 might say, "Who is the ACM?" Anybody know who the ACM is? 598 00:29:22,970 --> 00:29:25,870 They're big; they're bad; they're nationwide. 599 00:29:25,869 --> 00:29:28,000 They're the Association for Computing Machinery. 600 00:29:28,000 --> 00:29:29,788 It's the oldest computing society. 601 00:29:29,788 --> 00:29:32,720 They've been around for actually for about 60 years or so. And you're like, 602 00:29:32,720 --> 00:29:34,819 "But Marion, I thought you said 100 years. 603 00:29:34,819 --> 00:29:37,409 Yeah, before then, people called it math. 604 00:29:37,410 --> 00:29:39,900 So Association for 605 00:29:39,900 --> 00:29:42,190 Computing Machinery has this program hierarchy 606 00:29:42,190 --> 00:29:45,869 and what that means is the kind of programs that we write in this class, 607 00:29:45,868 --> 00:29:48,928 just like when you wrote your Karel programs you extend Karel or you 608 00:29:48,929 --> 00:29:50,419 extend Super Karel, 609 00:29:50,419 --> 00:29:53,929 you're going to be extending different kinds of programs, either a console 610 00:29:53,929 --> 00:29:56,420 program which is something that produces textural output, 611 00:29:56,420 --> 00:29:59,880 a dialog program which brings up little dialogue boxes that ask for 612 00:29:59,880 --> 00:30:00,740 information 613 00:30:00,740 --> 00:30:04,839 or a graphics program that actually draws some pretty funky stuff on the screen. 614 00:30:04,839 --> 00:30:07,769 All of those classes are 615 00:30:07,769 --> 00:30:12,679 classes that are inheriting from a class, a super class called program. 616 00:30:12,679 --> 00:30:15,890 So all of the things that you write as a dialogue program or a graphics program 617 00:30:15,890 --> 00:30:18,070 are all something that are programs. 618 00:30:18,069 --> 00:30:21,928 And all programs are something uptight J-Applet, which just means Java 619 00:30:21,929 --> 00:30:22,530 Applet 620 00:30:22,529 --> 00:30:26,210 and all Java Applets, are of some type called Applet. Anyone ever heard of 621 00:30:26,210 --> 00:30:27,940 an Applet? 622 00:30:27,940 --> 00:30:31,120 An Applet is something you can run on your web page, interestingly 623 00:30:31,119 --> 00:30:32,119 enough. That's 624 00:30:32,119 --> 00:30:35,379 kind of where the term comes from. It's like a lightweight application, and 625 00:30:35,380 --> 00:30:37,700 applet application, but small. 626 00:30:37,700 --> 00:30:41,220 And so it turns out since all of the programs that you're writing are actually 627 00:30:41,220 --> 00:30:43,309 inherit the properties of being an applet, 628 00:30:43,309 --> 00:30:46,779 they actually will be applets, which means you can put them on your web page and 629 00:30:46,779 --> 00:30:50,160 run your programs on your web page if you want and later on in the class we'll talk about how to do 630 00:30:50,160 --> 00:30:52,120 that, 631 00:30:52,119 --> 00:30:55,279 okay? But in this class, as least, you're not gonna write anything that 632 00:30:55,279 --> 00:30:59,180 directly extends like J-Applet or Applet or program. Everything you write is 633 00:30:59,180 --> 00:31:00,560 gonna extend down to this level, 634 00:31:00,559 --> 00:31:03,419 but it's important to know that there's different kinds of programs that you can actually 635 00:31:03,420 --> 00:31:05,600 write at that level. So 636 00:31:05,599 --> 00:31:09,849 let's look at an example of a Java program, and I'll show you your first Java 637 00:31:09,849 --> 00:31:10,699 program today. 638 00:31:10,700 --> 00:31:16,100 So we can feel good about Java no it's not that one. 639 00:31:16,099 --> 00:31:17,230 It's this one. 640 00:31:17,230 --> 00:31:20,529 It's small; it's tiny; it's fun; it's Java. All right, 641 00:31:20,529 --> 00:31:23,619 so let me expand this whole thing out 642 00:31:23,619 --> 00:31:27,469 so you can see the whole program still fits on one screen, okay. 643 00:31:27,470 --> 00:31:30,690 And you might suddenly notice there's a bunch of things in this program that look very 644 00:31:30,690 --> 00:31:32,350 similar to Karel. 645 00:31:32,349 --> 00:31:34,568 That's because Karel was implemented in Java. 646 00:31:34,568 --> 00:31:38,190 So the first thing you want to look at here is we have a file called helloprogram.java, 647 00:31:38,190 --> 00:31:41,759 just like your Karel programs are written with a .Java file, 648 00:31:41,759 --> 00:31:43,750 you are creating a .java file here. 649 00:31:43,750 --> 00:31:46,849 This is a source file because it has source code in it. 650 00:31:46,849 --> 00:31:50,969 Up at the top, you have a comment, "Gee, it actually uses the exactly same structure as Karel 651 00:31:50,970 --> 00:31:54,009 comments." Yeah, because Karel comments were actually Java comments. Comments in Karel and 652 00:31:54,009 --> 00:31:55,960 Java are exactly the same. 653 00:31:55,960 --> 00:31:59,829 Just like you imported stanford.karel.star, now you're gonna be 654 00:31:59,829 --> 00:32:03,309 using the stuff that the lovely folks at the ACM have provided for you, so you're 655 00:32:03,309 --> 00:32:08,970 going to import acm.graphics.star and acm.program.star. What 656 00:32:08,970 --> 00:32:10,150 are these things? 657 00:32:10,150 --> 00:32:11,120 These are just 658 00:32:11,119 --> 00:32:14,428 well, I won't back up because we're not on the slide. 659 00:32:14,429 --> 00:32:17,509 These are just remember I said you write your classes and someone else may have 660 00:32:17,509 --> 00:32:20,970 written some classes and they all get linked together before they're executed. 661 00:32:20,970 --> 00:32:23,808 These are just some other classes that someone else wrote that are going to get 662 00:32:23,808 --> 00:32:25,119 linked into what you do. 663 00:32:25,119 --> 00:32:28,699 Right, they provide you the definition for things like what a graphics program 664 00:32:28,700 --> 00:32:29,970 actually is. 665 00:32:29,970 --> 00:32:33,600 So now, what you're gonna do, as we talked about, all Java programs are just 666 00:32:33,599 --> 00:32:35,308 the collection of classes, 667 00:32:35,308 --> 00:32:38,428 so just like in Karel, we have public class 668 00:32:38,429 --> 00:32:40,250 and some name for your program. 669 00:32:40,250 --> 00:32:44,150 Here we'll call it Hello program. And a Hello program is a particular kind of 670 00:32:44,150 --> 00:32:47,970 program. It doesn't extend Super Karel because it's not a Super Karel program anymore. 671 00:32:47,970 --> 00:32:51,450 It's gonna be a graphics program. It's actually gonna draw some stuff on the screen, 672 00:32:51,450 --> 00:32:53,788 so it's gonna extend the graphics program. 673 00:32:53,788 --> 00:32:57,230 But all the boilerplates should look the same, right, that's what we had you do 674 00:32:57,230 --> 00:33:00,849 Karel because all the stuff from Karel just translates directly over to Java, 675 00:33:00,849 --> 00:33:04,529 except now we're sort of cooking with gas; now we're doing the real thing, okay. 676 00:33:04,529 --> 00:33:08,779 So it extends graphics program and guess what, inside here we have a run method 677 00:33:08,779 --> 00:33:12,259 just like Karel and that's where the program begins executing. 678 00:33:12,259 --> 00:33:16,390 Now, where things get funky is you're like, "Oh, may what happened to pick 679 00:33:16,390 --> 00:33:20,278 beeper and plug beeper and like life was so good; it was easy and you know, turn right and it was like 680 00:33:20,278 --> 00:33:21,589 the extent of it. 681 00:33:21,589 --> 00:33:26,000 What is it like add nugi label, hello world, like what is this all about, okay?" 682 00:33:26,000 --> 00:33:27,609 We'll go through this step by step. 683 00:33:27,609 --> 00:33:30,368 All this is saying is when you create a graphics program, we'll go through the 684 00:33:30,368 --> 00:33:31,730 details in just a second, 685 00:33:31,730 --> 00:33:35,230 you're gonna get a blank screen, you're going to get an empty canvas in some sense. You're gonna be 686 00:33:35,230 --> 00:33:37,870 an artist and you're gonna draw stuff on that canvas, and the thing that you're gonna draw stuff on that canvas 687 00:33:37,869 --> 00:33:41,319 and the thing that you're gonna draw on that canvas is some label and all 688 00:33:41,319 --> 00:33:44,849 that label is is just basically words and the words are gonna be Hello 689 00:33:44,849 --> 00:33:47,519 World, because you wanna write Hello World on the screen and you wanna 690 00:33:47,519 --> 00:33:49,819 write it at a particular location on the screen. 691 00:33:49,819 --> 00:33:52,939 The location on the screen you wanna write it at is 692 00:33:52,940 --> 00:33:56,070 100,75 and I'll tell you where that is on the screen in just a second. 693 00:33:56,069 --> 00:33:59,269 And then once you create this little label, you're gonna add it to your 694 00:33:59,269 --> 00:34:01,700 canvas. You're gonna say, "I have some canvas, 695 00:34:01,700 --> 00:34:04,370 plop that puppy onto my canvas," okay? 696 00:34:04,369 --> 00:34:07,969 So let's run the program and I'll just plop it onto the canvas or you'll see 697 00:34:07,970 --> 00:34:10,188 what's going on. Life will be good. 698 00:34:10,188 --> 00:34:15,489 So we run this program, we drop the microphone. Dropped the microphone again, 699 00:34:15,489 --> 00:34:21,588 all 700 00:34:21,588 --> 00:34:27,409 right. 701 00:34:27,409 --> 00:34:31,509 So we want to do Hello program. 702 00:34:31,509 --> 00:34:35,028 We're getting excited. We're running; we're running. 703 00:34:35,028 --> 00:34:38,559 The disc is just turning away and there's your first Java program. You're 704 00:34:38,559 --> 00:34:40,769 all Java programmers now. 705 00:34:40,768 --> 00:34:44,818 What did you do; you created a graphics program, which brought up this big window 706 00:34:44,818 --> 00:34:48,108 and said, "I'm blank canvas. Draw on me." 707 00:34:48,108 --> 00:34:49,159 And you said, "All right, 708 00:34:49,159 --> 00:34:51,699 Hello World woohoo 709 00:34:51,699 --> 00:34:54,469 and I'm done," because that's all you did. You said here's Hello World, put it 710 00:34:54,469 --> 00:34:55,749 up on the canvas for me 711 00:34:55,748 --> 00:34:58,908 at a location 100,75 and thanks for playing; that's all I'm gonna 712 00:34:58,909 --> 00:35:00,130 do. But 713 00:35:00,130 --> 00:35:03,430 now you've actually gone through the whole process of compiling your Java 714 00:35:03,429 --> 00:35:06,489 program and turning it into this intermediate code and this intermediate code gets 715 00:35:06,489 --> 00:35:07,099 executed and 716 00:35:07,099 --> 00:35:09,779 you actually did something and that's like half the battle right there. 717 00:35:09,780 --> 00:35:12,750 The next nine weeks is the other half of the battle, but half the battle is 718 00:35:12,750 --> 00:35:16,579 getting this up. I kid you not, really. If you can make that happen, 719 00:35:16,579 --> 00:35:17,659 you're just 720 00:35:17,659 --> 00:35:19,068 most of the way there. 721 00:35:19,068 --> 00:35:22,248 So let's do something a little more exciting than this. Let's actually do some 722 00:35:22,248 --> 00:35:24,989 interaction with the user. Let me show you another program. 723 00:35:24,989 --> 00:35:28,129 Remember this one is a graphics program. I told you there was a bunch of different 724 00:35:28,130 --> 00:35:30,479 kinds of programs you can have 725 00:35:30,478 --> 00:35:33,239 when I showed you the picture. I said, "We have a graphics program." Let's look at something 726 00:35:33,239 --> 00:35:40,048 called the console program over here. Uh-huh. [Inaudible]. No, 727 00:35:40,048 --> 00:35:41,099 not in Java. 728 00:35:41,099 --> 00:35:44,009 You're always extending one kind of program and a graphics program will 729 00:35:44,009 --> 00:35:47,889 actually, as you saw you can put up text. A console program is just meant to be a 730 00:35:47,889 --> 00:35:50,918 textural program, so you're not gonna do any drawing. 731 00:35:50,918 --> 00:35:55,048 But here's another program, right, again, a lot of the same things is before. You have 732 00:35:55,048 --> 00:35:56,599 some comment up at the top. 733 00:35:56,599 --> 00:35:57,900 You have some 734 00:35:57,900 --> 00:36:01,019 libraries that you're gonna import. In this case, you're not doing anything with graphics, 735 00:36:01,018 --> 00:36:04,528 so you don't need to import acm.graphics.star, you just need o 736 00:36:04,528 --> 00:36:09,268 import acm.program.star which just 737 00:36:09,268 --> 00:36:11,909 says, "Get me all the standard stuff for a program." If you're doing graphics, you 738 00:36:11,909 --> 00:36:15,368 also need to have a second line for acm.graphics.star. If you're not 739 00:36:15,369 --> 00:36:17,209 doing graphics, you don't. 740 00:36:17,208 --> 00:36:20,908 So again, public class. This one called add-to integers because guess what, it's gonna 741 00:36:20,909 --> 00:36:24,358 ask the user [Inaudible] programs, put tow integers and add them together, 742 00:36:24,358 --> 00:36:27,139 but in fact, it's gonna do something interactive with the user which is pretty 743 00:36:27,139 --> 00:36:28,489 exciting in itself. 744 00:36:28,489 --> 00:36:31,798 This is gonna extend the console program because it's not gonna have 745 00:36:31,798 --> 00:36:35,858 any graphics. Aw, yeah I know, it's sad times, but sometimes text is very 746 00:36:35,858 --> 00:36:36,808 powerful. 747 00:36:36,809 --> 00:36:38,290 What's it gonna do when it runs? 748 00:36:38,289 --> 00:36:41,179 It's gonna write out to the screen and this time we're gonna use something 749 00:36:41,179 --> 00:36:45,389 called print lin, we just like to drop some vowels here and there, which stands for 750 00:36:45,389 --> 00:36:49,679 print line, and if print a line, this program adds two numbers, then it's gonna 751 00:36:49,679 --> 00:36:53,379 read an integer from the user and we'll go through all this stuff in more detail. 752 00:36:53,380 --> 00:36:57,110 Don't worry; this is jus a high-level overview so you get some basic idea of what 753 00:36:57,110 --> 00:36:58,409 Java looks like. 754 00:36:58,409 --> 00:37:01,979 It asks the user for N1, right, because you have to be very scientific, so rather 755 00:37:01,978 --> 00:37:04,598 than give me the first number, you say enter N1, right, and 756 00:37:04,599 --> 00:37:05,510 suddenly 757 00:37:05,510 --> 00:37:07,079 we're much more formal. 758 00:37:07,079 --> 00:37:10,298 Enter N2, right, and so what this is actually doing it's asking the user for a 759 00:37:10,298 --> 00:37:14,009 number and whatever the number the user gives us, we stick in this location 760 00:37:14,009 --> 00:37:15,199 called N1. 761 00:37:15,199 --> 00:37:18,038 And whatever the number the user give us here we're gonna stick in a location 762 00:37:18,039 --> 00:37:21,079 called N2 and we'll actually talk about what these locations are and how they get set 763 00:37:21,079 --> 00:37:22,470 up and everything next time, 764 00:37:22,469 --> 00:37:25,529 but I just want you to see something before we can kind of go into all the details because 765 00:37:25,530 --> 00:37:27,140 we gotta start somewhere. 766 00:37:27,139 --> 00:37:30,018 Then we're gonna add N1 and N2 together and store them in a place 767 00:37:30,018 --> 00:37:31,149 called total 768 00:37:31,150 --> 00:37:33,460 and then we're gonna write out the total is, 769 00:37:33,460 --> 00:37:35,030 whatever the total is, and then 770 00:37:35,030 --> 00:37:39,190 a period. Right, so this is in some sense the world's most expensive calculator that 771 00:37:39,190 --> 00:37:40,338 adds two numbers. 772 00:37:40,338 --> 00:37:43,469 And we'll go ahead and run it, 773 00:37:43,469 --> 00:37:44,139 774 00:37:44,139 --> 00:37:46,189 add two integers. We're 775 00:37:46,188 --> 00:37:50,058 compiling; we're feeling good 776 00:37:50,059 --> 00:37:53,920 and that's the program we want to run, 777 00:37:53,920 --> 00:37:56,670 and now this comes along and notice, 778 00:37:56,670 --> 00:38:00,259 now we have some window that rather than putting graphics all over it and telling it 779 00:38:00,259 --> 00:38:04,710 where to display some words like Hello World, we just said, "Write some line," and 780 00:38:04,710 --> 00:38:07,329 so what it's gonna do is just sequentially write lines on the screen 781 00:38:07,329 --> 00:38:09,530 because this is what we think of as a console. 782 00:38:09,530 --> 00:38:13,080 All a console really is, the way you can think about it is it's a window that contains 783 00:38:13,079 --> 00:38:13,659 texts 784 00:38:13,659 --> 00:38:17,420 and can potentially interact with the user, so there's places where we might ask the user 785 00:38:17,420 --> 00:38:17,969 for input. 786 00:38:17,969 --> 00:38:21,479 So we said if this program adds two numbers, I hope you can see this in the back. It's tiny, 787 00:38:21,478 --> 00:38:23,009 tiny font. 788 00:38:23,009 --> 00:38:25,818 Enter N1 and it's sitting there with a blinking cursor, and any time you see the 789 00:38:25,818 --> 00:38:28,699 blinking cursor, that means, "Hey, I'm expecting some value." 790 00:38:28,699 --> 00:38:32,168 So give me something of value. What's some integer? [Inaudible]. 791 00:38:32,168 --> 00:38:35,400 Twelve; someone said 12; someone said one, so I'll take 12 as N1 and 792 00:38:35,400 --> 00:38:38,460 then it asks for N2. I'll give it one 793 00:38:38,460 --> 00:38:43,909 and low and behold, it says the total is 13 period, end of program, okay? 794 00:38:43,909 --> 00:38:46,108 At this point, there's a blinking cursor, but 795 00:38:46,108 --> 00:38:47,798 the program is done. 796 00:38:47,798 --> 00:38:52,048 But now you've just seen a real Java program that actually takes in values 797 00:38:52,048 --> 00:38:53,329 from the user, 798 00:38:53,329 --> 00:38:56,538 computes some, does some computation on them and displays output, 799 00:38:56,539 --> 00:39:00,079 okay? And this is a console program as opposed to a graphics program because 800 00:39:00,079 --> 00:39:02,519 all the stuff we're doing here is textural. Okay, 801 00:39:02,518 --> 00:39:06,088 so any questions about the basic idea of 802 00:39:06,088 --> 00:39:09,148 classes or objects or these different programs we're writing? The programs 803 00:39:09,148 --> 00:39:11,348 that are running, when they run, 804 00:39:11,349 --> 00:39:12,800 they are being, 805 00:39:12,800 --> 00:39:16,519 they're objects. They're instances that are being run for you. 806 00:39:16,518 --> 00:39:20,988 What they're doing as instances, they're objects that are inheriting all the 807 00:39:20,989 --> 00:39:24,889 behavior from the class template and then when we run, an instance is 808 00:39:24,889 --> 00:39:31,889 actually created in this run. Uh-huh? [Inaudible]. 809 00:39:34,478 --> 00:39:37,578 Because if you say acm.star, strangely enough, you won't necessarily 810 00:39:37,579 --> 00:39:39,379 get everything 811 00:39:39,378 --> 00:39:42,588 underneath ACM as well. You'll get everything at that level. 812 00:39:42,588 --> 00:39:46,418 So there's actually a package for ACM and there's a package ACM graphics, and 813 00:39:46,418 --> 00:39:48,748 there's a package ACM program 814 00:39:48,748 --> 00:39:53,000 and what you really want is everything inside ACM program and ACM graphics, 815 00:39:53,000 --> 00:39:56,389 not just the things that are in ACM graphics by itself. Yeah, 816 00:39:56,389 --> 00:39:58,158 it's an 817 00:39:58,159 --> 00:39:59,640 interesting 818 00:39:59,639 --> 00:40:02,038 technical question, and you 819 00:40:02,039 --> 00:40:09,039 don't need to worry about the details. Just add both of them and you'll be fine. [Inaudible]. No, 820 00:40:10,108 --> 00:40:12,958 the console program you just print out. That's one of the differences with the 821 00:40:12,958 --> 00:40:15,169 graphics [Inaudible]. 822 00:40:15,170 --> 00:40:18,420 With the graphics program, you have to tell it where stuff goes. 823 00:40:18,420 --> 00:40:25,420 Console program is just writing out line by line. Uh-huh? [Inaudible]. Sorry. [Inaudible]. 824 00:40:36,088 --> 00:40:38,969 Yeah, every time you run a Karel program, you can think of what it's doing is 825 00:40:38,969 --> 00:40:42,019 creating an instance of Karel which is that little guy you see on the screen 826 00:40:42,018 --> 00:40:45,498 and he's going around and doing stuff, so in Karel there was only one instance 827 00:40:45,498 --> 00:40:47,068 of the object. 828 00:40:47,068 --> 00:40:50,058 Here you'll actually see we'll create some objects where we can have multiple 829 00:40:50,059 --> 00:40:53,540 incidents of an object in the same roll and I'll show you some examples of that in just a second, but we 830 00:40:53,539 --> 00:40:56,298 just haven't gotten there yet, okay? 831 00:40:56,298 --> 00:40:58,179 So what we're gonna do now, 832 00:40:58,179 --> 00:41:00,599 is we're gonna think a little bit about 833 00:41:00,599 --> 00:41:03,778 graphics that we can actually draw. Because the graphics world it's easiest to see 834 00:41:03,778 --> 00:41:08,768 multiple objects. We're gonna put multiple stuff up inside our little graphics canvas. So 835 00:41:08,768 --> 00:41:14,798 what's this whole graphics thing about? 836 00:41:14,798 --> 00:41:17,938 Let me tell you a little bit about the graphics window and then we'll put a 837 00:41:17,938 --> 00:41:21,598 couple different objects up in the graphics window and you can see what I'm talking 838 00:41:21,599 --> 00:41:22,528 about. 839 00:41:22,528 --> 00:41:27,199 So in terms of graphics, all graphics that we're gonna do are modeled called 840 00:41:27,199 --> 00:41:30,648 a collage model and if you remember in the days of yore when you were a week 841 00:41:30,648 --> 00:41:31,148 tyke, 842 00:41:31,148 --> 00:41:34,888 did anyone have like a little felt board with little felt animals that you put on 843 00:41:34,889 --> 00:41:35,659 it? 844 00:41:35,659 --> 00:41:38,068 Yeah, that was a collage, 845 00:41:38,068 --> 00:41:42,088 or if you had a big piece of paper and you had some like crazy, not crazy 846 00:41:42,088 --> 00:41:44,078 glue, what was that, glue stick. You 847 00:41:44,079 --> 00:41:45,539 don't smell that stuff too much like, 848 00:41:45,539 --> 00:41:48,829 but you would take some piece of paper and you're like, "Oh, here's a picture of a cat," and you 849 00:41:48,829 --> 00:41:51,500 would like put some glue on the back of it and put it up on there, and then 850 00:41:51,500 --> 00:41:55,500 you'd say, "Oh, here's a picture of a dog," and put it up on there. That's the model 851 00:41:55,500 --> 00:41:57,000 for graphics in Java. 852 00:41:57,000 --> 00:41:59,590 We're gonna have these little pictures or little objects and we're 853 00:41:59,590 --> 00:42:03,380 gonna say, "Show up here and show up over there." So what 854 00:42:03,380 --> 00:42:04,749 you have is a collage 855 00:42:04,748 --> 00:42:07,259 which starts off as a blank canvas 856 00:42:07,259 --> 00:42:11,248 and you're going to put objects onto that canvas, okay? 857 00:42:11,248 --> 00:42:15,328 And so what we can do is create various kinds of shapes or pieces of texts and 858 00:42:15,329 --> 00:42:18,699 put them up in various places on the canvas and you just saw an example of that with 859 00:42:18,699 --> 00:42:19,829 Hello World, 860 00:42:19,829 --> 00:42:23,148 but I'll show you some of the other things that you can create. 861 00:42:23,148 --> 00:42:26,298 Two different kinds of objects that exist in the graphics world, 862 00:42:26,298 --> 00:42:28,829 one you just saw. It's called a GLabel for 863 00:42:28,829 --> 00:42:30,269 a graphic label. 864 00:42:30,269 --> 00:42:34,019 This is just text in some sense. It's text that you can put up in the 865 00:42:34,019 --> 00:42:34,489 world. 866 00:42:34,489 --> 00:42:38,769 There's also a GRect, which is a rectangle, oddly enough, 867 00:42:38,769 --> 00:42:42,829 a GOval, which is an oval or if you actually make the height and width the 868 00:42:42,829 --> 00:42:46,230 same, it becomes a circle, right. So that's why we don't have circle; we have oval 869 00:42:46,230 --> 00:42:48,639 and same thing with rect versus square because 870 00:42:48,639 --> 00:42:50,618 all squares are rectangle, 871 00:42:50,619 --> 00:42:55,449 and GLine, which just means a graphic line. So these are the different kinds of 872 00:42:55,449 --> 00:42:56,739 objects we can have. 873 00:42:56,739 --> 00:42:58,670 These are classes. 874 00:42:58,670 --> 00:43:02,358 They are templates for objects. We are going to create particular instances of these 875 00:43:02,358 --> 00:43:04,259 objects and put them up in the collage, 876 00:43:04,260 --> 00:43:08,449 but these just tell us the kinds of things we can have in the general class. So 877 00:43:08,449 --> 00:43:10,499 if we come back, 878 00:43:10,498 --> 00:43:11,819 if we close this guy, 879 00:43:11,820 --> 00:43:14,329 and we come back over here to fund the 880 00:43:14,329 --> 00:43:15,609 below program, 881 00:43:15,608 --> 00:43:17,798 what we've done 882 00:43:17,798 --> 00:43:18,918 is we've said, 883 00:43:18,918 --> 00:43:21,819 "I want a GLabel. GLabel is the class. 884 00:43:21,820 --> 00:43:26,789 When I say new GLabel, what that actually does is says, "Give me a new 885 00:43:26,789 --> 00:43:31,949 instance of that class. Give me an object that is a GLabel," and the things that you're 886 00:43:31,949 --> 00:43:36,129 going to specify about that particular instance or it has some text associated 887 00:43:36,130 --> 00:43:36,709 with it, 888 00:43:36,708 --> 00:43:40,538 which is Hello World. We've put all the texts inside the double quotes, okay. 889 00:43:40,539 --> 00:43:44,099 So Hello World without the double quotes is actually the text associated with 890 00:43:44,099 --> 00:43:46,838 this label and we give it some location, 891 00:43:46,838 --> 00:43:49,998 100,75. So now this little object, 892 00:43:49,998 --> 00:43:53,509 okay, which is an instance of a label says, "Hey, I'm one particular label in the 893 00:43:53,509 --> 00:43:53,989 world 894 00:43:53,989 --> 00:43:58,099 and the kind of label I am, I say Hello World, and I'm at location 895 00:43:58,099 --> 00:43:58,640 896 00:43:58,639 --> 00:44:01,629 100,75," and 897 00:44:01,630 --> 00:44:04,269 it's like, "Okay you have this label, what are you gonna do with it." And I'm like, 898 00:44:04,268 --> 00:44:07,978 "Put it on the canvas," and the way you put it on the canvas is you say, add. 899 00:44:07,978 --> 00:44:11,169 So all graphics programs, when you say add, 900 00:44:11,170 --> 00:44:14,420 there is something that you will specify to add, and the things that you were 901 00:44:14,420 --> 00:44:16,829 specifying to add are instances. 902 00:44:16,829 --> 00:44:20,309 They are individual objects that you're going to put on the canvas and the way 903 00:44:20,309 --> 00:44:23,750 you get those individual objects is you create a new version 904 00:44:23,750 --> 00:44:27,498 of some particular class, okay? So 905 00:44:27,498 --> 00:44:30,959 this creates that new label, location 175 and 906 00:44:30,960 --> 00:44:33,659 when it gets added, it gets put up there. Now, 907 00:44:33,659 --> 00:44:36,858 there is other kinds of things we could do with this, so if we're kind of return over 908 00:44:36,858 --> 00:44:40,278 here, 909 00:44:40,278 --> 00:44:44,759 this is just the add-to integers program, let's do add-to integers real quickly 910 00:44:44,759 --> 00:44:48,579 17, 25, 42, writes up same thing you just saw except now 911 00:44:48,579 --> 00:44:51,449 in excruciating detail. 912 00:44:51,449 --> 00:44:55,019 Let's say we want to do something that makes a GLabel more funky than 913 00:44:55,018 --> 00:44:57,068 we originally had, okay? 914 00:44:57,068 --> 00:45:00,438 So again, we're gonna have our Hello Program that's gonna extend the 915 00:45:00,438 --> 00:45:03,518 graphics program. Then we're gonna do things slightly differently. What we're gonna 916 00:45:03,518 --> 00:45:08,488 do here is we're going to create a new instance of a GLabel object. So if we say 917 00:45:08,489 --> 00:45:12,179 new GLabel and again, we're gonna name is Hello World and 918 00:45:12,179 --> 00:45:15,048 100,75, so I have some label that's 919 00:45:15,048 --> 00:45:18,380 Hello World and location 100,75, and I say, "Hey, you know what label, 920 00:45:18,380 --> 00:45:21,759 I want you to look different than you actually are, okay? 921 00:45:21,759 --> 00:45:24,719 So now what do I have this object, I have this little label, you can think of 922 00:45:24,719 --> 00:45:27,418 it as a little object that sits somewhere in the world that's not being 923 00:45:27,418 --> 00:45:30,460 displayed yet because I haven't added it yet to my canvas. 924 00:45:30,460 --> 00:45:33,809 It's being stored somewhere which I have named label, okay, 925 00:45:33,809 --> 00:45:37,509 and we'll talk about this notion of GLabel, label next time, but it's something I've 926 00:45:37,509 --> 00:45:38,588 created called Label 927 00:45:38,588 --> 00:45:41,628 which is just a new instance of this Hello World label. The 928 00:45:41,628 --> 00:45:44,808 first thing I want to say is, "Hey, you know, I want to change what the font looks like." Anyone know 929 00:45:44,809 --> 00:45:46,190 what font is. All 930 00:45:46,190 --> 00:45:49,349 right, you've probably used different fonts in your word processors. It's just the way characters 931 00:45:49,349 --> 00:45:52,068 actually appear on the screen. It's a thing that comes from type setting. 932 00:45:52,068 --> 00:45:55,909 I want the font to be san seraph 36, 933 00:45:55,909 --> 00:46:00,409 so what happens when I start off, is I say, "Create for me a new label 934 00:46:00,409 --> 00:46:04,808 that's name is Hello World," and so it says, "Okay, I have some label object, the label with the 935 00:46:04,809 --> 00:46:07,430 words associated with that label Hello World." Notice there's still nothing 936 00:46:07,429 --> 00:46:11,379 on the screen. Here's my screen. Here's my canvas. This is all in the 937 00:46:11,380 --> 00:46:14,499 computer's memory somewhere. It's saying, "Yeah, you've created some label. You haven't 938 00:46:14,498 --> 00:46:16,038 displayed it yet. You've just created it," 939 00:46:16,039 --> 00:46:21,139 and you say, "Hey I want to tell that label to change it's font to sans seraph 940 00:46:21,139 --> 00:46:21,878 36." 941 00:46:21,878 --> 00:46:23,739 The way I do that 942 00:46:23,739 --> 00:46:27,869 is I have an object that I've created. The object is named label. 943 00:46:27,869 --> 00:46:30,309 I use the name of the object 944 00:46:30,309 --> 00:46:34,380 followed by a dot, followed by a method that I'm going to call on that object, 945 00:46:34,380 --> 00:46:36,358 remember in Karel's world, we had methods. 946 00:46:36,358 --> 00:46:39,809 The way we called Karel's methods was we just gave the name of the commands to go 947 00:46:39,809 --> 00:46:41,219 execute that method. 948 00:46:41,219 --> 00:46:46,358 Now, all methods are associated with objects, at least for the time being. So 949 00:46:46,358 --> 00:46:49,818 when I have label and I say, "Set font," what that actually means 950 00:46:49,818 --> 00:46:53,639 is set the fonts for this particular label object 951 00:46:53,639 --> 00:46:57,328 to be Sans-Serif 36, and so when I execute that, 952 00:46:57,329 --> 00:47:00,369 what happens is it becomes 36 point font 953 00:47:00,369 --> 00:47:04,120 in Sans-Serif which means Serifs are just little things of 954 00:47:04,119 --> 00:47:07,009 if you can see the font up there has you know, swishes at the end 955 00:47:07,010 --> 00:47:10,360 of letters, those are serifs, so a font like this doesn't have any 956 00:47:10,360 --> 00:47:13,959 of the squishes at the end of the letter. Sans-Serif, sans means not, Okay? 957 00:47:13,958 --> 00:47:16,878 Then we say, "You know what, I'd really like you to be red because black is 958 00:47:16,878 --> 00:47:19,518 just so blase and red is really the new black, 959 00:47:19,518 --> 00:47:22,908 so set your color to be the red color." Like, 960 00:47:22,909 --> 00:47:24,528 okay, and 961 00:47:24,528 --> 00:47:27,909 so I execute that and it turns itself red. There's still nothing on the screen. This is all 962 00:47:27,909 --> 00:47:31,608 like of with the label and now that I've taken this label and I've taken this text and 963 00:47:31,608 --> 00:47:34,889 made it big and turned it red I finally say, "Hey, 964 00:47:34,889 --> 00:47:40,289 graphics program, add this label, add this object to your collage," 965 00:47:40,289 --> 00:47:44,759 and it says, "Okay," and it adds it at the location at which this label was created 966 00:47:44,760 --> 00:47:46,939 which was 100,75. 967 00:47:46,938 --> 00:47:51,349 So then it finally shows up on the screen. It only shows up on the screen when I actually do the add. 969 00:47:51,349 --> 00:47:56,298 Up to that point, all I've done is modify some of the properties of this thing, okay. 970 00:47:56,298 --> 00:48:00,599 So starting next time, what we're gonna actually get into is thinking about 971 00:48:00,599 --> 00:48:03,068 what is this GLabel thing about, 972 00:48:03,068 --> 00:48:07,159 what does it mean when we actually specify a method for an object and go into 973 00:48:07,159 --> 00:48:10,548 all that in a little bit more detail, but hopefully seeing an example of what your 974 00:48:10,548 --> 00:48:13,579 first Java program looks like. All right, I'll see you all on Wednesday.