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

Similar documents
Building Java Programs. Chapter 1: Introduction to Java Programming

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

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

Introduction to Computer Programming

Building Java Programs

Building Java Programs Chapter 1

Building Java Programs Chapter 1

Entering the world of Javatar

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

Outline. CIS 110: Introduction to Computer Programming. What is Computer Science? What is computer programming? What is computer science?

Building Java Programs

Building Java Programs. Introduction to Programming and Simple Java Programs

Lecture 1: Basic Java Syntax

CS 112 Introduction to Programming

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

Static Methods & Decomposition

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Lecture 7. Instructor: Craig Duckett OUTPUT

Introduction to Data Structures

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Computer Science II Lecture 1 Introduction and Background

Programming with Java

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Basic Programming Language Syntax

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

Lab # 2. For today s lab:

CSc 2310 Principles of Programming (Java) Jyoti Islam

CS 106B, Lecture 1 Introduction to C++

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 8: SEP. 29TH INSTRUCTOR: JIAYIN WANG

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

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

CSC116: Introduction to Computing - Java

Creating and Running Your First C# Program

EEE-425 Programming Languages (2013) 1

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

Central Washington University Department of Computer Science Course Syllabus

CSC116: Introduction to Computing - Java

Why do some students find programming in C, so difficult? It involves thinking. We have been programmed by our respective school boards not to think.

Full file at

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

Building Java Programs. Introduction to Java Programming

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

CS 241 Data Organization. August 21, 2018

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

Creating a Program in JCreator. JCreator is then used to create our program. But the first step is to create a new file.

CSE 240 Introduction to Computer Architecture

Software and Programming 1

Java Bytecode (binary file)

CS 231 Data Structures and Algorithms, Fall 2016

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

CSE 114, Computer Science 1 Course Information. Spring 2017 Stony Brook University Instructor: Dr. Paul Fodor

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

Announcements. 1. Forms to return today after class:

Midterms Save the Dates!

CSC 172 Data Structures and Algorithms. Fall 2017 TuTh 3:25 pm 4:40 pm Aug 30- Dec 22 Hoyt Auditorium

Welcome to CompSci 201

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to:

CSE 240 Introduction to Computer Architecture

CS 177 Recitation. Week 1 Intro to Java

CS 241 Data Organization using C

Lesson 1A - First Java Program HELLO WORLD With DEBUGGING examples. By John B. Owen All rights reserved 2011, revised 2015

Week 2: Data and Output

CMSC 150 LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE HELLO WORLD

You must pass the final exam to pass the course.

CHAPTER INTRODUCTION

CSE 332: Data Abstractions. Ruth Anderson Spring 2014 Lecture 1

Syllabus COSC-051-x - Computer Science I Fall Office Hours: Daily hours will be entered on Course calendar (or by appointment)

Introduction to JAVA

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 9: OCT. 4TH INSTRUCTOR: JIAYIN WANG

St. Edmund Preparatory High School Brooklyn, NY

Overview of the Class

EECS 282 Information Systems Design and Programming. Atul Prakash Professor, Computer Science and Engineering University of Michigan

COMP 202 Java in one week

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

(0) introduction to the course. how to learn a programming language. (0) course structure

Software and Programming 1

Advanced Programming Concepts. CIS 15 : Spring 2007

Darrell Bethea May 25, 2011

CompSci 125 Lecture 02

CSC116: Introduction to Computing - Java

Lesson 2A Data. Data Types, Variables, Constants, Naming Rules, Limits. A Lesson in Java Programming

CS 161: Object Oriented Problem Solving

Welcome to... CS113: Introduction to C

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

Introduction to Computer Science I

CS 374 Fall 2014 Homework 2 Due Tuesday, September 16, 2014 at noon

EECS 282 Information Systems Design and Programming. Atul Prakash Professor, Computer Science and Engineering University of Michigan

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

Overview of the Class

COMP 401 COURSE OVERVIEW

COMP 110 Project 1 Programming Project Warm-Up Exercise

Tips from the experts: How to waste a lot of time on this assignment

CS11 Java. Fall Lecture 1

AP Computer Science A: Java Programming

CS 161: Object Oriented Problem Solving

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

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

Transcription:

CSE 142 Lecture 1 Course Introduction; Basic Java

Welcome Today: Course mechanics A little about computer science & engineering (CSE) And how this course relates Java programs that print text 2

Handouts Anonymous survey Non-anonymous survey: to your TA Syllabus: read it carefully and entirely Turn in surveys at end of class 3

Course Information Two instructors; one course Lectures Core material; see programs developed Often spend time writing code rather than the slides Section Required (attendance = 1 homework assignment) Examples; practice Textbook Required; written exactly for this course Allows lectures/section to focus on design rather than details Python sessions: optional (more details later) 4

Course Resources Many resources for students http://www.cs.washington.edu/142 all resources, slides, example programs, etc. IPL: Mary Gates room 334 Your TA Instructions for downloading course software Videos on publisher s textbook site Practice-It! Discussion Board 5

Homework & Exams Weekly homework assignments Very related to lectures, section, textbook Usually due Tuesday evening (see syllabus for late days) Graded by your TA 50% of your grade Midterm (20%) and final (30%) No make-ups Open book, open notes Samples, review sessions, etc. later Grade questions TAs can fix obvious errors For more complex issues, request a regrade 6

Academic Integrity Do not cheat in our class! Vigorous enforcement out of fairness for most students We use homework-comparison software Discussing the general terms of the homework and the overall approach is allowed and helpful, but Assignments are individual effort Never share code or walk through a detailed approach Do not get line-by-line help Giving too much help is as bad as receiving it Full explanation in the syllabus read it carefully 7

Advice / expectations, part 1 Attend lecture on-time and well-rested 9:28 / 11:28 much more useful than 9:35 / 11:35 Do not pack up at 10:19, 12:19 (unfair to neighbors) Take lecture notes or otherwise participate actively Keep up with textbook reading Work through section-handout problems Start homework early Basically, eat your vegetables But also have fun this is great stuff so enjoy it! 8

Advice / expectations, part 2 Be open to this course changing your life Software has changed everything: science, engineering, social science, business, economics, advertising, politics, communication, Course is important for non-cse majors Many students discover an interest in CS and the CSE major via this course Example: Grossman never wrote a program before college Course designed for students with no experience Great to be a tortoise instead of a hare 9

End of mechanics Questions about course logistics? 10

Welcome Today: Course mechanics A little about computer science & engineering And how this course relates Java programs that print text 11

Myths CSE majors spend lives in dark offices alone writing code CSE is only about lines and lines of details CSE is not creative CSE is only for people that want to work at large software companies All the jobs moved to Bangalore See: http://www.cs.washington.edu/whycse 12

Another view "Computer science is no more about computers than astronomy is about telescopes. Edsger Dijkstra Computer science & engineering is about many things: Automating the organization and analysis of information Examples: Degrees of Facebook separation / driving directions Problem solving Logical thinking Being very precise: software does exactly what you say With many subspecialties: Graphics, robotics, computational biology, ubiquitous computing, artificial intelligence, programming languages, large-scale data processing, human-computer interaction, much, much more 13

Programming Writing programs is a big part of what CSE people do Also design them, evaluate them, improve them, etc. Writing programs often-but-not-always the fun part Involves taking the basic idea and doing it exactly A really useful skill for everyone CSE142 is an introduction to programming How to write and debug short programs Key features and techniques used in programming Specifying and automating tasks 14

Java We need a language for writing down programs English is far too imprecise Java is one such programming language There are 1000s of others, but sticking with one makes sense for an introductory course Python is another (optional sessions) Java is an industrial-strength language The real world writes 1,000,000-line programs with it Rich libraries (e.g., graphics) and tools (e.g., JGrasp) Advantages and disadvantages for learning Learning to steer on a fighter jet instead of a tricycle 15

Four layers You are going to learn a lot of things 1. Fundamental ideas bigger than CSE Example: Break a problem into logical pieces 2. Fundamental ideas of CSE Example: Repeat execution with slightly different data 3. Fundamental ideas of programming Example: Using a loop to do repeated execution 4. Precise details of Java you just have to get right Example: Where to use ( and ) versus { and } All 4 layers matter. The layers can help organize the material. 16

Welcome Today: Course mechanics A little about computer science & engineering And how this course relates Java programs that print text 17

Basic Java programs with println statements reading: 1.2-1.3 self-check: #5-14 exercises: #1-4

Compiling/running a program 1. Write it. code or source code: The set of instructions in a program. 2. Compile it. compile: Translate a program from one language to another. byte code: The Java compiler converts your code into a format named byte code that runs on many computer types. 3. Run (execute) it. output: The messages printed to the user by a program. source code compile byte code run output 19

A Java program public class Hello { public static void main(string[] args) { System.out.println("Hello, world!"); System.out.println(); System.out.println("This program produces"); System.out.println("four lines of output"); } } Its output: Hello, world! This program produces four lines of output 20

Structure of a Java program class: a program public class name { public static void main(string[] args) { statement; } } statement;... statement; method: a named group of statements statement: a command to be executed Every executable Java program consists of a class, that contains a method named main, that contains the statements (commands) to be executed 21

System.out.println A statement that prints a line of output on the console. pronounced "print-linn" sometimes called a "println statement" for short Two ways to use System.out.println : System.out.println("text"); Prints the given message as output. System.out.println(); Prints a blank line of output. 22

Names and identifiers You must give your program a name. public class Lecture1 { Naming convention: capitalize each word (e.g. MyClassName) Your program's file must match exactly (Lecture1.java) includes capitalization (Java is "case-sensitive") identifier: A name given to an item in your program. must start with a letter or _ or $ subsequent characters can be any of those or a number legal: _myname TheCure ANSWER_IS_42 $bling$ illegal: me+u 49ers side-swipe Ph.D's Cannot be keywords (see the text) 23

Syntax syntax: The set of legal structures and commands that can be used in a particular language. Every basic Java statement ends with a semicolon ; The contents of a class or method occur between { and } syntax error (compiler error): A problem in the structure of a program that causes the compiler to fail. Examples: Missing semicolon Too many or too few { } braces Illegal identifier for class name Class and file names do not match... 24

Syntax error example 1 public class Hello { 2 pooblic static void main(string[] args) { 3 System.owt.println("Hello, world!")_ 4 } 5 } Compiler output: Hello.java:2: <identifier> expected pooblic static void main(string[] args) { ^ Hello.java:3: ';' expected } ^ 2 errors The compiler shows the line number where it found the error. The error messages can be tough to understand! 25

Strings string: A sequence of characters to be printed. Starts and ends with a quote character: " The quotes do not appear in the output. Examples: "hello" "This is a string. It's very long!" Restrictions: May not span multiple lines. "This is not a legal String." May not contain a " character. "This is not a "legal" String either." 26

Escape sequences escape sequence: A special sequence of characters used to represent certain special characters in a string. \t tab character \n new line character \" quotation mark character \\ backslash character Example: System.out.println("\\hello\nhow\tare \"you\"?\\\\"); Output: \hello how are "you"?\\ 27

Questions What is the output of the following println statements? System.out.println("\ta\tb\tc"); System.out.println("\\\\"); System.out.println("'"); System.out.println("\"\"\""); System.out.println("C:\nin\the downward spiral"); Write a println statement to produce this output: / \ // \\ /// \\\ 28

Answers Output of each println statement: \\ ' """ C: in a b c he downward spiral println statement to produce the line of output: System.out.println("/ \\ // \\\\ /// \\\\\\"); 29

Questions What println statements will generate this output? This program prints a quote from the Gettysburg Address. "Four score and seven years ago, our 'fore fathers' brought forth on this continent a new nation." What println statements will generate this output? A "quoted" String is 'much' better if you learn the rules of "escape sequences." Also, "" represents an empty String. Don't forget: use \" instead of "! '' is not the same as " 30

Answers println statements to generate the output: System.out.println("This program prints a"); System.out.println("quote from the Gettysburg Address."); System.out.println(); System.out.println("\"Four score and seven years ago,"); System.out.println("our 'fore fathers' brought forth on"); System.out.println("this continent a new nation.\""); println statements to generate the output: System.out.println("A \"quoted\" String is"); System.out.println("'much' better if you learn"); System.out.println("the rules of \"escape sequences.\""); System.out.println(); System.out.println("Also, \"\" represents an empty String."); System.out.println("Don't forget: use \\\" instead of \"!"); System.out.println("'' is not the same as \""); 31

Some concepts Writing your first Java program involves a lot of details public static void main (String [] args) { } where to put semicolons Escape sequences etc. A couple key concepts Execute a sequence of commands Represent strings using particular rules Important because you might want characters literally that mean something else in Java This literal vs. not distinction is common in programming 32