Building Java Programs
A Back to Basics Approach
Fourth Edition
Stuart Reges
University of Washington
Marty Stepp
Stanford University
Boston Columbus Indianapolis New York San Francisco Hoboken Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo
Vice President, Editorial Director: Marcia Horton
Acquisitions Editor: Matt Goldstein
Editorial Assistant: Kristy Alaura
VP of Marketing: Christy Lesko
Director of Field Marketing: Tim Galligan
Product Marketing Manager: Bram Van Kempen
Field Marketing Manager: Demetrius Hall
Marketing Assistant: Jon Bryant
Director of Product Management: Erin Gregg
Team Lead, Program and Project Management: Scott Disanno
Program Manager: Carole Snyder
Project Manager: Lakeside Editorial Services L.L.C.
Senior Specialist, Program Planning and Support: Maura Zaldivar-Garcia
Cover Design: Joyce Wells
R&P Manager: Rachel Youdelman
R&P Project Manager: Timothy Nicholls
Inventory Manager: Meredith Maresca
Cover Art: Matt Walford/Cultura/Getty Images
Full-Service Project Management: Apoorva Goel/Cenveo Publisher Services
Composition: Cenveo Publisher Services
Printer/Binder: Edwards Brothers Malloy
Cover Printer: Phoenix Color
Text Font: Monotype
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.
Copyright 2017, 2014 and 2011 Pearson Education, Inc. or its affiliates. All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise. For information regarding permissions, request forms and the appropriate contacts within the Pearson Education Global Rights & Permissions department, please visit www.pearsonhighed.com/permissions/ .
Acknowledgements of third party content appear on pages , 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.
Unless otherwise indicated herein, any third-party trademarks that may appear in this work are the property of their respective owners and any references to third-party trademarks, logos or other trade dress are for demonstrative or descriptive purposes only. Such references are not intended to imply any sponsorship, endorsement, authorization, or promotion of Pearson's products by the owners of such marks, or any relationship between the owner and Pearson Education, Inc. or its affiliates, authors, licensees or distributors.
Library of Congress Cataloging-in-Publication Data
Names: Reges, Stuart, author. | Stepp, Martin, author.
Title: Building Java programs : a back to basics approach / Stuart Reges, University of Washington; Marty Stepp, Stanford University.
Description: Fourth Edition. | Hoboken, NJ : Pearson, 2016.
Identifiers: LCCN 2015049340 | ISBN 9780134322766 (alk. paper)
Subjects: LCSH: Java (Computer program language)
Classification: LCC QA76.73.J38 R447 2016 | DDC 005.13/3dc23 LC record available at http://lccn.loc.gov/2015049340
10 9 8 7 6 5 4 3 2 1
ISBN 10: 0-13-432276-2
ISBN 13: 978-0-13-432276-6
Preface
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 students 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 programming. 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:
New chapter on functional programming with Java 8. As explained below, we have introduced a chapter that uses the new language features available in Java 8 to discuss the core concepts of functional programming.
New section on images and 2D pixel array manipulation. Image manipulation is becoming increasingly popular, so we have expanded our DrawingPanel
class to include features that support manipulating images as two-dimensional arrays of pixel values. This extra coverage will be particularly helpful for students taking an AP/CS A course because of the heavy emphasis on two-dimensional arrays on the AP exam.
Expanded self-checks and programming exercises. Many chapters have received new self-check problems and programming exercises. There are roughly fifty total problems and exercises per chapter, all of which have been class-tested with real students and have solutions provided for instructors on our web site.
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 . See the dependency chart at the end of this section.
The following features have been retained from previous editions:
Next page