Java for Everyone Late Objects 2nd Edition pdf pdf

  free ebooks ==> www.ebook777.com CAY H O R STM A N N

  • •฀฀ •฀฀฀

  JAVA

  • •฀฀฀

  F O R E V E R Y O N E •฀฀฀ L A T E O B J E C T S •฀฀฀

  S E C O N D E D I T I O N C O M P A T I B L E W I T H J A V A 5 , 6 & 7

  free ebooks ==> www.ebook777.com

WileyPLUS is a research-based online environment

for effective teaching and learning.

  

WileyPLUS builds students’ confidence because it takes the guesswork

out of studying by providing students with a clear roadmap:

  • • what to do • how to do it • if they did it right

  

It offers interactive resources along with a complete digital textbook that help

students learn more. With WileyPLUS, students take more initiative so you’ll have greater impact on their achievement in the classroom and beyond. free ebooks ==> www.ebook777.com

ALL THE HELP, RESOURCES, AND PERSONAL

  www.wileyplus.com/resources

  Collaborate with your colleagues, 2-Minute Tutorials and all Student support from an find a mentor, attend virtual and live of the resources you and your experienced student user events, and view resources students need to get started

  www.WhereFacultyConnect.com

  Pre-loaded, ready-to-use Technical Support 24/7 Your WileyPLUS Account Manager, assignments and presentations

  FAQs, online chat, providing personal training created by subject matter experts and phone support and support J ava f o r E v E r y o n E L a t e O b j e c t s

  J ava f o r E v E r y o n E L a t e O b j e c t s s e c O n d e d i t i O n cay Horstmann

  San Jose State University John Wiley & Sons, Inc. VICE PRESIDENT AND EXECUTIVE PUBLISHER Don Fowley EXECUTIVE EDITOR Beth Lang Golub CONTENT MANAGER Kevin Holm SENIOR PRODUCTION EDITOR John Curley EXECUTIVE MARKETING MANAGER Christopher Ruel CREATIVE DIRECTOR Harry Nolan SENIOR DESIGNER Madelyn Lesure SENIOR PHOTO EDITOR Lisa Gee PRODUCT DESIGNER Thomas Kulesa CONTENT EDITOR Wendy Ashenberg EDITORIAL PROGRAM ASSISTANT Elizabeth Mills MEDIA SPECIALIST Lisa Sabatini PRODUCTION SERVICES Cindy Johnson COVER PHOTO © TeeJe/Flickr/Getty Images This book was set in Stempel Garamond by Publishing Services, and printed and bound by R.R. Donnelley & Sons Company. The cover was printed by R.R. Donnelley & Sons, Jefferson City.

  This book is printed on acid-free paper. ∞ Copyright © 2013, 2010 John Wiley & Sons, Inc. 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, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, website www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, (201) 748-6011, fax (201) 748-6008, website www.wiley.com/go/permissions. Evaluation copies are provided to qualified academics and professionals for review purposes only, for use in their courses during the next academic year. These copies are licensed and may not be sold or transferred to a third party. Upon completion of the review period, please return the evaluation copy to Wiley. Return instruc- tions and a free of charge return shipping label are available at www.wiley.com/go/returnlabel. Outside of the United States, please contact your local representative.

  ISBN 978-1-118-06331-6 (Main Book)

  ISBN 978-1-118-12941-8 (Binder-Ready Version) Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 P r E fa c E

  This book is an introduction to Java and computer programming that focuses on the essentials—and on effective learning. The book is designed to serve a wide range of student interests and abilities and is suitable for a first course in programming for computer scientists, engineers, and students in other disciplines. No prior program- ming experience is required, and only a modest amount of high school algebra is needed. Here are the key features of this book:

  Present fundamentals first.

  The book takes a traditional route, first stressing control structures, methods, pro- cedural decomposition, and arrays. Objects are used when appropriate in the early chapters. Students start designing and implementing their own classes in Chapter 8.

  Guidance and worked examples help students succeed.

  Beginning programmers often ask “How do I start? Now what do I do?” Of course, an activity as complex as programming cannot be reduced to cookbook-style instruc- tions. However, step-by-step guidance is immensely helpful for building confidence and providing an outline for the task at hand. “Problem Solving” sections stress the importance of design and planning. “How To” guides help students with common programming tasks. Additional Worked Examples are available online.

  Practice makes perfect.

  Of course, programming students need to be able to implement nontrivial programs, but they first need to have the confidence that they can succeed. This book contains a substantial number of self-check questions at the end of each section. “Practice It” pointers suggest exercises to try after each section. And additional practice opportu- nities, including code completion questions, guided lab exercises, and skill-oriented multiple-choice questions are available online.

  a visual approach motivates the reader and eases navigation.

  Photographs present visual analogies that explain the nature and behavior of computer concepts. Step-by- step figures illustrate complex program operations. Syntax boxes and example tables present a variety of typical and special cases in a compact format. It is easy to get the “lay of the land” by browsing the visuals, before focusing on the textual material.

  Focus on the essentials while being technically accurate. Visual features help the reader with navigation.

  An encyclopedic coverage is not helpful for a begin- ning programmer, but neither is the opposite— reducing the material to a list of simplistic bullet points. In this book, the essentials are presented in digestible chunks, with separate notes that go deeper into good prac- tices or language features when the reader is ready for the additional information. You will not find artificial over-simplifications that give an illusion of knowledge.

  vii

  viii Preface new to This Edition

  Problem Solving Strategies

  This edition adds practical, step-by-step illustrations of techniques that can help stu- dents devise and evaluate solutions to programming problems. Introduced where they are most relevant, these strategies address barriers to success for many students. Strategies included are:

  • Algorithm Design (with pseudocode) Adapting Algorithms •

  First Do It By Hand (doing sample • Discovering Algorithms by • calculations by hand) Manipulating Physical Objects Flowcharts • • Tracing Objects (identifying state and behavior) Test Cases •

  • Patterns for Object Data

  Hand-Tracing •

  • Thinking Recursively • Storyboards • • Reusable Methods Estimating the Running Time of an

  Algorithm

  • Stepwise Refinement

  optional Science and Business Exercises

  End-of-chapter exercises have been enhanced with problems from scientific and business domains. Designed to engage students, the exercises illustrate the value of programming in applied fields.

  new and reorganized Topics

  All chapters were revised and enhanced to respond to user feedback and improve the flow of topics. Loop algorithms are now introduced explicitly in Chapter 4. Debug- ging is now introduced in a lengthy Video Example in Chapter 5. Additional array algorithms are presented in Chapter 6 and incorporated into the problem-solving sections. Input/output is moved up to Chapter 7, but the first two sections may be used to introduce simple text file processing sooner. New example tables, photos, and exercises appear throughout the book.

  a Tour of the Book Figure 1 shows the dependencies between the chapters and how topics are organized.

  The core material of the book is: chapter 1.

  Introduction chapter 2. Fundamental Data Types chapter 3. Decisions chapter 4. Loops chapter 5. Methods chapter 6. Arrays and Array Lists chapter 7. Input/Output and Exception Handling

  These chapters use a traditional approach. Objects are only used for input/output and string processing.

  Preface ix Three chapters cover object-oriented programming and design: chapter 8.

  10. Graphical User Interfaces

  A gentle introduction to recursion is optional.

  11. Advanced User Interfaces

  7. Input/Output and Exception Handling

  6. Arrays and Array Lists

  5. Methods

  4. Loops

  3. Decisions

  2. Fundamental Data Types

  1. Introduction

  8. Objects and Classes Fundamentals Object-Oriented Design GUI and Web Programming Data Structures & Algorithms Web / WileyPLUS

  Objects and Classes chapter 9. Inheritance chapter 12. Object-Oriented Design (on the Web)

  6. Iteration

  15. The Java Collections Framework

  14. Sorting and Searching

  13. Recursion

  12. Object- Oriented Design

  9. Inheritance and Interfaces

  Figure 1 chapter Dependencies

  The first of these chapters enables students to write programs with buttons, text com- ponents, and simple drawings. The second chapter covers layout management and additional user-interface components.

  Graphical User Interfaces chapter 11. Advanced User Interfaces (on the Web)

  Graphical user interfaces are presented in two chapters: chapter 10.

  Sections 7.1 and 7.2 (text file processing) can be covered with Chapter 4.

  x Preface

  To support a course that goes more deeply into algorithms and data structures, three additional chapters are available in electronic form on the Web and in WileyPLUS:

chapter 13. Recursion chapter 14. Sorting and Searching chapter 15. The Java Collections Framework Any chapters can be incorporated into a custom print version of this text; ask your Wiley sales representative for details. Appendices The first four appendices are in the book; the remainder on the Web.

  a.

  The Basic Latin and Latin-1 Subsets of Unicode B. Java Operator Summary c. Java Reserved Word Summary D. The Java Library E. Java Syntax Summary f. HTML Summary G.

  Tool Summary H. Javadoc Summary I. Number Systems J. Bit and Shift Operations K. UML Summary L. Java Language Coding Guidelines

  Many instructors find it highly beneficial to require a consistent style for all assign- ments. If the style guide in Appendix L conflicts with instructor sentiment or local customs, however, it is available in electronic form so that it can be modified.

  Web resources

  This book is complemented by a complete suite of online resources and a robust WileyPLUS course. Go to www.wiley.com/college/horstmann to visit the online compan- ion sites, which include

  • Source code for all examples in the book.
  • Worked Examples that apply the problem-solving steps in the book to other realistic examples.
  • Video Examples in which the author explains the steps he is taking and shows his work as he solves a programming problem.
  • Lab exercises that apply chapter concepts (with solutions for instructors only).
  • Lecture presentation slides (in PowerPoint format).
  • Solutions to all review and programming exercises (for instructors only).
  • A test bank that focuses on skills, not just terminology (for instructors only).

  WileyPLUS

  WileyPLUS is an online teaching and learning environment that integrates the digital textbook with instructor and student resources. See pages xv–xvi for details.

  O N L I N E E X A M P L E A program using common loop algorithms.

  V I D E O E X A M P L E 4 . 2 Drawing a Spiral In this Video Example, you will see how to develop a program

that draws a spiral.

  Pointers in the book describe what students will find on the Web.

  Walkthrough xi

  a Walkthrough of the Learning aids

  The pedagogical elements in this book work together to focus on and reinforce key concepts and fundamental principles of programming, with additional tips and detail organized to support and deepen these fundamentals. In addition to traditional fea- tures, such as chapter objectives and a wealth of exercises, each chapter contains ele- ments geared to today’s visual learner.

  135

  4.2 The for Loop

4.2 The Loop

  for Throughout each chapter, The for loop is It often happens that you want to execute a sequence of statements a given number

margin notes show where used when a of times. You can use a while loop that is controlled by a counter, as in the following

value runs from a starting point to an example: new concepts are introduced ending point with a int counter = 1; // Initialize the counter constant increment while (counter <= 10) // Check the counter and provide an outline of key ideas. or decrement. } counter++; // Update the counter System.out.println(counter); {

  Because this loop type is so common, there is a spe- cial form for it, called the for loop (see Syntax 4.2). for (int counter = 1; counter <= 10; counter++) System.out.println(counter); { Additional online example code } provides complete programs for Some people call this loop count-controlled. In con- O N L I N E E X A M P L E A program using trast, the while loop of the preceding section can be students to run and modify. common loop algorithms. called an event-controlled loop because it executes until an event occurs; namely that the balance reaches the target. Another commonly used term for a count-controlled loop is definite. You know from the outset that the loop body will be executed a definite number of times; ten times in our exam- ple. In contrast, you do not know how many itera- tions it takes to accumulate a target balance. Such a You can visualize the for loop as an orderly sequence of steps. loop is called indefinite.

  Annotated syntax boxes provide a quick, visual overview of new language constructs. for Statement

  

Syntax 4.2

Syntax for ( initialization ; condition ; update ) { } statements expressions should be related. See page 163. These three Annotations explain required

  This initialization The condition is This update is components and point to more happens once checked before executed after before the loop starts. each iteration. each iteration. information on common errors for (int i = 5; i <= 10; i++) or best practices associated The variable i is This loop executes 6 times. sum = sum + i; { with the syntax. defined only in this for loop. } See page 161. See page 164.

  Analogies to everyday objects are used to explain the nature and behavior of concepts such as variables, data

  Like a variable in a computer types, loops, and more. program, a parking space has an identifier and a contents.

  xii Walkthrough Memorable photos

  reinforce analogies and help students pie(fruit) pie(fruit) remember the concepts. Apples and cherries are examples of arguments. Here, “fruit” is an example of a parameter variable. A recipe for a fruit pie may say to use any kind of fruit.

  Problem Solving sections teach

  techniques for generating ideas and

6.5 Problem Solving: Discovering Algorithms by Manipulating Physical Objects 277

  evaluating proposed solutions, often

  Now how does that help us with our problem, switching the first and the second

  using pencil and paper or other

  half of the array? Let’s put the first coin into place, by swapping it with the fifth coin. However, as

  artifacts. These sections emphasize

  Java programmers, we will say that we swap the coins in positions 0 and 4:

  that most of the planning and problem solving that makes students successful happens away from the computer.

  Next, we swap the coins in positions 1 and 5: H O W TO 1 . 1 How To guides give step-by-step

  Describing an Algorithm with Pseudocode

  guidance for common programming

  This is the first of many “How To” sections in this book that give you step-by-step proce- dures for carrying out important tasks in developing computer programs.

  tasks, emphasizing planning and

  Before you are ready to write a program in Java, you need to develop an algorithm—a method for arriving at a solution for a particular problem. Describe the algorithm in

  testing. They answer the beginner’s pseudocode: a sequence of precise steps formulated in English.

  For example, consider this problem: You have the choice of

  question, “Now what do I do?” and

  buying two cars. One is more fuel efficient than the other, but also more expensive. You know the price and fuel efficiency (in

  integrate key concepts into a

  miles per gallon, mpg) of both cars. You plan to keep the car for ten years. Assume a price of $4 per gallon of gas and usage of

  problem-solving sequence.

  15,000 miles per year. You will pay cash for the car and not Step 1 worry about financing costs. Which car is the better deal? Determine the inputs and outputs. In our sample problem, we have these inputs: purchase price1

  • and fuel efficiency1, the price and fuel efficiency (in mpg) of the first car purchase price2

  Worked Examples and

  • and fuel efficiency2, the price and fuel efficiency of the second car We simply want to know which car is the better buy. That is the desired output.

  Video Examples apply the

  steps in the How To to a

  WO R K E D E X A M P L E 1 . 1 Writing an Algorithm for Tiling a Floor

  different example, showing

  This Worked Example shows how to develop an algorithm for laying

  how they can be used to tile in an alternating pattern of colors. plan, implement, and test a solution to another programming problem. int cans = 6; V a r i a b l e N a m e C o m m e n t Table 1 Variable Declarations in Java Declares an integer variable and initializes it with 6. int total = cans + bottles; cans bottles Example tables support beginners

  The initial value need not be a constant. (Of course, and must have been previously declared.) bottles = 1; Error: The type is missing. This statement is not a declaration but an with multiple, concrete examples.

  These tables point out common int bottles = "10"; assignment of a new value to an existing variable—see Section 2.1.4. int bottles; Error: You cannot initialize a number with a string. errors and present another quick Declares an integer variable without initializing it. This can be a reference to the section’s topic. int cans, bottles; cause for errors—see Common Error 2.1 on page 37.

  Declares two integer variables in a single statement. In this book, we will declare each variable in a separate statement.

  • Figure 3 Parameter Passing
  • 1 Method call result1 = sideLength = 2 Initializing method parameter variable result1 = sideLength = 2 3 About to return to the caller result1 = sideLength = volume = 8 2 4 After method call result1 = 8 double result1 = cubeVolume (2); double volume = sideLength * sideLength * sideLength; return volume; double result1 = cubeVolume( 2 ); double result1 = cubeVolume(2); The parameter variable sideLength of the cubeVolume method is created when the method is called. 1<
  • The parameter variable is initialized with the value of the argument that was passed in the call. In our case, sideLength is set to 2.
  • 2<
  • The method computes the expression sideLength * sideLength * sideLength , which has the value 8. That value is stored in the variable volume .
  • 3<
  • The method returns. All of its variables are removed. The return value is trans-

  Optional science and business

  designed for easy reading, going well beyond simple color coding. Methods are set off by a subtle outline.

  Program listings are carefully

  For example, for a monthly appointment, you must check whether the day of the month matches. Then fill an array of Appointment objects with a mixture of appointments. Have the user enter a date and print out all appoint- ments that occur on that date.

  Scale the result so that no value is larger than 32767. •• Business P9.21 Implement a superclass Appointment and sub- classes Onetime , Daily , and Monthly . An appoint- ment has a description (for example, “see the dentist”) and a date and time. Write a method occursOn(int year, int month, int day) that checks whether the appointment occurs on that date.

  Sounds can be represented by an array of “sample val ues” that describe the intensity of the sound at a point in time. The program ch06/sound/SoundEffect. java reads a sound file (in WAV format), calls a method process for processing the sample values, and saves the sound file. Your task is to implement the process method by introducing an echo. For each sound value, add the value from 0.2 seconds ago.

  exercises engage students with realistic applications of Java.

  • •• Science P6.32

  end of each section are designed to make students think through the new material—and can spark discussion in lecture.

  Walkthrough xiii

  Self-check exercises at the

  25 + year + " years." ); 26 } 27 } 6. Write the for loop of the InvestmentTable.java program as a while loop. 7. How many numbers does this loop print? for (int n = 10; n &gt;= 0; n--)

{

System.out.println(n);

}

8. Write a for loop that prints all even numbers between 10 and 20 (inclusive). 9. Write a for loop that computes the sum of the integers from 1 to n . 10. How would you modify the for loop of the InvestmentTable.java program to print all balances until the investment has doubled? Now you can try these exercises at the end of the chapter: R4.3, R4.8, P4.8, P4.13. S E L F C H E C K

  section_1/DoubleInvestment.java 1 /** 2 This program computes the time required to double an investment. 3 */ 4 public class DoubleInvestment 5 { 6 public static void main(String[] args) 7 { 8 final double RATE = 5 ; 9 final double INITIAL_BALANCE = 10000 ; 10 final double TARGET = 2 * INITIAL_BALANCE; 11 12 double balance = INITIAL_BALANCE; 13 int year = ; 14 15 // Count the years required for the investment to double 16 17 while (balance &lt; TARGET) 18 { 19 year++; 20 double interest = balance * RATE / 100 ; 21 balance = balance + interest; 22 } 23

  Students can view animations of key concepts on the Web.

  segments to help students visualize the program flow. Color is used consistently to make variables and other elements easily recognizable.

  ferred to the caller, that is, the method calling the cubeVolume method. The caller puts the return value in the result1 variable. Parameter Passing 4 A N I M A T I O N Figure 3 Execution of a for Loop for ( int counter = 1 ; counter &lt;= 10; counter++) { System.out.println(counter); } Initialize counter 1 for (int counter = 1; counter &lt;= 10 ; counter++) { System.out.println(counter); } Check condition 2 for (int counter = 1; counter &lt;= 10; counter++) { System.out.println(counter); } Execute loop body 3 for (int counter = 1; counter &lt;= 10; counter++ ) { System.out.println(counter); } Update counter 4 for (int counter = 1; counter &lt;= 10 ; counter++) { System.out.println(counter); } Check condition again 5 counter = 1 counter = 1 counter = 1 counter = 2 counter = 2 Progressive figures trace code

24 System.out.println( "The investment doubled after "

  xiv Walkthrough Length and Size

  Common Error 6.4 Common Errors describe the kinds

  Unfortunately, the Java syntax for Data Type Number of Elements determining the number of elements

  of errors that students often make,

  in an array, an array list, and a string Array a.length is not at all consistent. It is a com-

  with an explanation of why the errors a.size()

  Array list mon error to confuse these. You just have to remember the correct syntax occur, and what to do about them.

  String a.length() for every data type.

  

Hand-Tracing

Programming Tip 3.5

  A very useful technique for understanding whether a pro- gram works correctly is called hand-tracing. You simulate the program’s activity on a sheet of paper. You can use this method with pseudocode or Java code.

  Get an index card, a cocktail napkin, or whatever sheet of paper is within reach. Make a column for each variable. Have the program code ready. Use a marker, such as a paper clip, to mark the current statement. In your mind, execute statements one at a time. Every time the value of a variable changes, cross out the old value and write the new

value below the old one.

Hand-tracing helps you For example, let’s trace the tax program with the data understand whether a from the program run on page 102. In lines 15 and 16, tax1 and program works correctly.

  Programming Tips explain tax2 8 public static void main(String[] args) are initialized to 0.

  good programming practices, 11 final double RATE2 = 0.25; 10 final double RATE1 = 0.10; 9 { marital tax1 tax2 income status and encourage students to be 12 final double RATE1_SINGLE_LIMIT = 32000; 14 13 final double RATE1_MARRIED_LIMIT = 64000; more productive with tips and 17 16 double tax2 = 0; 15 double tax1 = 0; techniques such as hand-tracing.

  In lines 22 and 25, income and maritalStatus are marital 24 System.out.print("Please enter s for single, m for married: "); 23 22 double income = in.nextDouble(); 21 System.out.print("Please enter your income: "); 20 Scanner in = new Scanner(System.in); 80000 m initialized by input statements. tax1 tax2 income status 25 String maritalStatus = in.next(); File Dialog Boxes

  Special Topic 7.2 In a program with a graphical user interface, you will want to use a file dialog box (such as the JFileChooser one shown in the fig ure below) whenever the users of your program need to pick a file. The class implements a file dialog box for the Swing user-interface toolkit.

  The JFileChooser class has many options to fine-tune the display of the dialog box, but in its showOpenDialog most basic form it is quite simple: Construct a file chooser object; then call the or showSaveDialog method. Both methods show the same dialog box, but the button for select- ing a file is labeled “Open” or “Save”, depending on which method you call.

  For better placement of the dialog box on the screen, you can specify the user-interface component over which to pop up the dialog box. If you don’t care where the dialog box pops up, you can simply pass null . The showOpenDialog and showSaveDialog methods return either

  Special Topics present optional JFileChooser.APPROVE_OPTION JFi leChooser.CANCEL_OPTION , if the user has chosen a file, or , if the user canceled the selection. If a file was chosen, then you call the getSelectedFile method to

  topics and provide additional File O N L I N E E X A M P L E JFileChooser chooser = new JFileChooser(); obtain a object that describes the file. Here is a complete example: explanation of others. New demonstrates how to A program that if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) Scanner in = null; features of Java 7 are also use a file chooser. File selectedFile = chooser.getSelectedFile(); { covered in these notes. in = new Scanner(selectedFile); showOpenDialog Call with method } . . .

  Random Fact 4.1 sity. It really was caused by a bug a no particular difficulty in getting pro- my own programs.” found in the Mark II, a huge electrome- the Moore School and afterwards, one me that a great part of my future life chanical computer at Harvard Univer- had always assumed there would be would be spent finding mistakes in the first bug was Maurice Wilkes wrote, “Somehow, at instant in time at which it dawned on According to legend, The pioneering computer scientist grams right. I can remember the exact The First Bug showSaveDialog method Button is “Save” when is called operator left in the log book next to if the term “bug” had already been in moth was trapped in a relay switch. active use at the time. the moth (see the figure), it appears as Actually, from the note that the A JFileChooser Dialog BoxRandom Facts provide historical and

  social information on computing—for interest and to fulfill the “historical and social context” requirements of the The First Bug ACM/IEEE curriculum guidelines.

  Walkthrough xv

  WileyPLUS

  WileyPLUS is an online environment that supports students and instructors. This book’s WileyPLUS course can complement the printed text or replace it altogether.

  for Students

  Different learning styles, different levels of proficiency, different levels of prepara- tion—each student is unique. WileyPLUS empowers all students to take advantage of their individual strengths. Integrated, multi-media resources—including audio and visual exhibits and demon- stration problems—encourage active learning and provide multiple study paths to fit each student’s learning preferences.

  • Worked Examples apply the problem-solving steps in the book to another realis- tic example.

  Video Examples present the author explaining the steps he is taking and showing • his work as he solves a programming problem. Animations of key concepts allow students to replay dynamic explanations that • instructors usually provide on a whiteboard.

  Self-assessments are linked to relevant portions of the text. Students can take control of their own learning and practice until they master the material.

  Practice quizzes can reveal areas where students need to focus. • “Learn by doing” lab exercises can be assigned for self-study or for use in the lab. • “Code completion” questions enable students to practice programming skills by • filling in small code snippets and getting immediate feedback.

  for Instructors

  WileyPLUS includes all of the instructor resources found on the companion site, and more.

  WileyPLUS gives you tools for identifying those students who are falling behind, allowing you to intervene accordingly, without having to wait for them to come to office hours.

  Practice quizzes for pre-reading assessment, self-quizzing, or additional practice • can be used as-is or modified for your course needs. Multi-step laboratory exercises can be used in lab or assigned for extra student • practice.

  WileyPLUS simplifies and automates student performance assessment, making assignments, and scoring student work.

  An extensive set of multiple-choice questions for quizzing and testing have been • developed to focus on skills, not just terminology. “Code completion” questions can also be added to online quizzes. • Solutions to all review and programming exercises are provided. •

  ISBN To order Java for Everyone, 2e, with its WileyPLUS course for your students, use 978-1-118-28614-2.

  xvi Walkthrough Students can read the book online and take advantage of searching and cross-linking.

  With WileyPLUS … Students can practice programming by filling in small code snippets and getting immediate feedback.

  Instructors can assign drill-and-practice questions to check that students did their reading and grasp basic concepts.

  Students can play and replay dynamic explanations of concepts and program flow.

  Students can watch and listen as the author solves a problem step-by-step. acknowledgments xvii

  acknowledgments

  Many thanks to Beth Lang Golub, Don Fowley, Elizabeth Mills, Thomas Kulesa, Wendy Ashenberg, Lisa Gee, Andre Legaspi, Kevin Holm, and John Curley at John Wiley &amp; Sons, and Vickie Piercey at Publishing Services for their help with this proj- ect. An especially deep acknowledgment and thanks goes to Cindy Johnson for her hard work, sound judgment, and amazing attention to detail.

  I am grateful to Jose Cordova, University of Louisiana, Monroe, Amitava Kar- maker, University of Wisconsin, Stout, Khaled Mansour, Washtenaw Community

  College, Patricia McDermott-Wells, Florida International University, Brent Seales, University of Kentucky, Donald Smith, Columbia College, and David Woolbright, Columbus State University, for their excellent work on the supplemental mate-

  rial. Thank you also to Jose-Arturo Mora-Soto, Jesica Rivero-Espinosa, and Julio- Angel Cano-Romero of the University of Madrid for their contribution of business exercises.

  Many thanks to the individuals who provided feedback, reviewed the manuscript, made valuable suggestions, and brought errors and omissions to my attention. They include: Lynn Aaron, SUNY Rockland Uday Chakraborty, University of

  Community College Missouri, St. Louis

  Karen Arlien, Bismarck State College Xuemin Chen, Texas Southern

  University

  Jay Asundi, University of Texas, Dallas Haiyan Cheng, Willamette University

  Eugene Backlin, DePaul University Chakib Chraibi, Barry University

  William C. Barge, Trine University Ta-Tao Chuang, Gonzaga University

  Bruce J. Barton, Suffolk County

  Community College Vincent Cicirello, Richard Stockton College

  Sanjiv K. Bhatia, University of Missouri,

  St. Louis Mark Clement, Brigham Young University

  Anna Bieszczad, California State

  University, Channel Islands Gerald Cohen, St. Joseph’s College

  Jackie Bird, Northwestern University Rebecca Crellin, Community College

  of Allegheny County

  Eric Bishop, Northland Pioneer College Leslie Damon, Vermont Technical

  Paul Bladek, Edmonds Community

  College College

  Geoffrey D. Decker, Northern Illinois Paul Logasa Bogen II, Texas A&amp;M

  University University

  Khaled Deeb, Barry University, School Irene Bruno, George Mason University

  of Adult and Continuing Education

  Paolo Bucci, Ohio State University Akshaye Dhawan, Ursinus College

  Joe Burgin, College of Southern Julius Dichter, University of Bridgeport

  Maryland

  Mike Domaratzki, University of Robert P. Burton, Brigham Young

  Manitoba University

  Philip Dorin, Loyola Marymount Leonello Calabresi, University of

  University Maryland University College

  Anthony J. Dos Reis, SUNY New Paltz Martine Ceberio, University of Texas,

  El Paso Elizabeth Drake, Santa Fe College

  xviii acknowledgments

  University

  Florida

  Frank Malinowski, Dalton College John S. Mallozzi, Iona College Kenneth Martin, University of North

  Merced

  Cheng Luo, Coppin State University Kelvin Lwin, University of California,

  University

  Hunter Lloyd, Montana State

  Jian Lin, Eastern Connecticut State

  Reynolds Community College

  University

  Samuel Kohn, Touro College April Kontostathis, Ursinus College Ron Krawitz, DeVry University Debbie Lamprecht, Texas Tech

  Lexington

  Julie King, Sullivan University,

  Institute of Technology

  Mugdha Khaladkar, New Jersey

  Deborah Mathews, J. Sargeant

  Louis Mazzucco, State University of

  Rajkumar Kempaiah, College of Mount

  Namdar Mogharreban, Southern

  Tony Tuan Nguyen, De Anza College Michael Ondrasek, Wright State

  College

  Nannette Napier, Georgia Gwinnett

  College

  Shamsi Moussavi, Massbay Community

  Illinois University

  Anchorage

  New York at Cobleskill and Excelsior College

  Sandeep Mitra, SUNY Brockport Kenrick Mock, University of Alaska

  California, Merced

  Jeanne Milostan, University of

  Calumet

  Michael L. Mick, Purdue University,

  University

  Drew McDermott, Yale University Hugh McGuire, Grand Valley State

  Saint Vincent

  Wisconsin, Stout

  Tom Duffy, Norwalk Community

  James Factor, Alverno College Chris Fietkiewicz, Case Western

  Stephen Gilbert, Orange Coast College Peter van der Goes, Rose State College Billie Goldstein, Temple University Michael Gourley, University of Central

  University

  Valerie Frear, Daytona State College Ryan Garlick, University of North Texas Aaron Garrett, Jacksonville State

  College

  Terrell Foty, Portland Community

  Reserve University

  College

  Grigoriy Grinberg, Montgomery

  Dave Evans, Pasadena Community

  College

  Amita Engineer, Valencia Community

  Polytechnic University, Pomona

  Michael Eckmann, Skidmore College Sander Eller, California State

  College

  Oklahoma

  College

  Amitava Karmaker, University of

  University

  of Technology

  Jonathan Kapleau, New Jersey Institute

  College

  Eric Jiang, University of San Diego Christopher M. Johnson, Guilford

  Mexico

  Rodney Hoffman, Occidental College May Hou, Norfolk State University John Houlihan, Loyola University Andree Jacobson, University of New

  Guy Helmer, Iowa State University Katherin Herbert, Montclair State

  Linwu Gu, Indiana University Bruce Haft, Glendale Community

  University

  Ric Heishman, George Mason

  University, Mankato

  Allan M. Hart, Minnesota State

  University

  Nancy Harris, James Madison

  College

  University acknowledgments xix K. Palaniappan, University of Missouri James Papademas, Oakton Community

  College

  Portland

  Oklahoma

  Monica Sweat, Georgia Tech University Joseph Szurek, University of Pittsburgh,

  Greensburg

  Jack Tan, University of Wisconsin Cynthia Tanner, West Virginia

  University

  Russell Tessier, University of

  Massachusetts, Amherst

  Krishnaprasad Thirunarayan, Wright

  State University

  Megan Thomas, California State

  University, Stanislaus

  Timothy Urness, Drake University Eliana Valenzuela-Andrade, University

  of Puerto Rico at Arecibo

  Tammy VanDeGrift, University of

  Philip Ventura, Broward College David R. Vineyard, Kettering

  Lincoln

  University

  Qi Wang, Northwest Vista College Jonathan Weissman, Finger Lakes

  Community College

  Reginald White, Black Hawk

  Community College

  Ying Xie, Kennesaw State University Arthur Yanushka, Christian Brothers

  University

  Chen Ye, University of Illinois, Chicago Wook-Sung Yoo, Fairfield University Bahram Zartoshty, California State

  University, Northridge

  Frank Zeng, Indiana Wesleyan

  University

  Hairong Zhao, Purdue University

  Calumet

  Stephen Zilora, Rochester Institute of

  Dave Sullivan, Boston University Vaidy Sunderam, Emory University Hong Sung, University of Central