CS211 Spring 2002 Lecture 2: OOP Overview 1/23/2003 ------------------------------------------------------------------------------- 0) Announcements: + Just added? See http://www.cs.cornell.edu/courses/cs211/2003sp/ Read syllabus! Do everything in "What To Do First"!!! + Online Announcements: are you reading them? + Where are these notes? Click on "Lecture Notes" + Office hours and consulting TBA (Mon at latest) + Topics and reading fleshed out for next 2 weeks + Assignment 1 posted, due Wed + E1 due Mon + Java Bootcamp tonight: Upson B17, 7:30-10:30 (or so) + Have you filled out a waiver? Did you give it to someone on staff? No waiver means no CMS means no HW to submit! ------------------------------------------------------------------------------- 1) Objectives/Topics of Lecture 2 + Reminder about reasons for programming + Procedural vs OO Programming + Class structure + Program structure + The gist of OOP + Execution model + Basic data structures + Ensure that you can do A1 ------------------------------------------------------------------------------- 2) Why are you here? Programming is _________________________________________________________ . Issues: problems with repetition, difficulty, fun.... ------------------------------------------------------------------------------- 3) Procedural vs OO Procedural Programming Procedure: _________________________________________________ Object-Oriented Programming Class: ___________________________________________________ Object: __________________________________________________ Why OOP? + modeling our world + "chunkification" and structured programming + code reuse + others? Other forms of programming? ------------------------------------------------------------------------------- 4) How to do OOP high-level: + Problem -> Approach -> Solution + iterate if necessary medium-level: programming as writing! + brainstorm: + research: + outline: + draft + rewrite: + polish: low-level: + stepwise refinement: "baby steps" + stubbing + top-down + bottom-up tricks of the trade: + how to stub + commenting as you go/partial debugging + mixing top-down/bottom up + personal reuse database ------------------------------------------------------------------------------- 5) OOP Fundamentals + Encapsulation: ____-a relationship - what will be a field? - what will be a method? - abstraction and information hiding + inheritance: ____-a relationship + polymorphism: ___________________ ------------------------------------------------------------------------------- 6) Class Structure + signature: + fields: + methods: + constructors: + others? example) public class Person { private String name; public Person(String n) { name=n; } public toString() { return name; } public addLastName(String ln) { name+=ln; } } ------------------------------------------------------------------------------- 7) Execution Model +-------------------------------------------+ | | | +--------------+ +--------------+ | | | static area | | program area | | | +--------------+ +--------------+ | | | | +--------------+ +--------------+ | | | stack | | heap | | | +--------------+ +--------------+ | | | +-------------------------------------------+ Program --> stored where? as what? Program running stores information (DATA) where? how? ------------------------------------------------------------------------------- 8) Basic Data Structures + VARIABLE +----+ Java Syntax | | <==== 1 - naming rules +----+ - scope x - assignment, operators Pros: Cons: + String - string literals: "abc", "", " ", etc - Strings as objects - java.lang.String in API Some handy tricks: Pros: Cons: + Arrays: - type[][].... var = new type[size1][size2].... - array of arrays in Java Pros: Cons: + Vectors (and ArrayLists): + Lists: - connection of info class Person { private Person friend; public void setFriend(Person p) { friend = p; } } + what else.....? -------------------------------------------------------------------------------