LECTURE NOTES CHAPTER 1 ASSIGNMENTS - surf web site - read Chapter 1 - 1/26 notify me of exam conflicts/McBurnie accomodations ADMINISTRIVIA - introduce self - office hours - course difficulty - course format - participation policy - exams - pair programming 1.1 WHAT IS PROGRAMMING? - computer - store data - communicate with devices - execute programs - programming - telling a computer what to do - provide sequences of instructions - program - instructions - decisions 1.2 THE ANATOMY OF A COMPUTER - CPU - comprises chip/integrated circuit - plastic/metal housing - complex silicon wiring - transistors: elements that let electrical signals control each other - function: locate & execute instructions - arithmetic - interact with devices and storage - get data - send data - storage: place to keep data and programs - primary/RAM/memory - fast - expensive - made of memory chips - volatile - secondary - less expensive - non-volatile - usually hard disk - magnetic-coated rotating platters - read/write head - removeable: floppy disk, tape, CD - peripheral devices - purpose: interact with people - output: display, speakers, printer - input: keyboard, mouse - bus: set of electrical lines connecting all of these components - motherboard: houses CPU, primary storage, buses, and connections to devices - networks: several computers connected together - types: dialup, broadband, local area - purpose: share data/workload - executing a program - load program and data - follow instructions - read-modify-write data - interact with devices - use data to make decisions - very fast 1.3 TRANSLATING HUMAN-READABLE PROGRAMS TO MACHINE CODE - machine instructions - instructions the CPU can actually execute - very simple - encoded as numbers - stored in memory - executed very quickly - varies among CPUs - Java virtual machine - software that simulates a CPU - must write special software to execute it on each real CPU - allows portability - communicate command sequence to computer - place data and commands in memory manually - high-level language plus compilers - use high-level language to express idea of what to do - compiler - special kind of program - translates a high-level language into a machine language - allocates memory to variables 1.4 THE JAVA PROGRAMMING LANGUAGE - advantages - relatively simple - secure - virtual machine catches and reports many mistakes - rich libraries - portable - runs on all machines without changing the code - operating system independent - suitable for environments of varying size: small and large versions - disadvantages - requires some syntax for even the most basic programs - multiple versions: 5.0 for this course - won't learn it all in one semester: too many library packages 1.5 BECOMING FAMILIAR WITH YOUR COMPUTER - we will do this during a lab day this coming Wednesday - we are using the integrated development environment Eclipse - file - collection of items of information that are kept together - often system-dependent naming rules - extension: required by some systems at the end of the file (the .blah part) - Java - we must name our programs with the .java extension - spaces are not allowed - case-sensitive - folder/directory - collection of files/folders - backup 1.6 COMPILING A SIMPLE PROGRAM - Hello, World example - free-form layout, but this course grades on style -- see guidelines online - class - create one - fundamental building block - class name and file name must match - method - create one - contains a collection of programming instructions that describe how to carry out a particular task - main: every application must have one - method body - designated by curly braces - executed sequentially - comment - ignored by the compiler - single line comment - multiple line comment - statement - an individual instruction - must end with a semicolon - calling an object's method 1.7 ERRORS - compile-time/syntax - compiler finds - violation of the language rules - compiler does not translate program into VM instructions - usually displays all errors that aware of - sometimes one error can trick it into thinking there are multiple errors - solution: do top-down and recompile after fixing each one - compile frequently so that you aren't overwhelmed by too many errors at once - run-time/logic/bug - does something other than what you intended - find these by extensive testing - defensive programming: structure so that errors as unlikely as possible to be catastrophic 1.8 THE COMPILATION PROCESS - edit-compile-test loop - type in the program statements (source code) - compile - turn source code into class files (virtual machine instructions) - generated files have the same name, but a .class extension - link: include any necessary library code - JVM runs the code