Unformatted text preview:

Copyright © 2005-2007 William C. BentonChapter 11Copyright © 2005-2007 William C. BentonOK. How is a computer organized?2Copyright © 2005-2007 William C. BentonEvery computer has a central processing unit (CPU) that executes sequences of simple instructions (aka programs)3Copyright © 2005-2007 William C. BentonThe CPU can execute programs that are contained in RAM.4Copyright © 2005-2007 William C. BentonWhen a program is not executing, its instructions will be stored on disk.512345RAM(memory)CPUVideoDisk interfaceDiskDisk. . .USB/FireWireBUSCopyright © 2005-2007 William C. Benton6Copyright © 2005-2007 William C. Benton7What is a program?Copyright © 2005-2007 William C. BentonA program is a sequence of instructions to accomplish a specific task (or tasks).8Copyright © 2005-2007 William C. BentonProgramming is providing sequences of (very) basic instructions to accomplish tasks.9Copyright © 2005-2007 William C. BentonTasks10•Many programs do only one task, like “edit image files”•This task is as complicated as you want to make it, though!•Some programs can do more than one task, like Internet Explorer678910Copyright © 2005-2007 William C. BentonHow do we provide instructions to the computer?11Copyright © 2005-2007 William C. BentonWe can write programs in a programming language, like Java, C, Basic, or assembly.12Copyright © 2005-2007 William C. BentonPrograms in high-level languages are easy for humans to read but can’t run directly on a CPU.13Copyright © 2005-2007 William C. BentonPrograms in machine language can execute directly on a CPU (but are very hard for humans to read).14Copyright © 2005-2007 William C. BentonSolution: translate from high-level to machine language.151112131415Copyright © 2005-2007 William C. BentonHow do we do this?16answer: not by hand! (if we can help it)Copyright © 2005-2007 William C. BentonThe Java compiler translates from Java code into Java virtual machine code.17Copyright © 2005-2007 William C. BentonThe Java compiler translates from Java code into Java virtual machine code.17Copyright © 2005-2007 William C. BentonGreat! So we can write our program in Java and have the Java compiler translate it into machine code.18(The Java Virtual Machine is actually a program that acts like a CPU.)Copyright © 2005-2007 William C. BentonWhat happens if we make a mistake?191617171819Copyright © 2005-2007 William C. BentonWhat happens if we make a mistake?19(What kinds of mistakes could we make?)Copyright © 2005-2007 William C. BentonTwo kinds of errors20•“Syntax errors,” or compile-time errors, prevent the Java compiler from translating your program•example: omitting a semicolon•“Logic errors,” or run-time errors, cause your program to do the wrong thing•example: giving the wrong directionsCopyright © 2005-2007 William C. BentonCompile-time errors prevent the compiler from “making sense of” your program (and translating it).21Copyright © 2005-2007 William C. Benton“Compile-time errors”22•Ifyourunallofyourwordstogether noonewillunderstandyou.•Ungrammatical sentences to understand hard can be.•Write complete sentences, which areCopyright © 2005-2007 William C. BentonA program that makes sense but does the wrong thing contains run-time errors.231920212223Copyright © 2005-2007 William C. BentonExamples24•Can be subtle:•“Heat water to 100 degrees C before adding yeast”•Or drastic:•use your imagination here•Also consider programs that just don’t meet requirementsCopyright © 2005-2007 William C. BentonWe can fix errors by applying the edit-compile-test cycle.25Copyright © 2005-2007 William C. BentonEdit-compile-test26•EDIT: we write our program in a text editor•COMPILE: we try and translate our program to machine code with a compiler•if there are compile-time errors, edit again!•TEST: we run our program to determine whether or not it behaves as expected•if there are run-time errors, edit again!testcompileeditJava compilerText editorCompiled program(.java files)Compiled program(.java files)Compiled programProgram source code(.java files)Program source code(.java files)Program source codeJava VMCompile-time errors?Run-time errors?Working program!No compile-time errors?No run-time errors?Compiled program(.java files)Compiled program(.java files)Compiled librariesCopyright © 2005-2007 William C. Benton27Copyright © 2005-2007 William C. BentonYou can do every step of the edit-compile-test cycle within the Eclipse program!282425262728Copyright © 2005-2007 William C. Benton29•A text editor to edit program text•A compiler to translate from Java code to Java virtual machine code•A virtual machine to run the program•(The Eclipse IDE combines all three)Programs you’ll use while programmingCopyright © 2005-2007 William C. Benton30public class Hello { public static void main(String [] args) { String greeting = "Hello, world!"; String yellingGreeting = greeting.toUpperCase(); System.out.println(greeting); System.out.println(yellingGreeting); }}What do you suppose this program does?Copyright © 2005-2007 William C. BentonSome review questions31Copyright © 2005-2007 William C. BentonWhat are the basic parts of a computer?32Copyright © 2005-2007 William C. BentonWhat is a program?332930313233Copyright © 2005-2007 William C. BentonWhat programs would you use while programming?34Copyright © 2005-2007 William C. BentonWhat kinds of errors can occur in our


View Full Document

UW-Madison CS 302 - Chapter 1 Lecture Notes

Download Chapter 1 Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter 1 Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter 1 Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?