CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 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
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
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
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
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
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
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.
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
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 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 Office hours: M-F 11:00-11:
COSC 120 Computer Programming
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Lecture #4 Agenda Cell phones off & name signs out Review Questions? Objects The birds-and-the-bees talk.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Lecture #4 Agenda Announcements Review Questions? Classes and objects UML class diagrams Creating.
8 November Forms and JavaScript. Types of Inputs Radio Buttons (select one of a list) Checkbox (select as many as wanted) Text inputs (user types text)
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
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.
Introduction to a Programming Environment
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:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 1.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall NEW   NEW 1.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
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
Floating point numerical information. Previously discussed Recall that: A byte is a memory cell consisting of 8 switches and can store a binary number.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
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
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
CS190/295 Programming in Python for Life Sciences: Lecture 1
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
Presentation transcript:

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 1

cell phones off laptops away name signs out 2

Announcements University-wide – no classes prior to 6:00 PM on: –Monday (9/17) – no class, no office hours –Wednesday (9/26) – no class, no office hours Exam #1 on Friday, 9/28 –Bring UB card to exam –No make-up without a valid excuse (medical, family emergency), backed up by written documentation Exam preparation –Sample exam will be posted on Friday next week (9/21) –In-lecture Q&A session on the following Monday (9/24) 3

Roadmap Expressions Variables Types Declarations 4

Computers don’t understand programs expressed in high- level languages  ? Programmer writes a program in a high-level language like Java; for example, the definition of example1.Terrarium is placed in a file named: example1.Terrarium.java

Compilation A compiler translates program to an equivalent low-level form that a computer can understand. Result is placed in a file named: example1.Terrarium.class Compiler translates Programmer writes a program in a high-level language like Java; for example, the definition of example1.Terrarium is placed in a file named: example1.Terrarium.java

Runtime Runtime refers to the time during which a program is executing, or running. Compiler translates

Objects exist only at runtime Objects do not exist while the programmer writes the program, except in their minds. Compiler translates

Classes vs. Objects If objects are the basic building blocks of object-oriented programs, and programmers don’t directly manipulate objects, what do programmers write? They write class definitions (in.java files) Objects are instances of classes. Classes are instantiated only at runtime.

Object communication To put an example1.Caterpillar object inside an example1.Terrarium object, send an “add” message to the example1.Terrarium object. We say we “invoke” (or “call”) the add “method”. > new example1.Terrarium().add(new example1.Caterpillar())

We can add a Caterpillar to the Terrarium like this: new example1.Terrarium().add(new example1.Caterpillar()) We can add an Ant to the Terrarium similarly: new example1.Terrarium().add(new example1.Ant()) Can we add a Caterpillar and an Ant to the same Terrarium? Can we write the following? new example1.Terrarium().add(new example1.Caterpillar()) new example1.Terrarium().add(new example1.Ant()) We can write it, but it won’t do what we want. Q: what happens?

A: Two example1.Terrarium objects are created. –One contains an example1.Caterpillar –The other contains an example1.Ant When adding the Ant, we cannot refer to the Terrarium we added the Caterpillar to, because: –we have no reference to it after adding the Caterpillar 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 ) t. add( a ) (notice ‘t’ used in two places) To do this, we need a variable

Another example: suppose we have a Caterpillar in a Terrarium: 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 12207: 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.

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;

Demonstrate in Eclipse Show variable declarations.

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; example1.Caterpillar c; t = new example1.Terrarium(); c = new example1.Caterpillar(); t.add(c); c.start();

Demonstrate in Eclipse Show legal and illegal assignments. Show complete example.

A bit of review example1.Terrarium t; example1.Caterpillar c; t = new example1.Terrarium(); c = new example1.Caterpillar(); t.add(c); c.start(); What happens in memory?

available used available Something like this! example1.Terrarium t; example1.Caterpillar c; t = new example1.Terrarium(); c = new example1.Caterpillar();

available used used available reserved for variable t available Each declaration is used by the compiler to ensure that memory is set aside for the corresponding variable example1.Terrarium t; example1.Caterpillar c; t = new example1.Terrarium(); c = new example1.Caterpillar();

available used used available reserved for variable t reserved for variable c available Both t and c have space reserved example1.Terrarium t; example1.Caterpillar c; t = new example1.Terrarium(); c = new example1.Caterpillar();

available example1.Terrarium object used used available reserved for variable t reserved for variable c available The value of the new expression is the starting address of the block of memory holding the representation of the newly created object. example1.Terrarium t; example1.Caterpillar c; t = new example1.Terrarium(); c = new example1.Caterpillar();

available example1.Terrarium object used used available reserved for variable c available The assignment stores that value in the space set aside for the variable t example1.Terrarium t; example1.Caterpillar c; t = new example1.Terrarium(); c = new example1.Caterpillar();

Example1.Caterpillar object available example1.Terrarium object used used available available The same applies to the creation of a new example1.Caterpillar object, and the assignment of its reference to the variable c example1.Terrarium t; example1.Caterpillar c; t = new example1.Terrarium(); c = new example1.Caterpillar();