COS 217: Introduction to Programming Systems



Similar documents
Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

How To Write Portable Programs In C

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

The programming language C. sws1 1

6.S096 Lecture 1 Introduction to C

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

CSC230 Getting Starting in C. Tyler Bletsch

AP Computer Science Java Subset

Object Oriented Software Design

Basic Programming and PC Skills: Basic Programming and PC Skills:

CS 253: Intro to Systems Programming

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Pemrograman Dasar. Basic Elements Of Java

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

1001ICT Introduction To Programming Lecture Notes

Informatica e Sistemi in Tempo Reale

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Programming Languages

ECE 122. Engineering Problem Solving with Java

CSCI 3136 Principles of Programming Languages

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Crash Course in Java

C / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Computer Programming I

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

CS 106 Introduction to Computer Science I

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

public static void main(string[] args) { System.out.println("hello, world"); } }

CSC 2405: Computer Systems II

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

CS 51 Intro to CS. Art Lee. September 2, 2014

Moving from CS 61A Scheme to CS 61B Java

CSE 307: Principles of Programming Languages

Introduction to Java

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

Chapter 1 Java Program Design and Development

The C Programming Language course syllabus associate level

Java Programming Fundamentals

C++ Programming Language

The Java Virtual Machine and Mobile Devices. John Buford, Ph.D. Oct 2003 Presented to Gordon College CS 311

Compiler Construction

02-201: Programming for Scientists

Sources: On the Web: Slides will be available on:

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Java Crash Course Part I

Canisius College Computer Science Department Computer Programming for Science CSC107 & CSC107L Fall 2014

An Overview of Java. overview-1

Sample CSE8A midterm Multiple Choice (circle one)

Lecture 1: Introduction

Simple C Programs. Goals for this Lecture. Help you learn about:

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Virtual Servers. Virtual machines. Virtualization. Design of IBM s VM. Virtual machine systems can give everyone the OS (and hardware) that they want.

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

El Dorado Union High School District Educational Services

Introduction to Scientific Computing Part II: C and C++ C. David Sherrill School of Chemistry and Biochemistry Georgia Institute of Technology

A Python Tour: Just a Brief Introduction CS 303e: Elements of Computers and Programming

CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

Syllabus for CS 134 Java Programming

Contents. Java - An Introduction. Java Milestones. Java and its Evolution

Object Oriented Software Design

El Dorado Union High School District Educational Services

picojava TM : A Hardware Implementation of the Java Virtual Machine

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

9/11/15. What is Programming? CSCI 209: Software Development. Discussion: What Is Good Software? Characteristics of Good Software?

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

The Java Virtual Machine (JVM) Pat Morin COMP 3002

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Keil C51 Cross Compiler

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Semester Review. CSC 301, Fall 2015

Data Structures Lecture 1

csce4313 Programming Languages Scanner (pass/fail)

Java CPD (I) Frans Coenen Department of Computer Science

An Incomplete C++ Primer. University of Wyoming MA 5310

Semantic Analysis: Types and Type Checking

CISC 181 Project 3 Designing Classes for Bank Accounts

Konzepte objektorientierter Programmierung

Government Girls Polytechnic, Bilaspur

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

CS1010 Programming Methodology A beginning in problem solving in Computer Science. Aaron Tan 20 July 2015

CS 40 Computing for the Web

Installing Java (Windows) and Writing your First Program

Chapter 13 Storage classes

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Conditions & Boolean Expressions

Computer Programming Tutorial

Transcription:

COS 217: Introduction to Programming Systems 1 Goals for Todayʼs Class Course overview Introductions Course goals Resources Grading Policies Getting started with C C programming language overview 2 1

Introductions Instructor-of-Record Vivek Pai, Ph.D. (Professor) vivek@cs.princeton.edu Preceptors (in alphabetical order) Robert Dondero, Ph.D. (Lead Preceptor) rdondero@cs.princeton.edu Sunha Ahn sahn@princeton.edu Dushyant Arora dushyant@cs.princeton.edu Sasha Koruga skoruga@cs.princeton.edu Meng Zhang mengz@princeton.edu 3 Course Goal 1: Programming in the Large Goal 1: Programming in the large Help you learn how to write large computer programs Specifically, help you learn how to: Write modular code Hide information Manage resources Handle errors Write portable code Test and debug your code Improve your codeʼs performance (and when to do so) Use tools to support those activities 4 2

Course Goal 2: Under the Hood Goal 2: Look under the hood Help you learn what happens under the hood of computer systems Specifically, two downward tours C Language Assembly Language language levels tour Application Program Operating System service levels tour Machine Language Hardware Goal 2 supports Goal 1 Reveals many examples of effective abstractions 5 Course Goals: Why C? Q: Why C instead of Java? A: C supports Goal 1 better C is a lower-level language C provides more opportunities to create abstractions C has some flaws Cʼs flaws motivate discussions of software engineering principles A: C supports Goal 2 better C facilitates language levels tour C is closely related to assembly language C facilitates service levels tour Linux is written in C 6 3

Course Goals: Why Linux? Q: Why Linux instead of Microsoft Windows? A: Linux is good for education and research Linux is open-source and well-specified A: Linux is good for programming Linux is a variant of Unix Unix has GNU, a rich open-source programming environment 7 Course Goals: Summary Help you to become a... Power Programmer!!! 8 4

Resources: Lectures and Precepts Lectures Describe concepts at a high level Slides available online at course Web site Stronger influence on exams Precepts Support lectures by describing concepts at a lower level Support your work on assignments Builds practically on a subset of information Important: Precepts begin TODAY 9 Resources: Website and Listserv Website Access from http://www.cs.princeton.edu Academics Course Schedule COS 217 Piazza http://piazza.com/class#spring2012/cos217/ Instructions provided in first precept 10 5

Resources: Books Required book C Programming: A Modern Approach (Second Edition), King, 2008. Covers the C programming language and standard libraries Highly recommended books The Practice of Programming, Kernighan and Pike, 1999. Covers programming in the large (Required for COS 333) Computer Systems: A Programmer's Perspective (Second Edition), Bryant and O'Hallaron, 2010. Covers under the hood Some key sections are on electronic reserve First edition is sufficient Programming with GNU Software, Loukides and Oram, 1997. Covers tools All books are on reserve in Engineering Library 11 Resources: Manuals Manuals (for reference only, available online) IA32 Intel Architecture Software Developer's Manual, Volumes 1-3 Tool Interface Standard & Executable and Linking Format Using as, the GNU Assembler See also Linux man command man is short for manual For more help, type man man 12 6

Resources: Programming Environment Option 1 hats.princeton.edu Friend Center 016 or 017 Computer Linux GNU SSH Your Pgm fez fedora Lab TAs 13 Resources: Programming Environment Option 2 hats.princeton.edu Your PC/Mac/Linux Computer Linux GNU SSH Your Pgm fez fedora 14 7

Resources: Programming Environment Other options Use your own PC/Mac/Linux computer; run GNU tools locally; run your programs locally Use your own PC/Mac/Linux computer; run a non-gnu development environment locally; run your programs locally Etc. Notes Other options cannot be used for some assignments (esp. timing studies) Instructors cannot promise support of other options Strong recommendation: Use Option 1 or 2 for all assignments First precept provides setup instructions 15 Grading Seven programming assignments (50%) Working code Clean, readable, maintainable code On time (penalties for late submission) Final assignment counts double (12.5%) Exams (40%) Midterm (15%) Final (25%) Class participation (10%) Lecture and precept attendance is mandatory 16 8

Programming Assignments Programming assignments 1. A de-comment program 2. A string module 3. A symbol table module 4. IA-32 assembly language programs 5. A buffer overrun attack 6. A heap manager module 7. A Unix shell Key part of the course See course Schedule web page for due dates/times First assignment is available now Advice: Start early to allow time for debugging (especially in the background while you are doing other things!) 17 Why Debugging is Necessary 18 9

Policies Study the course Policies web page! Especially the assignment collaboration policies Violation involves trial by Committee on Discipline Typical penalty is suspension from University for 1 academic year Some highlights: Donʼt view anyone elseʼs work during, before, or after the assignment time period Donʼt allow anyone to view your work during, before, or after the assignment time period In your assignment readme file, acknowledge all resources used Ask your preceptor for clarifications if necessary 19 Course Schedule Very generally Weeks Lectures Precepts 1-2 Intro to C (conceptual) Intro to Linux/GNU Intro to C (mechanical) 3-6 Pgmming in the Large Advanced C 6 7 Midterm Exam Recess 8-13 Under the Hood Assembly Language Pgmming Assignments Reading Period Final Exam See course Schedule web page for details 20 10

Any questions before we start? 21 C vs. Java: History We will use Not yet popular; our compiler supports only partially 1960 1970 1972 1978 1989 1999 BCPL B C K&R C ANSI C89 ISO C90 ISO/ANSI C99 LISP Smalltalk C++ Java 22 11

C vs. Java: Design Goals Java design goals Support object-oriented programming Allow same program to be executed on multiple operating systems Support using computer networks Execute code from remote sources securely Adopt the good parts of other languages (esp. C and C++) Implications for Java Good for application-level programming High-level Virtual machine insulates programmer from underlying assembly language, machine language, hardware Portability over efficiency Security over efficiency Security over flexibility 23 C vs. Java: Design Goals C design goals Support structured programming Support development of the Unix OS and Unix tools As Unix became popular, so did C Implications for C Good for system-level programming But often used for application-level programming sometimes inappropriately Low-level Close to assembly language; close to machine language; close to hardware Efficiency over portability Efficiency over security Flexibility over security 24 12

C vs. Java: Design Goals Differences in design goals explain many differences between the languages Cʼs design goal explains many of its eccentricities Weʼll see examples throughout the course 25 C vs. Java: Overview Dennis Ritchie on the nature of C: C has always been a language that never attempts to tie a programmer down. C has always appealed to systems programmers who like the terse, concise manner in which powerful expressions can be coded. C allowed programmers to (while sacrificing portability) have direct access to many machine-level features that would otherwise require the use of assembly language. C is quirky, flawed, and an enormous success. While accidents of history surely helped, it evidently satisfied a need for a system implementation language efficient enough to displace assembly language, yet sufficiently abstract and fluent to describe algorithms and interactions in a wide variety of environments. 26 13

C vs. Java: Overview (cont.) Bad things you can do in C that you canʼt do in Java Shoot yourself in the foot (safety) Shoot others in the foot (security) Ignore wounds (error handling) Dangerous things you must do in C that you donʼt in Java Explicitly manage memory via malloc() and free() Good things you can do in C, but (more or less) must do in Java Program using the object-oriented style Good things you canʼt do in C but can do in Java Write completely portable code 27 C vs. Java: Details Remaining slides provide some details Suggestion: Use for future reference Slides covered briefly now, as time allows 28 14

C vs. Java: Details (cont.) Overall Program Structure Building Hello.java: Java public class Hello { public static void main(string[] args) { System.out.println( "Hello, world"); % javac Hello.java % ls Hello.class Hello.java % hello.c: #include <stdio.h> C int main(void) { printf("hello, world\n"); return 0; % gcc217 hello.c % ls a.out hello.c % Running % java Hello Hello, world % % a.out Hello, world % 29 C vs. Java: Details (cont.) Java C Character type char // 16-bit unicode char /* 8 bits */ Integral types Floating point types Logical type Generic pointer type byte short int long // 8 bits // 16 bits // 32 bits // 64 bits float // 32 bits double // 64 bits boolean // no equivalent void* Constants final int MAX = 1000; (unsigned) char (unsigned) short (unsigned) int (unsigned) long float double long double /* no equivalent */ /* use integral type */ #define MAX 1000 const int MAX = 1000; enum {MAX = 1000; 30 15

C vs. Java: Details (cont.) Java C Arrays Array bound checking Pointer type Record type int [] a = new int [10]; float [][] b = new float [5][20]; int a[10]; float b[5][20]; // run-time check /* no run-time check */ // Object reference is an // implicit pointer class Mine { int x; float y; int *p; struct Mine { int x; float y; 31 C vs. Java: Details (cont.) Java C Strings String concatenation String s1 = "Hello"; String s2 = new String("hello"); s1 + s2 s1 += s2 Logical ops &&,,! &&,,! char *s1 = "Hello"; char s2[6]; strcpy(s2, "hello"); #include <string.h> strcat(s1, s2); Relational ops =,!=, >, <, >=, <= =,!=, >, <, >=, <= Arithmetic ops +, -, *, /, %, unary - +, -, *, /, %, unary - Bitwise ops >>, <<, >>>, &,, ^ >>, <<, &,, ^ Assignment ops =, *=, /=, +=, -=, <<=, >>=, >>>=, =, ^=, =, %= =, *=, /=, +=, -=, <<=, >>=, =, ^=, =, %= 32 16

C vs. Java: Details (cont.) Java C if stmt switch stmt if (i < 0) statement1; else statement2; switch (i) { case 1:... break; case 2:... break; default:... if (i < 0) statement1; else statement2; switch (i) { case 1:... break; case 2:... break; default:... goto stmt // no equivalent goto SomeLabel; 33 C vs. Java: Details (cont.) Java C for stmt while stmt do-while stmt for (int i=0; i<10; i++) statement; while (i < 0) statement; do { statement; while (i < 0) int i; for (i=0; i<10; i++) statement; while (i < 0) statement; do { statement; while (i < 0); continue stmt continue; continue; labeled continue stmt continue SomeLabel; /* no equivalent */ break stmt break; break; labeled break stmt break SomeLabel; /* no equivalent */ 34 17

C vs. Java: Details (cont.) return stmt Compound stmt (alias block) return 5; return; { Java statement1; statement2; return 5; return; { C statement1; statement2; Exceptions throw, try-catch-finally /* no equivalent */ Comments Method / function call /* comment */ // another kind f(x, y, z); someobject.f(x, y, z); SomeClass.f(x, y, z); /* comment */ f(x, y, z); 35 Example C Program #include <stdio.h> #include <stdlib.h> const double KMETERS_PER_MILE = 1.609; int main(void) { int miles; double kmeters; printf("miles: "); if (scanf("%d", &miles)!= 1) { fprintf(stderr, "Error: Expect a number.\n"); exit(exit_failure); kmeters = miles * KMETERS_PER_MILE; printf("%d miles is %f kilometers.\n", miles, kmeters); return 0; 36 18

Summary Course overview Goals Goal 1: Learn programming in the large Goal 2: Look under the hood Goal 2 supports Goal 1 Use of C and Linux supports both goals Learning resources Lectures, precepts, programming environment, course listserv, textbooks Course Web site: access via http://www.cs.princeton.edu 37 Summary Getting started with C C was designed for system programming Differences in design goals of Java and C explain many differences between the languages Knowing C design goals explains many of its eccentricities Knowing Java gives you a head start at learning C C is not object-oriented, but many aspects are similar 38 19

Getting Started Check out course Web site soon Study Policies page First assignment is available Establish a reasonable computing environment soon Instructions given in first precept 39 20