CS/ENGRD 2110 SPRING 2019

Similar documents
CS/ENGRD 2110 FALL 2018

CS/ENGRD 2110 SPRING 2019

CS/ENGRD 2110 SPRING 2018

CS/ENGRD 2110 FALL2017

Lecture 1. Course Overview Types & Expressions

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

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

Lecture 2: Variables & Assignments

Lecture 1. Course Overview, Python Basics

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

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

Announcements. 1. Forms to return today after class:

Lecture 1. Course Overview, Python Basics

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

Getting started with Java

CS112 Lecture: Primitive Types, Operators, Strings

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

CIS192: Python Programming

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

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

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

Announcements. Course Staff. Course Staff. Lectures 10/19/11. CS/ENGRD 2110 Fall Instructor. Administrative Assistant

Visual C# Instructor s Manual Table of Contents

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

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

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

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

Fall 2017 CISC124 9/16/2017

Lecture 1. Types, Expressions, & Variables

Computer Science 210: Data Structures

CPS122 Lecture: From Python to Java

Course Overview, Python Basics

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS61A Lecture 1. Amir Kamil UC Berkeley January 23, 2013

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

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

Full file at

TA hours and labs start today. First lab is out and due next Wednesday, 1/31. Getting started lab is also out

CS 241 Data Organization. August 21, 2018

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

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

Chapter 2: Data and Expressions

Introduction to Data Structures

1.00 Tutorial 1. Introduction to 1.00

CSE 142. Lecture 1 Course Introduction; Basic Java. Portions Copyright 2008 by Pearson Education

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

CS 1110, LAB 1: PYTHON EXPRESSIONS.

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

CS1 Lecture 3 Jan. 22, 2018

Full file at

Introduction to Nate Foster Spring 2018

Object-Oriented Programming for Managers

1.00/1.001 Tutorial 1

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

CS1 Lecture 3 Jan. 18, 2019

Declaration and Memory

Values, Variables, Types & Arithmetic Expressions. Agenda

These are notes for the third lecture; if statements and loops.

COMP 110 Introduction to Programming. What did we discuss?

Introduction to Computer Systems

Assignment 7: Due Wednesday May 11 at 6pm UPDATES on Monday May 9

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

Advanced Programming Concepts. CIS 15 : Spring 2007

Consolidation and Review

Primitive Types. Four integer types: Two floating-point types: One character type: One boolean type: byte short int (most common) long

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

Express Yourself. The Great Divide

CIS192 Python Programming. Robert Rand. August 27, 2015

Lecture 2. Variables & Assignment

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

Welcome to CS 115 (Winter 2018)

CIS 110: Introduction to Computer Programming

Sixth lecture; classes, objects, reference operator.

CS 3813/718 Fall Python Programming. Professor Liang Huang.

Summer Assignment for AP Computer Science. Room 302

Type Checking and Type Equality

Welcome to CS 115 (Winter 2019)

Outline. Logistics. Logistics. Principles of Software (CSCI 2600) Spring Logistics csci2600/

Announcements. Written Assignment 2 due today at 5:00PM. Programming Project 2 due Friday at 11:59PM. Please contact us with questions!

Chapter 2 Basic Elements of C++

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

Under the Hood: Data Representation. Computer Science 104 Lecture 2

COM S 211 Computers and Programming (also ENGRD 211)

MEAP Edition Manning Early Access Program Get Programming with Java Version 1

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

CMPE012 Computer Engineering 12 (and Lab) Computing Systems and Assembly Language Programming. Summer 2009

CS/ENGRD 2110 SPRING 2018

Chapter 2 Elementary Programming

CS 140 Programming with Objects

Lab 1: Setup 12:00 PM, Sep 10, 2017

Princeton University. Computer Science 217: Introduction to Programming Systems. Data Types in C

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

Lexical Structure (Chapter 3, JLS)

Lesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

COMP-202: Foundations of Programming. Lecture 5: More About Methods and Data Types Jackie Cheung, Winter 2016

WELCOME! (download slides and.py files and follow along!) LECTURE 1

CS1 Lecture 13 Feb. 13, 2019

Object Oriented Programming. Week 1 Part 1 An introduction to Java, Objects and JUnit

Transcription:

CS2110 2 THERE IS ROOM IN THE BALCONY! Romeo, Romeo, where art thou! Up in the balcony, where it s cheaper! CS/ENGRD 2110 SPRING 2019 Object-oriented programming, reasoning about complex problems Testing; Reasoning about correctness Program development Algorithmic complexity, analyzing algorithms, Data structures: linked lists, trees, hash tables, graphs, etc. Programming paradigms: recursion, parallel execution Lecture 1: Overview and intro to types http://courses.cs.cornell.edu/cs2110/2019sp 3 Email from July 2017! I m a rising junior studying I took 2110 in Sp 2016. At the time, I couldn t appreciate everything I was taught and how they were taught I was mostly preoccupied with completing the assignments and passing. But I m starting to realize how terrific a job you and the entire 2110 staff did teaching the material. I m at Verizon as a software engineering intern. Doing JUnit testing has become very routine; it was stressed heavily in 2110. I ve had to use basically all my knowledge of Java and OO programming for my internship, and I can safely say that I would be screwed if I hadn t taken 2110. While taking 2100, a lot of peers (including myself) were frustrated at how we had to master all the subtle nuances of Java. But now I confidently say that I am so thankful that I know all these concepts. 4 Usefulness of 2110 This summer I'm working in particle physics, making simulations of some of the background signal we d expect to see in our detector for an experiment run in the particle accelerator. What I'm working on a clustering algorithm to put together energy depositions from several quantized points in the detector to learn what the initial particle's energy and position was. After some thought, I decided the best first sweep over this data would be to do a depth first search starting about a high energy deposition in the calorimeter. It works great, and my PI was very excited about the results! Usefulness of 2110 Is CS2110 right for you? 5 6 I am working at a startup in Silicon Valley this summer that does subscription-based financial management and billing among other things. It has been pretty incredible the amount I've learned from your class that relates to this internship and I have definitely decided to pursue computer science (I was initially engineering physics). Knowledge of Java not required Only ~30% of you know Java others know Matlab, Python Requirement: comfort with some programming language, on the level of CS1110 (Python based) and CS1112 (Matlab based). Prior knowledge of OO not required. We assume you do not know Java! If you know Java, the first 3 weeks will be easier for you but you STILL have to learn things, probably unlearn some things, too! 1

7 Welcome to CS2110! 405 Freshmen 158 Sophomores 058 Juniors 031 Seniors 039 Meng/Masters 025 PhD 716 Total As of Fri evening, 18 Jan OO Programming and Data Structures Instructors: Michael Clarkson David Gries Recitation leaders (TAs): 23 Consultants: 21 Letter grade: 688 S/U grade: 22 AUDIT: 6 8 Lectures TR 10:10-11am, Statler auditorium Attendance mandatory ENGRD 2110 or CS 2110? Same course! We call it CS 2110 in online materials Non-engineers sign up for CS 2110 Engineers should sign up for ENGRD 2110 Sections (Recitations) 9 T 12:20 4 sections: T 1:25 T 2:30 2 sections: 2 sections: T 3:35 2 section: W 12:20 3 sections: W 01:25 3 sections: W 02:30 2 sections: W 07:30 1 section: Some time EARLY, visit StudentCenter and change your section to even out the numbers Attendance mandatory Sometimes flipped: you watch videos beforehand, come to recitation and do something Sometimes review, help on homework, new material No permission needed to switch sections, but do register for whichever one you attend 10 Recitation this week Eclipse essentials Practice with common types DO BEFOREHAND: o Install Java, Eclipse, DrJava (optional) o Watch tutorials on API & String Coursework Assignments: a real learning experience 11 7 8 programming assignments (37%) Two prelims (14% and 16%) Final exam (30%) Course evaluation (1%) Work in recitations (1-3%) Formula will change as course progresses and we make changes in assignments, give quizzes, etc. Exams are most important aspect in determining final grade 12 Teams of one or two A0 and then A1 will be posted soon on the CMS Finding a partner: choose your own or contact your TA. Piazza can be helpful. One way to do an assignment: Wait until the day before it is due. Result: Frustration, anger, impatience, long lines in consulting room. No fun. Not a good educational experience 2

Assignments: a real learning experience 13 One way to do an assignment: Read the handout immediately. Work on it every (other) day. Ponder. Look things up. Get help in consulting room, with no lines, or office hours. Fun, hard work, a great learning experience Piano lessons: Practice Daily? Or put off practicing until an hour before weekly lesson? 14 Academic Integrity Trust but verify! 99% of you are honest and don t try to cheat We use artificial intelligence tools to check some assignments, so catch the other 1% The software is accurate! It tests your code and notices similarities between code written by different people Sure, you can fool this software but it s easier to just do the assignments and if you try to fool it and screw up, you might fail the assignment or even the whole course. Resources Piazza 15 JavaHyperText. Course website: Link on Links or Resources page http://www.cs.cornell.edu/courses/javaandds/definitions.html Java resource: online materials at Oracle JDK web site https://docs.oracle.com/javase/8/docs/api/index.html?java/lan g/object.html 16 Click link on our links web page to register Incredible resource for 24 x 7 help with anything We keep an eye on it and answer questions. YOU can (and will) too. Visit the Piazza often. CS2111 Obtaining Java and Eclipse 17 An enrichment course Help students who might feel overwhelmed by CS2110 Gives more explanation of core ideas behind Java, programming, data structures, assignments, etc. Taught by Bracy, Gries, and a TA, 1 credit S/U Only for students who also take CS2110 Only requirement: Attend weekly lecture I would just like to thank you for taking the time to hold CS2111 this year. You have no idea how the class helped and impacted a lot of us. I would never had "survived" CS2110 without your generous share of your knowledge. I appreciated your time. 18 Follow instructions on our Resources web page Make sure you have Java JDK 1.8, if not download and install. We explain how on the web page. Then download and install the Eclipse IDE Test it out: launch Eclipse and click new>java Project This is one of a few ways Java can be used When program runs, output is visible in a little console window 3

19 DrJava IDE IDE: Integrated Development Environment DrJava is a much simpler IDE, few features We use it only to demo Java features and programming concepts. Has an interactions pane, which allows trying things without requiring a complete Java program. Great tool! DON T use it for course assignments use Eclipse Download jar file from links page of course website 20 Homework! Homework 1. Read article Why Software is So Bad. Link: Course website -> Lectures notes (Lecture 1) Homework 2. Get Java, Eclipse, DrJava on your computer. Homework 3. Spend some time perusing the course website. Look at course information, resources, links, etc. Homework 4. BEFORE EACH LECTURE/RECITATION: download pdf form of the slides, bring to class and look at them during lecture. We project not only PPT but also Eclipse and other things. Having PPT slides in paper form or on your laptop/tablet can help you during the lecture. Assignment A0 21 Introduction to Java, Eclipse, and the assert statement Due 123123123123 January at 11:59pm Submit on CMS 22 23 Relevant JavaHyperText Entries type primitive type type, strong versus weak typing cast function procedure variable expression function call procedure call assignment statement unicode variable declaration 24 Type: Set of values together with operations on them. Type integer: values:, 3, 2, 1, 0, 1, 2, 3, operations: +,, *, /, unary Can represent them in many ways decimal, binary, octal, maybe as strokes (that s 4) Do you know how your computer represents them? 4

25 Type: Set of values together with operations on them. Java Type int: values: 2 31.. 2 31 1 b % c : remainder when b is divided by c. 67 % 60 = 7 Integer.MAX_VALUE: name for max int value: 2 31 1: 2147483647 26 About int int: values: 2 31.. 2 31 1, i.e. Java Principle: A basic operation of type int must produce an int Integer.MAX_VALUE: name for max int value: 2 31 1: 2147483647 Integer.MAX_VALUE + 1 is 2 31 : 2147483648 WRAP-AROUND What do you think happens when Integer.MAX_VALUE + 1 is evaluated?. Talk to neighbors about possibilities. Know Java? KEEP QUIET Java designers decided on this Principle: primitive operations on type int should yield an int. Types in Java Most-used primitive types 27 Primitive Types Classes 28 int: values: 2 31.. 2 31 1 b % c : remainder when b is divided by c. 67 % 60 = 7 Fully integrated into Java We'll cover these today! We'll talk about these on Thursday double: values like : 22.51E6, 24.9 Write values in scientific notation char: values like : 'V' '$' '\n' operations: none Use single quotes for type char. '\n' is new-line char boolean: values: true false operations:! (not), && (and), (or) Can t use integers as booleans! 29 Primitive number types Integer types: byte short int long 1 byte 2 bytes 4 bytes 8 bytes Real types: float double 22.51E6 4 bytes 8 bytes 24.9 Use these to save space. Have an array of 1,000,000 integers in range 0..7? Use a byte array rather than an int array usual operators usual operators Don t worry about this in next 7-8 weeks. Use int and double. 30 Type: Set of values together with operations on them. Matlab and Python are weakly typed: One variable can contain at different times a number, a string, an array, etc. One isn t so concerned with types. Java strongly typed: A variable must be declared before it is used and can contain only values of the type with which it is declared Illegal assignment: Hello is not an int Valid Python sequence: x= 100; x= Hello World ; x= (1, 2, 3, 4, 5 ); Corresponding Java int x; x= 100; x= Hello ; Declaration of x: x can contain only values of type int 5

Weakly typed versus strongly typed 32 Basic variable declaration 31 Weakly typed: Shorter programs, generally. Programmer has more freedom, language is more liberal in applying operations to values. Strongly typed: Programmer has to be more disciplined. Declarations provide a place for comments about variables. More errors caught at compile-time (e.g. it s a syntax error to assign a string to an int variable). Note: weak and strong typing not well defined; literature has several definitions 32 Declaration: gives name of variable, type of value it can contain int x; double area; int[] a; x 5 int area Declaration of x, can contain an int value Declaration of area, can contain a double value Declaration of a, can contain a pointer to an int array. We explain arrays much later 20.1 double a int[] 33 Assignment statement 34 Assignment statement type restriction 33 Much like in other languages need ; at end: <variable>= <expression> ; int x; x= 10; other code x= x+1; Have to declare x before assigning to it. 34 Every expression has a type, which depends on its operators and the types of its operands in a natural way. Rule: In x= e; type of e has to be same as or narrower than type of x. Reason: To avoid possibly losing info without the programmer realizing it. double y= 5 + 1; int x= 75.5 + 1; The value of 5+1 is automatically cast from type int to type double. Illegal: The exp value is of type double. int x= 10; other code x= x+1; Can combine declaration with an initializing assignment. Shorthand for a declaration followed by an assignment. int x= (int) (75.5 + 1); You can cast to int explicitly. 76 will be stored in x. 35 Casting among types 36 char is a number type! 35 36 (int) 3.2 casts double value 3.2 to an int char is a number type: (int) 'V' (char) 86 any number type any number expression narrow may be automatic cast wider byte short int long float double (int) is a unary prefix operator, just like must be explicit cast, may truncate 3 evaluates to 3 (int) 3.2 evaluates to 3 Unicode repr. in decimal: 86 'V' Unicode: 16-bit char repr. Encodes chars in just about all languages. In java, use hexadecimal (base 16) char literals: '\u0041' is 'A' '\u0042' is 'B' '\u0056' is 'V' '\u0024' is $' '\u0950' is 'ॐ '\u5927' is ' ' '\u885b' is ' ' Om, the sound of the universe is (I think) a transliteration of David into Chinese (Da Wei) See www.unicode.org 6

37 A function in Matlab, Python, and Java 37 function s = sum(a, b) % Return sum of a and b s= a + b; def sum(a, b): """ return sum of a and b""" return a + b /** return sum of a and b */ public static double sum(double a, double b) { return a + b; } return type Matlab Python Specification: in comment before function Declarations of parameters a and b 7