Introduction to Java Programming Brief 8th Edition Edition Y. Daniel Liang - The ebook in PDF format is available for download
Introduction to Java Programming Brief 8th Edition Edition Y. Daniel Liang - The ebook in PDF format is available for download
https://ebookultra.com/download/java-programming-8th-edition-joyce-
farrell/
https://ebookultra.com/download/introduction-to-programming-with-
java-3rd-edition-john-dean/
https://ebookultra.com/download/brief-java-early-objects-9th-edition-
cay-horstmann/
https://ebookultra.com/download/a-very-brief-introduction-to-
watercolour-boudrouaz-bilel/
https://ebookultra.com/download/java-programming-7th-edition-joyce-
farrell/
https://ebookultra.com/download/introduction-to-syriac-daniel-m-
gurtner/
https://ebookultra.com/download/advanced-java-game-programming-
wallace-croft/
Introduction to Java Programming Brief 8th Edition
Edition Y. Daniel Liang Digital Instant Download
Author(s): Y. Daniel Liang
ISBN(s): 9780132130790, 0132130793
Edition: 8th Edition
File Details: PDF, 9.96 MB
Year: 2010
Language: english
INTRODUCTION TO
JAVA
TM
PROGRAMMING
This page intentionally left blank
INTRODUCTION TO
JAVA
TM
PROGRAMMING
BRIEF VERSION
Eighth Edition
Y. Daniel Liang
Armstrong Atlantic State University
Prentice Hall
Boston Columbus Indianapolis New York San Francisco Upper Saddle River
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 and Editorial Director, ECS: Marcia J. Horton
Editor in Chief, Computer Science: Michael Hirsch
Executive Editor: Tracy Dunkelberger
Assistant Editor: Melinda Haggerty
Editorial Assistant: Allison Michael
Vice President, Production: Vince O’Brien
Senior Managing Editor: Scott Disanno
Production Editor: Irwin Zucker
Senior Operations Specialist: Alan Fischer
Marketing Manager: Erin Davis
Marketing Assistant: Mack Patterson
Art Director: Kenny Beck
Cover Image: Male Ruby-throated Hummingbird / Steve Byland / Shutterstock;
Hummingbird, Nazca Lines / Gary Yim / Shutterstock
Art Editor: Greg Dulles
Media Editor: Daniel Sandin
Copyright © 2011, 2009, 2007, 2004 by Pearson Higher Education. Upper Saddle River, New Jersey, 07458.
All right reserved. Manufactured 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 sys-
tem, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To
obtain permission(s) to use materials from this work, please submit a written request to Pearson Higher Education,
Permissions Department, 1 Lake Street, Upper Saddle River, NJ 07458.
The author 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 author and
publisher make no warranty of any kind, expressed or implied, with regard to these programs or the documentation
contained in this book. The author 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.
10 9 8 7 6 5 4 3 2 1
ISBN-13: 978-0-13-213079-0
ISBN-10: 0-13-213079-3
This book is dedicated to Dr. S. K. Dhall and
Dr. S. Lakshmivarahan of the University of Oklahoma,
who inspired me in teaching and research. Thank you for being
my mentors and advisors.
■ This edition is completely revised in every detail to enhance clarity, presentation, content, complete revision
examples, and exercises.
■ In the examples and exercises, which are provided to motivate and stimulate student inter-
est in programming, one-fifth of the problems are new. new problems
■ In the previous edition, console input was covered at the end of Chapter 2. The new edi- early console input
tion introduces console input early in Chapter 2 so that students can write interactive pro-
grams early.
■ The hand trace box is added for many programs in early chapters to help noive students hand trace box
to read and trace programs.
■ Single-dimensional arrays and multidimensional arrays are covered in two chapters to multidimensional arrays
give instructors the flexibility to cover multidimensional arrays later.
■ The case study for the Sudoku problem has been moved to the Companion Website. A Sudoku problem simplified
more pedagogically effective simple version of the Sudoku problem is presented instead.
■ The design of the API for Java GUI programming is an excellent example of how the
object-oriented principle is applied. Students learn better with concrete and visual exam-
ples. So basic GUI now precedes the introduction of abstract classes and interfaces. The basic GUI earlier
instructor, however, can still choose to cover abstract classes and interfaces before GUI.
vii
viii Preface
exception handling earlier ■ Exception handling is covered before abstract classes and interfaces. The instructor can
still choose to cover exception handling later.
■ Chapter 12, “Object-Oriented Design and Patterns,” in the previous edition has been
design guidelines replaced by spreading the design guidelines and patterns into several chapters so that these
topics can be covered in appropriate context.
Learning Strategies
A programming course is quite different from other courses. In a programming course, you
learn from mistakes learn from examples, from practice, and from mistakes. You need to devote a lot of time to
writing programs, testing them, and fixing errors.
programmatic solution For first-time programmers, learning Java is like learning any high-level programming lan-
guage. The fundamental point is to develop the critical skills of formulating programmatic
solutions for real problems and translating them into programs using selection statements,
loops, methods, and arrays.
Once you acquire the basic skills of writing programs using loops, methods, and arrays,
object-oriented programming you can begin to learn how to develop large programs and GUI programs using the object-
oriented approach.
When you know how to program and you understand the concept of object-oriented pro-
Java API gramming, learning Java becomes a matter of learning the Java API. The Java API establish-
es a framework for programmers to develop applications using Java. You have to use the
classes and interfaces in the API and follow their conventions and rules to create applications.
The best way to learn the Java API is to imitate examples and do exercises.
Pedagogical Features
The book uses the following elements to get the most from the material:
■ Objectives list what students should have learned from the chapter. This will help them
determine whether they have met the objectives after completing the chapter.
■ Introduction opens the discussion with representative problems to give the reader an
overview of what to expect from the chapter.
■ Problems carefully chosen and presented in an easy-to-follow style, teach problem solv-
ing and programming concepts. The book uses many small, simple, and stimulating exam-
ples to demonstrate important ideas.
■ Chapter Summary reviews the important subjects that students should understand and
remember. It helps them reinforce the key concepts they have learned in the chapter.
■ Review Questions are grouped by sections to help students track their progress and eval-
uate their learning.
■ Programming Exercises are grouped by sections to provide students with opportunities
to apply on their own the new skills they have learned. The level of difficulty is rated as
easy (no asterisk), moderate (*), hard (**), or challenging (***). The trick of learning
programming is practice, practice, and practice. To that end, the book provides a great
many exercises.
■ LiveLab is a programming course assessment and management system. Students can
submit programs/quizzes online. The system automatically grades the programs/quizzes
and gives students instant feedback.
■ Notes, Tips, and Cautions are inserted throughout the text to offer valuable advice and
insight on important aspects of program development.
Preface ix
Note
Provides additional information on the subject and reinforces important concepts.
Tip
Teaches good programming style and practice.
Caution
Helps students steer away from the pitfalls of programming errors.
Design Guide
Provides the guidelines for designing programs.
Chapter 2 Elementary
Programming Chapter 10 Thinking in Objects Chapter 16 Event-Driven
Programming
Chapter 7 Multidimensional
Arrays
Chapter 20 Recursion
LiveLab
This book is accompanied by an improved faster Web-based course assessment and manage-
ment system. The system has three main components:
■ Automatic Grading System: It can automatically grade exercises from the text or created
by instructors.
■ Tracking grades, attendance, etc: The system enables the students to track grades and
instructors to view the grades of all students, and to track attendance.
Preface xi
The main features of the Automatic Grading System are as follows:
■ Allows students to compile, run and submit exercises. (The system checks whether their
program runs correctly—students can continue to run and submit the program before the
due date.)
■ Allows instructors to review submissions; run programs with instructor test cases; correct
them; and provide feedback to students.
■ Allows instructors to create/modify their own exercises, create public and secret test cases,
assign exercises, and set due dates for the whole class or for individuals.
■ All the exercises in the text can be assigned to students. Additionally, LiveLab provides
extra exercises that are not printed in the text.
■ Allows instructors to sort and filter all exercises and check grades (by time frame, student,
and/or exercise).
■ Allows instructors to delete students from the system.
■ Allows students and instructors to track grades on exercises.
■ Allows instructors to create/modify quizzes from test bank or a text file or to create com-
plete new tests online.
■ Allows instructors to assign the quizzes to students and set a due date and test time limit
for the whole class or for individuals.
■ Allows students and instructors to review submitted quizzes.
■ Allows students and instructors to track grades on quizzes.
Video Notes are Pearson’s new visual tool designed for teaching students key programming con-
cepts and techniques. These short step-by-step videos demonstrate how to solve problems from
design through coding. Video Notes allows for self-paced instruction with easy navigation includ-
ing the ability to select, play, rewind, fast-forward, and stop within each Video Note exercise.
Video Note margin icons in your textbook let you know what a Video Notes video is avail-
able for a particular concept or homework problem.
Video Notes are free with the purchase of a new textbook. To purchase access to Video
Notes, please go to www.pearsonhighered.com/liang.
Additional Supplements
The text covers the essential subjects. The supplements extend the text to introduce addition-
al topics that might be of interest to readers. The supplements listed in this table are available
from the Companion Web site.
To access the Video Notes and Web Chapters, instructors must log onto www.pearsonhighered.com/liang
and register.
Acknowledgments
I would like to thank Armstrong Atlantic State University for enabling me to teach what I
write and for supporting me in writing what I teach. Teaching is the source of inspiration for
continuing to improve the book. I am grateful to the instructors and students who have offered
comments, suggestions, bug reports, and praise.
This book has been greatly enhanced thanks to outstanding reviews for this and previous
editions. The reviewers are: Elizabeth Adams (James Madison University), Syed Ahmed
(North Georgia College and State University), Omar Aldawud (Illinois Institute of
Technology), Yang Ang (University of Wollongong, Australia), Kevin Bierre (Rochester
Institute of Technology), David Champion (DeVry Institute), James Chegwidden (Tarrant
County College), Anup Dargar (University of North Dakota), Charles Dierbach (Towson
University), Frank Ducrest (University of Louisiana at Lafayette), Erica Eddy (University of
Wisconsin at Parkside), Deena Engel (New York University), Henry A Etlinger (Rochester
Institute of Technology), James Ten Eyck (Marist College), Olac Fuentes (University of
Texas at El Paso), Harold Grossman (Clemson University), Barbara Guillot (Louisiana State
University), Ron Hofman (Red River College, Canada), Stephen Hughes (Roanoke College),
Vladan Jovanovic (Georgia Southern University), Edwin Kay (Lehigh University), Larry
King (University of Texas at Dallas), Nana Kofi (Langara College, Canada), George
Koutsogiannakis (Illinois Institute of Technology), Roger Kraft (Purdue University at
Calumet), Hong Lin (DeVry Institute), Dan Lipsa (Armstrong Atlantic State University),
James Madison (Rensselaer Polytechnic Institute), Frank Malinowski (Darton College), Tim
Margush (University of Akron), Debbie Masada (Sun Microsystems), Blayne Mayfield
(Oklahoma State University), John McGrath (J.P. McGrath Consulting), Shyamal Mitra
(University of Texas at Austin), Michel Mitri (James Madison University), Kenrick Mock
(University of Alaska Anchorage), Jun Ni (University of Iowa), Benjamin Nystuen
(University of Colorado at Colorado Springs), Maureen Opkins (CA State University, Long
Beach), Gavin Osborne (University of Saskatchewan), Kevin Parker (Idaho State
University), Dale Parson (Kutztown University), Mark Pendergast (Florida Gulf Coast
xiv Preface
University), Richard Povinelli (Marquette University), Roger Priebe (University of Texas at
Austin), Mary Ann Pumphrey (De Anza Junior College), Pat Roth (Southern Polytechnic
State University), Ronald F. Taylor (Wright State University), Carolyn Schauble (Colorado
State University), David Scuse (University of Manitoba), Ashraf Shirani (San Jose State
University), Daniel Spiegel (Kutztown University), Amr Sabry (Indiana University), Lixin
Tao (Pace University), Russ Tront (Simon Fraser University), Deborah Trytten (University
of Oklahoma), Kent Vidrine (George Washington University), and Bahram Zartoshty
(California State University at Northridge).
It is a great pleasure, honor, and privilege to work with Pearson. I would like to thank Tracy
Dunkelberger and her colleagues Marcia Horton, Margaret Waples, Erin Davis, Michael Hirsh,
Matt Goldstein, Jake Warde, Melinda Haggerty, Allison Michael, Scott Disanno, Irwin Zucker,
and their colleagues for organizing, producing, and promoting this project, and Robert Lentz
for copy editing.
As always, I am indebted to my wife, Samantha, for her love, support, and encouragement.
Y. Daniel Liang
y.daniel.liang@gmail.com
www.cs.armstrong.edu/liang
www.pearsonhighered.com/liang
BRIEF CONTENTS
1 Introduction to Computers, Programs, 16 Event-Driven Programming 533
and Java 1 17 Creating Graphical User Interfaces 571
2 Elementary Programming 23 18 Applets and Multimedia 613
3 Selections 71 19 Binary I/O 649
4 Loops 115 20 Recursion 677
5 Methods 155
6 Single-Dimensional Arrays 197
7 Multidimensional Arrays 235
APPENDIXES
8 Objects and Classes 263 A Java Keywords 707
9 Strings and Text I/O 301 B The ASCII Character Set 710
10 Thinking in Objects 343 C Operator Precedence Chart 712
11 Inheritance and Polymorphism 373 D Java Modifiers 714
12 GUI Basics 405 E Special Floating-Point Values 716
13 Exception Handling 431 F Number Systems 717
14 Abstract Classes and Interfaces 457
15 Graphics 497
INDEX 721
xv
CONTENTS
Chapter 1 Introduction to Computers, Programs,
and Java 1
1.1 Introduction 2
1.2 What Is a Computer? 2
1.3 Programs 5
1.4 Operating Systems 7
1.5 Java, World Wide Web, and Beyond 8
1.6 The Java Language Specification, API, JDK, and IDE 10
1.7 A Simple Java Program 11
1.8 Creating, Compiling, and Executing a Java Program 13
1.9 (GUI) Displaying Text in a Message Dialog Box 16
Chapter 3 Selections 71
3.1 Introduction 72
3.2 boolean Data Type 72
3.3 Problem: A Simple Math Learning Tool 73
3.4 if Statements 74
xvi
Contents xvii
3.5 Problem: Guessing Birthdays 75
3.6 Two-Way if Statements 79
3.7 Nested if Statements 80
3.8 Common Errors in Selection Statements 81
3.9 Problem: An Improved Math Learning Tool 82
3.10 Problem: Computing Body Mass Index 84
3.11 Problem: Computing Taxes 85
3.12 Logical Operators 88
3.13 Problem: Determining Leap Year 90
3.14 Problem: Lottery 91
3.15 switch Statements 93
3.16 Conditional Expressions 95
3.17 Formatting Console Output 95
3.18 Operator Precedence and Associativity 97
3.19 (GUI) Confirmation Dialogs 98
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