An Introduction To Problem Solving & Programming

1m ago
14 Views
1 Downloads
2.67 MB
30 Pages
Transcription

JAVA An Introduction toProblem Solving & ProgrammingFourth EditionPRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

Thank you for purchasing a new copy of the best-selling Savitch Java book. The ravereviews on Amazon by readers attest to the user-friendly presentation for beginners.You will now be able to access Prentice Hall’s free, web-based, programming environment called CodeKey. It is an on-line, interactive tutorial for readers learning how toprogram with the Java programming language. You will be able to complete selectedprogramming exercises from the text and receive automated feedback on your Java code.The on-line exercises will tell you how to improve your Java code when you modify existing programs from the book. Code Key will allow you to “test” your programs before submitting them for class assignments. You can use CodeKey for programming practice.CodeKey will give hints on how to improve your code, and how to debug it when necessary. You will be alerted to errors, and will be given programming hints on how to fixthem.You can access CodeKey at www.prenhall.com/codekeyPRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

JAVA An Introduction toProblem Solving & ProgrammingFourth EditionWALTER SAVITCHUpper Saddle River, NJ 07458PRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

Library of Congress Cataloging-in-Publication DataSavitch, Walter J.Java : an introduction to problem solving & programming / Walter Savitch.-- 4th ed.p. cm.Includes bibliographical references and index.ISBN 0-13-149202-01. Java (Computer program language) I. Title.QA76.73.J38S27 2005005.13'3--dc222004057347Vice President and Editorial Director, ECS: Marcia HortonPublisher: Alan R. AptAssociate Editor: Toni D. HolmVice President and Director of Production and Manufacturing, ESM: David W. RiccardiExecutive Managing Editor: Vince O’BrienAssistant Managing Editor: Camille TrentacosteProduction Editor: Irwin ZuckerDirector of Creative Services: Paul BelfantiArt Director: Kenny BeckCover Designer: Laura GardnerArt Editor: Xiaohong ZhuManufacturing Manager: Trudy PisciottiManufacturing Buyer: Lisa McDowellMarketing Manager: Pamela HerspergerMarketing Assistant: Barrie Reinhold 1999, 2001, 2004, 2005 by Pearson Education Inc.Pearson Prentice HallUpper Saddle River, NJ 07458All rights reserved. No part of this book may be reproduced, in any form or by any means, without permission inwriting from the publisher.The author and publisher of this book have used their best efforts in preparing this book. These efforts include the development, research, andtesting of the theories and programs to determine their effectiveness. The author and publisher make no warranty of any kind, expressed orimplied, with regard to these programs or the documentation contained in this book. The author and publisher shall not be liable in any eventfor incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs.Printed in the United States of America10 9 8 7 6 5 4 3 2 1ISBN 0-13-149202-0Pearson Education Ltd., LondonPearson Education Australia Pty. Ltd., SydneyPearson Education Singapore, Pte. Ltd.Pearson Education North Asia Ltd., Hong KongPearson Education Canada, Inc., TorontoPearson Educación de Mexico, S.A. de C.V.Pearson Education—Japan, TokyoPearson Education Malaysia, Pte. Ltd.Pearson Education, Inc., Upper Saddle River, New JerseyTRADEMARK INFORMATIONANSI is a registered trademark of American National StandardsInstitute.CodeWarrior is a registered trademark of Metrowerks, Inc.Java, Duke, and all Java based trademarks and logos are trademarksor registered trademarks of Sun Microsystems, Inc. in the UnitedStates and other countries.JBuilder and JBuilder Foundation are trademarks of Inprise/Borland.Mac, Macintosh, and MacOS are trademarks of Apple Computer, Inc.Netscape and Netscape Navigator are trademarks of NetscapeCommunications, Inc.TextPad is a trademark of Helios Software Solutions.UNIX is a trademark of UNIX System Laboratories.Windows, WindowsNT, and Internet Explorer are trademarks orregistered trademarks of Microsoft Corporation.FrontPage (Microsoft Corportation)PRELIMINARY PROOFSDreamWeaver (Maacromedia, Inc.) 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.GoLive(AdobeInc.)This material is protected under all copyright laws as they currently exist. Noportionof thisSystemsmaterialmay be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

To ChristinaPRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

Savitch4e FeaturesppFMv2.qxp 11/12/04 8:10 PM Page 24.4 GRAPHICS SUPPLEMENT (OPTIONAL) FEATURES OF THIS TEXTEarly optional graphics supplementscover GUIs built using both applets andthe JFrame class are integrated throughout the text. Advanced GUI chaptersgive additional graphics material.The whole is more than the sum of its parts. —ProverbNow that we have explained methods and parameters more completely, we will revisitmaterial from the previous graphics supplements to explain a few things more completely.We will use methods to rewrite one of our previous graphics applets in a cleaner way, wewill explain the Graphics class more completely, and we will introduce some additionaldrawing methods. Finally, we introduce the method init, which is another applet methodsimilar to paint but used for different purposes. FAQGraphics Supplement (Optional) Provides students answers to frequentlyasked questions within the context ofthe chapter. Quick ReferenceGotchaHelps students identify possibleprogramming pitfalls. Provides concise, user-friendly referencefor key programming concepts.Java TipGives students helpful information aboutthe Java programming language. Remember Reinforces concepts presented in thechapter.Self-Test QuestionsProvides students the opportunity topractice skills learned in the chapter.PRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means, without permissionin writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving and Programming, Fourth Edition (ISBN:0-13-149202-0).

PREFACE FOR INSTRUCTORSThis book is designed for a first course in programming and computer science. It coversprogramming techniques, as well as the basics of the Java programming language. It issuitable for courses as short as one quarter or as long as a full academic year. No previousprogramming experience is required, nor is any mathematics, other than a little highschool algebra. The book can also be used for a course designed to teach Java to studentswho have already had another programming course, in which case the first few chapterscan be assigned as outside reading.This book uses only standard classes available as part of Java. No additional classesare needed.All of the code in this book has been tested using Sun’s Java JDK version 5.0, beta2 release. To be fully compatible with this book, the Java used in your class should beversion 5.0 or higher.1Changes in This EditionIf you have not used the third edition of this text, you can skip this subsection. If you haveused the third edition, this subsection will tell you how this fourth edition differs from thethird.For instructors, the transition from the third to this fourth edition is easy. You can teachthe same course, presenting basically the same topics in the same order with only veryminor changes in the material covered. The largest required change is that this edition usesthe new Scanner class available in Java version 5.0 in place of the class SavichIn.2 Ifyou wish to change your course further, this edition includes Graphics Supplement sections that allow you to (optionally) add early graphics coverage. This edition also addscoverage of generic programming with type parameters.Chapter 1 through 9 each end with a Graphics Supplement section that covers graphicsapplications and GUIs using applets as well as JFrames. These Graphics Supplement sections are optional. If you desire more material on graphics and GUIs then after Chapter 9(in fact any time after Chapter 7), you can skip ahead to Chapter 12, which starts thedetailed coverage of Swing.The other major changes to this edition have to do with updating the text to match Javaversion 5.0: The new Scanner class is used for keyboard input. We explain and use automatic boxing and unboxing. The coverage of vectors has been updated to use generic typeparameters. An introduction to type parameters and generics is given in Chapter 10.Latest Java CoverageThis edition has been updated to use the latest features of Java version 5.0. In particular,we use the new Scanner class for keyboard input, we cover and use automatic boxing and1. Sun has changed the way it numbers versions. Version 5.0 was formerly called version 1.5 andyou may still find it referred to as version 1.5 in some contexts.2. If you wish to use the class SavitchIn, it is available in an appendix, and the source code isavailable over the Web. However, SavitchIn is not used anywhere in the text.viiPRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

viiiPreface for Instructorsunboxing, we do vectors using type parameters, and we include an introduction to genericprogramming using type parameters. As we wrote this book, we checked all code usingSun’s beta 2 release of Java 5.0.FlexibilityIf you are an instructor, this book adapts to the way you tech, rather than making youadapt to the book. This book does not tightly prescribe the sequence in which your coursemust cover topics. You can easily change the order in which you cover chapters and sections. The particulars about rearranging material are explained in the dependency chartthat follows this preface and in more detail in the “Prerequisites” section at the start ofeach chapter.This book uses no specialized libraries. Only standard classes available as part of thestandard Java libraries are used.Early GraphicsOptional Graphic Supplement sections end chapters starting with Chapter 1. This allowsyou the option of covering graphics and GUI programming from the start of your course.The Graphics Supplement sections emphasize applets but also cover GUIs built using theJFrame class. Any time after Chapter 7, you may move on to the main chapters on GUIprogramming (Chapters 12–14). Alternatively, the Graphics Supplement sections continuethrough Chapter 9, allowing you to continue with a mix of graphics and more traditionalprogramming. Instructors who prefer to postpone the coverage of graphics may postponeor skip the Graphics Supplement sections.Coverage of Problem-Solvingand Programming TechniquesThis book is designed to teach students basic problem-solving and programming techniques and is not simply a book about Java syntax. It contains numerous case studies andprogramming tips, as well as many sections that explain important problem-solving andprogramming techniques, such as loop design techniques, debugging techniques, styletechniques, abstract data types, and basic object-oriented programming techniques,including UML and event-driven programming, and generic programming using typeparameters.Object-Oriented and Traditional TechniquesAny course that really teaches Java must teach classes early, since everything in Javainvolves classes. A Java program is a class. The data type for strings of characters is aclass. Even the behavior of the equals operator ( ) depends on whether it is comparingobjects from classes or simpler data items. Classes cannot be avoided, except by means ofabsurdly long and complicated “magic formulas.” This book introduces classes fairlyearly. Some exposure to using classes is given in Chapters 1 and 2. Chapter 4 covers howPRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

Preface for Instructors ixto define classes. All of the basic information about classes, including inheritance, ispresented by the end of Chapter 7 (even if you omit Chapter 6). However, some topicsregarding classes, including inheritance, can be postponed to later in a course.Although this book introduces classes early, it does not neglect traditional programming techniques, such as top-down design and loop design techniques. These older topicsmay no longer be glamorous, but they are information that all beginning students need.Generic ProgrammingStudents are introduced to type parameters when they cover vectors in Chapter 10. Vectorsare presented in their latest version, when includes a type parameter for the base type ofthe vector. Students are then shown how to define their own classes that include a typeparameter.Language Details and Sample CodeThe book teaches programming technique, rather than simply the Java language. However,neither students nor instructors would be satisfied with an introductory programmingcourse that did not also teach the programming language. Until you calm a student’s fearsabout language details, it is often impossible to focus her or his attention on bigger issues.For this reason, the book gives complete explanations of Java language features and lots ofsample code. Programs are presented in their entirety, along with sample input and output.In many cases, in addition to the complete examples in the text, extra complete examplesare available over the Internet.Self-Test QuestionsSelf-test questions are spread throughout each chapter. These questions have a wide rangeof difficulty levels. Some require only a one-word answer, whereas others require thereader to write an entire, nontrivial program. Complete answers for all the self-test questions, including those requiring full programs, are given at the end of each chapter.Class TestedThe material in the book has been fully class tested. Much of the material and many of themethods of presentation were revised in response to this testing.Support MaterialThe support materials described here can be obtained from the publisher or over theInternet.PRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

x Preface for InstructorsSupport ResourcesThe source code from the book, code for extra programming examples, and links todownload locations for Java compilers and programming environments are provided onthe book’s web site:http://www.prenhall.com/savitchInstructor’s Resource GuideInstructor tools include a chapter-by-chapter Instructor’s Resource Guide that containsnumerous teaching hints, quiz questions with solutions, solutions to many programmingexercises, PowerPoint slides, and other teaching resources. Instructors should contact theirPrentice Hall sales representative to receive information on how to access the Instructor’sweb site. For the name and number of your sales representative, contact Prentice Hall viathe following web site:http://www.prenhall.com/Walter ers/savitchPRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

PREFACE FOR STUDENTSThis book is designed to teach you the Java programming language and, even more importantly, to teach you basic programming techniques. It requires no previous programmingexperience and no mathematics other than some simple high school algebra. However, toget the full benefit of the book, you should have a version of Java available on your computer, so that you can practice with the examples and techniques given. You should haveversion 5.0 (or higher) of Java. (Sun has changed the way it numbers version. Version 5.0was formerly called version 1.5 and you may still find it referred to as version 1.5 in somecontexts. If you have a copy of Java called “version 1.5,” that should be fine.)If You Have Programmed BeforeYou need no previous programming experience to use this book. It was designed forbeginners. If you happen to have had experience with some other programming language,do not assume that Java is the same as the programming language(s) you are accustomedto using. All languages are different, and the differences, even if small, are large enough togive you problems. Read at least the boxed material in Section 1.3 of Chapter 1 and all ofthe boxed material in Chapters 2 and 3. By the time you reach Chapter 4, you would bewise to read the entire chapter.If you have programmed before in either C or C , the transition to Java can be troublesome. At first glance, Java may seem almost the same as C or C . However, Java is verydifferent from these languages, and you need to be aware of the differences. Appendix 11compares Java and C to help you see what the differences are.Copies of the Programs in the TextAll the programs and other software examples in the book are available for downloadingfrom the book’s web site, so that you can practice with these examples without having totype them into your computer.Obtaining a Copy of JavaThere are links on the book’s web site that lead you to sites for downloading Java compilers and programming environments. For beginners we recommend Sun’s Java SDKfor your Java compiler and related software and TextPad as a simple editor environmentfor writing Java code. When downloading the Java SDK, be sure to obtain a versionnumber of 5.0 or higher.Books Web SiteThe source code from the book, code for extra programming examples, and links to download locations for Java compilers and programming environments are provided on thebook’s web site:http://www.prenhall.com/savitchxiPRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

xiiPreface for StudentsSelf-Test QuestionsEach chapter contains numerous self-test questions. Complete answers to these questionsare given at the end of each chapter. One of the best ways to practice what you are learningis to do the self-test questions before you look at the answers.This Text Is Also a Reference BookIn addition to using this book as a textbook, you can and should use it as a reference.When you need to check a point that you have forgotten or that you hear mentioned bysomebody, but have not yet learned yourself, just look in the index. Many index entriesgive a page number for “quick reference.” Turn to this quick reference page. It will contain a short entry, usually set off in a box, that gives all the essential points on that topic.You can do this to check details of the Java language as well as details on programmingtechniques.Boxed sections in every chapter give you a quick summary of the main points in thatchapter. You can use these boxes to review the chapter, or to check details of the Java language.We Want Your OpinionsThis book was written for you, and we would like to hear any comments you have on it.You can contact me via e-mail at the following address:[email protected], I cannot provide you with answers to the programming exercises. Onlyinstructors who adopt the book can receive (selected) answers from the publisher. For helpwith the programming exercises, you will have to contact your instructor. (Even if you arenot enrolled in a class, I still cannot provide answers to programming exercises.) Butremember that there are answers to all the self-test questions at the end of each chapter.Walter INARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

ACKNOWLEDGMENTSI thank the Computer Science and Engineering Department of the University of California, San Diego (UCSD), which is my home department and the place where I tested muchof this material. Many students in my classes were kind enough to help correct preliminaryversions of this text. These student comments and the comments of instructors who classtested this book were a tremendous help in shaping the final book. In particular, I extend aspecial thanks to Carole McNamee of California State University, Sacramento, and to PaulKube of UCSD for their detailed feedback and class testing of earlier editions of the book.I also extend a special thanks to Robert Burton of BYU for preparing a detailed analysis ofa draft for this edition. Their comments have helped tremendously in shaping this book.I thank all the reviewers who took the time to read drafts of earlier editions of the book.They provided invaluable detailed comments and suggestions that continue to benefit thisnew edition. In alphabetical order, they areJim Buffenbarger—Idaho State UniversityRobert P. Burton—Brigham Young UniversitySteve Cater—Kettering UniversityMartin Chelten—Moorpark Community CollegeMichael Clancy—University of California, BerkeleyTom Cortina—SUNY, Stony BrookPrasun Dewan—University of North CarolinaLaird Dornan—Sun Microsystems, Inc.H. E. Dunsmore—Purdue University, LafayetteAdel Elmaghraby—University of LouisvilleGobi Gopinath—Suffolk County Community College.Le Gruenwald—University of OklahomaGopal Gupta—University of Texas, DallasRicci Heishman—North Virginia Community CollegeRobert Herrmann—Sun Microsystems, Inc., Java SoftRobert Holloway—University of Wisconsin, MadisonLily Hou—Carnegie Mellon UniversityRob Kelly—SUNY, Stony BrookMichele Kleckner—Elon CollegeMike Litman—Western Illinois UniversityBlayne Mayfield—Oklahoma State UniversityJohn Motil—California State University, NorthridgeMichael Olan—Stockton StateJames Roberts—Carnegie Mellon UniversityAlan Saleski—Loyola University, ChicagoNan C. Schaller—Rochester Institute of TechnologyRyan Shoemaker—Sun Microsystems, Inc.Ken Slonneger—University of IowaDonald E. Smith—Rutgers UniversityBoyd Trolinger—Butte CollegeSubramanian Vijayarangam—University of Massachusetts, LowellxiiiPRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

xiv AcknowledgmentsI would to also thank the reviewers of this new edition:Robert Burton--Brigham Young UniversityEd Gellenbeck--Central Washington UniversityAnthony Larrain--Depaul UniversityMichael Long--California State UniversityDrew McDermott--Yale UniversityKen Slonneger--University of IowaNavabi Tadayon--Arizona State UniversityRichard Whitehouse--Arizona State UniversityMichael Young--University of OregonI also thank all the individuals at Prentice Hall who organized the reviewing and production of this book. In particular, I thank Toni Holm, Patrick Lindner, and Irwin Zucker.I extend a special thanks to my publisher, Alan Apt, for his invaluable support and advicethroughout the writing and production process. All these wonderful people cheerfully dida great job.Lew Rakocy prepared the programming solutions for the instructor’s guide, RobertBurton prepared the PowerPoint slides. I thank both of them for their conscientious work.I thank Sun Microsystems for allowing me to use the Duke icon in a number of my GUIexamples.W.S.PRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

DEPENDENCY CHARTThis chart shows the prerequisites for the chapters in the book. If there is a line betweentwo boxes, the material in the higher box should be covered before the material in thelower box. Minor variations to this chart are discussed in the “Prerequisites” section at thestart of each chapter. These variations usually provide more, rather than less, flexibilitythan what is shown on the chart.Chapter 1IntroductionChapter 2Primitive Types, StringsChapter 3Flow of ControlSection 6.1Array BasicsChapter 7InheritanceChapters 4 and 5Basic Classes and MethodsSection 8.1Exception BasicsSection 10.1‡VectorsChapter 12**Basic SwingChapter 13AppletsChapter 8*ExceptionsChapter 14More SwingChapter 6ArraysSection 10.2**Linked ListsSection 11.1 BasicRecursionSections 9.1 and 9.2Text FilesChapter 11*RecursionSection 10.3GenericsSection 9.4Binary FilesSection 9.3 TheFile Class* Note that some sections of these chapters can be covered sooner. Those sections are givenin this chart.** See the chapter’s “Prerequisites” section for full details.‡ Most of Section 10.1 (“Vectors”) can be covered before covering inheritance.xvPRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

PRELIMINARY PROOFS 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.This material is protected under all copyright laws as they currently exist. No portion of this material may be reproduced, in any form or by any means,without permission in writing from the publisher. For the exclusive use of adopters of the book JAVA: An Introduction to Problem Solving andProgramming, Fourth Edition (ISBN: 0-13-149202-0).

BRIEF TABLE OF CONTENTSChapter 1Chapter 2Chapter 3Chapter 4Chapter 5Chapter 6Chapter 7Chapter 8Chapter 9Chapter 10Chapter 11Chapter 12Chapter 13Chapter 14Appendix 1Appendix 2Appendix 3Appendix 4Appendix 5Appendix 6Appendix 7Appendix 8Appendix 9Appendix 10Appendix 11Introduction to Computers and Java 3Primitive Types, Strings, and Console I/O 45Flow of Control 129Defining Classes and Methods 221More About Objects and Meth