 Hey, welcome to Intro to AP Computer Science for new AP teachers. This video is called Using Objects One. I should note here that I am kind of doing things a little bit differently at this point than how the AP has it arranged. Just because I feel that this is a better way of scaffolding the information. I organize my e-book around this and so hopefully you'll see the logic of it. So in this lesson or unit, whatever you want to call it, we're going to be taking a look at what is an object. What does that actually mean? What's the difference between a class and an object? How do they relate? How do we create classes? How do we create objects? The idea of dot notation. How do we access attributes? How do we access methods? Now we've already seen this in the previous units with strings, but this is where we kind of talk about it a little bit more directly. You might have introduced it previously. Then we'll go through a quick introductory exercise. So what is an object? An object is just something that has attributes. So for example, a person has a height. A person has an age. So those are the attributes. These are the qualities that that person, that that object has. Whereas methods are the things that it can do. Or later you'll see, of course, setters and getters, methods allow us to access attributes. But what I'm doing here is I'm going to make the attributes public. Just to keep it simple and then we're going to scaffold up to a more complex thing with private access later. So that's why I said this is not, this part is not pure AP style, which requires private attributes. Now, again, you could easily combine setters and getters and private attributes here. I just like to do it a little bit separately. It helps some of the students who are having trouble adjusting to the Java's complexity. And you know, methods, you know, we've already seen methods with strings. So there is some knowledge, there is some, you know, schema, some background information the students can build on. So you can just bring those up, you know, talk about, you know, hey, we did this, we did that. Classes versus objects, the canonical kind of, you know, analogy is that a class is a blueprint for an object. It defines what are the attributes of this object? What are the methods? What can this object do? So an object is a specific instance of a class. So the class defines what an object is, then we have specific instances. So for example, we might have a student class. And then, you know, you say, you know, so and so, you know, Alice is a particular student. Becky is another particular student, etc, etc. So I put this chart together. So I used Ironman and Captain America. And so person, so a person has some different attributes. So a person has a first name, a last name, an age, a height, and is alive. So first name and last name, of course, would be strings. This would be a nice question to ask the students, you know, how do we do age? I think we did that actually in an earlier introductory lesson. So height would of course be a double and then is alive, you know, you're alive or you're not. So that would be a boolean. So that is the class over there. And then you see Ironman and Captain America are specific instances of this class. So Ironman has a first name, the last name, an age, a height, and is alive. Of course, the values will be different. Now, it's possible that, you know, Ironman and Captain America are the same age, but unlikely since Captain America spent decades frozen under the water. So, you know, there is that. But anyway, you know, they could both be alive. They could both be dead. One could be alive. One could be dead. You get the idea. So this kind of describes the relationship between classes and instances, classes define which attributes an instance can have. And then an instance has specific values for those attributes. So creating a class and an object. So students should already be familiar with class and the polyc static void, mainstream, args, etc, etc. So the class definition is very similar. So, you know, the class name, Pascal case, good to bring that back up. The big difference is there's no main method. And I see it time and time again, students trying to put a main method into a not into a class that doesn't require it. And so then the base of the set up an attribute is public, the data type, the name of the variable equals default value. Now, again, I know we don't need to add a default value. There are default values provided for us. I just put this in, because I think it really helps the students at this point, we talk about null and all that sort of stuff later. And then objects, to create an object in the other method, you need or in the other class, you need two classes. So class name equals new class. And again, this is all explained in more detail in my ebook. So I think I think also like these, these slides could be used with students. That's also what I'm thinking of, you know, double double the things we like to call it dot notation. This is just specific terminology. This is what allows us to access the attribute or method. And then we've already seen this with strings. So again, throughout my course, what I try to do is introduce an idea, come back to it over and over again and try to keep a consistent thread running through the course, where we're building up skills piece by piece by piece, because it gets pretty complex. And then so if we have a vows, which is our object, in this case, string object, index of a certain index of is our method, first a is the parameter, or value. And then so the idea is it's object dot attribute or object dot methods. This is what's called dot notation. So dot notation, in this particular case allows us to assign a value. So iron man dot first name equals Tony, Tony Stark. So then you have to talk about this point. Okay, this is with public access. Say, look, later, we're going to change this to private, we'll talk about that in a future unit. According to the AP, it's just it's just not considered good object oriented design. Again, get more in detail into that later. I try not to overload the students with too many concepts, because they're just not going to get it. And then it allows us to access the values of iron man dot first names of system dot out dot print line, iron man dot first name. So interaction exercise, you may see, we're kind of doing the same type of exercise over and over again, I always try to go back to what we did previously and to build on that at least where I can. So again, choosing a real world object could be one that they did in previous with strings or when they did with the primitives, come up with five attributes with three different data types, good place to review data types, write the class code based on what you showed in the class, create two example objects, assign the values, I should add it here, print them out. Okay, again, if you look at my ebook, there's a sample code there that you share with the students as well. So that is that so we talked about what an object is, the relationship between classes and objects, how to actually create a class and create an object, the idea of dot notation, which again, we see it we understand what it is, but that's the name for it. And hopefully a helpful introductory exercise that builds on the things that have come before. So thanks for watching. Have a good one.