CSE 115 Week 4 February 4 - 8, 2008. Monday Announcements Software installation fest Tuesday & Wednesday 4-7 in Baldy 21. Software installation fest Tuesday.

Slides:



Advertisements
Similar presentations
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Advertisements

CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Variable types We have already encountered the idea of a variable type. It is also possible to think about variables in terms of their kind, namely: 1)
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
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
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:
Road Map Introduction to object oriented programming. Classes
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.
CSE 115 Week 10 March , Announcements March 21 – Lab 7 Q & A in lecture March 21 – Lab 7 Q & A in lecture March 26 – Exam 7 March 26 – 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.
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.
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
Week 4 Recap CSE 115 Fall 2006 Section C. Decoupling Separation of concerns Defining what an object can do, not how it does it.
Java Syntax, Java Conventions, CSE 115 Conventions (Part 2) CSE 115 Spring 2006 January 30, February 1 & 3, 2006.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Terms and Rules Professor Evan Korth New York University (All rights reserved)
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 3 January 28 – February 1, Monday Announcements Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Software Installation.
CSE 115 Week 6 February , Announcements Software Installation Fest – Take 2 Software Installation Fest – Take 2 –Tuesday 2/ –Wednesday.
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.
Understanding class definitions Looking inside classes.
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.
Constructors A constructor is a method that creates an object in Java. It does not return anything and it is not void. It’s only purpose is to create an.
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
COMP More About Classes Yi Hong May 22, 2015.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Classes CS 21a: Introduction to Computing I First Semester,
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing functions that return values  return statement’s meaning and how it works  When and.
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.
Introduction to Methods. Previously discussed There are similarities in make up of that can help you remember the construct of a class a class in the.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 4.
1 CSC241: Object Oriented Programming Lecture No 02.
February 2 - 6,  2/4: Go over review sheet for Exam 1  2/6: Exam 1 & Lab 1 due  2/9: Go over Exam 1  2/11: Makeup exam for Exam 1.
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 3 Introduction to Classes and Objects Definitions Examples.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 26, 2009.
Programming Languages Dan Grossman 2013 Classes and Objects.
Friend Class Friend Class A friend class can access private and protected members of other class in which it is declared as friend. It is sometimes useful.
Chapter 4 Procedural Methods.
Chapter 4 void Functions
CSE 115 September 29 – October 3, 2008.
CSE 115 September 29 – October 3, 2008.
Chapter 7 Procedural Methods.
Notes from Week 5 CSE 115 Spring 2006 February 13, 15 & 17, 2006.
February , 2009 CSE 113 B.
Classes CS 21a: Introduction to Computing I
February 2 - 6, 2009 CSE 113 B.
SPL – PS3 C++ Classes.
Chapter 4 Test Review First day
Presentation transcript:

CSE 115 Week 4 February 4 - 8, 2008

Monday Announcements Software installation fest Tuesday & Wednesday 4-7 in Baldy 21. Software installation fest Tuesday & Wednesday 4-7 in Baldy 21. Pick up Exam 1’s in lab this week. Pick up Exam 1’s in lab this week. Lab 2 due this week. Office hour visits for Lab 1 must be completed this week. Lab 2 due this week. Office hour visits for Lab 1 must be completed this week.

Monday Method definitions Method definitions –Method header visibility returnType methodName (parameterList) visibility returnType methodName (parameterList) –Method body Enclosed between { } Enclosed between { } Code inside gives the steps the method should perform. Code inside gives the steps the method should perform.

Monday Method header Method header –No two methods can have the same method header –visibilty: usually public –returnType: the type of thing the method returns, if it does not return anything, the return type is listed as the keyword void

Monday Method header Method header –methodName: identifier that programmer picks, as style first letter is lower case, letters in subsequent words upper case –parameterList: additional information that is needed to complete the method – can be empty

Monday Parameter List Parameter List –If the parameter list is not empty, it is a comma-separate list of type identifier pairs, where type is the type of the parameter and identifier is the name of the parameter to be used inside the method body

Wednesday Announcements Software Installation Fest today 4-7 in Baldy 21. Software Installation Fest today 4-7 in Baldy 21. Exam 3 on Monday 2/11 Exam 3 on Monday 2/11 Exam Review Sessions start next week Tuesday 2/12 and Thursday 2/14 – see Schedule page for more details. Exam Review Sessions start next week Tuesday 2/12 and Thursday 2/14 – see Schedule page for more details. Lab 2 due this week. Office hour visits for Lab 1 must be completed this week. Lab 2 due this week. Office hour visits for Lab 1 must be completed this week.

Wednesday Constructors are methods, but the syntax for calling them and writing them is just different because of their specialized purpose. Constructors are methods, but the syntax for calling them and writing them is just different because of their specialized purpose.

Wednesday Note that no two methods can have the exact same header. However, two methods can have the same name if they differ in number and/or type of their parameters. This is called method overloading. Note that no two methods can have the exact same header. However, two methods can have the same name if they differ in number and/or type of their parameters. This is called method overloading.

Wednesday Local variables only exist inside a method. That is to say that their scope is only within the method body. It turns out that their lifetime is also only when the method is being executed. Local variables only exist inside a method. That is to say that their scope is only within the method body. It turns out that their lifetime is also only when the method is being executed. What if we wanted to use the same variable in multiple methods? What if we wanted to use the same variable in multiple methods?

Wednesday Instance variables Instance variables –Allow us to declare a variable to belong to the entire class. Its scope is within the class body and its lifetime is linked to the lifetime of the class –Syntax for variable declaration: private type identifier;

Wednesday private is a keyword meaning that the variable is only accessible within the class private is a keyword meaning that the variable is only accessible within the class type is the type of the instance variable type is the type of the instance variable

Wednesday identifier is the name given the variable by the programmer, our instance variables will start with an underscore and then follow the same rules for local variables identifier is the name given the variable by the programmer, our instance variables will start with an underscore and then follow the same rules for local variables

Wednesday So, the variable can be declared, but how can we set its value – remember it starts out null. So, the variable can be declared, but how can we set its value – remember it starts out null. We have two options: We have two options: –Create an instance for it in the constructor –Pass in a value for it to the constructor

Friday Announcements Exam 3 on Monday 2/11 Exam 3 on Monday 2/11 Exam Review Sessions start next week Tuesday 2/12 and Thursday 2/14 – see Schedule page for more details. Will be reviewing Exam 1 & 2. Exam Review Sessions start next week Tuesday 2/12 and Thursday 2/14 – see Schedule page for more details. Will be reviewing Exam 1 & 2. Lab 2 due this week. Office hour visits for Lab 1 must be completed this week. Lab 2 due this week. Office hour visits for Lab 1 must be completed this week.

Friday If we are trying to assign the value to an instance variable declaration, we saw that we had two options: If we are trying to assign the value to an instance variable declaration, we saw that we had two options: –Create an instance for it in the constructor –Pass in a value for it in the parameters of the constructor

Friday If we create an instance for it in the constructor then we are constructing a relationship whereby the object is responsible for creating the “subpart”. This is the relationship of composition. If we create an instance for it in the constructor then we are constructing a relationship whereby the object is responsible for creating the “subpart”. This is the relationship of composition.

Friday In the composition relationship, the lifetime of the subpart is connected to the lifetime of the whole. The part does not exist before the whole, and will not exist after the whole is destroyed. In the composition relationship, the lifetime of the subpart is connected to the lifetime of the whole. The part does not exist before the whole, and will not exist after the whole is destroyed.

Friday If we pass in a value to the parameter of the constructor, we are creating an association relationship. This relationship’s informal name is “knows a”. If we pass in a value to the parameter of the constructor, we are creating an association relationship. This relationship’s informal name is “knows a”.

Friday In the association relationship, the lifetime of the value referred to by the instance variable is not related to the lifetime of the object that holds the reference. The two objects merely need to communicate with one another in order to get some work done. In the association relationship, the lifetime of the value referred to by the instance variable is not related to the lifetime of the object that holds the reference. The two objects merely need to communicate with one another in order to get some work done.

Friday There are two ways to code the association relationship. See book for both alternatives. There are two ways to code the association relationship. See book for both alternatives.