11:15:40 In the last video, we looked. 11:15:40 At the software development cycle. The process that all applications go through from idea to finished product. And so. 11:15:51 So at this point, I want to introduce you to the concept of object oriented programming. We won't use this technique of programming till the latter portion of the course. 11:16:01 Shorthand notation for it is OOP, stands for object oriented programming. This topic used to be covered in CS 207, the sequel to this class and CS 300, and 4, which was the Final sequel to learning the Java programming language. 11:16:19 We have currently remove CS 304 as a course. So what has happened is object oriented programming is introduced near the end of this course and then you continue to use that technique. 11:16:34 Through CS 207. So what actually is object oriented programming? Well, let me get just. 11:16:43 Started. 11:16:48 What is OLP? Well, it's a programming methodology that views the program is consisting of objects. 11:16:55 So most of the programs we write in this class will be procedural where we have a task we need to solve and we write the algorithm, the step by step code to solve the problem and reach our answer. 11:17:08 But in object oriented programming, we think of the code building objects and those objects can act alone or interact with one another. 11:17:20 And the objects can represent real world objects or be an abstraction. For example, a water bottle. Now, if you think about a water bottle and we'll use that example a little bit in this following presentation. 11:17:37 It has attributes. How we describe it and behaviors. Yeah, believe it or not, a water bottle can have a behavior as to whether it might be full or not. 11:17:49 Can it be refilled? We'll talk about that. More in the next slide. So. 11:17:56 Object features as I introduced with the water bottle. There the characteristics of the object. How would you describe the object? 11:18:05 You know, it does a water bottle contain 20 ounces is the water bottle a 10 ounce bottle is a water bottle insulated. 11:18:15 In other words, it keeps drinks hot or cold or is it not insulated? And so you can think of the attributes how you would describe a particular object. 11:18:24 Now the object itself could also have behaviors, actions the object can take. So in other words, when you think of a water bottle, you could, drink from the water bottle. 11:18:36 Well, what would happen to its capacity. We would have less water remaining in the bottom. What about could we check capacity like, hey, how full is this water bottle? 11:18:47 Is there anything left for me to drink? And so those are behaviors or actions of the object. Does that make sense? 11:18:55 So in other words, the attributes describe the object, the behaviors might be fill water bottle. Drink from water bottle. 11:19:05 How much water is left in the bottle? Those would be behaviors and attributes would be those variables that store the information. 11:19:13 In other words, we'd have a variable capacity. The capacity of this water bottle is 20 ounces. 11:19:18 So is full, we would look at capacity, this capacity still at 20 ounces. Oh, yeah, then it is full. 11:19:27 So these are the ideas that we want to think about towards the end of the course, but I want to introduce you to this concept so that you understand the difference between procedural programming, which is mostly what we're doing in the beginning and object oriented. 11:19:41 So let's look at another example of an object. For example, a bank account. So if you think about that, what are the attributes of a bank account? 11:19:51 What are its behaviors? Let me get just started. So some attributes. Might be the account number of the bank account. 11:20:01 The customer information, their name, their address, things like that. Starting balance when you open up a bank account, how much money did you put into the bank? 11:20:10 Then what else? The current or ending balance, right? So where it started, where it is now. 11:20:18 Interest rate. Is there an interest rate on this bank account? Does it earn money? And now some of the behavior, so what can we do with this bank account? 11:20:27 Well, we could deposit money. We could add to the account. You could imagine that if we have a starting balance and then we have a certain deposit amount that would change the new ending balance. 11:20:38 Withdraw money. Again, we would have a starting balance. We would subtract away the money that we're taking out in the account and we'd have a new current or ending balance. 11:20:49 Another example, if there was interest in how we could probably compute that interest. And. Yeah, some banks charge fees. 11:20:59 So maybe once a month. There was a fee charged in which case that would affect our. Current or ending balance as well. 11:21:06 So you can see these are things you could probably write. In fact, deposit or withdrawal would just be a matter of withdrawal it would just be a matter of taking that starting balance adding the deposit amount and now we have a new ending balance and the starting balance, adding the deposit amount and now we have a new ending balance and the reverse for 11:21:20 withdraw. So the beauty of object oriented programming is the object contains these attributes and behaviors. And they're all in encapsulated in what's called a class. 11:21:31 The class contains the objects behaviors and attributes. And encapsulating them for the object. Now once they are encapsulated, access is specified in other words can someone directly access these storage spaces or do they have to go through the classes methods to do it? 11:21:52 So this is how work is high hidden, hence information hiding is accomplished. So for example, you are using a pre-written class system. 11:22:06 Dot dot print. You don't necessarily not have to know how system works but you need to know how to use it in order to make output appear. 11:22:18 You used it in your very first program, Hello World. So you use the system object with actual actually not knowing how the code is written behind it. 11:22:29 Later in the course, you'll be writing particular objects so you'll actually know how they work. 11:22:35 There is access specifiers, which I will talk about in an upcoming video and be more detailed about them when we actually get to objects near the end of the class. 11:22:48 Sorry, I should say end of the semester. So we don't confuse the word class. 11:22:52 If you notice when you're riding your Hello World program, you started with a class. So in other words, we did create a class object. 11:23:01 It's name started with an uppercase letter and it the file name had to be the same in order for the program to run. 11:23:10 I would like to note at this point in the course, please always read the summaries at the end of the chapter. 11:23:17 They really highlight some of the key things that you need to make sure that you know. As you finish that chapter. 11:23:26 Hey, a few more terms that I want to introduce you to now. And we will use throughout. One other term is called polymorphism. 11:23:36 It comes from the Greek, meaning having multiple form. 11:23:43 And so in other words, different data can be manipulated in the method that is correct for the data type. 11:23:49 So for a human, if I said now speak, depending if it was a duck, would go quack, a dog, wolf and a cat. 11:24:04 This is we'll see this earlier on in the course when we get to methods and the idea of method overloading. 11:24:07 So in other words, we'll write a method. It will have a. 11:24:12 Nature list. 11:24:16 On that signature list, the correct method will be called. I don't expect you to take away too much from this concept now. 11:24:21 I will revisit it. As needed, but I want you to know the word polymorphism, meaning having multiple forms. 11:24:28 We will use it when we get to method overloading. 11:24:34 Now here is another concept that is part. The idea of objects. Okay. I gave you a little reference there on inheritance, but let's not spend too much time. I'm not going to 11:24:51 This slide to you. I'll let you pause the video and you could carefully read the slide. But the idea is, imagine that you have a bicycle. 11:24:57 Bicycles basically have 2 wheels, a set of handle bars and a seat, right? That is an object and those would be the attributes of the object. 11:25:08 But if we look at other bicycles, okay, for example, road bikes have what drop down handle bars, tandem bicycles have 2 seats. 11:25:21 And so in other words, if we create a bicycle. We could take all the attributes of a bicycle and road bike or tandem by could inherit those. 11:25:31 Attributes and then we could add more attributes that are more specific. For that type of bike. Does that make sense? 11:25:42 And so those roll bikes, their drop down handle bars and the mountain bikes, what. Better gear ratio for any of you that's our bicycle riders. 11:25:49 I'm an avid bicyclist and so I have. One of all of those that's on the screen. 11:25:55 So the idea of the object oriented programming is you can create a parent class that has a certain set of attributes and then you could create subclasses. 11:26:08 That are even more descriptive to the parent. Okay. So each class is allowed to have one direct super class another one in other words one parent but the parent can have many children or sub-classes. 11:26:23 And that is the way you want to think about it. So the parent can have many subclasses, but the subclasses can only have one parent. 11:26:37 On this topic. Of object oriented programming. Java itself is an object oriented language. It is built on the principle of the object. 11:26:48 So as you can see here in the list, you see the class Java. Language object. Well, what are the components of the language itself? 11:26:58 Well, the language itself has some primitive data types and you can see the system down there as well. 11:27:06 So. The language is built encapsulated within a class. Each of these objects contain behaviors and methods and the objects also contain attributes or values. 11:27:20 Now remember, these classes can have subclasses which inherit the behaviors from the parent. So do you notice the indentation on this slide? 11:27:30 So the object is the parent and it contains the subclasses of Boolean character class math number. 11:27:38 Now look what happens to number. Number now becomes a parent and it has children of bite double float integer long and short. 11:27:48 We'll see that in a moment. And if you go back, notice the indentation goes back out. 11:27:55 Again, for the string in the system. So the string is not a primitive data type. It is actually an object. 11:28:01 And the system which you've already been working with. Is an object as well. These are all inherited in the language when you code in Java. 11:28:11 You get all of these for free. So there's that system that we've already started using. 11:28:17 Math, you'll note. Contains. Oh, actually we haven't worked it with math yet. 11:28:25 You will this week though during this module you'll use the math object. In a couple ways with actually one of the last assignments, the pizza assignment. 11:28:37 Okay. The string. Which will be useful shortly and an up copying, lab. 11:28:46 You can play around with the string now. For example, you're going to do another version of hello world, hello world 2, where you'll get the data of the. 11:28:57 Users age, which will be stored in an integer. But for fun or plus one extra credit, you could also get in the users name in that hello world too. 11:29:10 You will have to modify the flowchart. And you can do both, but it's going to be worth, plus one extra credit. 11:29:18 So that's sort of embedded in this show if you're paying attention. The Hello World 2 program comes in a later video. 11:29:31 The character object stores. Characters. Now how are character stored? This is important to note. 11:29:36 Characters are stored using, Unicode. Unicode covers all of the possible symbols that we would ever want to display. 11:29:48 Over the entire world. There is a subset of Unicode called ASCII, ASCII. 11:29:55 It stands for the American Standard Code for Information Interchange. And these are the common character letters and numbers and symbols that we would use, for example, in the United States. 11:30:07 It is a subset of Unicode which covers globally all the symbols that might be used. 11:30:13 And how does that work? Well, if you were ever a little kid and you created a secret code, maybe it was something as simple as, hey, instead of using the letter a I'm gonna use the number one so one is gonna represent a 2 is gonna represent B, etc., etc., through the alphabet. 11:30:33 But now what if your friend was also writing a secret code and they decided that the letter Z was one. 11:30:41 And they went backwards through the numbering to create their code. The 2 of you would not be able to translate your secret messages, would you? 11:30:51 Because you each had a different way to encrypt the alphabet to write your secret code. So that wouldn't work. 11:30:58 Hence, Unicode and the ASCII code give a certain exact set of numerical values for all of those symbols so that all computers can understand those symbols. 11:31:18 Now the next ones, the Boolean is a type of data type that stores true and false values. 11:31:24 If you've taken discrete structures, you were already exposed to some logic. You're gonna see logic in this class as well. 11:31:32 And so this comes in when we're asking questions that need true false answers. For example, those decision structures in those loops that will sit later on in the course. 11:31:43 Then the other data type that we're gonna use heavily is the numbers and more specifically the byte, the double the float, the integer, the long and the short. 11:31:52 I gave you a slide. It's in the left nap bar and it's probably posted for this week that talks about the primitive data types. 11:31:59 Their storage size and the range of values that can be stored in them. Please make yourself familiar with that. 11:32:06 I will bring it up again and another slide as well. Now, everything that you see on the screen. 11:32:16 All of that, the Java language library package with all of its classes and subclasses imported is important into every program by default. 11:32:26 So you get all of that when you start in the IDE and you start typing code. 11:32:35 Did you notice we could output, but we can't input. So how in the heck do we get input from the keyboard? 11:32:45 There's a utilities packet, Java. Dot you till. All applications do not necessarily require keyboard input. 11:32:53 For example, your first program, Hello World, did not need keyboard input. But you're gonna discover for our future programs, yes, we're gonna need some information from the user. 11:33:05 So we're gonna need 11:33:09 To import a utility to get a scanner. The scanner is used to get keyboard input. So how do you do this? 11:33:19 Above and outside the class. Opening header, you're going to write, import, Java. 11:33:27 Dot you till scanner. This those copy code. Files that I provide for you in the left nav bar, the common code to copy and paste. 11:33:39 Now, how does the scanner work? Well, just importing it is not enough. 11:33:51 It means I'm adding to the library of information for this program. The scanner, but you actually have to create one and use it. 11:33:54 So how is that done? 11:34:11 Noted you're gonna put import Java. Dot you till notice the uppercase S again scanner is an object. 11:34:13 You're going to put that statement above the public class. File name. So outside of the public class, this gets typed first. 11:34:17 Then inside the main method, here's where you're gonna declare your keyboard. Now keyboard is not a keyword. 11:34:26 It's what I chose. In fact, I would probably not choose the word keyboard because it's too many letters that I could miss skip. 11:34:34 I might call keyboard KBD. Or when I teach this class on campus depending on the student of the week. 11:34:40 I name the scanner after the student. But you can call it KVD or INP or input. 11:34:48 Whatever you're comfortable with pick something short and easy because you're gonna reference it often through your code and you don't want to have to miss type it. Okay. 11:34:57 So here's where I create a scanner and so I write scanner. Here's my identifier keyboard, equals new scanner and very specifically now I'm calling the system object dot what do I want it for input so system.in. 11:35:17 Now in stands for the standard input device of the system, which is the keyboard. The standard output device is a screen or monitor and the standard input device is the keyboard. 11:35:30 Okay, so you can see my comments here where I declare the variable storage of scanner type. So here's my scanner, my identifiers keyboard, but again it's programmer. 11:35:41 So you can call it whatever you like. Remember, we're gonna use the keyword new. 11:35:48 This means to create an object in memory, instantiate it. And so again, we don't need to worry about that. 11:35:57 Just saying that word creates the object for us. And so then we're gonna say what kind of scanner do we want? 11:36:01 We want a scanner for the standard council input device, which is a keyboard. This is our assignment operator, which assigns that new scanner to our identifier keyboard. 11:36:14 Okay. Then what happens? Well, as always, if you noticed in the flowchart video, I explained that we always have 2 of those parallelograms in a row. 11:36:26 The first parallelogram for the prompt. Here's an example of a prompt. System outprint, please enter an integer variable. 11:36:32 So in that parallelogram in your flowchart, you might just say, prompt for number because you can see in the next step. 11:36:41 I store number. So number equals keyboard. A call to next in there's next float, there's next double, there's next care, there's next line. 11:36:53 Please make yourself familiar with those. Next features. You can Google them if you would like. Okay. 11:37:00 The next ink method in this case. Of the scanner converts the bite values that are entered at the keyboard into an integer data type. 11:37:08 Okay, so on page 85, I believe, there's more scanner class methods in your text. 11:37:18 That out. Whoops. And so you can see them after that statement after those comments. I have a system outprint your number was and so whatever 11:37:30 Data is taken at the 11:37:32 I have now echoed that number back out to the screen. So that is called echoing. If I take a piece of data and I want to check that it went into the computer. 11:37:38 I can red display it and echo it out. That's a technique you may want to use to make sure that your code is doing what it's supposed to for to find those logic errors. 11:37:49 When you take data in, make sure that's actually the data that was being stored. 11:37:56 Okay, we're getting closer. 11:38:02 It's now lab time. What I'd like you to do. 11:38:07 Is modify. The Hello World Program. Add a prompt for your age. Now prompt is that screen output message requesting data so that's a system outprint line. 11:38:18 It should be specific as to the data you require. And then store the input value for use. Remember, you're going to make storage space for the data you're going to get before you ask for the data. 11:38:30 Remember that new storage box I showed in the flowchart example in the previous video. Then I want you to echo your age back to the screen. 11:38:38 After your name. So what I need you to do is rename your class Hello World 2 dot Java and save the file as hello world. 11:38:49 2 dot java before you begin. So again, let me help you. A little bit with your first flow chart where we're actually going to now. 11:39:02 Get some data from the user. So what you see on the screen is your original hello world. These are the things you're going to need to change for Hello World too. 11:39:14 So we're going to start. Now remember how I illustrated? Oh, I'm sorry. 11:39:20 I have these coming in as the original plan, right? So our output statement, we are now going to be adding that age variable that we're gonna display to the screen. 11:39:31 I also want to bring to your attention this plus sign. So plus, usually in in a mathematical feature, we'll add 2 values together. 11:39:41 But in an output statement it acts as a concatenation operator. The cat, I will call it for future reference. 11:39:50 And so in other words, if I have a string little hello world, my name is F. Dot porps and I want to add more to that. 11:39:59 String I will add this plus sign. I will make another string. I have my comma there and I am. 11:40:06 And then I'm gonna add another string. I'm sorry, I'm gonna add another variable at this point. 11:40:10 I'm gonna display age. You see another Concat operator. Adding the last portion of the string. 11:40:19 So this was our original problem. But now we have to get our age from the user. You can put your real age or any age you want. 11:40:27 It doesn't matter for me. The idea is I want to you to be able to show me that you can get data. 11:40:35 From the keyboard. Okay, so let me help you. One of the first things you're gonna want to do if your process requires keyboard input, the first box you're now going to draw is a process box that says import scanner and create scanner object. 11:40:51 This is to remind you that you need that import statement and then you have to create the object before you use it. 11:40:58 Then the next step. Is make storage space. In this case, our simple program is just going to collect data for the age of the user. 11:41:07 Although I gave you a hint, there's a way to get some extra credit. So maybe you're gonna need some more storage space. 11:41:16 Now, the next step, here's our 2 step. We're gonna prompt for age. See the parallelogram. 11:41:23 So we're gonna ask the user, what's your age? Then we're going to store it or get age. 11:41:28 That statement is going to look something like this, age equals keyboard. Dot next in as long as you called your keyboard keyboard, you can call it whatever you like. 11:41:38 And then finally we'll have the output statement. So you see the linear process step by step walk through the flowchart and you are good to go. 11:41:48 This is your next assignment. Hello World 2. I hope you have a nice week. Go Java programmer go. 11:41:59 We are not done with this module though at this point this was the back portion to chapter 2 after you finish this lab, get ready to jump in to the front portion of chapter 2.