EECS168 Exam 3 Review

Similar documents
Chapter 4 Defining Classes I

Introduction to Programming Using Java (98-388)

Defining Classes and Methods. Objectives. Objectives 6/27/2014. Chapter 5

Objectives. Defining Classes and Methods. Objectives. Class and Method Definitions: Outline 7/13/09

Defining Classes and Methods

Defining Classes and Methods

5. Defining Classes and Methods

5. Defining Classes and Methods

Chapter 6 Introduction to Defining Classes

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Java Primer 1: Types, Classes and Operators

Chapter 4. Defining Classes I

Defining Classes and Methods

Defining Classes and Methods

Methods and Data (Savitch, Chapter 5)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Mathematics/Science Department Kirkwood Community College. Course Syllabus. Computer Science CSC142 1/10

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Part 3. Why do we need both of them? The object-oriented programming paradigm (OOP) Two kinds of object. Important Special Kinds of Member Function

APCS Semester #1 Final Exam Practice Problems

Lecture 5: Methods CS2301

Recitation 02/02/07 Defining Classes and Methods. Chapter 4

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Objects and Classes. Basic OO Principles. Classes in Java. Mark Allen Weiss Copyright 2000

Chapter 4. Defining Classes I

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

You must pass the final exam to pass the course.

Chapter 7 User-Defined Methods. Chapter Objectives

Defining Classes and Methods

Programming II (CS300)

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012

CMPT 117: Tutorial 1. Craig Thompson. 12 January 2009

Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A

What will this print?

CSE 8B Intro to CS: Java

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Lecture 7. Log into Linux New documents posted to course webpage

Methods. Methods. Mysteries Revealed

Dot and Scope Resolution Operator

Defining Classes and Methods

11/19/2014. Objects. Chapter 4: Writing Classes. Classes. Writing Classes. Java Software Solutions for AP* Computer Science A 2nd Edition

CS313D: ADVANCED PROGRAMMING LANGUAGE

CLASSES AND OBJECTS IN JAVA

TaxiBot New attributes Variables Math! TaxiBot

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II

COP 3330 Final Exam Review

Anatomy of a Method. HW3 is due Today. September 15, Midterm 1. Quick review of last lecture. Encapsulation. Encapsulation

Programming II (CS300)

Java Methods. Lecture 8 COP 3252 Summer May 23, 2017

C++ Review. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

CompuScholar, Inc. 9th - 12th grades

2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17

CGS 2405 Advanced Programming with C++ Course Justification

Table of Contents Date(s) Title/Topic Page #s. Chapter 4: Writing Classes 4.1 Objects Revisited

Handout 7. Defining Classes part 1. Instance variables and instance methods.

Object-Oriented Programming (OOP) Basics. CSCI 161 Introduction to Programming I

Programming overview

TeenCoder : Java Programming (ISBN )

University of Maryland Baltimore County. CMSC 202 Computer Science II. Fall Mid-Term Exam. Sections

Methods. CSE 114, Computer Science 1 Stony Brook University

CS1150 Principles of Computer Science Methods

CHAPTER 7 OBJECTS AND CLASSES

Java Programming. Manuel Oriol, March 22nd, 2007

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2017 Instructors: Bill & Bill

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Computer Science II (20073) Week 1: Review and Inheritance

Data Structures. Data structures. Data structures. What is a data structure? Simple answer: a collection of data equipped with some operations.

Object-Oriented Programming Concepts

New Concepts. Lab 7 Using Arrays, an Introduction

ECE 122. Engineering Problem Solving with Java

Java Software Solutions for AP Computer Science 3rd Edition, Lewis et al. 2011


CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2018 Instructors: Bill & Bill

Chapter 6 Lab Classes and Objects

More on Arrays CS 16: Solving Problems with Computers I Lecture #13

Understanding class definitions

Interview Questions of C++

Announcements. 1. Forms to return today after class:

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

Introduction to Classes and Objects. David Greenstein Monta Vista High School

Objects and Classes Lecture 2

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

CS 170 Java Programming 1. Week 13: Classes, Testing, Debugging

CSE 113 A. Announcements - Lab

Today s Agenda. Quick Review

CST141 Thinking in Objects Page 1

Chapter 4: Writing Classes

CS112 Lecture: Defining Instantiable Classes

Comp 248 Introduction to Programming Chapter 4 & 5 Defining Classes Part B

public class TicketMachine Inner part omitted. public class ClassName Fields Constructors Methods

Week 7 - More Java! this stands for the calling object:

Simple Component Writer's Guide

EECS1710. Announcements. Labtests have been returned Term Test #01 marking is in progress. Next Labtest: Thu Oct 23/Fri Oct 24

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1

Transcription:

EECS168 Exam 3 Review

Exam 3 Time: 2pm-2:50pm Monday Nov 5 Closed book, closed notes. Calculators or other electronic devices are not permitted or required. If you are unable to attend an exam for any reason, no make-up exam will be given. That exam will be dropped from your grade. If a second exam is missed, a make-up exam will only be granted under extenuating circumstances, with prior permission from the instructor.

Exam 3 Exam 3 covers: Mostly Chapter 5 and 6 Classes and objects No graphics No Android No Arrays No Javadoc

Exam 3 How to prepare? Notes, practice questions, homeworks, labs, the textbook! Classes and Objects

Exam 3 Questions? T/F with justification, Multiple choice, short answers Read code, predict output Debug code: identify syntax errors & logic bugs, fix them Write code Other

Class and Method Definitions Java program consists of objects Objects of class types Objects that interact with one another Each Java class definition usually in a file by itself File name begins with name of the class Ends with.java Class can be compiled separately

Class and Instance Variables Class has Data: member variables (instance variables) Operations (behaviors): member methods Method definitions appear inside class definition Can be used only with objects of that class Each instance of this type has its own copies of the data items public and private

Defining Methods Modifiers public or private Return type or void Return a single item (must declare type), last statement: return What if I have statements after (unconditioned) return? Perform some action: no return value, e.g., write output static or non-static Parameters Body enclosed in braces { }

Methods When you use a method you "invoke" or "call" it Two kinds of Java methods Return a single item Could be used anywhere a value can be used Perform some other action a void method E.g. write output The method main is a void method Invoked by the system Not by the application program

Methods Local variables Variables declared inside a method are called local variables May be used only inside the method Blocks Compound statements: enclosed in braces { } The scope of variables declared in the block is from its declaration to the end of the block Variable declared outside the block usable both outside and inside the block

Methods Parameters Formal parameter: in the declaration Actual parameter: from the caller Parameters of primitive type Names of formal parameters are local to the method When method invoked Each parameter initialized to value in corresponding actual parameter Primitive actual parameter cannot be altered by invocation of the method Type conversion

Information Hiding Programmer using a class method need not know details of implementation Only needs to know what the method does Information hiding: Designing a method so it can be used without knowing details Also referred to as abstraction Method design should separate what from how Encapsulation Accessor and Mutator Methods

Encapsulation Declare all instance variables in the class as private. Provide public accessor methods to retrieve data Provide public methods manipulating data Including public mutator methods. Make any helping methods private.

Constructors A special method called when instances are created with new Reserve memory for member variables Initialize values of member variables Can have parameters To specify initial values if desired May have multiple definitions Each with different numbers or types of parameters Default constructor

Static Variables Static variables are shared by all objects of a class class variables: only one instance of the variable exists (note: this is not variables of class type) It can be accessed by all instances of the class Variables declared static final are considered constants

Static Methods Some methods may have no relation to any type of object Static method declared in a class Can be invoked without using an object Instead use the class name ClassName.MethodName(parameter1, );

Overloading Basics When two or more methods have same name within the same class Java distinguishes the methods by number and types of parameters If it cannot match a call with a definition, it attempts to do type conversions A method's name and number and type of parameters is called the signature

Variables of a Class Type Variables are implemented as memory locations Data of primitive type stored in the memory location assigned to the variable Variable of class type (reference) contains memory address of object. Object itself stored elsewhere in memory Compare objects Assignment operators for variables of class type Parameters of class type

Example 1: Number Class Design a class for natural numbers Similar to the wrapper class Integer Member variable the number (as int) Member functions the constructor A Boolean method to determine if the instance variable is prime A static method that takes in an int, and determines if it is prime

Example 2: TopTwo Design a class to trace the two largest numbers Member variables Two numbers (as int) Member functions put(int x): compare x with the two existing numbers, keep the largest two. getlargest() return the larger of the two numbers getsecond() return the smaller of the two numbers