Java Programming 7th Edition Joyce Farrell - The complete ebook is available for download with one click
Java Programming 7th Edition Joyce Farrell - The complete ebook is available for download with one click
https://ebookultra.com/download/java-programming-8th-edition-joyce-
farrell/
https://ebookultra.com/download/programming-logic-and-design-
comprehensive-6th-edition-joyce-farrell/
https://ebookultra.com/download/java-programs-to-accompany-
programming-logic-and-design-7th-edition-jo-ann-smith/
https://ebookultra.com/download/computer-programming-for-teens-1st-
edition-mary-e-farrell/
Advanced Java Game Programming Wallace Croft
https://ebookultra.com/download/advanced-java-game-programming-
wallace-croft/
https://ebookultra.com/download/java-programming-10-minute-
solutions-1st-edition-mark-watson/
https://ebookultra.com/download/killer-game-programming-in-java-1st-
edition-andrew-davison/
https://ebookultra.com/download/introduction-to-programming-with-
java-3rd-edition-john-dean/
https://ebookultra.com/download/the-java-tm-programming-language-4th-
edition-ken-arnold/
Java Programming 7th Edition Joyce Farrell Digital
Instant Download
Author(s): Joyce Farrell
ISBN(s): 9781285081953, 1285081951
Edition: 7
File Details: PDF, 32.45 MB
Year: 2014
Language: english
Buy. Rent. Access.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
TM
JAVA PROGRAMMING
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
SEVENTH EDITION
TM
JAVA PROGRAMMING
JOYCE FARRELL
Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Java Programming, © 2014 Course Technology, Cengage Learning
Seventh Edition
ALL RIGHTS RESERVED. No part of this work covered by the copyright
Joyce Farrell
herein may be reproduced, transmitted, stored, or used in any form or
Executive Editor: by any means—graphic, electronic, or mechanical, including but not
Kathleen McMahon limited to photocopying, recording, scanning, digitizing, taping, Web
distribution, information networks, or information storage and
Senior Product Manager: retrieval systems, except as permitted under Section 107 or 108 of the
Alyssa Pratt 1976 United States Copyright Act, without the prior written
Development Editor: Dan Seiter permission of the publisher.
Editorial Assistant: Sarah Ryan
Brand Manager: Kay Stefanski For product information and technology assistance, contact us at
Print Buyer: Julio Esperas Cengage Learning Customer & Sales Support, 1-800-354-9706
Art and Design Direction, For permission to use material from this text or product,
Production Management, and submit all requests online at www.cengage.com/permissions.
Composition: Integra Software
Further permissions questions can be emailed to
Services Pvt. Ltd.
[email protected].
Cover Designer: Lisa Kuhn/Curio
Press, LLC www.curiopress.com
Cover Photo: © Leigh Prather/Veer Library of Congress Control Number: 2012953690
Copyeditor: Mark Goodin Student Edition:
Proofreader: Pamela Hunt ISBN-13: 978-1-285-08195-3
Indexer: Alexandra Nickerson ISBN-10: 1-285-08195-1
Course Technology
20 Channel Center Street
Boston, MA 02210
USA
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
This is an electronic version of the print textbook. Due to electronic rights restrictions, some third party content may be suppressed. Editorial
review has deemed that any suppressed content does not materially affect the overall learning experience. The publisher reserves the right to
remove content from this title at any time if subsequent rights restrictions require it. For valuable information on pricing, previous
editions, changes to current editions, and alternate formats, please visit www.cengage.com/highered to search by
ISBN#, author, title, or keyword for materials in your areas of interest.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Brief Contents
v
Preface . . . . . . . . . . . . . . . . . . . . . . xxi
CHAPTER 1 Creating Java Programs . . . . . . . . . . . . . . . . 1
CHAPTER 2 Using Data . . . . . . . . . . . . . . . . . . . . . 51
CHAPTER 3 Using Methods, Classes, and Objects . . . . . . . 117
CHAPTER 4 More Object Concepts . . . . . . . . . . . . . . . 179
CHAPTER 5 Making Decisions . . . . . . . . . . . . . . . . . 241
CHAPTER 6 Looping . . . . . . . . . . . . . . . . . . . . . 299
CHAPTER 7 Characters, Strings, and the StringBuilder . . . . . 349
CHAPTER 8 Arrays . . . . . . . . . . . . . . . . . . . . . . 397
CHAPTER 9 Advanced Array Concepts . . . . . . . . . . . . . 443
CHAPTER 10 Introduction to Inheritance . . . . . . . . . . . . . 499
CHAPTER 11 Advanced Inheri tance Concepts . . . . . . . . . . 547
CHAPTER 12 Exception Handling . . . . . . . . . . . . . . . . 603
CHAPTER 13 File Input and Output . . . . . . . . . . . . . . . 675
CHAPTER 14 Introduction to Swing Components . . . . . . . . 739
CHAPTER 15 Advanced GUI Topics . . . . . . . . . . . . . . . 801
CHAPTER 16 Graphics . . . . . . . . . . . . . . . . . . . . . 879
CHAPTER 17 Applets, Images, and Sound . . . . . . . . . . . . 945
APPENDIX A Working with the Java Platform . . . . . . . . . . . 993
APPENDIX B Learning About Data Representation . . . . . . . 1001
APPENDIX C Formatting Output . . . . . . . . . . . . . . . 1009
APPENDIX D Generating Random Numbers . . . . . . . . . . 1021
APPENDIX E Javadoc . . . . . . . . . . . . . . . . . . . . 1029
Glossary . . . . . . . . . . . . . . . . . . . . 1037
Index . . . . . . . . . . . . . . . . . . . . . . 1063
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Contents
vi
Preface . . . . . . . . . . . . . . . . . . xxi
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . 44
Review Questions . . . . . . . . . . . . . . . . . . . . . . 45
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . 47
Programming Exercises . . . . . . . . . . . . . . . . . . 47
Debugging Exercises . . . . . . . . . . . . . . . . . . . 49 vii
Game Zone . . . . . . . . . . . . . . . . . . . . . . . . 49
Case Problems . . . . . . . . . . . . . . . . . . . . . . 50
C H AP T E R 2 Using Data . . . . . . . . . . . . . . . . . 51
Declaring and Using Constants and Variables . . . . . . . . . . 52
Declaring Variables . . . . . . . . . . . . . . . . . . . . 53
Declaring Named Constants . . . . . . . . . . . . . . . . 54
The Scope of Variables and Constants . . . . . . . . . . . . 56
Concatenating Strings to Variables and Constants . . . . . . . 56
Pitfall: Forgetting That a Variable Holds One Value at a Time . . . 58
Learning About Integer Data Types . . . . . . . . . . . . . . 62
Using the boolean Data Type . . . . . . . . . . . . . . . . 67
Learning About Floating-Point Data Types . . . . . . . . . . . . 69
Using the char Data Type . . . . . . . . . . . . . . . . . . 70
Using the Scanner Class to Accept Keyboard Input . . . . . . . 76
Pitfall: Using nextLine() Following One of the
Other Scanner Input Methods . . . . . . . . . . . . . . 79
Using the JOptionPane Class to Accept GUI Input . . . . . . . 85
Using Input Dialog Boxes . . . . . . . . . . . . . . . . . . 85
Using Confirm Dialog Boxes . . . . . . . . . . . . . . . . 89
Performing Arithmetic . . . . . . . . . . . . . . . . . . . . 91
Associativity and Precedence . . . . . . . . . . . . . . . . 93
Writing Arithmetic Statements Efficiently . . . . . . . . . . . 94
Pitfall: Not Understanding Imprecision in
Floating-Point Numbers . . . . . . . . . . . . . . . . . 94
Understanding Type Conversion . . . . . . . . . . . . . . . . 99
Automatic Type Conversion . . . . . . . . . . . . . . . . . 99
Explicit Type Conversions . . . . . . . . . . . . . . . . 100
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 104
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 105
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 109
Review Questions . . . . . . . . . . . . . . . . . . . . . 109
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 112
Programming Exercises . . . . . . . . . . . . . . . . . 112
Debugging Exercises . . . . . . . . . . . . . . . . . . 115
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 115
viii Case Problems . . . . . . . . . . . . . . . . . . . . . 116
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
C H AP T E R 4 More Object Concepts . . . . . . . . . . . 179
Understanding Blocks and Scope . . . . . . . . . . . . . . 180
Overloading a Method . . . . . . . . . . . . . . . . . . . 188
Automatic Type Promotion in Method Calls . . . . . . . . . 190
Learning About Ambiguity . . . . . . . . . . . . . . . . . 195 ix
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS
C H AP T E R 6 Looping . . . . . . . . . . . . . . . . . 299
Learning About the Loop Structure . . . . . . . . . . . . . . 300
Creating while Loops . . . . . . . . . . . . . . . . . . 301
Writing a Definite while Loop . . . . . . . . . . . . . . 301
Pitfall: Failing to Alter the Loop Control Variable Within
the Loop Body . . . . . . . . . . . . . . . . . . . . 303
Pitfall: Creating a Loop with an Empty Body . . . . . . . . . 304
Altering a Definite Loop’s Control Variable . . . . . . . . . . 305
Writing an Indefinite while Loop . . . . . . . . . . . . . 306
Validating Data . . . . . . . . . . . . . . . . . . . . . 308
Using Shortcut Arithmetic Operators . . . . . . . . . . . . . 312
Creating a for Loop . . . . . . . . . . . . . . . . . . . 317
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Learning How and When to Use a do … while Loop . . . . . . 321
Learning About Nested Loops . . . . . . . . . . . . . . . . 324
Improving Loop Performance . . . . . . . . . . . . . . . . 329
Avoiding Unnecessary Operations . . . . . . . . . . . . . 329
Considering the Order of Evaluation of Short-Circuit Operators . 330 xi
Comparing to Zero . . . . . . . . . . . . . . . . . . . 331
Employing Loop Fusion . . . . . . . . . . . . . . . . . . 332
Using Prefix Incrementing Rather than Postfix Incrementing . . 332
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 337
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 337
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 339
Review Questions . . . . . . . . . . . . . . . . . . . . . 339
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 342
Programming Exercises . . . . . . . . . . . . . . . . . 342
Debugging Exercises . . . . . . . . . . . . . . . . . . 346
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 346
Case Problems . . . . . . . . . . . . . . . . . . . . . 348
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS
C H AP T E R 8 Arrays . . . . . . . . . . . . . . . . . . 397
Declaring Arrays . . . . . . . . . . . . . . . . . . . . . 398
Initializing an Array . . . . . . . . . . . . . . . . . . . . 403
Using Variable Subscripts with an Array . . . . . . . . . . . . 406
xii Using Part of an Array . . . . . . . . . . . . . . . . . . 408
Declaring and Using Arrays of Objects . . . . . . . . . . . . 410
Using the Enhanced for Loop with Objects . . . . . . . . . 412
Manipulating Arrays of Strings . . . . . . . . . . . . . 412
Searching an Array and Using Parallel Arrays . . . . . . . . . 418
Using Parallel Arrays . . . . . . . . . . . . . . . . . . . 418
Searching an Array for a Range Match . . . . . . . . . . . 421
Passing Arrays to and Returning Arrays from Methods . . . . . 425
Returning an Array from a Method . . . . . . . . . . . . . 429
Don’t Do It . . . . . . . . . . . . . . . . . . . . . . . . 431
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 431
Chapter Summary . . . . . . . . . . . . . . . . . . . . . 432
Review Questions . . . . . . . . . . . . . . . . . . . . . 433
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 436
Programming Exercises . . . . . . . . . . . . . . . . . 436
Debugging Exercises . . . . . . . . . . . . . . . . . . 439
Game Zone . . . . . . . . . . . . . . . . . . . . . . . 439
Case Problems . . . . . . . . . . . . . . . . . . . . . 441
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has
deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS
The year was either never mentioned, or has been rubbed out.
9th. The noise of the sailors and the hum of business—sounds long
foreign to my ear—greeted me upon waking this morning, and on
looking out of my window I saw a number of people upon the quay
below, buying fish from the sailors of some fishing-boats that had
just come into the harbour. After breakfast I accompanied Sir
Humphry on a visit to the British Consul, Colonel D——, who politely
promised to send Sir Humphry a fisherman who could supply him
with some living torpedos for his experiments. Sir Humphry
afterwards rode out on his pony, George attending him, whilst I took
a walk on the hill above the town. I had intended to visit the
stalactite grotto at Corneale to-day, as Sir Humphry, who had seen it
ten years ago, said it was well worth notice; but on coming away
from Colonel D——'s I found that it was too late.
10th. I left Trieste early this morning, with a guide, to visit the
grotto. After a three hours' walk over two very long and steep hills,
from which however the view over the Adriatic, with numberless
white sails flitting across its waves, the two coasts, the harbour with
its shipping, the town and the gardens surrounding it planted with
cypresses and olives, was magnificent, we reached Corneale, a small
and dirty village, and having here provided ourselves with a man
carrying a large lamp, and some boys with candles, proceeded over
some very rough and stony fields to the grotto. The entrance was
not, as I had expected, in the side of a hill, but in the open fields,
and surrounded by a wall. Having lighted our lamp and candles, I
took off my coat, and we began the descent down some very slight
wooden stairs, the steps and railing of which were, as I afterwards
found to my cost, not only slippery, but quite rotten from the
continual dripping. The entrance, or hall, is a fine lofty dark vault,
supported in the middle by one enormous stalactite column. Beyond
this the cave becomes narrower, and the numberless stalactites of all
sizes present a greater variety of forms than it is possible to
describe: immense cauliflowers, trunks of trees, fruits; rounds and
ovals of all sizes, from that of a marble to globes of many feet in
diameter; pyramids rising up from below, and whose bases are lost
in profound darkness; myriads of peaks hanging from the roof, often
invisible to the eye, are seen at every step.
These different forms, the deathlike stillness of the cave, the total
darkness, except in those points where the guides placed themselves
so as to illuminate the most striking objects; deep precipices before
and around me, from out of which here and there a single snow
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com