CS-I Final Review Hao Jiang Computer Science Department Boston College.

Slides:



Advertisements
Similar presentations
PHP functions What are Functions? A function structure:
Advertisements

Lecture 6 Sept 11, 2008 Goals for the day: Linked list and project # 1 list class in STL (section 3.3) stack – implementation and applications.
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
The Singleton Pattern II Recursive Linked Structures.
SUMMARY: abstract classes and interfaces 1 Make a class abstract so instances of it cannot be created. Make a method abstract so it must be overridden.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Written by: Dr. JJ Shepherd
Methods. int month; int year class Month Defining Classes A class contains data declarations (static and instance variables) and method declarations (behaviors)
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Introduction and a Review of Basic Concepts
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS102--Object Oriented Programming Lecture 6: – The Arrays class – Multi-dimensional arrays Copyright © 2008 Xiaoyan Li.
CS-I MidTerm Review Hao Jiang Computer Science Department Boston College.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS 117 Spring 2002 Review for Exam 3 arrays strings files classes.
Sanjay Goel, School of Business, University at Albany, SUNY 1 MSI 692: Special Topics in Information Technology Lecture 4: Strings & Arrays Sanjay Goel.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
FEN 2012 UCN Technology: Computer Science1 C# - Introduction Language Fundamentals in Brief.
Object Oriented Programming: Java Edition By: Samuel Robinson.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
224 3/30/98 CSE 143 Recursion [Sections 6.1, ]
Lecture # 8 Constructors Overloading. Topics We will discuss the following main topics: – Static Class Members – Overloaded Methods – Overloaded Constructors.
CSC 142 Computer Science II Zhen Jiang West Chester University
Pointers. The structure of memory Computer memory is a linear sequence of addressable locations Addresses are numbered starting at zero In personal computers,
Pointers OVERVIEW.
Mohammad Amin Kuhail M.Sc. (York, UK) University of Palestine Faculty of Engineering and Urban planning Software Engineering Department Computer Science.
Generic Programming  Object Type  Autoboxing  Bag of Objects  JCL Collections  Nodes of Objects  Iterators.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
EE 422C Day 2 Java, Eclipse. Copyright Pearson Education, 2010 Based on slides bu Marty Stepp and Stuart Reges from
CS1101 Group1 Discussion 7 Lek Hsiang Hui comp.nus.edu.sg
U n i v e r s i t y o f H a i l 1 ICS 202  2011 spring  Data Structures and Algorithms 
CS-I MidTerm Review Hao Jiang Computer Science Department Boston College.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Lecture 8: Object Oriented Programming. What is a Programming Object? An object is an instance of a class. A class is a template for an object. Everything's.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
CSI 3125, Preliminaries, page 1 Overloading Methods In Java it is possible to define two or more methods within the same class that share the same name,
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
Java Programming Persistent Data Types. Persistent Data Structure A persistent data structure is a data structure having an internal state that never.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
LECTURE 21: RECURSION & LINKED LIST REVIEW CSC 212 – Data Structures.
OOP Basics Classes & Methods (c) IDMS/SQL News
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade Know: loops, switch/case Files Input failure (e.g. scan.hasNextInt())
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
Session 7 More Implications of Inheritance & Chapter 5: Ball World Example.
XuanTung Hoang 1 Something to discuss Feedbacks on Midterm Exam Final exam and term project  Final exam requires solid knowledge/skills in Java  Be more.
3.1 Objects. Data type. Set of values and operations on those values. Primitive/Built-In types. n Usually single values n Can build arrays but they can.
Functions + Overloading + Scope
Modern Programming Tools And Techniques-I
Object-Oriented Concepts
Objects as a programming concept
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Objects as a programming concept
Andy Wang Object Oriented Programming in C++ COP 3330
2.7 Inheritance Types of inheritance
COMPUTER 2430 Object Oriented Programming and Data Structures I
Classes & Objects: Examples
Variables and Their scope
CIS16 Application Development and Programming using Visual Basic.net
Chapter 11: More on the Implications of Inheritance
Suggested self-checks: Section 7.11 #1-11
Data Structures & Algorithms
String Class.
Review for Midterm 3.
Presentation transcript:

CS-I Final Review Hao Jiang Computer Science Department Boston College

About Programs Data and method (procedures, routines, functions) are two fundamental elements of programming Two basic tasks in constructing a program Define data types and data elements Define procedures that process data Two schemes of building a program Procedure oriented (what we have been learning) Object oriented (to be covered soon)

Recursion Recursion is an important method to construct functions to solve problems. To construct a recursive function: You should have a scheme to “reduce” your problem into smaller same problems that can be combined to solve the current problem. You know how to solve a trivial base problem. You make sure that the reeducation plan will NOT go infinitely.

Recursion Example: Example: A function that returns a string that reverse the original one, e.g. if the input is “abc” the output is “cba”. Base case: If the input has a single character, return itself. Reduction plan: Reverse the substring starting from the second character and then connect it with the first character. public static String reverseString(String str) { if (str.length() == 1) return str; string s = reverseString(str.substring(1)) + str.charAt(0); return s; }

Recursion Example: Example: Test whether a number is a power of 2. public static boolean isPowerOfTwo(int n) { if (n == 1) return true; if (n % 2 == 1) return false; return isPowerOfTwo(n/2); }

Array Array is a data structure for representing a sequence of data which have the same type and are indexed by numbers. Java Syntax: T[] a; // T can be any built-in or // user defined data types T[] b = new T[N]; // Declaration and creation T[][] c = new T[N][M]; // 2D array b array (length is a.length)

Applications of Arrays You should know how to manipulate elements in 1D and 2D arrays. You should understand how random shuffle works. You should be able to write programs to locate specific elements in an array.

Define New Data Types Data type is an abstraction of data and the methods that can be operated on the data. Data ( or properties) Methods Defines a data type

Class and Object In Java, we can define a new data type with a class. Each instance of a class is called an object. public class picture { private int width, height, depth; private double[][][] image; public Picture(int w, int h, int d) { width = w; height = h; depth = d; image = new double[w][h][d]; } public void read(String fileName) {…} public void write(String fileName) {…} public Picture rotate(double t) {…} public Picture resize(int w, int h) {…} } Data members ( the variables are called instance variables) Constructor More methods

Class and Object … Picture p = new Picture(256, 256, 3); p.read(“Spring2008.jpg”); Picture q = p.resize(512, 512, 3); q.write(“Spring2008Big.jpg”); … Create an Picture object Use method read Use method resize Use method write

Reference Types Picture p = new Picture(256, 256, 3); Variable p has a reference type. The value of p is a “reference” or “pointer” to the Picture object. If you do System.out.print(p), you will get a number that is the address of the picture object in memory (heap memory). p Object p contains a pointer to the picture object The scope of p is restricted in the current { }, but the object has a life time for the whole process.

Arguments of Reference Type void fun(T p) { p.method1(); p.method2(); } T q = new T(); fun(q); // q has been modified by // method1 and method2 q T object when calling void fun(T p), q copied its value to p p

Pass by Value void fun(T p) { p = new T(); p.method1(); p.method2(); } Does this one have the Same effect?

Pass by Value q T object p x void fun(T p) { p = new T(); p.method1(); p.method2(); } The original object does not change.

Arrays of Object void fun(T[] p) { for (int i = 0; i < p.length; i++) { p[i].method1(); p[i].method2(); } T[] q = new T[3]; q[0] = new T(); q[1] = new T(); q[2] = new T(); fun(q); Create the reference array Create the objects and put their references into the array

Object Oriented Programming Different from procedure based approach, object oriented programming starts from abstracting data instead of procedures. functionB functionA functionB Obj1: A Obj2:A Obj3:B Class AClass B Procedure based approach (using static methods in Java) program Object oriented approach

Inheritance class A { … public void f() {…} } class B extends A { … public void f() {…} } class C extends A { … } A BC Base class Derived classes A p = new B(); A q = new C(); p.f(); q.f();

Abstract Class and Interface public abstract class A { … public abstract void f(); } A is an abstract class. all the derived classes must override f(). public interface T { public void g(); public void f(); } class B implements T { … public void g() {…} public void f() {…} } T t = new B(); …

Linked List Linked list is a widely used data structure. We can use OOP methods to define the new data type List. null head class List { class Node { Object data; Node next; } Node head = null; public void append(Object d) {…} public void delete(int n) {…} }

About the Exam The exam is not hard if you know the stuff we did in class. Read (browse) the book before the exam. Look at the examples and try some exercises. Do not have to read other books. It is a good idea to try writing some programs on the paper. Be confident and relaxed; come to the exam on time.