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.

Slides:



Advertisements
Similar presentations
CPSC 388 – Compiler Design and Construction
Advertisements

Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Lecture 2 Calling and Defining Methods in Java. Introduction ●Calling and defining methods ●Declaring and defining a class ●Instances of a class ●The.
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Lecture #5 Agenda Cell phones off & name signs out Review Questions? UML class diagram introduction Our first class definition!
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Syntax & terminology review While the following slides are not exactly what we did on the board (object diagrams are not shown here) they cover most of.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE 115 Week 5 February , Monday Announcements Exam 3 today Exam 3 today Lab 3 due this week Lab 3 due this week Exam 4 Monday 2/18 Exam.
Week 4 Recap CSE 115 Spring Formal Parameter Lists Comma-separated list of formal parameters Formal parameters are listed giving the type of the.
Where do objects come from? Objects are instances of classes We instantiate classes: –e.g.new chapter1.Terrarium() –There are three parts to this expression:
CSE 113 Week 3 January 28 – February 1, Monday Announcements  Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Bring your laptop or.
Week 2 Recap CSE 115 – Spring Object Oriented Program System of objects that communicate with one another to solve some problem.
Wednesday, 10/9/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/9/02  QUESTIONS ??  Today:  Discuss HW #02  Discuss test question types  Review 
Week 4 Recap CSE 115 Fall 2006 Section C. Decoupling Separation of concerns Defining what an object can do, not how it does it.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Lecture #4 Agenda Announcements Review Questions? Classes and objects UML class diagrams Creating.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Week 5 Recap CSE 115 Spring Composition Informally called “has a” Represented in UML with a diamond- headed arc In code: Declare an instance variable.
CSE 115 Week 6 February , Announcements Software Installation Fest – Take 2 Software Installation Fest – Take 2 –Tuesday 2/ –Wednesday.
CSE 115 Week 4 February 4 - 8, Monday Announcements Software installation fest Tuesday & Wednesday 4-7 in Baldy 21. Software installation fest Tuesday.
Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 Announcements Attendance sheet is going around – be sure you sign it! First part of.
CSE 250: Data Structures Week 3 January 28 – February 1, 2008.
Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 End of Week Five! Questions? First part of essay assignment (choosing a topic) is posted.
Week 3 Recap CSE 115 – Spring Constructor Special capability of a class that sets up the initial state of the object. Constructor definitions are.
Week 3 Recap CSE 115 – Fall Java Source Code File Made up of: Package declaration Class definition.
CSE 116 Introduction to Computer Science For Majors II Carl Alphonce 219 Bell Hall.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of.
CSE 115 Week 2 January , Wednesday Announcements Pick up Syllabus if you need one Pick up Syllabus if you need one Recitation Change Form.
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 1.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
1 Chapter Four Creating and Using Classes. 2 Objectives Learn about class concepts How to create a class from which objects can be instantiated Learn.
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
CSIS 113A Lecture 5 Functions. Introduction to Functions  Building Blocks of Programs  Other terminology in other languages:  Procedures, subprograms,
FIGURE 4-10 Function Return Statements
Chapter 4: Writing Classes
FIGURE 4-10 Function Return Statements
CSE 115 September 29 – October 3, 2008.
Chapter 4 Writing Classes.
CSE 115 September 29 – October 3, 2008.
FIGURE 4-10 Function Return Statements
Object Oriented Programming in java
February , 2009 CSE 113 B.
FIGURE 4-10 Function Return Statements
Abstract Data Types Abstraction is to distill a system to its most fundamental parts. Applying the abstraction paradigm to the design of data structures.
Corresponds with Chapter 5
Chapter 4 Test Review First day
Presentation transcript:

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 Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 –Bring your laptop or desktop to have appropriate software installed!

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

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.

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

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

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.

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

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.

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

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

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!

Wednesday Game Plan Instantiation Dependency Continued Instantiation Dependency Continued

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.

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.

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.

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.

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 (=).

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.

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.

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!

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.

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.