******************************************************************************* 1) Administrivia - me - info sheet - check site and email often - talk to me about conflicts, disabilities, or meaning of life 2) Dire warnings - like a language class in time commitment and nature, b/c it needs to be - probably something to do for every class period - do not fall behind in this class - come to class, or don't bother taking it - do not expect to sit silently (switch to big lecture) - not for ppl with extensive programming or some OOP (talk to me) 3) Homework - explore sites - register for codelab & do the 2 exercises outside of any chapter - read chapter 0 4) Intro to computer science (for your technical knowledge only) **Programs? - taking initial data, doing calculations, showing results Programming - learning a language with a new kind of grammar and giving the computer instructions in it **How the computer works - CPU, main memory, hard disks, I/O devices - OS brings program from hard disk to main memory - CPU executes each instruction of the program - it uses main memory to store intermediate calculations - it uses I/O devices to get input or display output (GUI / text window) - to the uninitiated, user interface seems to BE the program **Binary numbers - data? (numbers, letters- represented by number codes anyway) - but numbers in computer aren't in base 10, they're in base 2 - the only digits are 0 and 1, instead of 0-9: binary digits -> "bits" - but just as you can make any number using 0-9, you can using 0-1 - represent numbers 0 - 10 in binary (you can do math, too) - with two bits, how many different numbers? (4) with three? (8) - n bits gives you 2^n numbers. how many to represent alphabet? (5) - memory = switches called transistors: each switch is one bit; on/off - why not base 10? (10-way switches are hard to get right! would crash.) - luckily you program with normal base 10 numbers; computer can translate - but this is how it's working under the hood **Main Memory - like a table with 8 bits per row: a byte, each with its own address - mine has 512 MB, which means 512 X 2^20 rows (~512 mill) - hard drives have around 30 GB, which is ~30 bill rows - main is smaller and temporary, hard drive is huge and permanent - I'll draw sections of memory all over in diagrams later - when running program, space for storing it - it's just text (numbers) - some scratch space for what it's working on right now - stack - some for longer lasting data, called objects - heap - and some for program-long data, called static or constant - these might hold whole numbers, floating point numbers, words, or even addresses of other memory locations (drawn as arrows) - CPU does magic: reads binary #s that contain instructions, changes binary #s that are data, sends instructions to I/O **How programming developed - first people wrote machine language; all in 0's and 1's - grunts - then they made assembly language, with words like "add" and "store" that translate directly into 0's and 1's - see spot run - then they made high-level languages, with more words and power, which don't translate directly - better for humans (Java- newish high-level) - a compiler program is needed to translate it into machine language - CodeWarrior is our compiler (I'll randomly interchange with CodeLab) - you'll type program in a text "source file", compile, run - slight difference with Java: compiler translates into "bytecode", and an "interpreter" executes (runs the same even on different machines) - you can get errors both when compiling and when running - compile-time: a mistake with the language - said something ungrammatical - run-time: mistake with instructions - said something silly - also: mistake with logic, correct but undesired - slip of the tongue 5) Simple demo program 6) Why a language? Why not make a compiler to translate English? - huge vocabulary, many redundant words, complicated grammar - ambiguity - computer is a stupid, stupid machine. it can only do exactly what you tell it to. so everything you say must have exactly one clear meaning. - so you have to learn this language: mostly English & math, but stricter - there are lots and lots of languages, many mutually unintelligible, but Java is new and popular and somewhat user-friendly - need grammar, and lots of problem solving to write correct instructions 7) Do some puzzles to sharpen up those abilities 1) Boy crossing river - Take rabbit over - Take lettuce over and take rabbit back - Take fox over - Take rabbit over again 2) Finding the celebrity - Must eliminate one person from consideration with each question - By asking "X, do you know Y?", you can eliminate either X or Y 3) One light stack of coins in ten - Number the stacks and take 1 from stack 1, 2 from stack 2, etc - Weigh the samples all together; if all were good it'd weigh 55 grams - The number of missing grams is equal to the counterfeit stack number 4) Natives and visitors - If Joe were telling the truth, then he would be a visitor, so he wouldn't be able to tell the truth. So Joe must be lying, and we know two things: at least one of them is a native, and Joe is a visitor. - If Frank were a visitor, then Bill would have to be a native; but that would make Frank's statement true, and he couldn't tell the truth. So Frank must be a native, and therefore Bill is a visitor. 5) Hunter and bear - North pole; white *******************************************************************************