This preview shows page 1-2-3-4-5-6-7-8-9-10-69-70-71-72-73-74-75-76-77-78-140-141-142-143-144-145-146-147-148-149 out of 149 pages.
“main”2005/1/11page iiiiiiiiiBETA Version, January 10th,2005:Introduction to Computing andProgramming in Java:A Multimedia ApproachMark Guzdial and Barbara EricsonCollege of Computing/GVUGeorgia Institute of TechnologyPRENTICE HALL, Upper Saddle River, New Jersey 07458“main”2005/1/11page iiiiiiiiiiiiCopyright held by Mark Guzdial and Barbara Ericson, 2005.“main”2005/1/11page iiiiiiiiiiiiiiDedicated to our children Matthew, Katherine, and Jennifer“main”2005/1/11page iviiiiiiiiContentsContents ivPreface 1I Introduction 71 Introduction to Computer Science and Media Computation 81.1 What is Computer Science About? . . . . . . . . . . . . . . . . . . . 81.2 What Computers Understand . . . . . . . . . . . . . . . . . . . . . . 131.3 Media Computation: Why Digitize Media? . . . . . . . . . . . . . . 151.4 Computer Science for Everyone . . . . . . . . . . . . . . . . . . . . . 161.4.1 It’s About Communication . . . . . . . . . . . . . . . . . . . 171.4.2 It’s About Process . . . . . . . . . . . . . . . . . . . . . . . . 172 Introduction to Java 192.1 Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192.1.1 History of Java . . . . . . . . . . . . . . . . . . . . . . . . . . 192.1.2 Introduction to Objects and Classes . . . . . . . . . . . . . . 202.2 Introduction to DrJava . . . . . . . . . . . . . . . . . . . . . . . . . . 212.2.1 Starting DrJava . . . . . . . . . . . . . . . . . . . . . . . . . 212.3 Java Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242.3.1 Math Operators . . . . . . . . . . . . . . . . . . . . . . . . . 242.3.2 Printing the Result of a Statement . . . . . . . . . . . . . . . 242.3.3 Types in Math Expressions . . . . . . . . . . . . . . . . . . . 272.3.4 Casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272.3.5 Relational Operators . . . . . . . . . . . . . . . . . . . . . . . 272.3.6 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292.4 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312.4.1 Declaring Variables . . . . . . . . . . . . . . . . . . . . . . . . 312.4.2 Using Variables in Calculations . . . . . . . . . . . . . . . . . 312.4.3 Memory Maps of Variables . . . . . . . . . . . . . . . . . . . 322.4.4 Object Variables . . . . . . . . . . . . . . . . . . . . . . . . . 342.4.5 Reusing Variables . . . . . . . . . . . . . . . . . . . . . . . . 362.4.6 Multiple References to an Object . . . . . . . . . . . . . . . . 372.5 Concepts Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392.5.1 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392.5.2 Relational Operators . . . . . . . . . . . . . . . . . . . . . . . 402.5.3 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402.5.4 Casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402.5.5 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41iv“main”2005/1/11page viiiiiiiiv3 Introduction to Programming 433.1 Programming is About Naming . . . . . . . . . . . . . . . . . . . . . 433.2 Files and their Names . . . . . . . . . . . . . . . . . . . . . . . . . . 453.3 Class and Object Methods . . . . . . . . . . . . . . . . . . . . . . . . 463.3.1 Invoking Class Methods . . . . . . . . . . . . . . . . . . . . . 463.3.2 Invoking Object Methods . . . . . . . . . . . . . . . . . . . . 473.4 Working with Turtles . . . . . . . . . . . . . . . . . . . . . . . . . . . 483.4.1 Defining Classes . . . . . . . . . . . . . . . . . . . . . . . . . 483.4.2 Creating Objects . . . . . . . . . . . . . . . . . . . . . . . . . 483.4.3 Sending Messages to Objects . . . . . . . . . . . . . . . . . . 513.4.4 Objects Control Their State . . . . . . . . . . . . . . . . . . . 523.4.5 Additional Turtle …