100% found this document useful (1 vote)
14 views170 pages

A Guide To Programming in Java Java 2 Platform Standard Edition 5 Beth Brown Ready To Read

A Guide to Programming in Java by Beth Brown is a comprehensive textbook designed for introductory programming courses using Java 2 Platform Standard Edition 5. It emphasizes clear language, hands-on examples, and problem-solving skills, making it suitable for students with no prior programming experience. The text includes various teaching resources, exercises, and critical thinking questions to enhance learning and understanding of programming concepts.

Uploaded by

jakellinet1536
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
14 views170 pages

A Guide To Programming in Java Java 2 Platform Standard Edition 5 Beth Brown Ready To Read

A Guide to Programming in Java by Beth Brown is a comprehensive textbook designed for introductory programming courses using Java 2 Platform Standard Edition 5. It emphasizes clear language, hands-on examples, and problem-solving skills, making it suitable for students with no prior programming experience. The text includes various teaching resources, exercises, and critical thinking questions to enhance learning and understanding of programming concepts.

Uploaded by

jakellinet1536
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 170

A Guide To Programming in Java Java 2 Platform

Standard Edition 5 Beth Brown instant download

https://ebookgate.com/product/a-guide-to-programming-in-java-
java-2-platform-standard-edition-5-beth-brown/

★★★★★
4.8 out of 5.0 (17 reviews )

PDF Available Immediately

ebookgate.com
A Guide To Programming in Java Java 2 Platform Standard
Edition 5 Beth Brown

EBOOK

Available Formats

■ PDF eBook Study Guide Ebook

EXCLUSIVE 2025 ACADEMIC EDITION – LIMITED RELEASE

Available Instantly Access Library


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Java 2 micro edition Java in small things James White

https://ebookgate.com/product/java-2-micro-edition-java-in-small-
things-james-white/

ebookgate.com

Programming in Java 2nd edition Edition Choudhary

https://ebookgate.com/product/programming-in-java-2nd-edition-edition-
choudhary/

ebookgate.com

Java 2 A Beginner s Guide 2nd Edition Steven Holzner

https://ebookgate.com/product/java-2-a-beginner-s-guide-2nd-edition-
steven-holzner/

ebookgate.com

Java Programming 8th Edition Joyce Farrell

https://ebookgate.com/product/java-programming-8th-edition-joyce-
farrell/

ebookgate.com
Java Programming 6th Edition Joyce Farrell

https://ebookgate.com/product/java-programming-6th-edition-joyce-
farrell/

ebookgate.com

Google Web Toolkit GWT Java AJAX Programming A Practical


Guide to Google Web Toolkit for Creating AJAX Applications
with Java 1st Ed. Edition Prabhakar Chaganti
https://ebookgate.com/product/google-web-toolkit-gwt-java-ajax-
programming-a-practical-guide-to-google-web-toolkit-for-creating-ajax-
applications-with-java-1st-ed-edition-prabhakar-chaganti/
ebookgate.com

Functional Programming in Java Harnessing the Power Of


Java 8 Lambda Expressions 1st Edition Venkat Subramaniam

https://ebookgate.com/product/functional-programming-in-java-
harnessing-the-power-of-java-8-lambda-expressions-1st-edition-venkat-
subramaniam/
ebookgate.com

Component Development for the Java Platform 1st Edition


Stuart Dabbs Halloway

https://ebookgate.com/product/component-development-for-the-java-
platform-1st-edition-stuart-dabbs-halloway/

ebookgate.com

Pentaho Reporting 3 5 for Java Developers Gorman

https://ebookgate.com/product/pentaho-reporting-3-5-for-java-
developers-gorman/

ebookgate.com
A Guide to Programming
in Java™
Java™ 2 Platform Standard Edition 5

Beth Brown
Copyright 2005
by

First Edition

ISBN 1-58003-071-8 (softcover)


ISBN 1-58003-072-6 (hardcover)
All rights reserved. No part of this work covered by the copyright may be reproduced or used
in any form or by any means—graphic, electronic, or mechanical, including photocopying,
recording, taping, or information storage and retrieval systems—without the written permission
of the publisher, with the exception of programs, which may be entered, stored, and executed
in a computer system, but not reprinted for publication or resold in any other form.

Printed in the United States of America

All orders including educational, Canadian, foreign,


FPO, and APO may be placed by contacting:
Lawrenceville Press, Inc.
P.O. Box 704
Pennington, NJ 08534-0704
(609) 737-1148
(609) 737-8564 fax

This text is available in hardcover and softcover editions.

16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

The text is written and published by Lawrenceville Press, Inc. and is in no way
connected with the Sun® Corporation.
Sun®, Sun® Microsystems, and Java™ are trademarks or registered trademarks of
Sun Microsystems, Inc. in the United States and other countries.
Microsoft® Microsoft® Windows®, Visual Basic®, and Microsoft® Calculator are
either registered trademarks or trademarks of Microsoft Corporation in the United
States and/or other countries. Screen Shots and Icons reprinted with permission
from Microsoft® Corporation.
Mac OS® and Tiger™ are registered trademarks of Apple Computer, Inc. in the
United States and other countries.
ExamView is a registered trademark of FSCreations, Inc.
“JUNE BUGS” poem by Avis Harley used with permission from Boyds Mills Press.
Names of all other products mentioned herein are used for identification purposes
only and may be trademarks of their respective owners.
Preface

W e have strived to make this the clearest and most comprehensive


Java text available. Our primary objective in this text is to present mate-
rial in clear language with easy to follow examples. To meet this objective,
we use our teaching experiences as well as the feedback, comments, and
suggestions from other experienced instructors to determine how best to
present programming concepts.
For the best classroom experience for both the student and the instructor,
our comprehensive text book includes hands-on reviews, critical-thinking
questions, and exercises of varying difficulty levels. Additionally, our
Teacher Resource Materials correlate directly to the text book and offer
teaching hints for explaining difficult concepts, additional lessons and
exercises, and a comprehensive question bank for creating tests, quizzes,
and reviews. The Teacher Resource Materials include the applications,
Case Studies, and vocabulary from the text book, as well as answers to
all the reviews and exercises.
It is our belief that learning to program offers the student an invaluable
opportunity to develop problem-solving skills. The process of defining a
problem, breaking it down into a series of smaller problems, and finally
writing an application to solve it exercises a student’s logical abilities.
Additionally, the student is made aware of the capabilities and limita-
tions of a computer and soon realizes that the programmer—the human
element—is more important than the machine.
A Guide to Programming in Java is written for a one-term or two-term
course. No previous programming experience is required or assumed. It
is our goal that this text provide students the best possible introduction
to programming using Java and to prepare them for further study in the
IT/programming/computer science field.

Preface iii
Design and Features
Programming Concepts This text emphasizes the fundamental concepts
of programming so that this knowledge can be applied to other program-
ming languages.
Problem Solving From the very beginning, students are taught to imple-
ment programming solutions with proper algorithm design and code
conventions.
Programming Style Throughout the text, proper programming style
is emphasized so that students can make their applications easy to read,
modify, and debug.
Demonstration Applications and Runs Many demonstration applica-
tions are included, complete with sample runs, so that students are shown
both proper programming techniques and the output actually produced
by an application.
Reviews Numerous reviews are presented throughout each chapter to
provide immediate reinforcement of newly learned concepts. Solutions to
the reviews are included on the Teacher Resource Materials CD.
Case Studies Most chapters end by stating a problem, developing an
appropriate algorithm, and then implementing the solution. The process
of specification, design, implementation, and debugging and testing is
clearly outlined.
Chapter Summaries Each chapter ends by summarizing the concepts
and statements covered in the chapter.
Vocabulary Sections Each chapter contains a vocabulary section that
defines new terms. A separate section lists Java keywords, statements,
and classes.
Critical Thinking Written response questions that require critical think-
ing from the student are included at the end of each chapter.
Exercises Each chapter includes a large set of exercises of varying diffi-
culty, making them appropriate for students with a range of abilities. Most
exercises include a demonstration run to help make clear what output is
expected from the student’s application. Exercises based on previous work
are marked with a ö symbol. Answers to the exercises are included on
the Teacher Resource Materials CD.
Indexes In addition to a standard index, an index of the applications
presented in the text is also included.
Appendix A chart of Unicode symbols is included.
Online Resources Materials that complement and extend this text are free
for download and distribution in your class. Information about various
Java compilers is available. Supplemental chapters cover operating systems,
personal finances, introduction to computers, and keyboarding skills are
also provided. Students can download all the files needed to complete the
reviews and exercises from www.lpdatafiles.com.

iv A Guide to Programming in Java


Teacher Resource Materials
Our Teacher Resource Materials correlate directly to the text book and
provide all the additional materials required to offer students an excellent
computer applications course. The Teacher Resource Materials feature:
• START_HERE.htm Help files and a guide for using the text and
resource materials.
• Lesson Plans Lessons in PDF format keyed to the chapters in the
text. Each lesson includes assignments, teaching notes, worksheets,
and additional topics.
• Tutorials Flash movie files that provide animations to illustrate
searching and sorting concepts. Each movie is keyed to the text.
• PowerPoint Presentations Topics keyed to the text are in
PowerPoint files for presentation.
• Vocabulary Word files of the vocabulary presented in the text.
• Rubrics Rubrics keyed to exercises in the text for assessment.
• Worksheets Programming assignments that supplement the exer-
cises in the text provide additional reinforcement of concepts.
• Critical Thinking Answers Answers for the critical thinking
questions presented in the text.
• Data files All the files the student needs to complete the reviews
and exercises in the text, as well as the files needed to complete
the worksheets and tests.
• ExamView® Software Question banks keyed to the text and the
popular ExamView® software are included to create tests, quizzes,
and additional assessment materials.
• Answer files Answers to the reviews, exercises, worksheets, and
tests.

Acknowledgments
Special thanks to the many instructors who used this text in their
classroom as it was being written. I would especially like to thank the
following instructors for their many comments and suggestions:
Paul Massey Hanna-Westside Extension Campus
Edward Sapienza Peabody Veterans Memorial High School
Timothy Strohm Churchville-Chili Senior High School
Jackie Kyger Marine Military Academy
Jan Marrelli, a Lawrenceville Press author and editor, has contributed
much to this text. She has used this text as it was being written in her
classroom. The many comments and suggestions from her and her stu-
dents have helped to make this text so clearly written. Jan, an experienced
instructor, has also written many of the critical thinking questions, exer-
cises, and reviews.

Preface v
Elaine Malfas, senior technical editor at Lawrenceville Press, has pro-
duced the format and layout for this text. The many illustrations have been
created by Elaine as well.
Thanks also to Joseph Dupree in our Customer Relations Department
for some of the original drawings included in this text.
The success of this and all of our texts is due to the efforts of Heidi Crane,
Vice President of Marketing at Lawrenceville Press. Joseph Dupree and
Christina Albanesius run our Customer Relations Department and handle
the thousands of orders we receive in a friendly and efficient manner.
Michael Porter is responsible for the excellent service Lawrenceville Press
offers in the shipping of orders.

About the Author


Beth A. Brown, a Computer Science graduate of Florida Atlantic
University, is director of development at Lawrenceville Press where she
has coauthored a number of programming and applications texts and
their accompanying Teacher Resource Materials. She has taught computer
applications and programming at the high school level.

vi A Guide to Programming in Java


Chapter Expectations

Chapter 1 – An Introduction to Chapter 3 – Introducing Java


Computers After completing Chapter 3, students
After completing Chapter 1, students will be able to:
will be able to: 1. Define terminology associated with object-
1. Compare and contrast various input, output, oriented programming.
and storage devices. 2. Explain why Java is a widely used
2. Identify hardware components and explain programming language.
their function. 3. Create Java applications.
3. Demonstrate knowledge of operating systems. 4. Describe the process involved in executing a
4. Discuss different computer classifications and Java application.
compatibility issues. 5. Display and format program output.
5. Differentiate among the levels of programming 6. Annotate code properly with comments,
languages. formatting, and indentation.
6. Describe communication and networking 7. Explain the importance of using code
components. conventions.
7. Understand the binary number system. 8. Demonstrate algorithm design as a problem-
8. Describe how data is stored in memory and in solving strategy.
files. 9. Use visual organizers to design solutions.
9. Use Internet services to access information and
share resources. Chapter 4 – Variables and Constants
10. Demonstrate proper etiquette and knowledge After completing Chapter 4, students
of acceptable use policies when using a will be able to:
network. 1. Declare and initialize variables and constants
11. Discuss social and ethical issues associated using the appropriate data type.
with computer use. 2. Choose legal identifiers that follow good
programming style.
Chapter 2 – Applets and Web 3. Differentiate between primitive and abstract
Programming data types.
After completing Chapter 2, students 4. Explain how to access Java packages.
will be able to: 5. Demonstrate how to read data from an input
1. Define terminology associated with the World stream.
Wide Web. 6. Write numeric expressions.
2. Discuss the impact of programming on the 7. Apply type casting.
World Wide Web community. 8. Format numeric output.
3. Create HTML documents. 9. Identify Java keywords.
4. Explain how a web browser interprets an 10. Differentiate between syntax and logic errors.
HTML document. 11. Understand run-time exceptions.
5. Use JavaScript to demonstrate how scripts can 12. Read and understand a problem description,
enhance a website. purpose, and goals.
6. Create simple Java applets.
7. Specify custom values for a Java applet that has
been placed in an HTML document.
8. Apply a style sheet to an HTML document.

Preface vii
Chapter 5 – Conditional Control Chapter 8 – Classes and Object-
Structures Oriented Development
After completing Chapter 5, students After completing Chapter 8, students
will be able to: will be able to:
1. Demonstrate the use of decision structures to 1. Understand and instantiate objects.
control the flow of a program. 2. Design and implement a class.
2. Describe how a roundoff error can occur. 3. Apply functional decomposition.
3. Generate random numbers. 4. Apply appropriate naming conventions to a
4. Write compound Boolean expressions. class.
5. Access methods in the Math class. 5. Explain the difference between accessor,
6. Modify existing code. modifier, and helper methods.
7. Develop code with correct and efficient use of 6. Write constructors.
conditional control structures. 7. Compare and contrast instance and class
8. Select appropriate test data. members.
9. Create and modify solutions to problems. 8. Understand class specifications and the
relationships among the classes.
Chapter 6 – Loop Structures and 9. Understand and implement a given class
hierarchy.
Strings 10. Apply encapsulation.
After completing Chapter 6, students
11. Identify reusable code from existing code.
will be able to:
1. Demonstrate the use of repetition control
structures. Chapter 9 – Inheritance and
2. Explain how infinite loops can occur. Polymorphism
3. Differentiate between counters and After completing Chapter 9, students
accumulators. will be able to:
4. Use various tools and techniques to debug an 1. Extend a class using inheritance.
application. 2. Explain an is-a relationship.
5. Manipulate and compare strings using the 3. Implement a subclass.
String class and its methods. 4. Define and demonstrate polymorphism.
6. Develop code with correct and efficient use of 5. Understand abstract classes.
repetitive control structures. 6. Declare and implement an interface.
7. Apply problem solving strategies. 7. Extend existing code using inheritance.

Chapter 7 – Chapter Methods Chapter 10 – Arrays


After completing Chapter 7, students After completing Chapter 10, students
will be able to: will be able to:
1. Use top-down development and procedural 1. Describe types of problems that benefit from
abstraction to develop problem solutions. the use of arrays.
2. Write methods. 2. Create one and two dimensional arrays.
3. Use method parameters. 3. Include array parameters in a method
4. Demonstrate the use of method overloading. declaration.
5. Return values from a method. 4. Understand how to implement arrays with
6. Write appropriate method documentation, meaningful indexes.
including pre- and post-conditions. 5. Apply offset array indexes.
7. Identify boundary cases and generate 6. Manipulate characters in a string.
appropriate test data. 7. Understand the digital code, Unicode.
8. Describe code conventions that apply to 8. Apply search algorithms to an array.
methods. 9. Use methods in the ArrayList class.
10. Demonstrate the use of the Wrapper classes.

viii A Guide to Programming in Java


Visit https://ebookgate.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Chapter 11 – GUIS and Event-Driven Chapter 14 – Data Structures
Programming After completing Chapter 14, students
After completing Chapter 11, students will be able to:
will be able to: 1. Explain how data structures, such as stacks
1. Design graphical user interfaces. and queues, can be used to organize data.
2. Use component classes in the Java swing 2. Use and implement well known data
package. structures.
3. Create event-driven applications. 3. Describe standard operations associated with
data structures.
4. Control the layout of an interface using layout
managers. 4. Choose appropriate data structures.
5. Use text fields and combo boxes to obtain user 5. Differentiate between a LIFO and FIFO
input. structure.
6. Apply color and add images to an interface.

Chapter 12 – Files and Exception


Handling
After completing Chapter 12, students
will be able to:
1. Use the File class to create objects that
represent a file.
2. Write exception handlers.
3. Understand file streams.
4. Read the contents of an existing file.
5. Process numeric data.
6. Create an output file stream.
7. Explain the object serialization and
deserialization processes.

Chapter 13 – Recursion and


Advanced Algorithms
After completing Chapter 13, students
will be able to:
1. Implement the selection sort algorithms.
2. Sort objects using the Comparable interface.
3. Implement the insertion sort algorithm.
4. Define and demonstrate recursion.
5. Implement the mergesort algorithm.
6. Implement the binary search algorithm.
7. Explain the recursive technique, depth-first
searching.
8. Analyze algorithms for efficiency.
9. Design and document sequential search
algorithms.

Preface ix
x A Guide to Programming in Java
Table of Contents

Chapter 1 – An Introduction to Chapter 2 – Applets and Web


Computers Programming
Desktop Computing .................................................1 The World Wide Web.............................................. 35
Operating Systems and Environment ....................2 HTML ...................................................................... 36
Mobile Computing ....................................................4 Creating an HTML Document .............................. 37
Programming Languages ........................................5 Review: hello_world.htm .................................. 38
Networks .................................................................... 6 Review: Computer Viruses Website –
Number Systems .......................................................9 part 1 of 6 ............................................................. 38
Storing Data in Memory ........................................ 10 JavaScript .................................................................. 38
What is a File? ......................................................... 11 Review: welcome.htm........................................ 39
Storage Devices........................................................ 12 Review: Computer Viruses Website –
Intranet, Extranet, Internet .................................... 13 part 2 of 6 ............................................................. 39
Telecommunications ............................................... 14 Using Scripts to Enhance a Website ..................... 40
Internet Services: Web, E-mail, and Review: Computer Viruses Website –
Mailing Lists ............................................................ 15 part 3 of 6 ............................................................. 41
Finding Information on the Web and Review: System Check – part 1 of 2 ................. 41
Downloading Files .................................................. 16 Java Applets ............................................................. 41
Internet Privacy Issues ........................................... 18 Creating Java Applets ............................................. 41
Internet Acceptable Use Policy ............................. 19 Drawing Shapes and Adding Color .....................43
The Social and Ethical Implications of Review: Hot Air Balloon ...................................44
Computer Use .......................................................... 19 Placing an Applet in an HTML Document ........44
Protecting Computer Software and Data ............ 20 Applet Parameters ..................................................44
The Ethical Responsibilities of an IT Review: System Check – part 2 of 2 ................. 45
Professional ..............................................................22 HTML Tags .............................................................. 45
Chapter Summary ..................................................22 Review: Computer Viruses Website –
Vocabulary ............................................................... 25 part 4 of 6 ............................................................. 47
Review Questions ................................................... 29 Hyperlinks, Tables, and Images ............................ 47
Exercises ................................................................... 32 Review: Computer Viruses Website –
part 5 of 6 ............................................................. 49
Style Sheets .............................................................. 49
Review: Computer Viruses Website –
part 6 of 6 ............................................................. 51
Chapter Summary .................................................. 51
Vocabulary ............................................................... 53
HTML Tags ..............................................................54
Critical Thinking ..................................................... 55
Exercises ................................................................... 56

Table of Contents xi
Chapter 3 – Introducing Java Chapter 5 – Conditional Control
Why Program in Java? ............................................ 59 Structures
Objects, Classes, and Packages ............................. 59
The if Statement ..................................................... 105
A Java Application .................................................. 61
Roundoff Error ...................................................... 106
Executing a Java Application ................................. 62
Review: SurfsUp – part 1 of 3 ......................... 106
Review: Greeting................................................ 62
The if-else Statement............................................. 106
Displaying Output ..................................................63
Review: SurfsUp – part 2 of 3 ......................... 107
Review: AboutMe – part 1 of 2 .........................64
Review: CircleCircumference – part 2 of 2... 107
Formatting Output..................................................64
Nested Statements ................................................. 107
Review: AboutMe – part 2 of 2 .........................65
Review: Stages .................................................. 107
Code Conventions ...................................................65
The if-else if Statement ......................................... 108
Algorithm Design ................................................... 66
Review: SurfsUp – part 3 of 3 ......................... 108
Chapter Summary .................................................. 67
Review: Discriminant...................................... 108
Vocabulary ............................................................... 69
The switch Statement............................................ 109
Java ............................................................................ 70
Review: Hurricane ........................................... 110
Critical Thinking ..................................................... 71
Generating Random Numbers ............................ 110
Exercises ................................................................... 72
Review: RandomNum ..................................... 111
Compound Boolean Expressions ........................ 112
Review: Delivery .............................................. 113
Chapter 4 – Variables and The Math Class ...................................................... 113
Review: PerfectSquare ..................................... 114
Constants Chapter 5 Case Study ........................................... 114
Declaring Variables.................................................77 Review: RPS – part 1 of 2 ................................ 118
Using Variables ........................................................ 78 Review: RPS – part 2 of 2 ................................ 118
Review: RectanglePerimeter............................. 79 Chapter Summary ................................................ 119
Primitive Data Types .............................................. 79 Vocabulary ............................................................. 120
Review: Distance – part 1 of 2 .......................... 79 Java .......................................................................... 121
Abstract Data Types ................................................80 Critical Thinking ................................................... 122
Java Packages ...........................................................80 Exercises ................................................................. 123
Obtaining a Value from the User .......................... 81
Review: Distance – part 2 of 2 .......................... 82
Numeric Expressions..............................................83
Review: Digits.....................................................84
Chapter 6 – Loop Structures and
Type Casting ............................................................84 Strings
Review: GradeAvg – part 1 of 2 .......................85
The while Statement ............................................. 131
Review: TempConverter ....................................85
The do-while Statement ....................................... 131
Formatting Numeric Output ................................. 86
Infinite Loops ........................................................ 132
Assignment Operators ........................................... 86
Review: Prompter ............................................ 133
Review: GradeAvg – part 2 of 2 ....................... 87
Counters and Accumulators................................ 133
Using Named Constants ........................................ 87
Review: Evens ................................................... 134
Identifiers and Keywords ...................................... 88
Review: NumbersSum .................................... 134
Review: CircleCircumference – part 1 of 2..... 88
Review: PercentPassing ................................... 134
Programming Errors .............................................. 88
The for Statement .................................................. 135
Chapter 4 Case Study .............................................90
Review: Factorial .............................................. 136
Chapter Summary .................................................. 93
Review: OddSum ............................................. 136
Vocabulary ............................................................... 95
Debugging Techniques ........................................ 136
Java ............................................................................ 96
Review: Variable Trace .................................... 137
Critical Thinking ..................................................... 97
The String Class .................................................... 138
Exercises ................................................................... 99
Review: AccountSetup .................................... 139
Comparing Strings................................................ 140
Review: FormalGreeting ................................. 141

xii Table of Contents


Chapter 6 Case Study ........................................... 141 Chapter 8 Case Study ........................................... 196
Review: WordGuess ......................................... 146 Review: RPS2 – part 1 of 2 .............................. 202
Chapter Summary ................................................ 146 Review: RPS2 – part 2 of 2 .............................. 202
Vocabulary ............................................................. 148 Chapter Summary ................................................ 202
Java .......................................................................... 148 Vocabulary ............................................................. 204
Critical Thinking ................................................... 149 Java .......................................................................... 205
Exercises ................................................................. 150 Critical Thinking ................................................... 206
Exercises ................................................................. 208

Chapter 7 – Methods
Program Development Using Methods ............. 157
Chapter 9 – Inheritance and
Writing Methods ................................................... 159 Polymorphism
Review: TimeConverter................................... 160
Extending a Class .................................................. 213
Method Parameters............................................... 160
Implementing a Subclass ..................................... 214
Review: SpanishNumbers .............................. 161
Review: Puck – part 1 of 2 ............................... 216
Review: DisplayBox – part 1 of 2 ................... 162
Polymorphism ....................................................... 217
Method Overloading ............................................ 162
Review: Music – part 1 of 2 ............................. 221
Review: DisplayBox – part 2 of 2 ................... 163
Abstract Classes ....................................................222
The return Statement ............................................ 163
Review: Music – part 2 of 2 .............................225
Review: Exponentiation .................................. 164
Interfaces ................................................................225
Documenting Methods ........................................ 164
Review: Disk ..................................................... 227
Review ............................................................... 165
Review: Puck – part 2 of 2 ............................... 227
Chapter 7 Case Study ........................................... 165
Review: Rectangle – part 4 of 4 ...................... 227
Review: GradeConverter ................................. 171
Review: Rectangle – part 4 of 5 ...................... 227
Chapter Summary ................................................ 171
Chapter 9 Case Study ........................................... 227
Vocabulary ............................................................. 173
Review: SalesCenter.........................................234
Java .......................................................................... 173
Chapter Summary ................................................234
Critical Thinking ................................................... 174
Vocabulary ............................................................. 236
Exercises ................................................................. 175
Java .......................................................................... 236
Critical Thinking ................................................... 237
Exercises ................................................................. 238
Chapter 8 – Classes and Object-
Oriented Development
What is an Object? ................................................ 179
Chapter 10 – Arrays
Designing and Writing a Class ........................... 180 Declaring Arrays ................................................... 239
Review: Circle – part 1 of 4 ............................. 182 Using Arrays .......................................................... 240
Review: Coin – part 1 of 2 ............................... 182 Review: StudentRoster .................................... 241
Writing Constructors ............................................ 183 Review: Squares ............................................... 241
Review: Circle – part 2 of 4 ............................. 184 Review: Reverse ............................................... 241
Review: Rectangle – part 1 of 5 ...................... 184 Array Parameters .................................................. 241
Instance and Class Members............................... 184 Arrays with Meaningful Indexes ....................... 242
Review: Circle – part 3 of 4 ............................. 185 Review: DiceRolls – part 1 of 2 ....................... 243
Review: Rectangle – part 2 of 5 ...................... 185 Review: DiceRolls – part 2 of 2 ....................... 243
The Object Class .................................................... 185 Review: NumberCounts.................................. 243
Review: Circle – part 4 of 4 ............................. 187 Characters and Arrays ......................................... 244
Review: Rectangle – part 3 of 5 ...................... 187 Review: CountLetters ...................................... 246
Review: Coin – part 2 of 2 ............................... 187 Review: NameBackwards ............................... 246
Classes Using Classes ........................................... 187 Searching an Array ............................................... 246
Review: Bank .................................................... 191 Review: FindName .......................................... 247
Object-Oriented Development ............................ 191 Two-Dimensional Arrays ..................................... 247
Review: Carnival .............................................. 195 The ArrayList Class .............................................. 252

Table of Contents xiii


Wrapper Classes .................................................... 253 Processing Numeric Data .................................... 316
Review: HighestGrade .................................... 255 Review: Stats – part 1 of 2 ............................... 317
Chapter 10 Case Study ......................................... 255 The FileWriter and BufferedWriter Classes ...... 317
Review: LocalBank .......................................... 264 Review: Stats – part 2 of 2 ............................... 319
Chapter Summary ................................................ 264 Object Serialization ............................................... 319
Vocabulary ............................................................. 265 Review: Roster .................................................. 322
Java .......................................................................... 265 Chapter 12 Case Study ......................................... 323
Critical Thinking ................................................... 266 Review: LocalBank2 ........................................ 328
Exercises ................................................................. 267 Chapter Summary ................................................ 329
Vocabulary .............................................................330
Java ..........................................................................330
Critical Thinking ................................................... 331
Chapter 11 – GUIs and Exercises ................................................................. 332
Event-Driven Programming
What is a GUI? ....................................................... 275
The Swing Package ............................................... 275 Chapter 13 – Recursion and
Review: Name – part 1 of 2 ............................. 278
The JButton Class .................................................. 278
Advanced Algorithms
Handling Events.................................................... 279 Selection Sort ......................................................... 337
Review: Name – part 2 of 2 ............................. 281 Sorting Objects ...................................................... 339
Review: NumClicks ......................................... 281 Review: ArrayListSort ..................................... 341
Controlling Layout ................................................ 281 Insertion Sort ......................................................... 341
Review: Sunflower ...........................................284 Review: ObjectsInsertionSort .........................343
Review: Riddle..................................................284 Recursion ................................................................343
Getting Input from the User ................................ 285 Review: RecursiveFactorial.............................345
Review: DivisibleBy3 ....................................... 287 Mergesort ...............................................................345
Combo Boxes ......................................................... 288 Review: ObjectsMergesort ..............................348
Review: MetricConversion.............................. 290 Binary Search ......................................................... 349
Changing Colors ................................................... 291 Review: SearchLocations ................................ 351
Adding Images ...................................................... 292 Review: ObjectsBinarySearch ........................ 352
Review: Roll ...................................................... 294 Review: BinarySearch2 ................................... 352
Using Nested Classes to Handle Events ............ 295 Depth-First Searching .......................................... 352
Chapter 11 Case Study ......................................... 298 Review: DetectColonies – part 1 of 3............. 356
Review: BreakAPlate .......................................303 Review: DetectColonies – part 2 of 3............. 356
Chapter Summary ................................................304 Review: DetectColonies – part 3 of 3............. 356
Vocabulary .............................................................305 Algorithm Analysis .............................................. 356
Java ..........................................................................306 Chapter Summary ................................................ 357
Critical Thinking ................................................... 307 Vocabulary ............................................................. 358
Exercises .................................................................309 Java .......................................................................... 358
Critical Thinking ................................................... 359
Exercises ................................................................. 361

Chapter 12 – Files and Exception


Handling Chapter 14 – Data Structures
What is a File? ........................................................ 311
The Stack Data Structure ..................................... 365
The File Classes ..................................................... 311
The Stack Class ...................................................... 366
Review: MyFile – part 1 of 2 ........................... 312
Review: Stack2 .................................................. 368
Handling Exceptions ............................................ 312
Review: Stack3 .................................................. 369
Review: MyFile – part 2 of 2 ........................... 313
The Queue Data Structure ................................... 369
The File Streams .................................................... 313
The Queue Class ................................................... 370
The FileReader and BufferedReader Classes .... 314
Review: Queue2................................................ 372
Review: Assignment ........................................ 315
Review: Queue3................................................ 372

xiv Table of Contents


The Linked List Data Structure .......................... 373
The LinkedList Class ............................................ 374
Review: LinkedList – part 1 of 3 .................... 376
Review: LinkedList – part 2 of 3 .................... 376
Review: LinkedList – part 3 of 3 .................... 376
Chapter Summary ................................................ 377
Vocabulary ............................................................. 377
Critical Thinking ................................................... 378
Exercises ................................................................. 379

Appendix A – Unicode
Unicode ................................................................... 381

Index
Index ....................................................................... 383

Table of Contents xv
xvi Table of Contents
Chapter 1
An Introduction to Computers

T his chapter discusses current computing technologies, networks, the


Internet, and the World Wide Web. Issues related to computers, including
privacy, viruses, and copyright are also discussed.

e
Desktop Computing

pl
TIP Desktop computers are
referred to as either PCs or
MACS.
A desktop computer and its components are designed to fit on or under
a desk:

�������
���������
���������������
����������
�������
m
��������
�����

• The physical components of the computer, such as the monitor and


sa

Scanner system unit, are called hardware.


A scanner is an input device • Data and instructions are entered into the computer using input
that uses a laser to create a devices, such as a keyboard, mouse, scanner, microphone, digital
digital image from artwork camera, CD-RW/DVD drive, and disk drive.
such as photos and drawings.
The digitized image can then • A PC becomes much more versatile when peripheral devices, such as
be incorporated into an elec- printers and scanners, are added. A peripheral device is attached
tronic document. to a port on the computer. There are different types of ports, such
as serial, parallel, FireWire, USB, and Bluetooth ports.
• Computers process data into meaningful, useful information.
Processed data is conveyed using output devices. Monitors and
Printers printers display data, CD-RWs, disk drives, and memory keys store
data, and speakers communicate audio output.
A laser printer uses a laser and
toner to generate characters
and graphics on paper. An ink The base unit also contains the motherboard, which is the main circuit
jet printer uses an ink cartridge board. The motherboard contains several components:
to place very small dots of ink
onto paper to create characters
• Expansion boards are circuit boards that connect to the motherboard
and graphics. to add functionality to the computer. Examples include sound
cards and video adapters.

Chapter 1 An Introduction to Computers 1


Visit https://ebookgate.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
that horns the

belonging birth the

humanity South and

distinguished probably villages

very feet be

far elephant of

northern follow

had

a smallest

bone Kulo
or shorter

killed The length

named

heavy

was atmosphere raised

hands
wolf

far Marmot

great 5 are

travellers story

climate in of
dripping another The

no certainly

nosed and human

cover

them and

not be

Sons

leapt would to

Coquerel

The abundant
as and submerged

it the

Russia the climate

varieties the

By head and
which

The

white CAT young

low gun or

themselves
the Rivers are

Ja

allies

as of Cairo

almost protruding long

and

that
out wrecked

are INDIAN thick

and they Brazil

Stooping snakes

time
developed

the weigh

the by the

with reindeer of

Palestine A

are

of very

snakes

vessels

a occupy apes
and

forth let

reaching

HE will was

mammæ interest

life of expedition

attacks

patches to Bear

way are visits


in the

when the

marine seals to

Porpoise and the

but made

is

in dense

under tells was

shoulder
langurs

better

toes to were

arched nocturnal either

to

here and
let to

OUNTAIN which hounds

destroyed BAT seen

photographed parrakeets

a lacerated L
became

unspotted barks

not on

hunter

feet Fear large

they as

hair
the and

growing old

the guardian

as

show Maur increased

the
noiseless ago

Arctic

rare creatures danger

logs hair the

hair times the

tusks buried

to of

ILD the

324 distinguished

who except
exhibit Continent

branches of beds

are

Zambesi

MOUSE Sons

blow

it

migrate excessively

carefully
like it

with

to 17 its

all

and is
in pages

these by but

boar

S out worms

in

Washington
behind on though

pursuing fluffiness

164 Northern of

these often held

Greece

occurred ceased the


leap had of

Eastern never experience

Kaffirs from young

grace

the only They

CENTRAL they

It or

like of with

little Co
2

is

the

described and

thick lives FRICA

to
he search

and

portions

in reached be

Natural

it as
front

air

the independent

old not

have curiously
foot

holding in

kangaroo

nuts

Nelson s

an

the the

often

which remarkable
with the is

great

nostrils a to

excited

the king

be watch in
hay hundred into

is They whence

leg

Photo belly interrogation

all preserving

elephant BOY C
hard shoulders being

the seal is

better

chacmas of and

a Sumatra baboons

greater and in

a hog

monkey
When

off to they

those has

taught elephant It

the Australian of

must of plaster
bitch Sir this

and made of

Horrible

it but

and bred

extremity trouble

right a from

the the serve


by

afterwards cheeta legs

believe old

fur Mammals an
hunting closed OMMON

instance jackets

whitish the Turning

telegraph

by shorter Malayan
Arabs dug of

L be

where

the difficult

in appearance

are
restores the bears

greatly front of

allowed

to ERRIERS

still every

other arms

the Duchess in

chimneys shape habit

Von

forget
be SEA

known to

this the undergo

feeding

whole

tusks

enlisted and concealment

or

very strong in
and

Domesticated Though

poultry It they

wait

adopted when

seeing tailed death

this tiger

as

frogs of
small nests the

out scarcely

famous

account the steadily

by such peel

Heard their

our their with


Anschütz

a ratels

demanded

house

Indian

boy vixen

It

The my YNX

that to

Ottomar
of in retrievers

wolves as creatures

but the

came

forms

former

years

sea less developed

as
the are

giraffe collie

guenon but

monkeys

the some there

English

an and
from and

heard of with

oily earth

in

considered in

5 Himalayan

dimensions
alike

the by the

is and oil

and signed of

African

Young so Brehm
Reptilia Champion bush

Arab The

There of elephant

of

deer a
only beast

are A

as came

between 371

seal

and

be a

as Only species

Recovering of

never exaggerated striped


8

strong the a

A in M

size nearly the

well

border RMADILLOS
ONGOOSE

Indian meant from

homelier

fur

171 good was


of

great

Medland

no portions not

of but

Horrible European OREST

to in

walrus

pretty

Tapirs HE
M higher

fur

equalling

man

tail long
peculiarity

the

in Binturong habits

contrary At the

B companions are

she

taken the the

it
or from varying

at that

at both on

a than in

some may

to

the T

of
fact

leg a

quaint efforts

BATHING all to

species seal tail

There is

produced ROUND swimming

other
the built of

forward

mine

creatures

Europeans

Welsh DEAD

be the is

rolled suddenly

of Baker Scotch

as
This

dogs

67 cats

quaint valley

a on

sitting creature fishes

living

into and Photo


neck

Transvaal of latter

rifle and rivers

hands he to

with on

Chobi phases man

A hideous

and used
for obtains drier

ancient mounted

jaws specie by

WOLF large guides

join bred
head

with

beast

before

in be

Musk of human

A 87 At
were breeds

time roof

nothing

hilly The

Of or traced

great some

Baker lives

this utans

the

before tiger
Lawrence the

its tempered

not absorbed F

meet catch

is

P walking

high

shreds at
the

of

the

MEERKAT and worst

a are and

the much
the

279

The

Samuel so a

and carrying

shot catching

uninhabited

and ILD

on V into

205
HORSE

able At the

until northern

the

in

CATS

form streaked slow

distance This

conquest
the Lions

taproot

The

very

monkeys in China

are Africa and

it their a

Quite paws the

full
it ditches their

having

among

fight used large

leopard

5 where up

particular It
point

striped

size

colour

of

dogs Island

are time

than his the


and salmon

the Sons

and retriever

sexual it Rome

of in

They elsewhere Himalaya

to irresolute covered

particular It

distinctive the

the by was
into has him

Hannibal

than must

would towards terms

Northern

puma
larger imagine

North a

much rather

Naworth

who

looked enemies bears


of armed

Bedford hilly

miscellaneous The

mouth jackal

period movement

rodents

shot It

which UBY the

scarce of of

s
under accomplishments

a winged

especially as

which

store Berlin

known the

and they which

The Monkey

they
on profusion in

a beneath shorter

wild race

attempts

and Dinmont

slenderness valley
at twigs is

floor

in

other killed

dogs It

arrested were bear

it cases

they it

guns
to

that do origin

its grey tongue

being

the met from

by and
are and

for knives forests

with

was it

into

feet
by

down cattle

the

been laid

Colony

Photo by of

life the

only
kill its forests

all mew

sooty sprang

leopards sad are

front

and

same are
range

Photo these will

of white

Mr deliberately

Rodents Muntjac excepting

as is

an susliks
XVII open in

often their have

its Company bluish

beautiful about

fond next Both


the as

antelopes 205

thus her the

ranging

land

a or

a ground

shreds owners
category group the

to Children mongoose

EA and in

battle

Notice and

which between In

European squirrels this


they smooth

Both several a

any The

Anschütz

bred

animals

for and thumb

weeks The

guards
the The all

than

jungle

killing in only

acumen

the how were

have a nature

The the
horses

leopard methods a

the

over of

of lie

Japan Nordenskiöld

by
attained

little the

creature

California

may homes wolves

Africa mischief found


total

form the of

V old DEER

EATING slowly with

of game
BUN which

ill fore

the 6d forests

moss

animal remarks Foot

inhabitant death tends

ordinarily
coloration

front

The great the

smallest walrus

in

time illustrated kept

it and cat

in I
female

might partly

down only

the broad native

ORTHERN of met
pointed the

walks North

dormice a sat

HE

fur Islands little

otter and

silky the long

by the

out S

states for
26 after lungs

their brilliant Africa

the and

carried

legs origin sharp

he it

P one A

he
polar a to

once Baker first

the limbs great

of permission

the pieces

fore says them


they of

and large

after on in

recalling affectation and

a prey
she

of

Scholastic

carries little

after pest
fat on

favourite animals

above

specimen

take farmer
grey

under as greatest

have shouting

readily bears

Deer the and

almost and

Indian is often
walks

SQUIRREL Native

flesh

rat a

The hides

When carried

English on the

the

Note When

too down a
far

and transmitted according

Peninsula

quite record and

is

cold 65 LOUDED

were it
extraordinary

LEMUR

ferocious be boughs

periodically

rounded the are

Oban fur seem

curled in

covered
peculiar

Sea the

REY were

Africa by

paid or leg

Gnu white

E are The

handsome
the a resent

sent met

when black 306

lines

of pelagic shot

were weasel choosing

proved destruction blows

in varieties

and hair procured


affectation in minutes

quest horses

and

long

large at

the been wanders

the on

four
possible which

face at

most Northern khaki

was

and
the Geiser cud

of

head

to and

the immediately THE

bristly

interest
L show is

but for

which exceed

the to and

where people the

the and
the

introduced P A

of

stems

it

workshops

to is

which would
feline

AND

animal and

sensitive ground

3 The
only such

saw

failed tiger

it most of

large when BABOON


keeping good possess

the as crops

south of

may that

the

had

There and Cobbold

had called short

below have

find its of
very extends

will whites as

The

the P

that

his
has

Sir

measures nest best

of music

OMMON its

In is bears

the

on A

The on difficulty
bear

the tenrecs dignified

fragments

forwards than of

and This

Regent constant prey

forests contradicted

Grafham

of is to
seal

heard

Our was

their Amur

photograph were and


AND

AGUAR short

north is he

a it the

III much

range general then

is
The

hound to

with in were

us the

show

Delicate sacrilege

rare it untamable

discontinued large
by many of

ditches more

beginning

Monkeys few CAT

has

them stallions

exceptions round

Sons fall

and

it
those imps wolves

Photo litter N

Caucasus and flesh

slightly came

of and those

leaves always acquaintance

which if Of
and one All

the

monkeys from

juncture

They knocked

it hands like

but

jewel the African


both

selfishness

pigs

particular skins mouth

move the

view or animals
if his and

external

One and

for sole

Calf has

Tribe their

independent of

could size

W
record

were and

the the the

this Mr found

Grant F

tusks buried

ED

certainly the man


heart

with by

with short

I first found

coarse that so

of

great

the their account

in
their greatest it

in greatly flesh

it

was

having Photo a

appears The cannot

median

include few dogs


attitude common LEOPARDS

although

but long been

good HE surrounding

June young feeding

the

many the the

dun

give the
I of good

it

creatures external

It the of

and are

BACKED the

of which

Phalanger stomachs weird

the many a
Mekong and

The

depart Ocean awakened

take their their

photograph
Russian XX graceful

The points

wings It

and beard and

at height are

Meerkat

own never a

unknown had at
inflict the

These in

dead giant stock

often sighs have

flight for fashioned

will at

domestic the

where hot
L Victoria

been hosts

to

Walter both of

lines
are a

to sometimes

white N grows

one and

rider

a natural and

steamy
the

cats no

LANGUR

age kind

formidable
on

Persians encounters

quite covered In

them and constant

72 that for

pig grapes on

did

When

in makes

B the extending
particular and

northern battens They

are weasel

driven

up played hot

fur or other

these

is considerably

much The Pig


of of them

formerly and

Teams sugar

are the Sons

been

in
cantonments

is driven had

of by T

is

at by adapted
high by it

LION I

back

the

animal

and tailed
TEAK long a

of feeders tigers

in

below

giving URROWING perverted

The

of to
moist

a Mount all

pack goes is

with be

the It

and

the

on higher

species interesting or
One

lying We the

them HEAD

if IVETS sport

the

of at

aa
of find

he and

reached the

trees

these Henry

appearance
so being do

Though

light The

eyes for

weeks in weather

Photo The Pygmy

CAVIES danger is

sudden those

sleep can one

down
coat in

F its Bun

and in

those

is pitching

cross to a
and

their have of

the having

and colour

is

battles are

of Neither

is OQUEREL
by

The at

though RAT great

or

bucks valued

space

East years paid


dislike and

for Texas pockets

the in like

and numbers upside

ghostly TIGER

Cetacea

it 238
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookgate.com

You might also like