Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 115 Week 3 January 28 – February 1, 2008. Monday Announcements Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Software Installation.

Similar presentations


Presentation on theme: "CSE 115 Week 3 January 28 – February 1, 2008. Monday Announcements Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Software Installation."— Presentation transcript:

1 CSE 115 Week 3 January 28 – February 1, 2008

2 Monday Announcements Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 –Bring your laptop or desktop to have appropriate software installed!

3 Monday Game Plan Exam 1 Exam 1 Class Definitions continued Class Definitions continued

4 Monday Inside the class body where we would define the capabilities, we have the definition of a special type of capability, the constructor Inside the class body where we would define the capabilities, we have the definition of a special type of capability, the constructor Constructor helps us set up the initial state of the object. Constructor helps us set up the initial state of the object.

5 Monday Constructor is made up of: Constructor is made up of: –Constructor header –Constructor body

6 Monday Constructor header: Constructor header: public identifier () public identifier () –public means the same here as before –identifier is the name of the constructor, which must be the same as the name of the class –() called parameter list

7 Monday Constructor body is enclosed by { and } Constructor body is enclosed by { and } Contains code that would help us set up the initial state of the object. Contains code that would help us set up the initial state of the object.

8 Monday Note that the () in the constructor definition are a parameter list. Note that the () in the constructor definition are a parameter list. We see these when we were creating an object as well We see these when we were creating an object as well That’s because what we are actually doing when we create an object is allocating space for the object (new) and calling the constructor That’s because what we are actually doing when we create an object is allocating space for the object (new) and calling the constructor

9 Monday The () in the call to the constructor are called the argument list. The contents of the two sets of () will have to match. We’ll talk more about this later. The () in the call to the constructor are called the argument list. The contents of the two sets of () will have to match. We’ll talk more about this later.

10 Monday We will begin to build relationships between our classes. We will begin to build relationships between our classes. When we do, we will see that relationships have formal names, informal names, ways to be expressed in UML and ways to be expressed in (Java) code When we do, we will see that relationships have formal names, informal names, ways to be expressed in UML and ways to be expressed in (Java) code

11 Monday Our first relationship will be the instantiation dependency relationship, or “uses a” informally. Our first relationship will be the instantiation dependency relationship, or “uses a” informally. UML indicator – see Green UML indicator – see Green

12 Wednesday Announcements Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 –Bring your laptop or desktop to have appropriate software installed!

13 Wednesday Game Plan Instantiation Dependency Continued Instantiation Dependency Continued

14 Wednesday If we need to refer to an object again once we’ve created it, we need to give it a name. If we need to refer to an object again once we’ve created it, we need to give it a name. Variables in programming allow us to name objects and refer to them later. Variables in programming allow us to name objects and refer to them later. For example, this will allow us to add multiple ants to the same terrarium. For example, this will allow us to add multiple ants to the same terrarium.

15 Wednesday To use a variable, we must declare it. To use a variable, we must declare it. To declare a variable we use the following syntax To declare a variable we use the following syntax type identifier; type is the type of thing the variable refers to. type is the type of thing the variable refers to. identifier is the name the programmer is giving to the variable. identifier is the name the programmer is giving to the variable.

16 Wednesday Where does the declaration go? Where does the declaration go? Where it goes makes a difference in how it can be used in our program. Where it goes makes a difference in how it can be used in our program. For now, we will put the variable declaration inside the constructor body. For now, we will put the variable declaration inside the constructor body.

17 Wednesday This makes the variable a local variable, meaning that the variable is local to the constructor and only exists within the scope of the constructor’s body. This makes the variable a local variable, meaning that the variable is local to the constructor and only exists within the scope of the constructor’s body. There are other places to put variables in our code and we will learn about those shortly. There are other places to put variables in our code and we will learn about those shortly.

18 Wednesday When a variable is declared, it is a null reference. We need to give it a value in order for it to be useful. When a variable is declared, it is a null reference. We need to give it a value in order for it to be useful. To assign a value to a variable, we use the assignment operator, which is the equals sign (=). To assign a value to a variable, we use the assignment operator, which is the equals sign (=).

19 Wednesday Assignment syntax: Assignment syntax: identifier = expression; identifier is the name that the programmer has given the variable identifier is the name that the programmer has given the variable expression is an expression whose value is assigned to the variable named by identifier expression is an expression whose value is assigned to the variable named by identifier Note that assignment is from the right to the left. Note that assignment is from the right to the left.

20 Wednesday Knowing about local variables allows us to create a variant of the dependency relationship called Local Variable Dependency. This can still be informally called the “uses a” relationship, but the code and the UML are slightly different. Knowing about local variables allows us to create a variant of the dependency relationship called Local Variable Dependency. This can still be informally called the “uses a” relationship, but the code and the UML are slightly different.

21 Friday Announcements Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 –Bring your laptop or desktop to have appropriate software installed!

22 Friday Game Plan What’s going on inside the machine when we create variables. What’s going on inside the machine when we create variables.

23 Friday Today we looked at how the computer allocates space for the variables we create and how the use of the assignment operator can actually cause us to lose a reference to an object we previously created. Today we looked at how the computer allocates space for the variables we create and how the use of the assignment operator can actually cause us to lose a reference to an object we previously created.


Download ppt "CSE 115 Week 3 January 28 – February 1, 2008. Monday Announcements Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Software Installation."

Similar presentations


Ads by Google