Tony Gaddis's accessible, step-by-step presentation helps beginning students understand the important details necessary to become skilled programmers at an introductory level. Gaddis motivates the study of both programming skills and the Java programming language by presenting all the details needed to understand the "how" and the "why"-but never losing sight of the fact that most beginners struggle with this material. His approach is both gradual and highly accessible, ensuring that students understand the logic behind developing high-quality programs.In Starting Out with Java: Early Objects, Gaddis looks at objects-the fundamentals of classes and methods-before covering procedural programming. As with all Gaddis texts, clear and easy-to-read code listings, concise and practical real-world examples, and an abundance of exercises appear in every chapter.
Les mer
Preface xvChapter 1 Introduction to Computers and Java 11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Why Program? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Computer Systems: Hardware and Software . . . . . . . . . . . . . . . . . . . . . 21.4 Programming Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.5 What Is a Program Made of? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91.6 The Programming Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161.7 Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Review Questions and Exercises 24Programming Challenge 28Chapter 2 Java Fundamentals 312.1 The Parts of a Java Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312.2 The print and printIn Methods, and the Java API . . . . . . . . . . . . . . 372.3 Variables and Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432.4 Primitive Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492.5 Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 602.6 Combined Assignment Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 692.7 Conversion between Primitive Data Types . . . . . . . . . . . . . . . . . . . . . . 702.8 Creating Named Constants with final . . . . . . . . . . . . . . . . . . . . . . . . 742.9 The String Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 762.10 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812.11 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 832.12 Programming Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 872.13 Reading Keyboard Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 892.14 Dialog Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972.15 The printf Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1042.16 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107Review Questions and Exercises 109Programming Challenges 113Chapter 3 A First Look at Classes and Objects 1193.1 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1193.2 More about Passing Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1393.3 Instance Fields and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1423.4 Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1453.5 A Bank Account Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1513.6 Classes, Variables, and Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1623.7 Packages and import Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 1633.8 Focus on Object-Oriented Design: Finding the Classes and Their Responsibilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1643.9 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173Review Questions and Exercises 173Programming Challenges 177Chapter 4 Decision Structures 1814.1 The if Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1814.2 The if-else Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1904.3 The Payroll Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1934.4 Nested i f Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1974.5 The if-else-if Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2054.6 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2104.7 Comparing String Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2184.8 More about Variable Declaration and Scope . . . . . . . . . . . . . . . . . . . 2234.9 The Conditional Operator (Optional) . . . . . . . . . . . . . . . . . . . . . . . . . 2254.10 The switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2264.11 Formatting Numbers with the Decimal Format Class. . . . . . . . . . . . 2364.12 Focus on Problem Solving: The Sales Commission Class . . . . . . . . . . 2404.13 The Random Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2474.14 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250Review Questions and Exercises 251Programming Challenges 256Chapter 5 Loops and Files 2635.1 The Increment and Decrement Operators . . . . . . . . . . . . . . . . . . . . . 2635.2 The while Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2675.3 Using the while Loop for Input Validation . . . . . . . . . . . . . . . . . . . . . 2745.4 The do-while Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2775.5 The for Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2805.6 Running Totals and Sentinel Values . . . . . . . . . . . . . . . . . . . . . . . . . . 2915.7 Nested Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2965.8 The break and continue Statements . . . . . . . . . . . . . . . . . . . . . . . . 2995.9 Deciding Which Loop to Use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2995.10 Introduction to File Input and Output . . . . . . . . . . . . . . . . . . . . . . . . 3005.11 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320Review Questions and Exercises 321Programming Challenges 326Chapter 6 A Second Look at Classes and Objects 3336.1 Static Class Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3336.2 Overloaded Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3406.3 Overloaded Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3456.4 Passing Objects as Arguments to Methods . . . . . . . . . . . . . . . . . . . . . 3526.5 Returning Objects from Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3556.6 The toString Method. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3586.7 Writing an equals Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3626.8 Methods That Copy Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3646.9 Aggregation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3676.10 The this Reference Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3806.11 Inner Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3836.12 Enumerated Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3866.13 Garbage Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3956.14 Focus on Object-Oriented Design: Class Collaboration . . . . . . . . . . . 3976.15 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401Review Questions and Exercises 402Programming Challenges 407Chapter 7 Arrays and the ArrayList Class 4137.1 Introduction to Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4137.2 Processing Array Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4247.3 Passing Arrays as Arguments to Methods . . . . . . . . . . . . . . . . . . . . . . 4367.4 Some Useful Array Algorithms and Operations . . . . . . . . . . . . . . . . . . 4407.5 Returning Arrays from Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4527.6 String Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4547.7 Arrays of Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4587.8 The Sequential Search Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4627.9 The Selection Sort and the Binary Search Algorithms . . . . . . . . . . . . . 4657.10 Two-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4737.11 Arrays with Three or More Dimensions . . . . . . . . . . . . . . . . . . . . . . . 4857.12 Command-Line Arguments and Variable-Length Argument Lists . . . . 4867.13 The ArrayList Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4907.14 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498Review Questions and Exercises 499Programming Challenges 503Chapter 8 Text Processing and Wrapper Classes 5118.1 Introduction to Wrapper Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5118.2 Character Testing and Conversion with the Character Class . . . . . . . 5128.3 More about String Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5198.4 The StringBuilder Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5338.5 Tokenizing Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5428.6 Wrapper Classes for the Numeric Data Types . . . . . . . . . . . . . . . . . . . 5518.7 Focus on Problem Solving: The Test Score Reader Class . . . . . . . . . . 5558.8 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559Review Questions and Exercises 559Programming Challenges 563Chapter 9 Inheritance 5699.1 What Is Inheritance? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5699.2 Calling the Superclass Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . 5809.3 Overriding Superclass Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5889.4 Protected Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5969.5 Classes That Inherit from Subclasses. . . . . . . . . . . . . . . . . . . . . . . . . . 6039.6 The Object Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6089.7 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6109.8 Abstract Classes and Abstract Methods . . . . . . . . . . . . . . . . . . . . . . . 6159.9 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6219.10 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632Review Questions and Exercises 633Programming Challenges 639Chapter 10 Exceptions and Advanced File I /O 64510.1 Handling Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64510.2 Throwing Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66610.3 Advanced Topics: Binary Files, Random Access Files, and Object Serialization . . . . . . . . . . . . . . . . . . 67410.4 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690Review Questions and Exercises 691Programming Challenges 697Chapter 11 GUI Applications-Part 1 70111.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70111.2 Dialog Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70411.3 Creating Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71511.4 Equipping GUI Classes with a main Method. . . . . . . . . . . . . . . . . . . . 73911.5 Layout Managers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74111.6 Radio Buttons and Check Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75811.7 Borders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77111.8 Focus on Problem Solving: Extending the JPanel Class . . . . . . . . . . . 77311.9 Splash Screens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78711.10 Using Console Output to Debug a GUI Application . . . . . . . . . . . . . . 78811.11 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 792Review Questions and Exercises 793Programming Challenges 798Chapter 12 GUI Applications-Part 2 80312.1 Read-Only Text Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80312.2 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80412.3 Combo Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82112.4 Displaying Images in Labels and Buttons . . . . . . . . . . . . . . . . . . . . . . 82712.5 Mnemonics and Tool Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83312.6 File Choosers and Color Choosers . . . . . . . . . . . . . . . . . . . . . . . . . . . 83512.7 Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83912.8 More about Text Components: Text Areas and Fonts . . . . . . . . . . . . . 84812.9 Sliders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85312.10 Look and Feel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85712.11 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859Review Questions and Exercises 860Programming Challenges 865Chapter 13 Applets and More 86913.1 Introduction to Applets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86913.2 A Brief Introduction to HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87113.3 Creating Applets with Swing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88113.4 Using AWT for Portability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88913.5 Drawing Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89413.6 Handling Mouse Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91413.7 Timer Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92513.8 Playing Audio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92913.9 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 934Review Questions and Exercises 934Programming Challenges 940Chapter 14 Recursion 94314.1 Introduction to Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94314.2 Solving Problems with Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94614.3 Examples of Recursive Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95014.4 A Recursive Binary Search Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 95714.5 The Towers of Hanoi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96014.6 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 964Review Questions and Exercises 965Programming Challenges 968Chapter 15 Databases 97115.1 Introduction to Database Management Systems . . . . . . . . . . . . . . . . 97115.2 Tables, Rows, and Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97415.3 The SQL SELECT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97715.4 Introduction to JDBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98615.5 Inserting Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99415.6 Updating and Deleting Existing Rows . . . . . . . . . . . . . . . . . . . . . . . . 99615.7 Creating and Deleting Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99815.8 Creating a New Database with Java DB . . . . . . . . . . . . . . . . . . . . . . 100115.9 Scrollable Result Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100315.10 Result Set Meta Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100515.11 Displaying Query Results in a J Table . . . . . . . . . . . . . . . . . . . . . . . 100815.12 Relational Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101915.13 Advanced Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104015.14 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1042Review Questions and Exercises 1042Programming Challenges 1047Appendix A Getting Started with Alice 1049Index 1077Available on the book's online resource page at www.pearsonhighered.com/gaddis:Appendix B The ASCII/Unicode CharactersAppendix C Operator Precedence and AssociativityAppendix D Java Key WordsAppendix E Installing the JDK and JDK DocumentationAppendix F Using the javadoc UtilityAppendix G More about the Math ClassAppendix H PackagesAppendix I Working with Records and Random-Access FilesAppendix J Installing Java DBAppendix K The QuickSort AlgorithmAppendix L Answers to Checkpoints QuestionsAppendix M Answers to Odd-Numbered Review QuestionsCase Study 1 The Amortization ClassCase Study 2 The PinTester ClassCase Study 3 Parallel ArraysCase Study 4 The Serial Number ClassCase Study 5 A Simple Text Editor Application
Les mer

Produktdetaljer

ISBN
9780132164764
Publisert
2011-04-27
Utgave
4. utgave
Utgiver
Vendor
Pearson
Vekt
1710 gr
Høyde
254 mm
Bredde
203 mm
Aldersnivå
05, U
Språk
Product language
Engelsk
Format
Product format
Heftet
Antall sider
1128

Forfatter

Biographical note

Tony Gaddis is the principal author of the Starting Out with series of textbooks. He has nearly two decades of experience teaching computer science courses, primarily at Haywood Community College. Tony is a highly acclaimed instructor who was previously selected as the North Carolina Community College Teacher of the Year, and has received the Teaching Excellence award from the National Institute for Staff and Organizational Development. The Starting Out with series includes introductory textbooks covering Programming Logic and Design, Alice, C++, Java, Microsoft Visual Basic, and Python.