Building Java Programs - A Back to Basics Approach Stuart Reges instant download
Building Java Programs - A Back to Basics Approach Stuart Reges instant download
https://textbookfull.com/product/building-java-programs-a-back-
to-basics-approach-stuart-reges-2/
https://textbookfull.com/product/building-java-programs-a-back-
to-basics-approach-stuart-reges-2/
https://textbookfull.com/product/building-java-programs-a-back-
to-basics-approach-5th-edition-stuart-reges/
https://textbookfull.com/product/building-python-programs-1st-
edition-stuart-reges/
https://textbookfull.com/product/simpler-living-back-to-basics-
guides-2nd-edition-jeff-davidson/
College physics : a strategic approach 4th Edition
Stuart Field
https://textbookfull.com/product/college-physics-a-strategic-
approach-4th-edition-stuart-field/
https://textbookfull.com/product/artificial-intelligence-a-
modern-approach-4th-edition-stuart-russell/
https://textbookfull.com/product/restful-java-web-services-a-
pragmatic-guide-to-designing-and-building-restful-apis-using-
java-3rd-edition-balachandar/
https://textbookfull.com/product/a-functional-approach-to-java-
augmenting-object-oriented-java-code-with-functional-
principles-1st-edition-ben-weidig/
https://textbookfull.com/product/back-trouble-a-new-approach-to-
prevention-and-recovery-based-on-the-alexander-technique-deborah-
caplan/
GLOBAL GLOBAL
EDITION EDITION
For these Global Editions, the editorial team at Pearson has Building Java™ Programs
EDITION
FOURTH
This is a special edition of an established
title widely used by colleges and universities
Stepp
Reges
throughout the world. Pearson published this
exclusive edition for the benefit of students
outside the United States and Canada. If you
purchased this book within the United States
EDITION
GLOBAL
or Canada, you should be aware that it has
been imported without the approval of the
Publisher or Author.
Stuart Reges
University of Washington
Marty Stepp
Stanford University
The authors and publisher of this book have used their best efforts in preparing this book. These efforts include the
development, research, and testing of the theories and programs to determine their effectiveness. The authors and
publisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation
contained in this book. The authors and publisher shall not be liable in any event for incidental or consequential damages
in connection with, or arising out of, the furnishing, performance, or use of these programs.
Acknowledgements of third-party content appear on pages 1219–1220, which constitute an extension of this copyright page.
PEARSON, and MYPROGRAMMINGLAB are exclusive trademarks in the U.S. and/or other countries owned by
Pearson Education, Inc. or its affiliates.
Pearson Education Limited
Edinburgh Gate
Harlow
Essex CM20 2JE
England
and Associated Companies throughout the world
Visit us on the World Wide Web at:
www.pearsonglobaleditions.com
© Pearson Education Limited 2018
The rights of Stuart Reges and Marty Stepp to be identified as the authors of this work have been asserted by them
in accordance with the Copyright, Designs and Patents Act 1988.
Authorized adaptation from the United States edition, entitled Building Java Programs: A Back to Basics Approach,
4th Edition, ISBN 978-0-13-432276-6, by Stuart Reges and Marty Stepp published by Pearson Education © 2017.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any
form or by any means, electronic, mechanical, photocopying, recording or otherwise, without either the prior written
permission of the publisher or a license permitting restricted copying in the United Kingdom issued by the Copyright
Licensing Agency Ltd, Saffron House, 6–10 Kirby Street, London EC1N 8TS.
All trademarks used herein are the property of their respective owners. The use of any trademark in this text does not vest
in the author or publisher any trademark ownership rights in such trademarks, nor does the use of such trademarks imply
any affiliation with or endorsement of this book by such owners.
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library
10 9 8 7 6 5 4 3 2 1
ISBN 10: 1-292-16168-X
ISBN 13: 978-1-292-16168-6
Typeset in Monotype by Cenveo Publisher Services
Printed and bound in Malaysia.
The newly revised fourth edition of our Building Java Programs textbook is designed
for use in a two-course introduction to computer science. We have class-tested it with
thousands of undergraduates, most of whom were not computer science majors, in our
CS1-CS2 sequence at the University of Washington. These courses are experiencing
record enrollments, and other schools that have adopted our textbook report that stu-
dents are succeeding with our approach.
Introductory computer science courses are often seen as “killer” courses with high
failure rates. But as Douglas Adams says in The Hitchhiker’s Guide to the Galaxy, “Don’t
panic.” Students can master this material if they can learn it gradually. Our textbook uses
a layered approach to introduce new syntax and concepts over multiple chapters.
Our textbook uses an “objects later” approach where programming fundamentals
and procedural decomposition are taught before diving into object-oriented program-
ming. We have championed this approach, which we sometimes call “back to basics,”
and have seen through years of experience that a broad range of scientists, engineers,
and others can learn how to program in a procedural manner. Once we have built a
solid foundation of procedural techniques, we turn to object-oriented programming.
By the end of the course, students will have learned about both styles of programming.
Here are some of the changes that we have made in the fourth edition:
Since the publication of our third edition, Java 8 has been released. This new version
supports a style of programming known as functional programming that is gaining in
popularity because of its ability to simply express complex algorithms that are more
easily executed in parallel on machines with multiple processors. ACM and IEEE have
released new guidelines for undergraduate computer science curricula, including a
strong recommendation to cover functional programming concepts.
We have added a new Chapter 19 that covers most of the functional concepts
from the new curriculum guidelines. The focus is on concepts, not on language
features. As a result, it provides an introduction to several new Java 8 constructs
but not a comprehensive coverage of all new language features. This provides
flexibility to instructors since functional programming features can be covered as
an advanced independent topic, incorporated along the way, or skipped entirely.
Instructors can choose to start covering functional constructs along with tradi-
tional constructs as early as Chapter 6. See the dependency chart at the end of this
section.
The following features have been retained from previous editions:
Programming
Chapter Control Flow Data Techniques Input/Output
Chapters 1–6 are designed to be worked through in order, with greater flexibility
of study then beginning in Chapter 7. Chapter 6 may be skipped, although the case
study in Chapter 7 involves reading from a file, a topic that is covered in Chapter 6.
Chapters 1-6
Programming Fundamentals
Chapter 12 Chapter 9
Recursion Inheritance, Chapter 19
Interfaces Section 19.5
Chapter 13
Searching, Chapter 10
Sorting ArrayLists
Chapter 11
Collections
Chapter 14
Chapter 15 Stacks,
Implementing Queues
Collections
Chapter 16
Linked Lists
Chapter 17
Binary Trees
Chapter 18
Hashing,
Heaps
Supplements
Answers to all self-check problems appear on the web site and are accessible to
anyone. Our web site has the following additional resources for students:
• Online-only supplemental chapters, such as a chapter on creating Graphical User
Interfaces
• Source code and data files for all case studies and other complete program
examples
• The DrawingPanel class used in the optional graphics Supplement 3G
Our web site has the following additional resources for teachers:
MyProgrammingLab
MyProgrammingLab is an online practice and assessment tool that helps students fully
grasp the logic, semantics, and syntax of programming. Through practice exercises
and immediate, personalized feedback, MyProgrammingLab improves the program-
ming competence of beginning students who often struggle with basic concepts and
paradigms of popular high-level programming languages. A self-study and homework
tool, the MyProgrammingLab course consists of hundreds of small practice exercises
organized around the structure of this textbook. For students, the system automatically
detects errors in the logic and syntax of code submissions and offers targeted hints that
enable students to figure out what went wrong, and why. For instructors, a comprehen-
sive grade book tracks correct and incorrect answers and stores the code inputted by
students for review.
For a full demonstration, to see feedback from instructors and students, or
to adopt MyProgrammingLab for your course, visit the following web site:
http://www.myprogramminglab.com/
VideoNotes
We have recorded a series of instructional videos to accompany the textbook. They are
VideoNote
available at the following web site: www.pearsonglobaleditions.com/reges.
Roughly 3–4 videos are posted for each chapter. An icon in the margin of the page
indicates when a VideoNote is available for a given topic. In each video, we spend
5–15 minutes walking through a particular concept or problem, talking about the
challenges and methods necessary to solve it. These videos make a good supplement
to the instruction given in lecture classes and in the textbook. Your new copy of the
textbook has an access code that will allow you to view the videos.
Acknowledgments
First, we would like to thank the many colleagues, students, and teaching assistants
who have used and commented on early drafts of this text. We could not have written
this book without their input. Special thanks go to Hélène Martin, who pored over
early versions of our first edition chapters to find errors and to identify rough patches
that needed work. We would also like to thank instructor Benson Limketkai for spend-
ing many hours performing a technical proofread of the second edition.
Second, we would like to thank the talented pool of reviewers who guided us in
the process of creating this textbook:
Finally, we would like to thank the great staff at Pearson who helped produce the
book. Michelle Brown, Jeff Holcomb, Maurene Goo, Patty Mahtani, Nancy Kotary,
and Kathleen Kenny did great work preparing the first edition. Our copy editors
and the staff of Aptara Corp, including Heather Sisan, Brian Baker, Brendan Short,
and Rachel Head, caught many errors and improved the quality of the writing.
Marilyn Lloyd and Chelsea Bell served well as project manager and editorial assis-
tant respectively on prior editions. For their help with the third edition we would like
to thank Kayla Smith-Tarbox, Production Project Manager, and Jenah Blitz-Stoehr,
Computer Science Editorial Assistant. Mohinder Singh and the staff at Aptara, Inc.,
were also very helpful in the final production of the third edition. For their great
work on production of the fourth edition, we thank Louise Capulli and the staff of
Lakeside Editorial Services, along with Carole Snyder at Pearson. Special thanks go
to our lead editor at Pearson, Matt Goldstein, who has believed in the concept of our
book from day one. We couldn’t have finished this job without all of their hard work
and support.
Stuart Reges
Marty Stepp
Contributor
Ankur Saxena, Amity University
Reviewers
Arup Bhattacharya, RCC Institute of Technology
Soumen Mukherjee, RCC Institute of Technology
Khyat Sharma
12
13
Expressions 91
Literals 93
Arithmetic Operators 94
Precedence 96
Mixing Types and Casting 99
2.2 Variables 100
Assignment/Declaration Variations 105
String Concatenation 108
Increment/Decrement Operators 110
Variables and Mixing Types 113
2.3 The for Loop 115
Tracing for Loops 117
for Loop Patterns 121
Nested for Loops 123
2.4 Managing Complexity 125
Scope 125
Pseudocode 131
Class Constants 134
2.5 Case Study: Hourglass Figure 136
Problem Decomposition and Pseudocode 137
Initial Structured Version 139
Adding a Class Constant 140
Further Variations 143
Introduction
1.1 Basic Computing Concepts
■ Why Programming?
This chapter begins with a review of some basic terminology about com- ■ Hardware and Software
puters and computer programming. Many of these concepts will come up ■ The Digital Realm
in later chapters, so it will be useful to review them before we start delving
■ The Process of Programming
■ Why Java?
into the details of how to program in Java. ■ The Java Programming
Environment
We will begin our exploration of Java by looking at simple programs that
1.2 And Now—Java
produce output. This discussion will allow us to explore many elements
■ String Literals (Strings)
that are common to all Java programs, while working with programs that ■ System.out.println
are fairly simple in structure. ■ Escape Sequences
■ print versus println
After we have reviewed the basic elements of Java programs, we will ■ Identifiers and Keywords
explore the technique of procedural decomposition by learning how to
■ A Complex Example:
DrawFigures1
break up a Java program into several methods. Using this technique, we ■ Comments and Readability
can break up complex tasks into smaller subtasks that are easier to manage
1.3 Program Errors
and we can avoid redundancy in our program solutions. ■ Syntax Errors
■ Logic Errors (Bugs)
27
Why Programming?
At most universities, the first course in computer science is a programming course.
Many computer scientists are bothered by this because it leaves people with the
impression that computer science is programming. While it is true that many trained
computer scientists spend time programming, there is a lot more to the discipline. So
why do we study programming first?
A Stanford computer scientist named Don Knuth answers this question by saying
that the common thread for most computer scientists is that we all in some way work
with algorithms.
Algorithm
A step-by-step description of how to accomplish a task.
It has often been said that a person does not really understand something
until after teaching it to someone else. Actually a person does not really
understand something until after teaching it to a computer, i.e., expressing
it as an algorithm.1
1Knuth, Don. Selected Papers on Computer Science. Stanford, CA: Center for the Study of Language and
Information, 1996.
Language: English
THE WORLD'S
BEST POETRY
IN TEN VOLUMES, ILLUSTRATED
Editor-in-Chief
BLISS CARMAN
Associate Editors
John Vance Cheney Charles G. D. Roberts
Charles F. Richardson Francis H. Stoddard
Managing Editor
John R. Howard
By FRANCIS A. GUMMERE
II.
TABLE OF CONTENTS.
————————
INTRODUCTORY ESSAY: PAGE
"The Old Case of Poetry in a New
Court."
By Francis Barton Gummere ix
POEMS OF TRAGEDY:
Greece and Rome 3
The Orient 26
Germany 44
Italy: Spain 55
Switzerland: Russia 88
Scotland: Ireland: England 120
America 172
The Sea 181
HUMOROUS POEMS:
Woman 197
Miscellaneous 239
Parodies: Imitations 396
Ingenuities: Oddities 426
LIST OF ILLUSTRATIONS.
————————
JOHANN WOLFGANG von GOETHE. Frontispiece
Photogravure after a photograph from a
portrait by Stieler.
PAGE
FRANCESCA DA RIMINI 1
Dante's tale of the unhappy lovers
whom he saw in the realm of shades will
live in poetry and art. This color-plate,
from the painting by A. Cabanel, shows
their tragic death at the hand of the
enraged brother.
THE DIVER 45
"Hark! a shriek from the crowd rang
aloud from the shore,
And behold! he is whirled in the
grasp of the main."
From photogravure after a drawing by
A. Michaelis.
FRANCESCA DA RIMINI.
The tale of the fated lovers, Francesca and Paolo,
whose fleeting spirits Dante saw in his visit to the
realms of the dead, will always live in poetry and in art.
His brief story of their approach in mutual sympathy,
over the reading of a book, is given in our second
volume: the scene of their tragic death at the hand of
her enraged husband is the subject of this painting by
Alexandre Cabanel, the French artist.
POEMS OF TRAGEDY.
PARRHASIUS.
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.
textbookfull.com