CS100J, Fall 2001 Tues 9/4 Lecture 2 ------------------------------------------------------------------------------- Announcements: + new? See Overview on www.cs.cornell.edu/Courses/cs100j/2001fa/! + Project 1 (P1) due Thurs 9/6 + Staff page on website being updated this week + CW and Savitch in bookstore + reading for Thurs: Savitch Chaps 2.1-2.4, skip 82-85 + future reading for Tues: 3.1, 3.4 + consulting in lab: Labs-->Carpenter + office hours -- see Staff-->Staff Listing + revised sections: - Section 17 (HO 314) goto Upson 111 (TA schedule conflict) - we will create new section at other time to compensate ------------------------------------------------------------------------------- Topics: + reminders from previous lecture + reintroduction of DIS + CS100J policy reminders + lecture policies + objectives/advice + fundamental programming concepts - definition of programming - how programming works - problem solving - algorithms ------------------------------------------------------------------------------- Reminders + CS99/CS100J/CS100M, alternatives + policies -- see website, click on everything, see Overview ------------------------------------------------------------------------------- DIS + history, background + why CS100/intro courses? + pet peeves (reading newspapers, very late, walking in front during lecture, arguing/pleading for late submissions) ------------------------------------------------------------------------------- Problem solving + problems are physical and abstract + build models which are physical and abstract + models will solve the problem where we cannot/will not + use a computer! need to write software... + PROGRAMMING: automating problem solving ------------------------------------------------------------------------------- Computer Rudiments + hardware: physical components of a computer + software: "the intelligence" that runs the hardware - create with programming (coming up!) + information: bits and bytes -- sequences of 1s and 0s (digits) that represent non-digital information + memory: "space" inside a computer to store information - software can "borrow" a portion to use - programming involves using memory + file: collection of information with a name + directory: collection of files + folder: same as directory + path: location of file or directory starting from the "uppermost" directory + ASCII/text: characters found on the keyboard - uses 8 bits to represent a character which is a byte - ASCII (or text) format is universal - can load into almost editor and wordprocessor - can edit files with programs called text editors + Program: file composed of instructions using a computer language - usually text because we need to type those instructions! - the process of telling the computer to activate commands in a program is called running or executing - information is passed from your text to the computer - computer activates each instruction in sequence + Interpreting: computer reads each line of code and acts up it before acting upon the next line + Compiling: process of converting code into an unreadable format - more bits and bytes, but condensed - can create "runnable" (executable) files that quickly run your programs + Input: - any information you supply to a program + Output: - any information reported by a program ------------------------------------------------------------------------------- Process of Programming + start with problem + look for solution + brainstorm, outline, write, rewrite, polish (1) Gather data - figure out abstract and concrete "things" in problem (2) Gather processes - determine behaviors these "things" have (3) Algorithm - try to connect things and behaviors in a sequence of steps/instructions called an ALGORITHM ------------------------------------------------------------------------------- Forming an algorithm + break solution down into sequence of steps (each step is an instruction) + use PSEUDOCODE (langauge that resembles a computer language) terms: repeat, if, else, otherwise, continue, return, stop, start, etc + avoid minutia and over-generality -- look for the middle... (often depends on task at hand!) + may have to keep breaking down steps + final algorithm is a program in "words" + example: think recipe - someone else wrote a sequence of instructions - used terms that are accepted and have known values/meanings - you, the human, act on the instructions - something is created and hopefully tastes good + general examples: scheduling of office hours, simulation of dishroom, number guessing, etc ------------------------------------------------------------------------------- Computer Language + need to translate English language algorithm into a computer language + many options: MATLAB, Maple, Java, C, C++, C#, etc + Choose MATLAB and Java for CS100 ------------------------------------------------------------------------------- Language Elements + computer language usually written (in the future, spoken) + has syntax (grammar) and semantics (meaning) + characters (keyboard symbols) -> tokens (words) -> statements (sentences) ------------------------------------------------------------------------------- Characters + usually keyboard characters (ASCII text) + ASCII has 128 characters + some are nonprinting -- see ascii.txt for full list + also, try entering $char(0:127)$ in MATLAB (do not enter $s: I use the $ notation to indicate a code fragment or statement to enter) + technically, Java uses UNICODE - over 65000 characters - see p88, Appendix 3, website: Material->Java->Miscellaneous->UNICODE - special non-printing characters can be reproduced with ESCAPE CHARACTERS o see pp86-88 o ex) \n (newline) ------------------------------------------------------------------------------- Tokens + characters form "words", which are called TOKENS + tokens include: numbers, operators, variables, keywords, punctuation, token separators, strings, comments (described in more detail soon) ------------------------------------------------------------------------------- Statements + combine tokens to create "sentences", which are called STATEMENTS + each "sentence" forms an instruction/command + "sentences" are called statements ------------------------------------------------------------------------------- Example of first program: // FirstProgram // DIS, 2001 // Program prints welcome message to the world. public class FirstProgram { public static void main(String[] args) { System.out.println("Hello, world!"); } }