CS125 Exam Review Winter 2008. Some Exam Info Tuesday (22nd) at 4:00-6:30pm in the PAC CHECK YOUR SEAT!!! Read Final Exam Information on website –Practice.

Slides:



Advertisements
Similar presentations
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Advertisements

Written by: Dr. JJ Shepherd
Java Software Solutions
CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
CS 106 Introduction to Computer Science I 11 / 28 / 2007 Instructor: Michael Eckmann.
Wednesday, 12/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/11/02  QUESTIONS??  Today: CLOSING CEREMONIES!  HW #5 – Back Monday (12/16)
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Enhancing classes Visibility modifiers and encapsulation revisited
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Object Oriented Concepts in Java Objects Inheritance Encapsulation Polymorphism.
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
1 Exercise /* A lockbox can be open or closed. If closed, only a valid password will open the box. Once the box is open, the contents can be retrieved.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
More with Methods (parameters, reference vs. value, array processing) Corresponds with Chapters 5 and 6.
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.
Java Implementation: Part 3 Software Construction Lecture 8.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
CMSC 202 Arrays. Aug 6, Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same type –An.
1 Java: AP Curriculum Focus and Java Subset Alyce Brady.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Parameters… Classes Cont Mrs. C. Furman October 13, 2008.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
10-Nov-15 Java Object Oriented Programming What is it?
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Programming in Java CSCI-2220 Object Oriented Programming.
(c) University of Washington15-1 CSC 143 Java List Implementation via Arrays Reading: 13.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
More Methods and Arrays Material from Chapters 5 to 7 that we didn’t cover in 1226.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
Constructors & Garbage Collection Ch. 9 – Head First Java.
Method Overloading  Methods of the same name can be declared in the same class for different sets of parameters  As the number, types and order of the.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Composition When one class contains an instance variable whose type is another class, this is called composition. Instead of inheritance, which is based.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
COM S 228 Introduction to Data Structures Instructor: Ying Cai Department of Computer Science Iowa State University Office: Atanasoff.
Classes, Interfaces and Packages
Chapter 4Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapters 4 and 5: Excerpts l Class and Method Definitions l Information.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Written by: Dr. JJ Shepherd
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
CS Prelim Review – 10/15/09  First prelim is TOMORROW at 7:30 PM  Review session – Tonight 7:30 PM, Phillips 101  Things you should do:  Review every.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
OOP: Encapsulation &Abstraction
Wrapper Classes ints, doubles, and chars are known as primitive types, or built-in types. There are no methods associated with these types of variables.
CS139 – Fall 2010 How far we have come
Object Oriented Programming (OOP) LAB # 8
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Defining Classes and Methods
Java Programming Language
2009 Test Key.
Review for Midterm 3.
Presentation transcript:

CS125 Exam Review Winter 2008

Some Exam Info Tuesday (22nd) at 4:00-6:30pm in the PAC CHECK YOUR SEAT!!! Read Final Exam Information on website –Practice questions & old exams –Reference sheet Bring WATCARD, pen, pencil, eraser only

Old Topics Primitive variables Declare Initialize Operations Mod, Division String methods Board class Coordinate class Scanner next(), nextLine() Boolean statements AND,OR,NOT If statements Loops for while Tracing

Overloading Two methods in the same class with… Exact same method name Different parameters (by number or type) Ignore return type Examples: indexOf, putPeg Midterm: Why the overloaded methods didn’t work?

Class Diagrams public class Cat { //instance variables private String name; //constructor public Cat(String n) {…} //methods public void meow() {…} } Cat - String name … + Cat(String n) - void meow() …

Information Hiding (1/2) Designing methods so the user doesn’t need to understand how they work –Examples, putPeg, removePeg (we use them, but don’t know how they work) Why do this? _______, _______, _______ Pre- and post- conditions

Information Hiding (2/2) Visibility modifiers - public or private –Public: accessed from anywhere –Private: accessed within its own class Make sure you understand this key idea :) Applies to methods or variables ________ variables are always private So how do we use them?

Encapsulation Type of information hiding Separating interface & implementation Interface –What the user accesses…method signatures, pre- and post- conditions Implementation –What programmer sees Where do private methods fall?

How Objects are stored Recall reference variables (objects) reference object Holds the memory location of where to find the object Actual object (instance variables, etc.)

Comparing Objects Blob b1 = new Blob(2); Blob b2 = new Blob(2); Blob b3 = b1; b1==b2 ? b1.equals(b2) ? b1==b3 ? Blob b1 = new Blob(2); Blob b2 = new Blob(2); Blob b3 = b1 b3.tripleValue() b1.equals(b2) ? b1.equals(b3) ? b1==b3 ?

Passing Parameters to methods “Passed-by- value” “Passed-by- reference” Type of Parameter PrimitiveObject What is passed? Copy of primitive Reference to object Change to original? ___

Example 1 Output? Blah myObject = new Blah(); int n1=3, n2=5; myObject.makeEqual(n1,n2); System.out.println(n1==n2); //somewhere else public void makeEqual(int n1,int n2) { n2=n1; } Output: _________

Example 2 Square s1 = new Square(5); Square s2 = new Square(3); s1.makeEqual(s2); System.out.println(s1.equals(s2)); Output: _________

Top-Down Design Step-wise refinement Helper methods Stubs

Static Methods Usually, we call methods on objects –myBoard.putPeg(…), rect.area() Sometimes it doesn’t make sense to call a method on an object, so we call it directly from a class –Math.abs(-7)

Static Methods Static methods can only call ______ methods and variables Interpreting reference sheet: Math class: + static double abs (double a), returns double Store absolute value of -5.4 in double num: __________________________

Constants Key word: final Arbitrary numbers should never appear in code (except 0 or 1) Usually declared/initialized: public static final int PI = 3.14 (As a side note, why public? why static?)

Declaring Arrays (1/7) type[] arrayName = new type[size] 1.char[] letters = new char[5]; 2.String[] names; names = new String[30/2*3]; 3. int a=10; MyObject[] mult = new int[a]

Array of Objects (2/7) Person[] class = new Person[5]; Here, references are made for 5 Person objects… but they are all null. (NullPointerException, anyone?) class

Initializing Arrays (3/7) While primitive variables are usually assigned a default value (0,false,etc.) it is good practice to initialize them. -Or you may want different initial values Initialize alpha array to the alphabet (I.e. alpha[0]=‘a’, alpha[1]=‘b’, etc.) char[] alpha = new char[26]; …

Initialize Array of Objects (4/7) for (int i=0; i<class.length; i++) { class[i] = new Person(); } class Person

Using Arrays (5/7) Student[] class = new Student[#]; Find length: class.length Index range _______ to _______ To access individual element –class[index] –Treat ‘class[2]’ like any other single Student object

Using Arrays (6/7) You should easily know how to: –Search –Iterate (go through) –Manipulate values –Pass an array as a method parameter –Return an array from a method

Array Questions (7/7) 1.Find lowest/highest value in array. 2.Shift all values of an array up (and last value is now first) (Think about how you would do these…)

2-D Arrays Type[][] myArray = new Type[3][5]; myArray.length myArray[0].length

2-D Arrays 2D arrays are 1D arrays where each array is a 1D array

2-D Arrays Same rules as 1-D array Examples…

Inheritance Person Student Person Student Student extends Person, Student is a Person Student inherits everything public the Person has. super class (more general) Student has ‘everything’ Person has and (maybe) more.

… Say Coffee extends Drink: Drink d = new Coffee(); ok? Coffee c = new Drink(); ok? Wanting any drink and getting coffee is good; wanting coffee and getting a drink may not be.

Overriding Methods A subclass overrides a method in its super class. –Use the exact same method signature –Used to make the method more tailored to the class –Example, Lab 12 Vehicle Not the same as overloading. What’s the difference?

Accessing Super Class Keyword: super Use super(params) –To access parent’s constructor –Must be first line in child’s constructor Use super.someMethod(params) –To access parent’s someMethod method

Method Resolution Somewhere in HotDrink class: this.methodName() –Looks at itself first –HotDrink -> Drink ->… super.methodName() –Starts looking in parent class –Drink -> Object Object Drink HotDrink Coffee

Examples Person p = new Student(“Josh”,19); p.setAge(20); -Will compile if _______ has setAge method -Will look in the _______ class for setAge