Lecture 1. Course Overview Types & Expressions

Similar documents
Lecture 1. Course Overview, Python Basics

Lecture 1. Course Overview, Python Basics

Lecture 1. Types, Expressions, & Variables

Lecture 2. Variables & Assignment

Lecture 2: Variables & Assignments

Course Overview, Python Basics

CS/ENGRD 2110 FALL 2018

Lecture 1: Introduction, Types & Expressions

CS/ENGRD 2110 SPRING 2018

CS/ENGRD 2110 SPRING 2019

CS/ENGRD 2110 SPRING 2019

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

QUIZ: What value is stored in a after this

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

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

CS/ENGRD 2110 FALL2017

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims

CS 241 Data Organization using C

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Visual C# Instructor s Manual Table of Contents

Full file at

COMP Primitive and Class Types. Yi Hong May 14, 2015

Declaration and Memory

Midterms Save the Dates!

CIS 110: Introduction to Computer Programming

KOMAR UNIVERSITY OF SCIENCE AND TECHNOLOGY (KUST)

Full file at

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

San José State University Department of Computer Science CS151, Section 04 Object Oriented Design Spring 2018

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

ECE Object-Oriented Programming using C++ and Java

Primitive Data Types: Intro

Bits, Words, and Integers

CS 115 Lecture 4. More Python; testing software. Neil Moore

CHAPTER 3 Expressions, Functions, Output

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

COMP 110 Introduction to Programming. What did we discuss?

CS/ENGRD 2110 SPRING Lecture 3: Fields, getters and setters, constructors, testing

JAVA REVIEW cs2420 Introduction to Algorithms and Data Structures Spring 2015

CSE 115. Introduction to Computer Science I

CS 241 Data Organization. August 21, 2018

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

CS1 Lecture 3 Jan. 18, 2019

Basic Programming Elements

CMPSCI 250: Introduction to Computation. Lecture #1: Things, Sets and Strings David Mix Barrington 22 January 2014

Slide 1 CS 170 Java Programming 1 Expressions Duration: 00:00:41 Advance mode: Auto

Welcome to CS61A! Last modified: Thu Jan 23 03:58: CS61A: Lecture #1 1

CS 115 Data Types and Arithmetic; Testing. Taken from notes by Dr. Neil Moore

Python Programming Exercises 1

Getting started with Java

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

A Java program contains at least one class definition.

Operators. Lecture 3 COP 3014 Spring January 16, 2018

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

LECTURE 3 C++ Basics Part 2

On a 64-bit CPU. Size/Range vary by CPU model and Word size.

Topic 4 Expressions and variables

CIS192: Python Programming

SAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik

Variables and Data Representation

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

ECE 122 Engineering Problem Solving with Java

Lecture 3. Functions & Modules

Expression Evaluation and Control Flow. Outline

Curriculum Map Grade(s): Subject: AP Computer Science

ESc101 : Fundamental of Computing

61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013

Information Science 1

Outline. Data and Operations. Data Types. Integral Types

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

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

These are reserved words of the C language. For example int, float, if, else, for, while etc.

Java Fall 2018 Margaret Reid-Miller

Chapter 2 Working with Data Types and Operators

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Announcements. 1. Forms to return today after class:

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Introduction to Data Structures

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

CS/ENGRD 2110 FALL Lecture 2: Objects and classes in Java

Week 3: Objects, Input and Processing

CPS122 Lecture: From Python to Java

cs1114 REVIEW of details test closed laptop period

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

Information Science 1

Introduction to: Computers & Programming: Review prior to 1 st Midterm

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

Chapter 6 Primitive types

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

Basic Data Types and Operators CS 8: Introduction to Computer Science, Winter 2019 Lecture #2

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

Beijing Jiaotong University CS-23: C++ Programming Summer, 2019 Course Syllabus

Chapter 2: Data and Expressions

Fall 2017 CISC124 9/16/2017

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

CSE 336. Introduction to Programming. for Electronic Commerce. Why You Need CSE336

Transcription:

Lecture 1 Course Overview Types & Expressions

CS 1110 Spring 2012: Walker White Outcomes: Basics of (Java) procedural programming Usage of assignments, conditionals, and loops. Ability to write recursive programs. Basics of (Java) object-oriented programming Ability to write programs using classes. Fluency with Java and the Java API Knowledge of base classes and specifications. Website: www.cs.cornell.edu/courses/cs1110/2012sp/ 1/24/12 Overview, Types & Expressions 2

Intro Programming Classes Compared CS 1110: Java No prior programming experience No calculus Non-numerical problems Later assignments: processing images making games CS 1112: Matlab No prior programming experience One semester of calculus Math & engineering-type problems CS 1110 is required for all later CS courses 1/24/12 Overview, Types & Expressions 3

Related Courses CS 1130: Transition to OO (using Java) CS 1132: Transition to Matlab Require previous experience with programming Self-paced, 1-credit (4 weeks), S/U Engineers take CS1110 CS1132 or CS1112 CS1130 CS 2110: Computers & Programming Also in Java More advanced OO topics Prerequisite: CS 1110 or CS 1130. Could move to CS 1130 if this course is too easy 1/24/12 Overview, Types & Expressions 4

Helping You Succeed: Class Resources Section/labs. In the ACCEL Lab, Carpenter Library 2nd floor. Guided exercises on computer, with TA and consultants walking around, helping. Mandatory. Quizzes. Let you know what material is important for you to know at that point. You will know exactly what the quiz will cover. Everyone expected to get A on each quiz. Lectures: Not just slides. See interactive demos almost every lecture. We try to make it interesting. Course text: (Optional) CD at back of book has 250 2-4 minute lectures. CD missing? Using Mac OS X? See course website. One-on-one sessions beginning 3rd week. Work for 30 minutes with Walker White, TA, or consultant on the computer 1/24/12 Overview, Types & Expressions 5

Helping You Succeed: Class Resources Interludes. Discussion of some aspect of computing, internet, or CS to help you understand the computing world we live in. AEW Workshops. 1 credit, 2 hours. No homework. Small, collaborative classes parallel to course. No class first week. See link on course website, talk to advisors in Olin 167. iclickers. Everyone: get your own clicker. By Thursday. We use them to judge the sense of understanding of the class, to encourage staying alert. Part of your participation grade. Piazza. Our town square, a place to ask and answer questions. Course Management System. Visit cms.csuglab.cornell.edu/ Not listed? Email Betsy Appleton, ea86@cornell.edu, ask to add you to CS 1110 CMS. Include your Cornell netid in your email. 1/24/12 Overview, Types & Expressions 6

Assignments Larger programming tasks (every two weeks) First assignment requires mastery Submit, get feedback, resubmit, until correct Everyone eventually scores 10/10 Later assignments designed to be fun A4: Color models A5: Graphics and drawing A6: Image processing (jpeg, png...) A7: Breakout game 1/24/12 Overview, Types & Expressions 7

Other Course Issues Recitations (Labs) in the Engineering ACCEL LAB ACCEL Lab: into (old) Engineering Library, walk straight until you come to a staircase on your left, go up the stairs. Register for ANY section. But go to one you want. Times of the recitation-labs: Attend ONE of them. Tuesday: 12:20, 1:25, 2:30, 3:35 Wednesday: 12:20, 1:25, 2:30, 3:35 Academic Integrity We ask you not to cheat, in any way, shape, or form. In return, we try to be fair about the amount of work, in grading the work, and in giving you a course grade. See website for more information Do Quiz 0 on Course CMS. 1/24/12 Overview, Types & Expressions 8

Reading for This and Next Lecture Reading: Sections 1.1, 1.2, 1.3. Lab 1 will give you practice with concepts in 1.2. May not understand all the reading because a lot of new terms, but doing the reading will enhance next lecture. Plive (optional): Lesson 0; also Page 1.3, Activity 1-4.1 Summary of lectures all on course website Today and Tuesday: Introduce our IDE, DrJava Introduce types, expressions, and assignments Learn to use DrJava as a fancy calculator 1/24/12 Overview, Types & Expressions 9

DrJava: An IDE for Java IDE: Integrated Development Environment Makes programming easier Other IDEs: Eclipse, NetBeans Analogy: Web Design Tools Could just write pure HTML But design tools make easier DrJava: Interactions pane Works like a calculator Allows us to get started quickly But you still have to understand types 1/24/12 Overview, Types & Expressions 10

How Java Represents Data Everything on a computer reduces to numbers ASCII codes convert letters to numbers Pixel colors are just numbers (red, blue, green) So how can Java tell all these numbers apart? Memorize this definition! Type: Write it down several times. A set of values and the operations on them. Examples of operations: +, /, * The meaning of these depends on the type 1/24/12 Overview, Types & Expressions 11

Type: Set of values and the operations on them Type integer: values:, 3, 2, 1, 0, 1, 2, 3, 4, 5, operations: +,, *, /, unary Type int: A FINITE set of integers values: 2147483648, 2147483647,, 3, 2, 1, 0, 1, 2, 3, 4, 5,, 2147483646, 2147483647 operations: +,, *, % (7 % 3 = remainder when dividing 7 by 3), /, unary Principal: These int operations must yield an int. Example: 1 / 2 rounds toward 0 Why this restriction? 2 31.. 2 31 1 Bounds: Integer.MIN_VALUE-1, Integer.MAX_VALUE+1 1/24/12 Overview, Types & Expressions 12

Type: Set of values and the operations on them Type double: values: Numbers in scientific notation, e.g. 22.3 22.51 * 10 6.00002251 22.51 * 10 6 mantissa exponent Important points: Only approximations to real numbers; can t represent all of them. We must distinguish between type int and double! double numbers always have period or exponent (e.g. 2.0). Can t use notation 10 6. Exponents have to be written differently. 1/24/12 Overview, Types & Expressions 13

Type: Set of values and the operations on them mantissa exponent Type double: values: 22.51E6 equivalent to 22510000 or 22.51 * 10 6 22.51E 6 equivalent to.00002251 or 22.51 * 10 6 An approximation to the real numbers. operations: +,, *, /, unary 1.0/2.0 is 0.5 not 0. Operation / behaves differently for double Double.MIN_VALUE 4.9E-324 Double.MAX_VALUE 1.7976931348623157E308 Smallest POSITIVE value 1/24/12 Overview, Types & Expressions 14

Aside: Why Is It Called double? Historically, real number type was float Short for floating point number Increasing/decreasing the exponent floats the decimal place left or right Mantissas are only allowed so many digits Floats have very small mantissas 111,111.11 1,111,111.11 Doubles allow for double the digits! 1/24/12 Overview, Types & Expressions 15

Casting: Converting Value Types Basic form: (type)value (double) 2 casts 2 to type double. Value is 2.0 Widening cast. Java does it automatically if needed (int) 2.56 casts 2.56 to type int. Value is 2 Narrowing cast. Java never does it automatically because it might lose information. Narrow to wide: int long float double Other examples: (double)(int) 2.56 Value is 2.0 (double) 2.56 Value is 2.56 1/24/12 Overview, Types & Expressions 16

Type: Set of values and the operations on them Type boolean: values: true, false operations:! (not) && (and) (or)!b read not b true if b is false and false if b is true b && c read b and c true if both b and c are true, false otherwise b c, read b or c is true if b is true or c is true, false otherwise i < j i <= j i == j i >= j i > j i!= j evaluate to true or false Cannot cast to or from int, double ==, not = 1/24/12 Overview, Types & Expressions 17

Type: Set of values and the operations on them Type String: values: any sequence of characters operation(s): + (catenation, or concatenation) String literal: sequence of chars in double quotes " abcex3$g<&" or "Hello World! String catenation: "bc" + "fg" Cannot cast to or from the other types + is overloaded: Outcome of x + y depends on type If one operand (x or y) is a String, the other is converted to a String (if necessary) and catenation is done. Otherwise, if one operand is a double, the other is cast to a double (if necessary) and a double addition is done. Otherwise, both operands are ints and an int addition is done. 1/24/12 Overview, Types & Expressions 18

Operator Precedence What is the difference between the following? 2*(1+3) 2*1 + 3 add, then multiply multiply, then add Operations are performed in a set order Parentheses make the order explicit What happens when there aren t parentheses? Operator Precedence: The fixed order that Java processes operators in absence of parentheses 1/24/12 Overview, Types & Expressions 19

Precedence of Java Operators (p. 23) Unary operators: +! Binary arithmetic: * / % Binary arithmetic: + Arithmetic comparisons: < > <= >= Equality relations: ==!= Logical and: && Logical or: You will practice all of these in Lab 1. 1/24/12 Overview, Types & Expressions 20

Function Calls Java supports functions as well A function in an expression is function call Will explain the meaning of this later Function expressions have the form fun(x,y, ) function name argument Basic Java math functions have prefix Math. Examples: Math.sin(2.0) Math.round(3.5) Experiment with this during the first lab 1/24/12 Overview, Types & Expressions 21