CS 121 Intro to Programming:Java - Lecture 2. Professor Robert Moll (+ TAs) CS BLDG

Similar documents
CS 121 Intro to Programming:Java - Lecture 2. Professor Robert Moll (+ TAs) CS BLDG


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

CS 121 Intro to Programming:Java - Lecture 4 Course home page:

CSC116: Introduction to Computing - Java

Chapter 1. Introduction to Computers and Programming. M hiwa ahmad aziz

CSC116: Introduction to Computing - Java

Announcements. 1. Forms to return today after class:

CompSci 125 Lecture 02

Survey #2. Variable Scope. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings. Scope Static.

Introduction to Data Structures

Java Basics Lecture: January 26, 2012 (On-line Lecture 1)

Introduction. Lecture 1 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

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

Survey #2. Teen Talk Barbie TM Reloaded. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Partially Filled Arrays ArrayLists

Introduction to Computation and Problem Solving

CSC116: Introduction to Computing - Java

Computer Science II Data Structures

CHAPTER 1 Introduction to Computers and Java

Introduction. Introduction to OOP with Java. Lecture 01: Introduction to OOP with Java - AKF Sep AbuKhleiF -

Introduction to Software Development (ISD) David Weston and Igor Razgon

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2015

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

CS 106B, Lecture 1 Introduction to C++

II. Compiling and launching from Command-Line, IDE A simple JAVA program

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016

Programs as Models. Procedural Paradigm. Class Methods. CS256 Computer Science I Kevin Sahr, PhD. Lecture 11: Objects

Midterms Save the Dates!

Midterms Save the Dates!

Announcements. Course syllabus Tutorial/lab signup form (due 4pm today) Lecture 1 notes Homework 1 Initial assessment

CS110/CS119 Introduction to Computing (Java) Bob Wilson S-3-176

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History

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

EECS168 Exam 3 Review

Lecture 1: Overview & Intro to Java

CS 432 Fall Mike Lam, Professor. Compilers. Advanced Systems Elective

Survey #2. Assignment #3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings. Static Interface Types.

Searching for Information. A Simple Method for Searching. Simple Searching. Class #21: Searching/Sorting I

CS61BL. Lecture 1: Welcome to CS61BL! Intro to Java and OOP Testing Error-handling

Midterms Save the Dates!

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

Welcome to CS 115 (Winter 2018)

Lecture 02, Fall 2018 Friday September 7

AP Computer Science A: Java Programming

Software Construction

Tutorial 1 CSC 201. Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

More on Objects February 2, 2012

Chapter 1 Introduction to Computers, Programs, and Java

Lesson 01 Introduction

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

ECOR Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

COMP Computer Basics. Yi Hong May 13, 2015

AP Computer Science Summer Work Mrs. Kaelin

Programming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11

AP Computer Science Unit 1. Writing Programs Using BlueJ

Week 2: Data and Output

Introduction to Computer Science Unit 2. Notes

Controls Structure for Repetition

Welcome to CompSci 201

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

CS 6371: Advanced Programming Languages

Operating Systems CMPSC 473. Introduction January 15, Lecture 1 Instructor: Trent Jaeger

Midterms Save the Dates!

Welcome to CS 135 (Winter 2018)

AP Computer Science Unit 1. Writing Programs Using BlueJ

Index. Course Outline. Grading Policy. Lab Time Distribution. Important Instructions

CSE 240 Introduction to Computer Architecture

AP Computer Science A

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

Midterms Save the Dates!

Java Programming. Zheng-Liang Lu. Java 301 Summer Department of Computer Science & Information Engineering National Taiwan University

CS 241 Data Organization. August 21, 2018

COMP 215: INTRO TO PROGRAM DESIGN. Prof. Chris Jermaine Chris Prof. Chris Dr. Chris

Anatomy of a Java Program: Comments

Welcome to CS 115 (Winter 2019)

Welcome to... CS113: Introduction to C

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

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Structured Programming

Languages and Compilers

CIS 130 Exam #2 Review Suggestions

PeerWise Study. Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Constants Using Classes and Objects

CS 113 PRACTICE FINAL

Computer Programming-1 CSC 111. Chapter 1 : Introduction

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

Review: Array Initializer Lists

Overview of the Class

Introduction to Java Unit 1. Using BlueJ to Write Programs

CS61C C/Assembler Operators and Operands Lecture 2 January 22, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson)

Midterms Save the Dates!

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

Using Classes and Objects. Lecture 7. Midterms Save the Dates! Extra Credit Survey

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

Introduction to Computer Systems

Programming by Delegation

assembler Machine Code Object Files linker Executable File

Introduction to Computer Systems

Transcription:

CS 121 Intro to Programming:Java - Lecture 2 Course home page: Professor Robert Moll (+ TAs) CS BLDG 276-545-4315 moll@cs.umass.edu http://twiki-edlab.cs.umass.edu/bin/view/moll121/webhome First OWL assignment was due today First programming assignment is up, due Friday at 5. Office hours are off and running today - see website Also: survey; OWL #2; Read Ch 3 for next Tuesday! Honors section: meet me after class!!!!

Course Materials: No textbook. We re using a (free!) electronic book Additional features: the Wiki - the web world for course administration OWL - heavyweight assignment system IDE - Dr Java is the class s integrated development environment

Is this the right class for you? Do you know how to program in any language? (if you do, consider 191B..) Do you know your way around your computer? (RAM, downloading, text files, applications, spreadsheets, Excel, secondary storage, byte, Internet, www ) If many of these terms/concepts are a stretch, consider taking CS 105, CS 120, CS 145.. How s your math? You need to be comfortable with basic math, logic, compound interest, simple logic Do you want to take this class? If you re here because you need an R2, you ve got the wrong course. This one s too hard. Do an easier R2. (Also - if you re a computer art student, see me after class)

More Administration The class is organized into four discussion sections The grading formula: Embedded Questions: 8% Programming assignments: 20% OWL assignments: 15% Midterm exam: 21% Final Exam: 36% Also: to get C in the course, you must get at least a C on final! Collaboration- unless otherwise stated: conceptual collaboration ok, do your own coding (more on this later) System: You ll need Java 1.5 (1.6) You ll need Dr Java. Information about this online

The layout of the course: Tuesday: a big-picture lecture day Thursday - Discussion - will be just that: discussion, + a fast-paced interactive problem-solving experience. You are expected to attend class - but roll isn t taken. Miss classes and lectures at your own peril. Bring your brains. For Thursday: Do second homework assignment! Bring your questions!

The pieces of the class The textbook The IDE - Dr Java The website (has: office hours, assignments, lec notes, etc) OWL weekly hwk Programming projects 2 exams Lecture Discussion Office hours

Hardware / Software Hardware is easy - it s the physical computer - the chips, the buses, and so forth. Software is more subtle - it s the pattern of instructions that directs the hardware: Knitting Origami Travel instructions Chili recipe Fact of Life: in the computer world, hardware can vary!

Why Java? Designed for big projects, complexity control Machinery for programming the web Hardware neutral (more or less) Object-oriented means: main currency are objects (rather than simply statements) Objects are realizations of blueprints, called classes There are libraries of thousands of these, waiting to be recycled

public class Howto{ // a baby intro example public static void main(string args[]) { System.out.println("Welcome to 121"); System.out.println("3 + 5"); System.out.println(3 + 5); } } Prints: Welcome to 121 3 + 5 8

Errors Compile-time errors - syntax, type errors Run-time errors - divide by 0 Logic errors - Everything works fine - get wrong answer System.out.println(5 + 3; System.out.println(5/0); System.out.println( area = + + (3 * radius));

How + works 3 + 5 -> 8 three + five -> threefive three + 5 -> three5 three + 5 -> three 5 three + (5 + 4) -> three9 three + 5 + 4 -> three54 5 + three + 4 -> 5three4

Languages, translators, and computing Our little program is actually incomprehensible to a computer How can a language for programming that s fairly natural for humans (e.g. Java) be faithfully converted into machine language gibberish? For languages such as Java, the translator is called a compiler. 01011010101011 01011010101011 <--- machine language! 11010101101010 10000000000011

There s a problem: My machine language (a Mac, with a PowerPC G4 processor) Is different from your machine language (a Windows machine, with an Intel processor) Can a program that s been compiled on my machine run on your machine (which has a very different machine language)??

Two translation styles Compiler (War & Peace, Russian -> English) Interpreter (Simultaneous translator at the U.N.) Compiled translation presents problems: a compiled program on my computer may not run on your computer - my machine language may be different from your machine language. Java has a solution that (mostly) handles this portability issue: Two step translation from Java source code to machine level object code

Bytecode compiler Java Virtual Machine (JVM) Source Code: Howto.java Bytecode: Howto.class Running program Step 1: Source code is compiled into a universal machine language called bytecode. Step 2: Each machine invokes its special interpreter for bytecode, which produces that computer s running machine code

Java s Object Model This subject will occupy us for a good deal of the next month or so!

The Object Model We model things as objects Objects have attributes, and behaviors Trip (attributes: start, end, days, distance) (behaviors: getdays, setdays, distperday..) Horse (attributes: name, breed, age, height) (behaviors: getage, setage..) Car House Student Tree

Where are all of these characteristics written down? Answer: In a class declaration or definition A class declaration for an object is different from an object, in the same way that the blueprint for a house is different from a house. Still - How do you make an object? How do you invoke its behaviors?

Infant objects Attributes name age (in months) Behaviors getname getage anothermonth (make kid one month older)

public class InfantTester{ public static void main (String[] args){ Infant mykid = new Infant( Kit,4); System.out.println( name: + mykid.getname()); mykid.anothermonth(); System.out.println("my kid is now + mykid.getage()); } }

Broadly, two kinds of behaviors: Tell or get behaviors - how old s the kid, what s the kid s name, what s the kid s weight in ounces, what s the kid s weight in kilos. These do queries, calculations, reports.. Tell behaviors do NOT change the calling object Mutating behaviors - These alter the calling object - a name is changed, an age is increased, a car s gas tank is filled, etc. When a mutator does what it does, the state of the calling object changes.

public class Infant{ private String name; private int age; // in months public Infant(String who, int months){ name = who; age = months; } public String getname(){return name;} public int getage(){return age;} } public void anothermonth(){age = age + 1;}

Assignment Statements and Identifiers An identifier is the name of a variable (or method, or class..) int number = 7; // number now holds 7 number = 4; // number now holds 4 number = number + 2; // number now holds 6 Assignment is NOT equality! Assignment is an action operator: Compute the RHS, Then copy the result to the variable named on the LHS