CS Week 2. Jim Williams, PhD

Similar documents
CS 200 Using Objects. Jim Williams, PhD

Welcome to the Primitives and Expressions Lab!

Week 6 CS 302. Jim Williams, PhD

CS Week 2. Jim Williams

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

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Building Java Programs. Introduction to Programming and Simple Java Programs

PRIMITIVE VARIABLES. CS302 Introduction to Programming University of Wisconsin Madison Lecture 3. By Matthew Bernstein

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

Computational Expression

Lec 3. Compilers, Debugging, Hello World, and Variables

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

3. Java - Language Constructs I

Fundamentals of Programming Data Types & Methods

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Topic 4 Expressions and variables

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

CS 11 java track: lecture 1

Software and Programming 1

CT 229 Methods Continued

Inf1-OOP. Textbooks. Who and What. Organizational Issues. Why Java? Course Overview. Hello, World! in Java. Ewan Klein, Perdita Stevens

Getting started with Java

Fall 2017 CISC124 9/16/2017

AP CS Unit 3: Control Structures Notes

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

Chapter 2: Data and Expressions

Lecture Set 4: More About Methods and More About Operators

CS 302: Introduction to Programming

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

Building Java Programs

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

CS111: PROGRAMMING LANGUAGE II

Inf1-OOP. Textbooks. Who and What. Organisational issues. Why Java? Course Overview. Hello, World! in Java

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

( &% class MyClass { }

Building Java Programs

Introduction to Programming Using Java (98-388)

Introduction Basic elements of Java

Building Java Programs

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Course Outline. Introduction to java

CS 200 File Input and Output Jim Williams, PhD

COMP 202 Java in one week

13 th Windsor Regional Secondary School Computer Programming Competition

Lecture Set 4: More About Methods and More About Operators

DM550 Introduction to Programming part 2. Jan Baumbach.

Materials covered in this lecture are: A. Completing Ch. 2 Objectives: Example of 6 steps (RCMACT) for solving a problem.

CS11 Java. Fall Lecture 1

Welcome to the Using Objects lab!

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

CS 200 Arrays, Loops and Methods Jim Williams, PhD

Section 2.2 Your First Program in Java: Printing a Line of Text

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

Lab Session # 1 Introduction to C Language. ALQUDS University Department of Computer Engineering

Software and Programming 1

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Inf1-OP. Course Overview. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. February 26, School of Informatics

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

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Basic Programming Elements

Welcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs

Java Bytecode (binary file)

Midterms Save the Dates!

Announcements. 1. Forms to return today after class:

Chapter 2: Data and Expressions

Welcome to CSE 142! Whitaker Brand. University of Washington, Winter 2018

CS111: PROGRAMMING LANGUAGE II

Darrell Bethea May 25, 2011

Introduction to Computer Science Unit 2. Notes

Computer Science II Lecture 1 Introduction and Background

Full file at

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Lecture 1: Basic Java Syntax

Introduction to Java

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

Elementary Programming

Administrative Stuff. Inf1-OP. Additional help? Who to contact for help? Course Overview

Chapter 5: Methods. by Tony Gaddis. Starting Out with Java: From Control Structures through Objects. Fourth Edition

Computer Components. Software{ User Programs. Operating System. Hardware

Who and what can help? Inf1-OP. Lecturer: Timothy Hospedales TA: Natalia Zon

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

LECTURE 2 (Gaya College of Engineering)

CS 177 Spring 2010 Exam I

Welcome to the Using Objects lab!

Section 2.2 Your First Program in Java: Printing a Line of Text

CS2141 Software Development using C/C++ C++ Basics

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

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

Lecture 2: Operations and Data Types

COMP-202: Foundations of Programming

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

Join the course group CS230-S18! Post questions, answer them if you know the answer!

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

COMP s1 Lecture 1

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

Chapter 02: Using Data

CHAPTER 7 OBJECTS AND CLASSES

last time in cs recitations. computer commands. today s topics.

Chapter 2: Using Data

CPS109 Lab 1. i. To become familiar with the Ryerson Computer Science laboratory environment.

Transcription:

CS 200 - Week 2 Jim Williams, PhD

Society of Women Engineers "Not just for women and not just for engineers; all students are welcome. We are especially looking for more computer science students!" - Emile Wille (Marketing Officer for SWE)

This Week Team Lab: Tuesday or Wednesday Program 1: Due Thursday Lecture: Primitive Data Types and Expressions

Team Labs First meeting this week. 1350 cs and 1370 cs a. 1st floor, around corner from elevators Meet TAs & LAs a. Work in small groups and pairs Discuss Terms, Trace & Explain code Edit-Compile-Run Cycle on the command-line

Pair Programming 2 people working together on 1 computer. One person types, the other provides direction and reviews. Many report more confidence in solution and more enjoyment programming. Important to switch roles (who has the keyboard). Provide respectful, honest and friendly feedback.

Learning to Trace with Java Visualizer Java Visualizer available via our course website or: https://cscircles.cemc.uwaterloo.ca/java_visualize/

Programming Process Users Editor Compiler (Virtual) Machine Hello.java Hello.class Computer Programmer Files

Programming Errors Naming/Saving Editor Syntax/Compile time Compiler Runtime & Logic (Virtual) Machine Hello.java Hello.class Computer Programmer Files

Edit-Compile-Run Cycle From the command-line: notepad javac java

Programming Process Question For the class named Cat, what is the name of the file that the compiler creates and is provided to the Java Virtual Machine to run? Cat.txt Cat.java Cat.class Cat

Learning Programming Lots of little steps that quickly build Not mastering little steps creates bigger steps Goes beyond Remembering and Understanding to Applying, Analyzing, Evaluating and Creating. Goal: Have basic fluency in Java and be able to solve small problems using it.

Primitive Data Types int whole numbers (4 bytes) double floating point numbers (8 bytes) char single character (2 bytes) boolean true or false value (>= 1 bit) less commonly used: float (4), long (8), short (2), byte (1)

Primitive Data Type Conversion Which work? double a = 5; double b = 6.0; int c = 3.0F; float d = b; c = d; d = c; char e = 'A'; int f = e; short s = f; int h = 4 + 10 / 3; int i = 10.0 / 3; int j = (int) 10.0 / 3; double k = (int) 10.0 / 3.0

Operator Precedence & Associativity

Constant public class World { public static void main(string []args) { int size = 3; final int MAX_SIZE = 10;

String class A reference (class), not a primitive data type. Frequently used final String TITLE_PREFIX = "Welcome to "; int week = 2; String welcome = "Week " + week; System.out.println( TITLE_PREFIX + welcome);

What are the values in a, b & c? int a = 5; int b = 7; int c = a; b = c; a = b; a: 5 b: 7 c: 5 a: 5 b: 5 c: 5 a: 5 b: 5 c: 7

What are the values in a, b & c? int a = 2; int b = 1; int c = a + b; a = b; a = c; a: 2 b: 1 c: 3 a: 3 b: 1 c: 3 a: 2 b: 1 c: 2

Swap values in a & b int a = 5, b = 3; Write code to swap values in a & b. a = b; b = a; a = b; c = b; b = a; a = b; b = c; c = a; c = b; b = a; a = c; Google "swapping values without third variable" for many creative ways.

Application: Temperature Conversion (Degrees Fahrenheit 32) x 5 / 9 = Degrees Celsius What symbols have different meanings in Java? What changes must be made to implement this equation in Java?

My List X vs * equals (==) vs assignment (=) value is stored on the left hand side of assignment (=) operator Variables: name areas of computer memory, declare before use, declare type of data, initialize Variable names: start with letter, include letters numbers and _, but no spaces Conventions: camelcasing, spell out names Semicolon at the end of statements

CS Core Principles: Algorithms: A step-by-step set of operations to be performed. Analogy: Recipe, Instructions Abstraction: a technique for managing complexity. Analogy: Automobile, CS200 Computer View

Methods Lots of existing code that you can use rather than writing yourself. To use, "call the method". The method executes (runs) and may return a value.

Calling Class (static) Methods double numints = Math.pow( 2, 32); double root = Math.sqrt( 16); int num1 = 16; int num2 = 3; double result; result = num2 + Math.sqrt( num1);

Defining Methods public class M { //method definition static void mprint() { System.out.println("my print"); public static void main(string []args) { M.mPrint(); // method call.

mprint - which is Call, Definition? static void mprint() { System.out.println("my print"); public static void main(string []args) { mprint(); mprint call then mprint definition mprint definition then mprint call

Argument vs. Parameter public static void main(string []args) { int num = 10; printcount( 23); printcount( num+3); static void printcount(int count) { System.out.println( count);

Is count: Argument or Parameter? public static void main(string []args) { int num = 10; printcount( 23); printcount( num+3); static void printcount(int count) { System.out.println( count); argument parameter

Returning a Value from a Method static int triple(int num) { return num * 3; public static void main(string []args) { int value = 5; int result = triple( value);

Which is called first: calc or println? static int calc(int num) { num -= 33; return num; public static void main(string []args) { int n = 55; System.out.println( calc( n)); calc println error

What prints out? static void calc(int num) { num = 3; public static void main(string []args) { int n = 5; calc( n); System.out.println( n); 3 5 35 error

Return to Converter double degreescelsius; double degreesfahrenheit = 100.0; degreescelsius = (degreesfahrenheit - 32.0) * 5.0 / 9.0;