CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 645-4739 1.

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
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall NEW   NEW 1.
Lecture #3 – Agenda Cell phones off & name signs out –I’ll judge signs on Wednesday next week Quick review & Questions Activity Problem solving.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE116: Introduction to Computer Science 2 Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE111: Great Ideas in Computer Science 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 1.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Summary of the lecture We introduced the local variable dependency –This is a binary relationship (a relationship between two classes), similar to instantiation.
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 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:
Lecture #5 Agenda Cell phones off & name signs out Review Questions? UML class diagram introduction Our first class definition!
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
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 1.
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:
CSE111: Great Ideas in Computer Science 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
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 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
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE111: Great Ideas in Computer Science 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 Office hours: M-F 11:00-11:
CSE111: Great Ideas in Computer Science 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
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 1.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE111: Great Ideas in Computer Science 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.
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
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.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 1.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall NEW   NEW 1.
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 1.
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 1.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Presentation transcript:

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

Agenda Announcements –Cell phones off & name signs out –Web-CAT: back up, lab 1 Next week –No new lab, but… hand in lab 1 and do exercises –Monday: review and Q&A –Wednesday: first exam Today –variables –terminology –maybe class definitions

Last time we saw… –how to instantiate a class to create an object new example1.Terrarium() –how to call a method on a newly created object: new example1.Terrarium().add(new example1.Caterpillar())

How do we make the Caterpillar move? We call “start()” on the Caterpillar. How do we do this? Can we write the following? new example1.Terrarium().add(new example1.Caterpillar()) new example1.Caterpillar().start() We can, but it won’t do what we want. Q: what happens?

A: Two example1.Caterpillar objects are created. –One is placed in the example1.Terrarium, and is NOT “started”. –The other is NOT put into the example1.Terrarium, but is “started”. We cannot refer to the Caterpillar we added to the Terrarium, because: –we have no reference to it after adding it. The value of an expression is lost if it is not –used right away, or –remembered.

We want to write something like this: t. add( c ) c. start() (notice ‘c’ used in two places) To do this, we need a variable

A variable is: (at its most basic) a storage location in memory for example, location 120: space for a variable

A variable has: a name a location a type a value a scope a lifetime  in the HLL (Java)  in memory  representation scheme/size  contents We’ll discuss these later

Why are types important? Recall the discussion from early in the semester about how to interpret a string like “ ” – the proper interpretation depends on the encoding scheme (e.g. two’s complement or IEEE754) The type of a variable tells the compiler, among other things, which encoding schemed to use to read/write data from/to the variable. It also tells us what methods we can call.

Why are names important? The location of a variable in memory is not known until runtime. The name of a variable allows us to refer to the variable without knowing where in memory the variable might end up. Names make programs easier to write and to read/understand.

Variable declaration A variable declaration consists of two basic things: –the type of the variable –the name of the variable Java insists that all variables be declared before use (not all languages require this).

The variable declaration Consists minimally of: type & name What is a type? A class is a type. –Remember: objects are instantiated from classes. Examples of variable declarations: example1.Terrariumt; example1.Caterpillar c;

Naming conventions CamelCase ( camel hump at start of each word ) –lower case letter to start –letter or digit follows –each new word, except first, capitalized Examples: t myTerrarium theVeryHungryCaterpillar

Syntax (a little more formal) variable declarations appear in many places in Java programs a variable declaration in Java –ALWAYS has: type identifer In our example –type identifier ; –semicolon is a terminator

We have a variable… … so now what? After we declare a variable, we need to assign a value to it. We do that using an assignment statement. Unlike an expression, a statement has no value.

assignment statement variable = expression ; ‘=’ is the ASSIGNMENT OPERATOR Example: t = new example1.Terrarium();

Syntax example1.Terrarium t; t = new example1.Terrarium(); example1.Caterpillar c; c = new example1.Caterpillar(); t.add(c); c.start();

Live demo in DrJava Created two example1.Caterpillar objects: –each has the same: set of properties (e.g. location, direction, color) set of capabilities (we only saw “start()”) –each has its own: values for its properties; Caterpillars… –…are at distinct locations –…move independently of each other –…happen to have the same color (green)

available 112 available 108 available used used Terrarium object Caterpillar object available

Object diagram (corresponding to memory diagram on previous slide) example1.Terrarium example1.Caterpillar t c Boxes denote variables Ovals denote objects Arrows denote references This diagram is an abstraction of the one on the previous slide: it ignores irrelevant details, such as the addresses and sizes of the two objects being shown. An abstraction is thus a simplification.