Outline. Compiling, interpreting, and running. The C Programming Language. Java vs. C. Administrative trivia Goals of the class Introduction to C

Similar documents
COS 217: Introduction to Programming Systems

The C Programming Language course syllabus associate level

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

System Calls and Standard I/O

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

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

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

The programming language C. sws1 1

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

File Handling. What is a file?

Crash Course in Java

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

Informatica e Sistemi in Tempo Reale

Pemrograman Dasar. Basic Elements Of Java

Introduction to Java

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

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

How To Write Portable Programs In C

Tutorial on C Language Programming

As previously noted, a byte can contain a numeric value in the range Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets!

Computer Programming Tutorial

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)

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

An Overview of Java. overview-1

Java Programming Fundamentals

Java CPD (I) Frans Coenen Department of Computer Science

CSC230 Getting Starting in C. Tyler Bletsch

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

Java Crash Course Part I

1001ICT Introduction To Programming Lecture Notes

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

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

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

CS 106 Introduction to Computer Science I

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

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

CP Lab 2: Writing programs for simple arithmetic problems

C++FA 5.1 PRACTICE MID-TERM EXAM

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

Semantic Analysis: Types and Type Checking

C PROGRAMMING FOR MATHEMATICAL COMPUTING

AP Computer Science Java Subset

6.S096 Lecture 1 Introduction to C

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

C++ Programming Language

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Object Oriented Software Design

J a v a Quiz (Unit 3, Test 0 Practice)

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

Operating Systems. Privileged Instructions

ELEC3730 Embedded Systems Lecture 1: Introduction and C Essentials

Introduction to Java. CS 3: Computer Programming in Java

Object Oriented Software Design

Habanero Extreme Scale Software Research Project

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

Module 816. File Management in C. M. Campbell 1993 Deakin University

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

Chapter 2 Introduction to Java programming

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

ECE 122. Engineering Problem Solving with Java

Moving from CS 61A Scheme to CS 61B Java

C++ INTERVIEW QUESTIONS

Java Interview Questions and Answers

13 File Output and Input

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

Chapter 1 Java Program Design and Development

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

System Calls Related to File Manipulation

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

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

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

So far we have considered only numeric processing, i.e. processing of numeric data represented

Introduction to Programming II Winter, 2014 Assignment 2

Java Basics: Data Types, Variables, and Loops

The Java Virtual Machine (JVM) Pat Morin COMP 3002

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

Keil C51 Cross Compiler

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

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

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

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Object-Oriented Programming in Java

Programming Languages CIS 443

Computer Programming I

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

Programmierpraktikum

How To Use The C Preprocessor

DNA Data and Program Representation. Alexandre David

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

java Features Version April 19, 2013 by Thorsten Kracht

The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

picojava TM : A Hardware Implementation of the Java Virtual Machine

Fundamentals of Programming

Illustration 1: Diagram of program function and data flow

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Transcription:

Outline ompiling, interpreting, and running Administrative trivia Goals of the class Introduction to 1 2 The Programming Language Java vs. Systems programming language Originally used to write Unix and Unix tools Data types and control structures close to most machines Now also a popular application programming language Pros and cons an do whatever you want: flexible and efficient an do whatever you want: can shoot yourself in the foot Abstraction exposes the raw machine Java hides a lot of it Bad things you can do in that you can t do in Java Shoot yourself in the foot (safety) Others shoot you in the foot (security) Ignoring wounds (error handling) Notable features All functions are call-by-value Pointer (address) arithmetic Simple scope structure I/O and memory management facilities provided by libraries History BPL B K&R ANSI 1960 1970 1972 1978 1988 LISP Smalltalk ++ Java 3 Dangerous things you have to do in that you don t in Java memory management: malloc/free Good things that you can do in but you might not; Java makes you objected-oriented methodology Good things that you can t do in but you can in Java portability 4

Java vs. Java vs., cont d Program ompile Run hello.java: public class hello { public static void main(string[] args) { System.out.println( Hello, world ); javac hello.java ls hello.java hello.class java hello Hello, world hello.c: #include <stdio.h> main() { printf( Hello, world\n ); gcc hello.c ls a.out hello.c a.out Hello, world 5 Boolean har type Void type Integer types Floating point types onstant Arrays Bound check boolean char // 16-bit unicode // no equivalent float double byte // 8 bits short // 16 bits int // 32 bits long // 64 bits // 32 bits // 64 bits final int MAX = 1000; int [] A = new int [10]; float [][] B = new float [5][20]; // run-time checking int char /* 8 bits */ void short int long float double #define MAX 1000 int A[10]; float B[5][20]; /* no run-time check */ 6 Java vs., cont d Java vs., cont d Pointer type Record type String type String concatenate Logical ompare Arithmetic Bit-wise ops // no pointer class r { int x; float y; s1 + s2 &&,,! String s1 = Hello ; String s2 = new String( hello ); =,!=, >, <, >=, <= +, -, *, /,, unary - >>, <<, >>>, &,, ^ int *p; struct r { int x; float y; #include <string.h> strcat( s1, s2 ); &&,,! char *s1 = Hello ; char s2[6]; strcpy( s2, hello ); =,!=, >, <, >=, <= +, -, *, /,, unary - >>, <<, &,, ^ omments Block Assignments Function / procedure call Function return Procedure return { Foo( x, y, z ); return 5; return; /* comments */ // another kind statement1; =, *=, /=, +=, -=, <<=, >>=, >>>=, =, ^=, =, = /* comments */ { statement1; =, *=, /=, +=, -=, <<=, >>=, =, ^=, =, = Foo( x, y, z ); return 5; return; 7 8

Java vs., cont d Java vs., cont d onditional Switch if (expression) statement1 else switch (n) { case 1: case 2: default: switch (n) { case 1: case 2: default: if (expression) statement1 else for loop while loop do- while loop Terminate a loop body continue; for (int i=0;i<10;i++) while (expression) do { while (expression) while (expression) continue; int i; for (i=0; i<10; i++) do { while (expression) goto Exception // no equivalent throw, try-catch-finally goto L; /* no equivalent */ Terminate a loop 9 10 Standard I/O Standard I/O in program Three standard I/O streams copyfile.c: #include <stdio.h> Three standard I/O streams Stderr Binding Flexible/dynamic binding of streams to actual devices or files Default binding bound to keyboard and bound to the terminal screen 11 Basic calls for standard I/O int getchar(void); int putchar(int c); int puts(const char *s); char *gets(char *s); Use man pages man getchar a.out < file1 > file2 a.out < file1 a.out > file2 main() { int c; c = getchar(); while (c!= EOF) { putchar(c); c = getchar(); a.out < file1 a.out a.out > file2 12

pipe a.out a.out What s all this good for? In the old days: hard-code input/output devices into programs Hard to program and very hard to port to different input/output devices a.out < file1 a.out > file2 13 14 What s all this good for? program Along came Unix (early 1970s) First OS to have complete features of standard I/O redirection and pipes Standard I/O redirection Write program once Same program can be made to work for different input/output devices at run time Good practice of modularity 15 What s all this good for? program2 program1 Pipes Write small programs that specialize in very simple tasks onnect lots of smaller programs to make bigger programs Makes bigger programs easier to write Earliest and best success story of programming with components Standard I/O redirection and pipes: big part of Unix success Good practice of modularity is a learned art 16

Formatted Output: printf Formatted Input: scanf int printf(char *format, ); Translate arguments into characters according to format Output the formatted string to onversions (read man printf for more) d integer f float lf double 3f float with 3 decimal places percent int scanf(const char *format, ); Read characters from Interpret them according to format and put them into the arguments onversions (read man scanf for more) d integer f float lf double literal Examples int x = 217; printf( ourse number is: d, x ); 17 Example double v; scanf( lf, &v ); int day, month, year; scanf( d/d/d, &month, &day, &year); 18 Standard Error Handing: Example is the second output stream for output errors Some functions to use int fprintf(file *stream, const char *format, ); Same as printf except the file stream int fputc(int c, FILE *stream); putc() is the same as fputc() int fgetc(file *stream); getc() is the same as fgetc() Example fprintf(, This is an error.\n ); fprintf(, This is correct.\n ); printf( This is correct.\n ); #include <stdio.h> const float KMETERS_PER_MILE = 1.609; int main(void) { int miles; float kmeters; printf( miles: ); if ( scanf( d, &miles)!= 1 ) { fprintf(, Error: Expect a number.\n ); exit(1); kmeters = miles * KMETERS_PER_MILE; printf( = f kilometers.\n, kmeters ); 19 20

Summary The goal of this course: Master the art of programming Learn and assembly languages for systems programming Introduction to computer systems It is easy to learn by knowing Java is not object oriented, but many structures are similar Standard I/O functions are quite different from Java s input and output 21