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

Similar documents
CIS 110: Introduction to Computer Programming

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

Outline. CIS 110: Introduction to Computer Programming. Announcements. For Loops. Redundancy in Patterns. A Solution with Our Current Tools

Lecture 1 - Introduction (Class Notes)

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

CSC116: Introduction to Computing - Java

CSC116: Introduction to Computing - Java

! Learn how to think like a computer scientist. ! Learn problem solving. ! Read and write code. ! Understand object oriented programming

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

Fundamentals of Programming. By Budditha Hettige

CIS 110: Introduction to Computer Programming

How to make a "hello world" program in Java with Eclipse *

AP Computer Science A: Java Programming

CS 11 java track: lecture 1

CIS 110: Introduction to Computer Programming. Lecture 2 Decomposition and Static Methods ( 1.4)

CSC116: Introduction to Computing - Java

CS 177 Recitation. Week 1 Intro to Java

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

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

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

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

Lecture 02, Fall 2018 Friday September 7

Building Java Programs. Introduction to Programming and Simple Java Programs

Summer Assignment for AP Computer Science. Room 302

Introduction to Data Structures

Intensive Introduction to Computer Science. Course Overview Programming in Scratch

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

CompSci 125 Lecture 02

Programming with Java

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

Lecture 7. Instructor: Craig Duckett OUTPUT

AP Computer Science A

CSCI455: Introduction to Programming System Design

Week 2: Data and Output

CS 106 Introduction to Computer Science I

Java Bytecode (binary file)

Chapter 2: Programming Concepts

Lecture 1: Introduction to Java

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

COMP-202 Unit 0: Course Details

Computer Hardware. Java Software Solutions Lewis & Loftus. Key Hardware Components 12/17/2013

Lesson 01 Introduction

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

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

CP122 CS I. Chapter 1: Introduction

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

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

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

CS 241 Data Organization using C

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

Chapter 1. Introduction

C02: Overview of Software Development and Java

Lesson 04: Our First Java Program (W01D4

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

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

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

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

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

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

CS 106B, Lecture 1 Introduction to C++

List of Slides 1 Title 2 Chapter 2: Sequential execution and program errors 3 Chapter aims 4 Section 2: Example:Hello world 5 Aim 6 Class: programs ar

Basic Programming Language Syntax

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

Lab # 2. For today s lab:

What is programming? Elements of Programming Languages. From machine code to programming languages. What is a programming language?

CP122 CS I. Hello, World!

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

Entering the world of Javatar

13 th Windsor Regional Secondary School Computer Programming Competition

Chapter 3 Intro to Java

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

Syntax of Variable Declarations. Variables Usages as Expressions. Self-assignment Statements. Assignment. Scoping and Naming Rules

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

UEE1302 (1102) F10: Introduction to Computers and Programming

CMSC 150 LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE HELLO WORLD

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

COMP 110 Project 1 Programming Project Warm-Up Exercise

For the course, we will be using JCreator as the IDE (Integrated Development Environment).

Welcome to CSSE 220. We are excited that you are here:

17 Hello world 18 Type: String: literal 19 Standard API: System: out.println() 20 Hello world 21 Statement 22 Statement: simple statements are ended w

Introduction to Computer Programming

TTh 9.25 AM AM Strain 322

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

Computer Science II Lecture 1 Introduction and Background

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

CHAPTER INTRODUCTION

2 rd class Department of Programming. OOP with Java Programming

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

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

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

CS 161: Object Oriented Problem Solving

Introduction to JAVA

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

Algorithms and Programming I. Lecture#12 Spring 2015

CS11 Java. Fall Lecture 1

Fundamentals of Programming Session 4

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

Transcription:

Outline CIS 110: Introduction to Computer Programming Lecture 1 An introduction of an introduction ( 1.1 1.3)* 1. What is computer science and computer programming? 2. Introductions and logistics 3. The anatomy of a Java program *(no, you shouldn t have read those yet =P) 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 2 What is Computer Science? What is computer programming? What is computer science? (By demonstration!) 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 3 Computer programming is not computer science Programming languages Software engineering Artificial intelligence/machine learning Graphics Computer architecture Compilers Embedded and real-time systems Formal methods Theory of computation Computer security and privacy Databases and data management Operating systems and networking Mobile, distributed, and ubiquitous systems Computational biology Algorithms and complexity analysis Human-computer interaction What unifies all these crazy, different things? 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 4 Algorithmic Thinking Algorithm: a step-by-step procedure to solve a problem Algorithmic thinking: a structured approach to problem solving It represents a universally applicable attitude and skill set everyone, not just computer scientists, would be eager to learn and use. - Jeannette M. Wing (CMU professor) The Three Skills of Algorithmic Thinking Precision Accurately and completely describe how to solve a problem Decomposition Break up a big problem into smaller ones. Abstraction Recognize that several problems are the same. 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 5 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 6 1

How are CS and Programming Related? It has often been said that a person does not really understand something until after teaching it to someone else. Actually a person does not really understand something until after teaching it to a computer, i.e., expressing it as an algorithm. - Donald Knuth What is Computer Programming? Two things for our purposes: A way to practice algorithmic thinking skills in a concrete way A practical skill you can use in your own job While computer programming is not computer science, programming allows us to exercise the core skills that all computer scientists possess. Also, sharpening our algorithmic thinking makes us better programmers! 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 7 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 8 Logistics About me My name: Peter-Michael Osera. Call me whatever you want, e.g., Peter Pete Michael Mike Mikey PM Pete-Moss (Lots more, many inappropriate) I am a 4 th year Ph.D. student (not a professor). Programming languages researcher. Former program manager @ Microsoft (VC++ compiler). Die-hard supporter of e-sports and pro-gaming. 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 9 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 10 CIS 110: the Highlights 2 lecture offerings (11-12 and 1-2) Required lab section (10% of your grade) Required textbook: Building Java Programs: A Back to Basics Approach, Reges and Stepp Piazza message board system No curve, slide if necessary Late day policy (4 late days) 2 exams, 1 final See the syllabus for more details CIS 110 vs. CIS 120 CIS 110 and 120 = the CS intro sequence. Both emphasize algorithmic thinking via programming. CIS 110: Assumes no prior programming experience. Focuses on control issues in programming. Uses the Java programming language. CIS 120: Assumes prior programming experience. Focuses on data representation issues in programming. Initially uses OCaml then goes back to Java. To swap classes, please speak to your instructor. 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 11 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 12 2

What is a Computer Program? Imagine that we need to tell our best friend to do something, but he doesn t speak our language. Computer Programming PUT THE JELLY ON THE BREAD THEN PUT IT ALL IN YOUR MOUTH???? 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 13 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 14 Translation The analogy revealed We can translate our instructions so that our best friend understands them. You (the programmer) The compiler The computer (your new best friend) PUT THE JELLY ON THE BREAD AND THEN PUT IT ALL IN YOUR MOUTH Ilagay ang halaya SA tinapay AT pagkatapos a y ilagay ito LAHAT SA INYONG bibig PUT THE JELLY ON THE BREAD AND THEN PUT IT ALL IN YOUR MOUTH The computer program Ilagay ang halaya SA tinapay AT pagkatapos a y ilagay ito LAHAT SA INYONG bibig Machine code 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 15 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 16 Programming Languages Natural languages (e.g., English) are Ambiguous. Overly general. Difficult to translate (in fact, a big research field!). Solution: create specialized programming languages that are good at specifying instructions to computers. Examples: Ada, Algol, BASIC, C, C++, C#, CLOS, D, Eiffel, Fortran, F#, Haskell, and so many more! The Java Programming Language Created in 1990 by Sun Microsystems Alternative to C/C++ Object-oriented language (Almost) Everything is an object Platform independent Java programs run on Windows, Mac, or Linux Most popular language out there See the TIOBE programming index 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 17 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 18 3

Our First Computer Program Our first computer program. public class HelloWorld { public static void main(string[] args) { System.out.println( Hello World!); (jgrasp demonstration) 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 19 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 20 The Compilation Pipeline (In jgrasp) [Step 2: compile the source code] Running your compiled program Step 3: tell the computer to run your program (In jgrasp) [Step 1: write source code] (Output: Java bytecodes) 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 21 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 22 The structure of a Java Program Syntax, syntax, syntax public class HelloWorld { public static void main(string[] args) { System.out.println( Hello World!); A statement that prints Hello World to the console. Statements are commands to be executed by your program. A class named HelloWorld. For now, classes are containers for our programs. A method named main. main is a special method because this is where the program begins execution. Syntax: the rules to form legal programs Class template public class <name> { Method template public static void <name>( ) { <statement> ; <statement> ; 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 23 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 24 4

Syntax errors Syntax errors occur when you violate a syntax rule. 1 public class HelloWorld { 2 public static void main(string[] args) { 3 System.out.println("Hello World!"); 4 System.out.println() 5 System.out.println("I like pie"); 6 System.out.println("I like pie a lot"); 7 8 Line numbers. Not part of the program. Need to fix syntax errors before your program can be compiled! 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 25 Naming and Identifiers In Java, names have several restrictions. Must not be a reserved keyword (e.g., public, class). Many others, see page 20 of the text for the complete list. Must start with a letter, _ (underscore), or $. Otherwise can contain, letters, numbers, _, or $. E.g., HelloWorld42 is valid, 12HelloWorld is not. Java is a case-sensitive language. E.g., main and Main are different names. The name of a class must match its containing Java file E.g., the HelloWorld class is found in HelloWorld.java 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 26 System.out.println Prints to the screen or console. How to pronounce it: print-lin Two uses: System.out.println( msg ) prints msg to the screen along with a newline. System.out.println() prints a newline. Strings A string is a piece of data that represents text. E.g., to be println ed to the console. Syntax: text goes here Text surrounded by quotes. Restrictions: Cannot span over multiple lines this is a syntax error! Cannot contain a quotation mark when does this string begin and end? 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 27 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 28 Escape sequences Escape sequences allow us to write special characters in strings. Quotation mark: \ Tab character: \t Newline character: \n Backslash: \\ Ex: System.out.println( \\\\\ \ \ \ \\ ); prints \\ \ to the console! 9/6/2011 CIS 110 (11fa) - University of Pennsylvania 29 5