CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

Similar documents
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

OO software systems are systems of interacting objects.

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CS111: PROGRAMMING LANGUAGE II

CS171:Introduction to Computer Science II

Tutorials. Tutorial every Friday at 11:30 AM in Toldo 204 * discuss the next lab assignment

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

Building Java Programs

CS171:Introduction to Computer Science II

Building Java Programs. Chapter 2: Primitive Data and Definite Loops

Building Java Programs

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

Enumerated Types. CSE 114, Computer Science 1 Stony Brook University

Getting started with Java

Public-Service Announcements

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Lecture Set 4: More About Methods and More About Operators

Java Basic Programming Constructs

H212 Introduction to Software Systems Honors

Expressions and Control Statements

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

CS 106 Introduction to Computer Science I

Research Group. 2: More types, Methods, Conditionals

Lecture Set 4: More About Methods and More About Operators

COMP-202: Foundations of Programming. Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016

Object-Oriented Design Lecture 14 CSU 370 Fall 2007 (Pucella) Friday, Nov 2, 2007

Controls Structure for Repetition

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

Administration. Objects and Arrays. Objects. Agenda. What is an Object? What is a Class?

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Lecture 2: Operations and Data Types

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015

Java Simple Data Types

Flow of Control Branching 2. Cheng, Wei COMP May 19, Title

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Lec 7. for loops and methods

Programming in the Small II: Control

APCS Semester #1 Final Exam Practice Problems

Chapter 4: Control Structures I

Programming with Java

CS 61B Data Structures and Programming Methodology. June David Sun

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

Building Java Programs

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

CS313D: ADVANCED PROGRAMMING LANGUAGE

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CS 106A, Lecture 5 Booleans and Control Flow

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Simple Java Reference

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Pull Lecture Materials and Open PollEv. Poll Everywhere: pollev.com/comp110. Lecture 12. else-if and while loops. Once in a while

Lexical Considerations

COMP 202 Java in one week

Following is the general form of a typical decision making structure found in most of the programming languages:

COMP-202: Foundations of Programming. Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015

Course Outline. Introduction to java

Programming Basics. Digital Urban Visualization. People as Flows. ia

Units 0 to 4 Groovy: Introduction upto Arrays Revision Guide

Announcements. 1. Forms to return today after class:

Public-Service Announcements

CS1150 Principles of Computer Science Boolean, Selection Statements

CS111: PROGRAMMING LANGUAGE II

Array Elements as Function Parameters

CSE 114 Computer Science I

Building Java Programs Chapter 2

Datatypes, Variables, and Operations

Object-Oriented Programming

1. An operation in which an overall value is computed incrementally, often using a loop.

Lexical Considerations

Administrivia. Last modified: Fri Aug 25 10:59: CS61B: Lecture #2 1

( &% class MyClass { }

CSE 113 A. Announcements - Lab

Programming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester

CIS133J. Working with Numbers in Java

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Key Java Simple Data Types

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Fall 2017 CISC124 9/16/2017

Topic 4 Expressions and variables

Lecture 14. 'for' loops and Arrays

Control Structures in Java if-else and switch

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

CSE 142, Summer 2014

Introduction to Java & Fundamental Data Types

CSE 142, Summer 2015

Michele Van Dyne Museum 204B CSCI 136: Fundamentals of Computer Science II, Spring

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

Transcription:

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Tuesday 10:00 AM 12:00 PM * Wednesday 4:00 PM 5:00 PM Friday 11:00 AM 12:00 PM OR request appointment via e-mail *Tuesday adjustments: 11:00 AM 1:00 PM on 10/11, 11/1 and 12/6

Dr. Carl Alphonce Last time Primitives ROADMAP Today Control structures Coding exercises! Coming up Collections

ANNOUNCEMENT Dr. Carl Alphonce

Dr. Carl Alphonce Registration closes this Sunday (10/23) @ 11:59PM Reserve your spot as soon as possible!

REVIEW Dr. Carl Alphonce

primitive type: boolean the boolean type has two values, true and false boolean operators: && (and), (or) and! (not) examples: P Q P && Q P Q!Q true true true true false true false false true true false true false true - false false false false - boolean x; x = true; boolean y = false; boolean z = x && y; // declaration // assignment // combined // using && operator

the int type includes integral values in a given range (we ll return to this in a later lecture): 0, +1, -1, +2, -2, primitive type: int int operators: +, integer addition (operator type is int int à int), integer subtraction (operator type is int int à int) *, integer multiplication (operator type is int int à int) /, integer division (quotient) (operator type is int int à int) %, integer remainder (operator type is int int à int) examples: int x = 5; int y = 3; int q = x / y; // q has value 1 int r = x % y; // r has value 2 // note: x = q * y + r

MOVING ON Dr. Carl Alphonce

static members: methods and variables static methods a static method is invoked on a class, rather than an object a static method has no access to instance variables its invocation record has no this static variables a static variable is accessed via a class, rather than an object a static variable is often declared public a static variable is often given a name of all upper-case letters, as in java.awt.color.red

public static void main(string[] args) { } main method main method is standard entry point for a Java program main method is invoked by Java runtime system static reserved word indicates member is associated with CLASS not INSTANCE parameter of main square brackets are special syntax used with arrays we will discuss arrays at start of CSE116 the parameter args is initialized with command line arguments arguments given on the command line when the program is run

The System class is defined in the java.lang package. System.out.println The name System can therefore be used in an unqualified way, even without an explicit import directive. out is a public and static variable of the System class, whose type is PrintStream The PrintStream class defines a static method named println println accepts an argument of any type, and prints a textual representation of the argument on the console (see the output in the console view if running in Eclipse, or the terminal window from which the program was started if running outside of Eclipse).

CONTROL STRUCTURES Dr. Carl Alphonce

requirements for a language to be a programming language Recall that not every language is a programming language A programming language must be able to express sequence In Java selection repetition sequence can be expressed by the order of statements and the nesting of expressions selection can be expressed by conditional statements (if statement, ifelse statement), as well as by polymorphism repetition can be expressed by looping statements (while statement, for statement, foreach statement) There are additional ways in which selection and repetition can be expressed (e.g. pattern matching, unification / recursion)

Control structures conditional statements (SELECTION) if-else statement if statement loop statements (REPETITION) while statement (while loop) for statement (for loop)

Dr. Carl Alphonce Control Structures à selection à if-else statement

if ( <expr> ) <stmt 1 > else <stmt 2 > if-else statement <stmt 2 > Control structure overview if-else statement false true <expr> <stmt 1 >

if-else statement example public void message(int x) { if (x == 4) { System.out.println(" leaf clover!"); } else { System.out.println("Sorry :-("); } System.out.println("Play again!"); }

Dr. Carl Alphonce Control Structures à selection à if statement

Control structure overview if statement if ( <expr> ) <stmt> if statement <expr> false true <stmt>

if-else statement example public void message(int x) { if (x == 4) { System.out.println(" leaf clover!"); } System.out.println("Play again!"); }

Dr. Carl Alphonce PAIR CODING EXERCISE PREP

Dr. Carl Alphonce

Dr. Carl Alphonce

Dr. Carl Alphonce

Dr. Carl Alphonce

Dr. Carl Alphonce

Dr. Carl Alphonce

Dr. Carl Alphonce

Dr. Carl Alphonce

PAIR CODING EXERCISE Define a class quiz.question. In this class define a method named answer. Dr. Carl Alphonce Define this method so that it returns true if its int argument is negative, and false otherwise. Submit to Exercise-01 in Web-CAT enter the usernames of everyone in your group! You have 8 minutes to complete this exercise.

PAIR CODING EXERCISE Define a class quiz.question. In this class define a method named answer. Dr. Carl Alphonce Define this method so that it returns true if its int argument is negative, and false otherwise. Submit to Exercise-01 in Web-CAT enter the usernames of everyone in your group! You have 8 minutes to complete this exercise.