100% found this document useful (2 votes)
5 views

An Introduction to Object Oriented Programming with Java 5th Edition by Thomas Wu ISBN 0073523305 9780073523309 pdf download

The document is an introduction to the 5th edition of 'An Introduction to Object Oriented Programming with Java' by Thomas Wu, focusing on object-oriented programming concepts using Java. It highlights key changes from the previous edition, including discussions on Java 5.0 features, exclusive use of console input/output, and more examples from natural sciences. The book is organized to promote object-oriented thinking and includes programming exercises of varying difficulty levels.

Uploaded by

twilashaut3t
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
5 views

An Introduction to Object Oriented Programming with Java 5th Edition by Thomas Wu ISBN 0073523305 9780073523309 pdf download

The document is an introduction to the 5th edition of 'An Introduction to Object Oriented Programming with Java' by Thomas Wu, focusing on object-oriented programming concepts using Java. It highlights key changes from the previous edition, including discussions on Java 5.0 features, exclusive use of console input/output, and more examples from natural sciences. The book is organized to promote object-oriented thinking and includes programming exercises of varying difficulty levels.

Uploaded by

twilashaut3t
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

An Introduction to Object Oriented Programming

with Java 5th Edition by Thomas Wu ISBN


0073523305 9780073523309 install download

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-wu-
isbn-0073523305-9780073523309-16398/

Explore and download more ebooks or textbooks


at ebookball.com
Get Your Digital Files Instantly: PDF, ePub, MOBI and More
Quick Digital Downloads: PDF, ePub, MOBI and Other Formats

An Introduction to Object Oriented Programming With Java 5th Edition


by Thomas Wu 0073523305 9780073523309

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-
wu-0073523305-9780073523309-15256/

An Introduction to Object Oriented Programming With Java 5th Edition


by Thomas Wu 0073523305 9780073523309

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-
wu-0073523305-9780073523309-15330/

An Introduction to Object Oriented Programming with Java 5th Edition


by Thomas Wu ISBN 9780073523309 0073523305

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-wu-
isbn-9780073523309-0073523305-15552/

An Introduction to Object Oriented Programming with Java 5th Edition


by Thomas Wu ISBN 0073523305 9780073523309

https://ebookball.com/product/an-introduction-to-object-oriented-
programming-with-java-5th-edition-by-thomas-wu-
isbn-0073523305-9780073523309-16398/
Object Oriented Programming with Java 1st edition By Hanumanth Ladwa
ISBN 8450193403 9788450193403

https://ebookball.com/product/object-oriented-programming-with-
java-1st-edition-by-hanumanth-ladwa-
isbn-8450193403-9788450193403-25034/

Microsoft Visual C# 2017 An Introduction to Object Oriented


Programming 7th Edition by Joyce Farrell ISBN 1337102100 9781337102100

https://ebookball.com/product/microsoft-visual-c-2017-an-
introduction-to-object-oriented-programming-7th-edition-by-joyce-
farrell-isbn-1337102100-9781337102100-25038/

Beginning C 3 0 an introduction to object oriented programming 1st


edition by Jack Purdum 0470261293 978-0470261293

https://ebookball.com/product/beginning-c-3-0-an-introduction-to-
object-oriented-programming-1st-edition-by-jack-
purdum-0470261293-978-0470261293-15238/

Object Oriented Programming Using C An Introduction 1st Edition by


Pardoe, King 0333692411 978-0333692417

https://ebookball.com/product/object-oriented-programming-using-
c-an-introduction-1st-edition-by-pardoe-
king-0333692411-978-0333692417-15282/

Java Graphical User Interfaces An Introduction to Java Programming 1st


Edition by David Etheridge ISBN

https://ebookball.com/product/java-graphical-user-interfaces-an-
introduction-to-java-programming-1st-edition-by-david-etheridge-
isbn-11352/
www.allitebooks.com
An Introduction to Object-Oriented
TM
Programming with Java
Fifth Edition

C.Thomas Wu
Naval Postgraduate School

www.allitebooks.com
AN INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING WITH JAVA™, FIFTH EDITION

Published by McGraw-Hill, a business unit of The McGraw-Hill Companies, Inc., 1221 Avenue of the
Americas, New York, NY 10020. Copyright © 2010 by The McGraw-Hill Companies, Inc. All rights reserved.
Previous editions © 2006, 2004, and 2001. No part of this publication may be reproduced or distributed in any
form or by any means, or stored in a database or retrieval system, without the prior written consent of The
McGraw-Hill Companies, Inc., including, but not limited to, in any network or other electronic storage or
transmission, or broadcast for distance learning.

Some ancillaries, including electronic and print components, may not be available to customers outside the
United States.

This book is printed on acid-free paper.

1 2 3 4 5 6 7 8 9 0 DOC/DOC 0 9

ISBN 978–0–07–352330–9
MHID 0–07–352330–5

Global Publisher: Raghothaman Srinivasan


Director of Development: Kristine Tibbetts
Developmental Editor: Lorraine K. Buczek
Senior Marketing Manager: Curt Reynolds
Senior Project Manager: Jane Mohr
Lead Production Supervisor: Sandy Ludovissy
Lead Media Project Manager: Stacy A. Patch
Associate Design Coordinator: Brenda A. Rolwes
Cover Designer: Studio Montage, St. Louis, Missouri
(USE) Cover Image: © Getty Images
Compositor: Macmillan Publishing Solutions
Typeface: 10.5/12 Times Roman
Printer: R. R. Donnelley Crawfordsville, IN

All credits appearing on page or at the end of the book are considered to be an extension of the copyright page.

Library of Congress Cataloging-in-Publication Data

Wu, C. Thomas.
An introduction to object-oriented programming with Java / C. Thomas Wu (Otani).—5th ed.
p. cm.
Includes index.
ISBN 978–0–07–352330–9— ISBN 0–07–352330–5 (hard copy : alk. paper) 1. Object-oriented
programming (Computer science) 2. Java (Computer program language) I. Title.
QA76.64.W78 2010
005.1'17—dc22

2008053612

www.mhhe.com

www.allitebooks.com
To my family

www.allitebooks.com
www.allitebooks.com
Contents

Preface xi

0 Introduction to Computers and


Programming Languages 1
0.1 A History of Computers 2
0.2 Computer Architecture 4
0.3 Programming Languages 11
0.4 Java 12

1 Introduction to Object-Oriented Programming and


Software Development 15
1.1 Classes and Objects 16
1.2 Messages and Methods 18
1.3 Class and Instance Data Values 20
1.4 Inheritance 23
1.5 Software Engineering and Software
Life Cycle 24

2 Getting Started with Java 29


2.1 The First Java Program 30
2.2 Program Components 39
2.3 Edit-Compile-Run Cycle 49
2.4 Sample Java Standard Classes 52
2.5 Sample Development 69
v

www.allitebooks.com
vi Contents

3 Numerical Data 85
3.1 Variables 86
3.2 Arithmetic Expressions 94
3.3 Constants 99
3.4 Displaying Numerical Values 101
3.5 Getting Numerical Input 107
3.6 The Math Class 113
3.7 Random Number Generation 117
3.8 The GregorianCalendar Class 120
3.9 Sample Development 125
3.10 Numerical Representation (Optional) 136

4 Defining Your Own Classes—Part 1 151


4.1 First Example: Defining and Using a Class 152
4.2 Second Example: Defining and Using Multiple Classes 162
4.3 Matching Arguments and Parameters 166
4.4 Passing Objects to a Method 168
4.5 Constructors 173
4.6 Information Hiding and Visibility Modifiers 180
4.7 Class Constants 183
4.8 Local Variables 191
4.9 Calling Methods of the Same Class 193
4.10 Changing Any Class to a Main Class 197
4.11 Sample Development 198

5 Selection Statements 221


5.1 The if Statement 222
5.2 Nested if Statements 233
5.3 Boolean Expressions and Variables 239
5.4 Comparing Objects 247
5.5 The switch Statement 252
5.6 Drawing Graphics 256
5.7 Enumerated Constants 266
5.8 Sample Development 272

www.allitebooks.com
Contents vii

6 Repetition Statements 303


6.1 The while Statement 304
6.2 Pitfalls in Writing Repetition Statements 313
6.3 The do–while Statement 319
6.4 Loop-and-a-Half Repetition Control 323
6.5 The for Statement 327
6.6 Nested for Statements 332
6.7 Formatting Output 334
6.8 Loan Tables 339
6.9 Estimating the Execution Time 342
6.10 Recursive Methods (Optional) 346
6.11 Sample Development 351

7 Defining Your Own Classes—Part 2 373


7.1 Returning an Object from a Method 374
7.2 The Reserved Word this 378
7.3 Overloaded Methods and Constructors 386
7.4 Class Variables and Methods 391
7.5 Call-by-Value Parameter Passing 395
7.6 Organizing Classes into a Package 402
7.7 Using Javadoc Comments for
Class Documentation 403
7.8 The Complete Fraction Class 408
7.9 Sample Development 418

8 Exceptions and Assertions 445


8.1 Catching Exceptions 446
8.2 Throwing Exceptions and Multiple catch Blocks 453
8.3 Propagating Exceptions 458
8.4 Types of Exceptions 466
8.5 Programmer-Defined Exceptions 469
8.6 Assertions 471
8.7 Sample Development 477

www.allitebooks.com
viii Contents

9 Characters and Strings 495


9.1 Characters 496
9.2 Strings 499
9.3 Pattern Matching and Regular Expression 510
9.4 The Pattern and Matcher Classes 517
9.5 Comparing Strings 521
9.6 StringBuffer and StringBuilder 523
9.7 String Processing and Bioinformatics 529
9.8 Sample Development 533

10 Arrays and Collections 555


10.1 Array Basics 556
10.2 Arrays of Objects 567
10.3 The For-Each Loop 577
10.4 Passing Arrays to Methods 582
10.5 Two-Dimensional Arrays 589
10.6 Lists and Maps 596
10.7 Sample Development 609

11 Sorting and Searching 633


11.1 Searching 634
11.2 Sorting 638
11.3 Heapsort 646
11.4 Sample Development 659

12 File Input and Output 685


12.1 File and JFileChooser Objects 686
12.2 Low-Level File I/O 695
12.3 High-Level File I/O 700

www.allitebooks.com
Contents ix

12.4 Object I/O 709


12.5 Sample Development 716

13 Inheritance and Polymorphism 733


13.1 A Simple Example 734
13.2 Defining Classes with Inheritance 737
13.3 Using Classes Effectively with Polymorphism 741
13.4 Inheritance and Member Accessibility 744
13.5 Inheritance and Constructors 749
13.6 Abstract Superclasses and Abstract Methods 753
13.7 Inheritance versus Interface 758
13.8 Sample Development 759

14 GUI and Event-Driven Programming 787


14.1 Simple GUI I/O with JOptionPane 790
14.2 Customizing Frame Windows 793
14.3 GUI Programming Basics 799
14.4 Text-Related GUI Components 808
14.5 Layout Managers 820
14.6 Effective Use of Nested Panels 830
14.7 Other GUI Components 839
14.8 Menus 857
14.9 Handling Mouse Events 861

15 Recursive Algorithms 881


15.1 Basic Elements of Recursion 882
15.2 Directory Listing 883
15.3 Anagram 885
15.4 Towers of Hanoi 888
15.5 Quicksort 890
15.6 When Not to Use Recursion 895

www.allitebooks.com
x Contents

Appendix A How to Run Java Programs 903

Appendix B Sample Programs 911

Appendix C Standard Classes and Interfaces 933

Appendix D UML Diagrams 955

Index 963
Preface

T his book is an introduction to object-oriented programming using the Java


programming language. We use the object-first approach where objects are used
from the first sample program. Object-oriented thinking is emphasized and pro-
moted from the beginning. Students learn how to use objects first and then learn
how to define their own objects.

Key Changes in the 5th Edition


The key differences between this edition and the fourth edition are as follows:
1. More Discussion on Java 5.0 Features and Java 6.0 Compatibility. Many
of the new Java 5.0 features are explained and used in the sample programs.
They include the enumerator type, the for-each loop construct, auto boxing
and unboxing, and the generics.
2. Exclusive Use of Console Input and Output. All the GUI related topics,
including the JOptionPane class, are moved to Chapter 14. Sample programs
before Chapter 14 use the standard console input (Scanner) and output
(System.out). Those who want to use JOptionPane for simple input and output
can do so easily by covering Section 14.1 before Chapter 3.
3. More Examples from Natural Sciences. In several key chapters, we illus-
trate concepts using examples from biology and chemistry. For example, in
Chapter 4, we use the elements in the periodic table to illustrate the concept of
programmer-defined classes. In Chapter 9, we demonstrate how the string
processing techniques are applied to implement DNA sequencing and other
common DNA operations.
4. Level-by-level Organization for Programming Exercises. Programming
exercises at the end of chapters are organized into three levels of difficulties.
The one-star level exercises require the basic understanding of the materials
covered in the chapter. The two-star level exercises require some additional
thinking beyond the basic understanding. The three-star level exercises are

xi
xii Preface

most difficult and require significant effort. For some of the three-star exer-
cises, students must find or study additional information beyond those pre-
sented in the book. Please keep in mind that the level of difficulties is only a
general guideline. One student may find some level-three exercises much eas-
ier than level-two exercises, for example.

Book Organization
There are 16 chapters in this book, numbered from 0 to 15. The first 11 chapters
cover the core topics that provide the fundamentals of programming. Chapters 11 to
15 cover intermediate-level topics such as sorting, searching, recursion, inheritance,
polymorphism, and file I/O. There are more than enough topics for one semester.
After the first 11 chapters (Ch 0 to Ch 10), instructors can mix and match materials
from Chapters 11 to 15 to suit their needs. We first show the dependency relation-
ships among the chapters and then provide a brief summary of each chapter.

Chapter Dependency
For the most part, chapters should be read in sequence, but some variations are
possible, especially with the optional chapters. Here’s a simplified dependency
graph:

0
1

4
5

6
7

8 9 10
*Note: Some examples use arrays,
11 12 13 14* 15 but the use of arrays is not an
integral part of the examples.
These examples can be modified
to those that do not use arrays.
Many topics from the early part
of the chapter can be introduced
as early as after Chapter 2.
Preface xiii

Brief Chapter Summary


Here is a short description of each chapter:
• Chapter 0 is an optional chapter. We provide background information on
computers and programming languages. This chapter can be skipped or as-
signed as an outside reading if you wish to start with object-oriented pro-
gramming concepts.
• Chapter 1 provides a conceptual foundation of object-oriented programming.
We describe the key components of object-oriented programming and illus-
trate each concept with a diagrammatic notation using UML.
• Chapter 2 covers the basics of Java programming and the process of editing,
compiling, and running a program. From the first sample program presented in
this chapter, we emphasize object-orientation. We will introduce the standard
classes String, Date, and SimpleDateFormat so we can reinforce the notion of
object declaration, creation, and usage. Moreover, by using these standard
classes, students can immediately start writing practical programs. We describe
and illustrate console input with System.in and the Scanner class and output with
System.out.
• Chapter 3 introduces variables, constants, and expressions for manipulating
numerical data. We explain the standard Math class from java.lang and
introduce more standard classes (GregorianCalendar and DecimalFormat) to
continually reinforce the notion of object-orientation. We describe additional
methods of the Scanner class to input numerical values. Random number
generation is introduced in this chapter. The optional section explains how the
numerical values are represented in memory space.
• Chapter 4 teaches the basics of creating programmer-defined classes. We
keep the chapter accessible by introducting only the fundamentals with illus-
trative examples. The key topics covered in this chapter are constructors, vis-
ibility modifiers (public and private), local variables, and passing data to
methods. We provide easy-to-grasp illustrations that capture the essence of
the topics so the students will have a clear understanding of them.
• Chapter 5 explains the selection statements if and switch. We cover boolean
expressions and nested-if statements. We explain how objects are compared
by using equivalence (==) and equality (the equals and compareTo methods).
We use the String and the programmer-defined Fraction classes to make the
distinction between the equivalence and equality clear. Drawing 2-D graphics
is introduced, and a screensaver sample development program is developed.
We describe the Java 5.0 feature called enumerated type in this chapter.
• Chapter 6 explains the repetition statements while, do–while, and for. Pitfalls
in writing repetition statements are explained. One of the pitfalls to avoid is
the use of float or double for the data type of a counter variable. We illustrate
this pitfall by showing a code that will result in infinite loop. Finding the great-
est common divisor of two integers is used as an example of a nontrivial loop
statement. We show the difference between the straightforward (brute-force)
and the clever (Euclid’s) solutions. We introduce the Formatter class and show
xiv Preface

how the output can be aligned nicely. The optional last section of the chapter
introduces recursion as another technique for repetition. The recursive version
of a method that finds the greatest common divisor of two integers is given.
• Chapter 7 is the second part of creating programmer-defined classes. We
introduce new topics related to the creation of programmer-defined classes
and also repeat some of the topics covered in Chapter 4 in more depth. The
key topics covered in this chapter are method overloading, the reserved
word this, class methods and variables, returning an object from a method,
and pass-by-value parameter passing. As in Chapter 4, we provide many
lucid illustrations to make these topics accessible to beginners. We use the
Fraction class to illustrate many of these topics, such as the use of this and
class methods. The complete definition of the Fraction class is presented in
this chapter.
• Chapter 8 teaches exception handling and assertions. The focus of this chap-
ter is the construction of reliable programs. We provide a detailed coverage of
exception handling in this chapter. We introduce an assertion and show how it
can be used to improve the reliability of finished products by catching logical
errors early in the development.
• Chapter 9 covers nonnumerical data types: characters and strings. Both the
String and StringBuffer classes are explained in the chapter. Another string
class named StringBuilder is briefly explained in this chapter. An important ap-
plication of string processing is pattern matching. We describe pattern match-
ing and regular expression in this chapter. We introduce the Pattern and
Matcher classes and show how they are used in pattern matching. One section
is added to discuss the application of string processing in bioinformatics.
• Chapter 10 teaches arrays. We cover arrays of primitive data types and of ob-
jects. An array is a reference data type in Java, and we show how arrays are
passed to methods. We describe how to process two-dimensional arrays and
explain that a two-dimensional array is really an array of arrays in Java. Lists
and maps are introduced as a more general and flexible way to maintain a col-
lection of data. The use of ArrayList and HashMap classes from the java.util
package is shown in the sample programs. Also, we show how the WordList
helper class used in Chapter 9 sample development program is implemented
with another map class called TreeMap.
• Chapter 11 presents searching and sorting algorithms. Both N2 and Nlog2N
sorting algorithms are covered. The mathematical analysis of searching and
sorting algorithms can be omitted depending on the students’ background.
• Chapter 12 explains the file I/O. Standard classes such as File and JFile-
Chooser are explained. We cover all types of file I/O, from a low-level byte
I/O to a high-level object I/O. We show how the file I/O techniques are used
to implement the helper classes—Dorm and FileManager—in Chapter 8 and 9
sample development programs. The use of the Scanner class for inputting data
from a textfile is also illustrated in this chapter.
Preface xv

• Chapter 13 discusses inheritance and polymorphism and how to use them ef-
fectively in program design. The effect of inheritance for member accessibil-
ity and constructors is explained. We also explain the purpose of abstract
classes and abstract methods.
• Chapter 14 covers GUI and event-driven programming. Only the Swing-
based GUI components are covered in this chapter. We show how to use the
JOptionPane class for a very simple GUI-based input and output. GUI com-
ponents introduced in this chapter include JButton, JLabel, ImageIcon,
JTextField, JTextArea, and menu-related classes. We describe the effective use
of nested panels and layout managers. Handling of mouse events is described
and illustrated in the sample programs. Those who do not teach GUI can skip
this chapter altogether. Those who teach GUI can introduce the beginning part
of the chapter as early as after Chapter 2.
• Chapter 15 covers recursion. Because we want to show the examples where
the use of recursion really shines, we did not include any recursive algorithm
(other than those used for explanation purposes) that really should be written
nonrecursively.
xvi Preface

Hallmark Features of the Text

Problem Solving

Sample Development Programs


Sample Development
2.5 Sample Development
Most chapters include a sample development
Printing the Initials
Now that we have acquired a basic understanding of Java application programs, let’s
section that describes the process of
write a new application. We will go through the design, coding, and testing phases of the
software life cycle to illustrate the development process. Since the program we develop
incremental development.
here is very simple, we can write it without really going through the phases. However, it is
extremely important for you to get into a habit of developing a program by following the
software life cycle stages. Small programs can be developed in a haphazard manner, but
not large programs. We will teach you the development process with small programs first,
so you will be ready to use it to create large programs later.
We will develop this program by using an incremental development technique,
which will develop the program in small incremental steps. We start out with a bare-
bones program and gradually build up the program by adding more and more code to
it. At each incremental step, we design, code, and test the program before moving on
to the next step. This methodical development of a program allows us to focus our at-
tention on a single task at each step, and this reduces the chance of introducing errors
into the program.

Problem Statement
We start our development with a problem statement. The problem statement for our
sample programs will be short, ranging from a sentence to a paragraph, but the problem
statement for complex and advanced applications may contain many pages. Here’s the
problem statement for this sample development exercise:
Write an application that asks for the user’s first, middle, and last names and
replies with the user’s initials.

Overall Plan
Our first task is to map out the overall plan for development. We will identify classes nec-
essary for the program and the steps we will follow to implement the program. We begin
with the outline of program logic. For a simple program such as this one, it is kind of
obvious; but to practice the incremental development, let’s put down the outline of pro-
gram flow explicitly. We can express the program flow as having three tasks: Level-by-level Organization for
1. Get the user’s first, middle, and last names.
program
tasks
2. Extract the initials to formulate the monogram.
Programming Exercises
3. Output the monogram. Level 1 Programming Exercises ★
Having identified the three major tasks of the program, we will now identify the
classes we can use to implement the three tasks. First, we need an5.object In the RollDice program, we created three Die objects and rolled them once.
to handle
the input. At this point, we have learned about only the Scanner class, soRewrite it program so you will create only one Die object and roll it three
we will usethe
here. Second, we need an object to display the result. Again, we will use System.out,
times. as
it is the only one we know at this point for displaying a string value. For the string
6. Write a program that computes the total ticket sales of a concert. There are
three types of seatings: A, B, and C. The program accepts the number of
tickets sold and the price of a ticket for each of the three types of seats. The
total sales are computed as follows:
totalSales = numberOfA_Seats * pricePerA_Seat +

numberOfB_Seats * pricePerB_Seat +
numberOfC_Seats * pricePerC_Seat;

Write this program, using only one class, the main class of the program.
Development Exercises
7. Define a new class named Temperature. The class has two accessors—to-
For the following exercises, use the incremental development methodology to
Fahrenheit and toCelsius—that return the temperature in the specified unit
implement the program. For each exercise, identify the program tasks, create
a design document with class descriptions, and draw the program diagram. and two mutators—setFahrenheit and setCelsius—that assign the temperature
Map out the development steps at the start. Present any design alternatives and in the specified unit. Maintain the temperature internally in degrees Fahrenheit.
justify your selection. Be sure to perform adequate testing at the end of each Using this class, write a program that inputs temperature in degrees
development step. Fahrenheit and outputs the temperature in equivalent degrees Celsius.
11. In the sample development, we developed the user module of the keyless
entry system. For this exercise, implement the administrative module that
allows the system administrator to add and delete Resident objects and
modify information on existing Resident objects. The module will also allow
the user to open a list from a file and save the list to a file. Is it proper to
implement the administrative module by using one class? Wouldn’t it be
a better design if we used multiple classes with each class doing a single,
well-defined task?
12. Write an application that maintains the membership lists of five social clubs
in a dormitory. The five social clubs are the Computer Science Club, Biology
Club, Billiard Club, No Sleep Club, and Wine Tasting Club. Use the Dorm
Development Exercises
class to manage the membership lists. Members of the social clubs are give students an opportunity
Resident objects of the dorm. Use a separate file to store the membership
list for each club. Allow the user to add, delete, and modify members of to practice incremental
each club.
development.
Preface xvii

Object-Oriented Approach
We take the object-first approach to teaching object-oriented programming with emphasis
on proper object-oriented design. The concept of objects is clearly illustrated from the very
first sample program.

/*
Chapter 2 Sample Program: Displaying a Window
File: Ch2Sample1.java
*/
import javax.swing.*;
class Ch2Sample1 {
public static void main(String[] args) {
JFrame myWindow;
myWindow = new JFrame();
myWindow.setSize(300, 200);
myWindow.setTitle("My First Java Program");
myWindow.setVisible(true);
}
}

Good practices on
object-oriented design
are discussed
User module Dorm Resident
throughout the book
and illustrated through
numerous sample Door
programs.

Administrative Dorm Resident


module

A helper class A class we One or more classes


provided to us implement we implement

Figure 8.8 Program diagrams for the user and administrative modules. Notice the same Dorm and
Resident classes are used in both programs. User and administrative modules will include one or more
classes (at least one is programmer-defined).
xviii Preface

Illustrative Diagrams
Illustrative diagrams are used to explain all key concepts of programming such as the
difference between object declaration and creation, the distinction between the primitive
data type and the reference data type, the call-by-value parameter passing, inheritance, and
many others.

Numerical Data Object

int number1, number2; Professor alan, turing;


number1 = 237; alan = new Professor();
number2 = number1; turing = alan;

number1 alan

number2 turing

int number1, number2; Professor alan, turing;


number1 = 237; alan = new Professor();
number2 = number1; turing = alan;

number1 237 alan

number2 turing

:Professor

int number1, number2; Professor alan, turing;


number1 = 237; alan = new Professor();

number2 = number1; turing = alan;

number1 237 alan

number2 237 turing

:Professor

Figure 3.3 An effect of assigning the content of one variable to another.

Lucid diagrams are used effectively to explain Person[] temp;


entry
data structures and abstract data types. 0 1 2 3
int newLength = (int) (1.5 * entry.length);

temp = new Person[newLength];

:Person :Person :Person :Person


A B C D

temp

0 1 2 3 4 5

for (int i = 0; i < entry.length; i++) {


entry temp[i] = entry[i];
0 1 2 3 }
entry = temp;

:Person :Person :Person :Person


A B C D

temp
Note: The old array will eventually
get returned to the system via
garbage collection.
0 1 2 3 4 5

Figure 10.16 How a new array that is 150 percent of the original array is created. The size of the
original array is 4.
Preface xix

Student Pedagogy
Design Guidelines
provide tips on good
Always define a constructor and initialize data members fully in the
constructor so an object will be created in a valid state. program design.

Things to Remember
boxes provide tips for
List the catch blocks in the order of specialized to more general exception classes.
students to remember key At most one catch block is executed, and all other catch blocks are ignored.
concepts.

Tips, Hints, and Pitfalls


It is not necessary to create an object for every variable we use. Many novice pro-
grammers often make this mistake. For example, we write provide important points
for which to watch out.
Fraction f1, f2;
f1 = new Fraction(24, 36);
f2 = f1.simplify( );

We didn’t write

Fraction f1, f2;


f1 = new Fraction(24, 36);
f2 = new Fraction(1, 1); //not necessary
f2 = f1.simplify( );

because it is not necessary. The simplify method returns a Fraction object, and in
the calling program, all we need is a name we can use to refer to this returned
Fraction object. Don’t forget that the object name (variable) and the actual object
instance are two separate things.

You Might Want to Know


We can turn our simulation program into a real one by replacing the Door class
boxes give students with a class that actually controls the door. Java provides a mechanism called Java
interesting bits of Native Interface (JNI) which can be used to embed a link to a low-level device dri-
information. ver code, so calling the open method actually unlocks the door.

Quick Check
1. What will be displayed on the console window when the following code is exercises at the end of
executed and the user enters abc123 and 14? the sections allow
Scanner scanner = new Scanner(System.in);
students to test their
try { comprehension of
int num1 = scanner.nextInt(); topics.
System.out.println("Input 1 accepted");
int num2 = scanner.nextInt();
System.out.println("Input 2 accepted");
} catch (InputMismatchException e) {
System.out.println("Invalid Entry");
}

www.allitebooks.com
xx Preface

Supplements for Instructors and Students


The book is supported by a rich array of supplements available through the text’s
website located at www.mhhe.com/wu
For Instructors, a complete set of PowerPoints, solutions to the chapter exercises,
and other resources are provided.
For Students, source code for all example programs, answers to Quick Check
exercises, and other resources are provided, as well as the optional galapagos pack-
age, which includes the Turtle class that is necessary in solving various chapter
exercises.

Acknowledgments
I would like to thank my good friends at McGraw-Hill’s editorial and production
departments. Needless to say, without their help, this book would not have seen the
light of the day. I thank especially Raghu Srinivasan and Lorraine Buczek for their
infinite patience.
External reviewers are indispensable in maintaining the accuracy and improv-
ing the quality of presentation. Numerous professors have participated as reviewers
over the course of five editions, and I thank them all again for their comments, sug-
gestions, and encouragement. I especially thank the reviewers of the Comprehen-
sive edition for their valuable input towards the revision of this fifth edition text.

Personal Story
In September, 2001, I changed my name for personal reasons. Prof. C. Thomas
Wu is now Prof. Thomas W. Otani. To maintain continuity and not to confuse
people, we continue to publish the book under my former name. For those who
care to find out a little about my personal history, they can do so by visiting
www.mhhe.com/wu
Introduction to
Computers and
Programming Languages

O b j e c t i v e s

After you have read and studied this chapter, you


should be able to
0
• State briefly a history of computers.
• Name and describe five major components of
the computer.

• Convert binary numbers to decimal numbers


and vice versa.

• State the difference between the low-level and


high-level programming languages.

1
2 Chapter 0 Introduction to Computers and Programming Languages

I n t r o d u c t i o n

B efore we embark on our study of computer programming, we will present some


background information on computers and programming languages in this optional
chapter. We provide a brief history of computers from the early days to present and
describe the components found in today’s computers. We also present a brief history
of programming languages from low-level machine languages to today’s object-
oriented languages.

0.1 A History of Computers


Humans have evolved from a primitive to a highly advanced society by continually
inventing tools. Stone tools, gunpowder, wheels, and other inventions have changed
the lives of humans dramatically. In recent history, the computer is arguably the
most important invention. In today’s highly advanced society, computers affect our
lives 24 hours a day: Class schedules are formulated by computers, student records
are maintained by computers, exams are graded by computers, dorm security sys-
tems are monitored by computers, and numerous other functions that affect us are
controlled by computers.
Although the first true computer was invented in the 1940s, the concept of a
Charles computer is actually more than 160 years old. Charles Babbage is credited with
Babbage inventing a precursor to the modern computer. In 1823 he received a grant from
the British government to build a mechanical device he called the Difference
Difference Engine, intended for computing and printing mathematical tables. The device was
Engine based on rotating wheels and was operated by a single crank. Unfortunately, the
technology of the time was not advanced enough to build the device. He ran into
difficulties and eventually abandoned the project.
But an even more grandiose scheme was already with him. In fact, one of the
reasons he gave up on the Difference Engine may have been to work on his new con-
Analytical cept for a better machine. He called his new device the Analytical Engine. This
Engine device, too, was never built. His second device also was ahead of its time; the tech-
nology did not yet exist to make the device a reality. Although never built, the Ana-
lytical Engine was a remarkable achievement because its design was essentially
based on the same fundamental principles of the modern computer. One principle
that stands out was its programmability. With the Difference Engine, Babbage would
have been able to compute only mathematical tables, but with the Analytical Engine
he would have been able to compute any calculation by inputting instructions on
punch cards. The method of inputting programs to computers on punch cards was
actually adopted for real machines and was still in wide use as late as the 1970s.
The Analytical Engine was never built, but a demonstration program was
Ada Lovelace written by Ada Lovelace, a daughter of the poet Lord Byron. The programming lan-
guage Ada was named in honor of Lady Lovelace, the first computer programmer.
In the late 1930s John Atanasoff of Iowa State University, with his graduate
student Clifford Berry, built the prototype of the first automatic electronic calculator.
0.1 A History of Computers 3

One innovation of their machine was the use of binary numbers. (We discuss binary
numbers in Sec. 0.2.) At around the same time, Howard Aiken of Harvard University
was working on the Automatic Sequence-Controlled Calculator, known more com-
MARK I monly as MARK I, with support from IBM and the U.S. Navy. MARK I was very
similar to the Analytical Engine in design and was described as “Babbage’s dream
come true.”
MARK I was an electromechanical computer based on relays. Mechanical
relays were not fast enough, and MARK I was quickly replaced by machines based
ENIAC I on electronic vacuum tubes. The first completely electronic computer, ENIAC I
(Electronic Numerical Integrator And Calculator), was built at the University of
Pennsylvania under the supervision of John W. Mauchly and J. Presper Eckert.
Their work was influenced by the work of John Atanasoff.
ENIAC I was programmed laboriously by plugging wires into a control
panel that resembled an old telephone switchboard. Programming took an enor-
mous amount of the engineers’ time, and even making a simple change to a pro-
gram was a time-consuming effort. While programming activities were going on,
the expensive computer sat idle. To improve its productivity, John von Neumann
of Princeton University proposed storing programs in the computer’s memory.
stored program This stored program scheme not only improved computation speed but also al-
lowed far more flexible ways of writing programs. For example, because a pro-
gram is stored in the memory, the computer can change the program instructions
to alter the sequence of the execution, thereby making it possible to get different
results from a single program.
generations of We characterized these early computers with vacuum tubes as first-generation
computers computers. Second-generation computers, with transistors replacing the vacuum
tubes, started appearing in the late 1950s. Improvements in memory devices also
increased processing speed further. In the early 1960s, transistors were replaced by
integrated circuits, and third-generation computers emerged. A single integrated
circuit of this period incorporated hundreds of transistors and made the construction
of minicomputers possible. Minicomputers are small enough to be placed on desk-
tops in individual offices and labs. The early computers, on the other hand, were so
huge that they easily occupied the whole basement of a large building.
Advancement of integrated circuits was phenomenal. Large-scale integrated
circuits, commonly known as computer chips or silicon chips, packed the power
equivalent to thousands of transistors and made the notion of a “computer on a sin-
gle chip” a reality. With large-scale integrated circuits, microcomputers emerged in
the mid-1970s. The machines we call personal computers today are descendants of
the microcomputers of the 1970s. The computer chips used in today’s personal
computers pack the power equivalent to several millions of transistors. Personal
computers are fourth-generation computers.
Early microcomputers were isolated, stand-alone machines. The word per-
sonal describes a machine as a personal device intended to be used by an individual.
However, it did not take long to realize there was a need to share computer resources.
For example, early microcomputers required a dedicated printer. Wouldn’t it make
more sense to have many computers share a single printer? Wouldn’t it also make
sense to share data among computers, instead of duplicating the same data on
4 Chapter 0 Introduction to Computers and Programming Languages

individual machines? Wouldn’t it be nice to send electronic messages between the


computers? The notion of networked computers arose to meet these needs.
network Computers of all kinds are connected into a network. A network that connects
computers in a single building or in several nearby buildings is called a local-area
LAN network or LAN. A network that connects geographically dispersed computers is
called a wide-area network or WAN. These individual networks can be connected
WAN further to form interconnected networks called internets. The most famous internet
is simply called the Internet. The Internet makes the sharing of worldwide informa-
internet
tion possible and easy. The hottest tool for viewing information on the Internet is a
Web browser. A Web browser allows you to experience multimedia information
consisting of text, audio, video, and other types of information. We will describe
how Java is related to the Internet and Web browsers in Section 0.4.

If you want to learn more about the history of computing, there is a wealth of information
available on the Web.You can start your exploration from
www.yahoo.com/Computers_and_Internet/History
For more information on the pioneers of computers, visit
en.wikipedia.org/wiki/category:Computer_pioneers

1. Who was the first computer programmer?


2. Who designed the Difference Engine and Analytical Engine?
3. How many generations of computers are there?

0.2 Computer Architecture


A typical computer today has five basic components: RAM, CPU, storage devices,
I/O (input/output) devices, and communication devices. Figure 0.1 illustrates these
five components. Before we describe the components of a computer, we will ex-
plain the binary number system used in a computer.

Binary Numbers
To understand the binary number system, let’s first review the decimal number sys-
tem in which we use 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. To represent a number in
the decimal system, we use a sequence of one or more of these digits. The value that
each digit in the sequence represents depends on its position. For example, consider
the numbers 234 and 324. The digit 2 in the first number represents 200, whereas
the digit 2 in the second number represents 20. A position in a sequence has a
value that is an integral power of 10. The following diagram illustrates how the
0.2 Computer Architecture 5

Output
Devices
RAM

Communication
CPU
Devices
Storage
Devices
Input
Devices

Monitor
Printer (output device)
(output device)
Main Unit (housing
CPU, RAM, storage
devices, and
communication
devices)

Keyboard
(input device) Mouse
(input device)

Figure 0.1 A simplified view of an architecture for a typical computer.

values of positions are determined:


Decimal
Point

••• • •••
104 103 102 101 100 10⫺1 10⫺2 10⫺3
Position Values
The value of a decimal number (represented as a sequence of digits) is the sum
of the digits, multiplied by their position values, as illustrated:

2 4 8 • 7

102 101 100 10⫺1


⫽ 2 ⫻ 102 ⫹ 4 ⫻ 101 ⫹ 8 ⫻ 100 ⫹ 7 ⫻ 10⫺1

⫽ 2 ⫻ 100 ⫹ 4 ⫻ 10 ⫹ 8 ⫻ 1 ⫹ 7 ⫻ 1兾10

⫽ 200 ⫹ 40 ⫹8 ⫹ 7兾10 ⫽ 248.7


6 Chapter 0 Introduction to Computers and Programming Languages

base-2
In the decimal number system, we have 10 symbols, and the position values
numbers are integral powers of 10. We say that 10 is the base or radix of the decimal number
system. The binary number system works the same as the decimal number system
binary number but uses 2 as its base. The binary number system has two digits (0 and 1) called bits,
and position values are integral powers of 2. The following diagram illustrates how
bits the values of positions are determined in the binary system:

Binary
Point

••• • •••
24 23 22 21 20 2⫺1 2⫺2 2⫺3
Position Values

The value of a binary number (represented as a sequence of bits) is the sum of


the bits, multiplied by their position values, as illustrated:

1 0 1 • 1

22 21 20 2⫺1
binary-to-
decimal ⫽ 1 ⫻ 22 ⫹ 0 ⫻ 21 ⫹ 1 ⫻ 20 ⫹ 1 ⫻ 2⫺1
conversion
⫽ 1 ⫻ 4 ⫹ 0 ⫻ 2 ⫹ 1 ⫻ 1 ⫹ 1 ⫻ 1兾2

⫽4 ⫹0 ⫹1 ⫹ 1兾2 ⫽ 5.5

So the binary number 101.1 is numerically equivalent to the decimal num-


ber 5.5. This illustration shows how to convert a given binary number to the
decimal equivalent. How about converting a given decimal number to its binary
equivalent?
The following steps show how to convert a decimal number (only the whole
numbers) to the equivalent binary number. The basic idea goes something like
this:
1. Divide the number by 2.
decimal-to-
binary 2. The remainder is the bit value of the 20 position.
conversion 3. Divide the quotient by 2.
4. The remainder is the bit value of the 21 position.
5. Divide the quotient by 2.
6. The remainder is the bit value of the 22 position.
7. Repeat the procedure until you cannot divide any further, that is, until the
quotient becomes 0.
0.2 Computer Architecture 7

The following diagram illustrates the conversion of decimal number 25.

Division Division Division Division Division


#5 #4 #3 #2 #1
0 1 3 6 12
苶1苶1苶
2冄1 苶3苶1苶
2冄1 苶6苶1苶
2冄1 苶1苶2苶1苶
2冄1 2冄1苶2苶5苶1苶
0 2 6 12 24
1 1 0 0 1
24 23 22 21 20
16 ⫹ 8 ⫹ 0 ⫹ 0 ⫹ 1 ⫽ 25

The binary system is more suitable for computers than the decimal system be-
cause it is far easier to design an electrical device that can distinguish two states
(bits 0 and 1) than 10 states (digits 0 through 9). For example, we can represent 1 by
turning the switch on and 0 by turning the switch off. In a real computer, 0 is repre-
sented by electrical voltage below a certain level and 1 by electrical voltage at or
above this level.

When you pay closer attention to the on/off switch on computers and other
electronic devices, you should notice an icon like this

This is a stylized representation of binary digits 0 and 1.

RAM
RAM Random access memory or RAM is a repository for both program instructions and
data manipulated by the program during execution. RAM is divided into cells,
byte with each cell having a unique address. Typically, each cell consists of 4 bytes (B),
and a single byte (1 B) in turn consists of 8 bits. Each bit, which can be either on
or off, represents a single binary digit. RAM is measured by the number of bytes
it contains. For example, 128 kilobytes (KB) of RAM contains 128 ⫻ 1024 ⫽
131,072 B because 1 KB is equal to 210 ⫽ 1024 B. Notice that 1 K is not equal to
103, although 103 ⫽ 1000 is a close approximation to 210 ⫽ 1024. The first IBM
PC introduced in 1981 came with 16 KB of RAM, and the first Macintosh com-
puter introduced in 1984 came with 128 KB of RAM. In contrast, a typical PC
today has anywhere from 1GB (gigabytes) to 4GB of RAM. Given that 1GB is equal
to 1024 MB (megabytes) and 1 MB is equal to 1024 KB, we know that 2GB means
2 ⫻ 1024 MB ⫽ 2048 MB ⫽ 2048 ⫻ 1024 KB ⫽ 2,097,152 KB ⫽ 2,097,152 ⫻
1024 B ⫽ 2,147,483,648 B.
8 Chapter 0 Introduction to Computers and Programming Languages

CPU
CPU The central processing unit or CPU is the brain of a computer. The CPU is the com-
ponent that executes program instructions by fetching an instruction (stored in
RAM), executing it, fetching the next instruction, executing it, and so on until it en-
register counters an instruction to stop. The CPU contains a small number of registers, which
are high-speed devices for storing data or instructions temporarily. The CPU also
contains the arithmetic-logic unit (ALU), which performs arithmetic operations such
as addition and subtraction and logical operations such as comparing two numbers.
clock speed CPUs are characterized by their clock speeds. For example, in the Intel
Pentium 200, the CPU has a clock speed of 200 megahertz (MHz). The hertz is a
unit of frequency equal to 1 cycle per second. A cycle is a period of time between
two on states or off states. So 200 MHz equals 200,000,000 cycles per second. The
fastest CPU for commercially available personal computers was around 200 MHz
in 1997 when the first edition of this textbook was published. But by the beginning
of 1998, many vendors started selling 300-MHz machines. And in a mere 6 months,
by the middle of 1998, the top-of-the-line personal computers were 400-MHz ma-
chines. As of this writing in late 2008, we see computers with 2.93-GHz (2930-
MHz) CPU being advertized and sold. The increase of the CPU speed in the last two
decades is truly astonishing. The clock speed of the Intel 8080, the CPU introduced
in 1974 that started the PC revolution, was a mere 2 MHz. In contrast, the clock
speed of the Intel Pentium 4 introduced in 2001 was 2 GHz (2000 MHz). Table 0.1
lists some of the Intel processors.

I/O Devices
I/O devices Input/output or I/O devices allow communication between the user and the CPU.
Input devices such as keyboards and mice are used to enter data, programs, and
commands in the CPU. Output devices such as monitors and printers are used to
display or print information. Other I/O devices include scanners, bar code readers,
magnetic strip readers, digital video cameras, and musical instrument digital inter-
face (MIDI) devices.

Storage Devices
Storage devices such as disk and tape drives are used to store data and programs. Sec-
nonvolatile and
volatile
ondary storage devices are called nonvolatile memory, while RAM is called volatile
memory memory. Volatile means the data stored in a device will be lost when the power to the
device is turned off. Being nonvolatile and much cheaper than RAM, secondary stor-
age is an ideal medium for permanent storage of large volumes of data. A secondary
storage device cannot replace RAM, though, because secondary storage is far slower
in data access (getting data out and writing data in) compared to RAM.
The most common storage device today for personal computers is a disk
drive. There are two kinds of disks: hard and floppy (also known as diskettes). Hard
disks provide much faster performance and larger capacity, but are normally not re-
movable; that is, a single hard disk is permanently attached to a disk drive. Floppy
disks, on the other hand, are removable, but their performance is far slower and
their capacity far smaller than those of hard disks. As the standard floppy disks can
0.2 Computer Architecture 9

A table of Intel processors. For some CPUs, several types with different
Table 0.1 clock speeds are possible. In such case, only the fastest clock speed is
shown. For more information on Intel CPUs, visit http://www.intel.com.

Table CPU
Date
Introduced
Clock Speed
(MHz)
4004 11/15/71 0.108
8008 4/1/72 0.200
1970s 8080 4/1/74 2
8088 6/1/79 8

80286 2/1/82 12
1980s 80386SX 6/16/88 16
80486DX 4/10/89 25

Pentium 3/22/93 66
Pentium Pro 11/1/95 200
1990s Pentium II 5/7/97 300
Pentium II Xeon 6/29/98 400
Pentium III 10/25/99 733

Xeon 9/25/01 2000


Pentium 4 4/27/01 2000
2000s Itanium 2 7/8/02 1000
Pentium 4 Extreme 2/2/04 3400
Edition
Core 2 Extreme 7/27/06 3200

store only up to approximately 1.44 MB, they are becoming less useful in today’s
world of multimegabyte image and sound files. They are fast becoming obsolete,
and hardly anybody uses them anymore. Removable storage media with much
higher capacity such as zip disks (capable of holding 100 to 250 MB of data) re-
placed floppy disks in late 1990s. Computer technology moves so quickly that zip
disks themselves are already becoming obsolete. The most common form of
portable storage medium today (2008) is a compact USB flash drive, also known as
a thumb drive, whose capacity ranges from 125 MB to 16 GB.
Hard disks can store a huge amount of data, typically ranging from 160 GB
(gigabyte; 1 GB ⫽ 1024 MB) to 500 GB for a standard desktop PC in 2008. Portable
and removable hard disk drives, with performance and capacity that rival those of
nonremovable hard disks, are also available, but their use is not widespread.
Compact disks (CDs) are commonly used for storing massive amounts of data,
approximately 700 MB. Many software packages we buy today—computer games,

www.allitebooks.com
10 Chapter 0 Introduction to Computers and Programming Languages

word processors, and others—come with a single CD. Before the CD became a popu-
lar storage device for computers, some software packages came with more than
20 floppy diskettes. Because of the massive storage capacity of the CD, most computer
vendors eliminated printed manuals altogether by putting the manuals on the CD.

Many companies, in addition to CD or in lieu of, provide “boxless” online distribu-


tion of software. With this scheme, we buy and download the software directly to
our computers from the company websites. From some book publishers, especially
in the professional market, we can even buy an online version of their books. The
online version is most commonly downloaded as a single file stored in the Portable
Document Format (PDF) format.

Communication Devices
communication A communication device connects the personal computer to an internet. The tradi-
device tional communication device for computers at home and in small offices was the
modem. A modem, which stands for modulator-demodulator, is a device that con-
verts analog signals to digital and digital signals to analog. By using a modem, a
computer can send to and receive data from another computer over the phone line.
The most critical characteristic of a modem is its transmission speed, which is mea-
sured in bits per second (bps). A typical speed for a modem is 56,000 bps, commonly
called a 56K modem. Under an ideal condition (no line noise or congestion), a 56K
modem can transfer a 1 MB file in about 21⁄2 minutes. Frequently, though, the actual
transfer rate is much lower than the possible maximum. So-called DSL and cable
modems are not truly modems because they transfer data strictly in digital mode,
which allows for much faster connection speeds of 144K or above. High-speed satel-
lite connection to the Internet is also available today.
A communication device for connecting a computer to a LAN is a network
interface card (NIC). A NIC can transfer data at a much faster rate than the fastest
modem. For instance, a type of NIC called 10BaseT can transfer data at the rate of
10 Mbps over the network. Traditional networks are connected, or wired, by the cables.
Increasingly, networks are connected wirelessly, where data are carried over radio
waves. Wireless networking is called WiFi or 802.11 networking. Today you will find
wireless networking almost universally available at airports, hotels, and universities.

1. Name five major components of a computer.


2. What is the difference between volatile and nonvolatile memory?
3. What does the acronym CPU stand for?
4. How many bytes does the 64 KB RAM have?
5. Which device connects a computer to the Internet using a phone line?
0.3 Programming Languages 11

0.3 Programming Languages


Programming languages are broadly classified into three levels: machine languages,
machine assembly languages, and high-level languages. Machine language is the only pro-
language gramming language the CPU understands. Each type of CPU has its own machine
language. For example, the Intel Pentium and Motorola PowerPC understand differ-
ent machine languages. Machine-language instructions are binary-coded and very
low level—one machine instruction may transfer the contents of one memory loca-
tion into a CPU register or add numbers in two registers. Thus, we must provide many
machine-language instructions to accomplish a simple task such as finding the aver-
age of 20 numbers. A program written in machine language might look like this:
10110011 00011001
01111010 11010001 10010100
machine code 10011111 00011001
01011100 11010001 10010000
10111011 11010001 10010110

assembly One level above machine language is assembly language, which allows
language “higher-level” symbolic programming. Instead of writing programs as a sequence
of bits, assembly language allows programmers to write programs by using sym-
bolic operation codes. For example, instead of 10110011, we use MV to move the
contents of a memory cell into a register. We also can use symbolic, or mnemonic,
names for registers and memory cells. A program written in assembly language
might look like this:
MV 0, SUM
assembly code MV NUM, AC
ADD SUM, AC
STO SUM, TOT

Since programs written in assembly language are not recognized by the CPU,
assembler we use an assembler to translate programs written in assembly language into
machine-language equivalents. Compared to writing programs in machine lan-
guage, writing programs in assembly language is much faster, but not fast enough
for writing complex programs.
high-level High-level languages were developed to enable programmers to write pro-
languages grams faster than when using assembly languages. For example, FORTRAN
(FORmula TRANslator), a programming language intended for mathematical com-
putation, allows programmers to express numerical equations directly as

high-level code X = (Y + Z) / 2

COBOL (COmmon Business-Oriented Language) is a programming language in-


tended for business data processing applications. FORTRAN and COBOL were de-
veloped in the late 1950s and early 1960s and are still in use. BASIC (Beginners
All-purpose Symbolic Instructional Code) was developed specifically as an easy
language for students to learn and use. BASIC was the first high-level language
12 Chapter 0 Introduction to Computers and Programming Languages

available for microcomputers. Another famous high-level language is Pascal, which


was designed as an academic language. Since programs written in a high-level lan-
compiler guage are not recognized by the CPU, we must use a compiler to translate them to
assembly language equivalents.
The programming language C was developed in the early 1970s at AT&T Bell
Labs. The C++ programming language was developed as a successor of C in the
early 1980s to add support for object-oriented programming. Object-oriented pro-
gramming is a style of programming gaining wider acceptance today. Although the
concept of object-oriented programming is old (the first object-oriented program-
ming language, Simula, was developed in the late 1960s), its significance wasn’t
realized until the early 1980s. Smalltalk, developed at Xerox PARC, is another
well-known object-oriented programming language. The programming language
we use in this book is Java, the newest object-oriented programming language,
developed at Sun Microsystems.

0.4 Java
Java Java is a new object-oriented language that is receiving wide attention from both indus-
try and academia. Java was developed by James Gosling and his team at Sun Microsys-
tems in California. The language was based on C and C++ and was originally intended
for writing programs that control consumer appliances such as toasters, microwave
ovens, and others. The language was first called Oak, named after the oak tree outside
of Gosling’s office, but the name was already taken, so the team renamed it Java.
Java is often described as a Web programming language because of its use in
applet writing programs called applets that run within a Web browser. That is, you need a
Web browser to execute Java applets. Applets allow more dynamic and flexible dis-
semination of information on the Internet, and this feature alone makes Java an at-
tractive language to learn. However, we are not limited to writing applets in Java. We
application can write Java applications also. A Java application is a complete stand-alone
program that does not require a Web browser. A Java application is analogous to a
program we write in other programming languages. In this book, we describe Java
applications only because our objective is to teach the fundamentals of object-oriented
programming that are applicable to all object-oriented programming languages.
We chose Java for this textbook mainly for its clean design. The language de-
signers of Java took a minimalist approach; they included only features that are in-
dispensable and eliminated features that they considered excessive or redundant.
This minimalist approach makes Java a much easier language to learn than other
object-oriented programming languages. Java is an ideal vehicle for teaching the
fundamentals of object-oriented programming. All the sample programs in this
book are tested against the newest version, Java 6.0.

S u m m a r y

• Charles Babbage invented the Difference Engine and Analytical Engine,


precursors to the modern computer.
• Ada Lovelace is considered the first computer programmer.
Exercises 13

• The first two modern computers were MARK I and ENIAC I.


• John von Neumann invented the stored-program approach of executing
programs.
• Computers are connected into a network. Interconnected networks are
called internets.
• Binary numbers are used in computers.
• A typical computer consists of five components: RAM, CPU, storage
devices, I/O devices, and communication devices.
• There are three levels of programming languages: machine, assembly, and
high-level.
• Java is one of the newest high-level programming languages in use today.
This textbook teaches how to program using Java.

K e y C o n c e p t s
network binary numbers
LAN binary-to-decimal conversion
WAN machine language
internets and Internet assembly language
CPU assembler
RAM high-level language
I/O devices compiler
communication devices Java

C h a p t e r 0 E x e r c i s e s

Review Exercises
1. Visit your school’s computer lab or a computer store, and identify the
different components of the computers you see. Do you notice any unique
input or output devices?
2. Visit your school’s computer lab and find out the CPU speed, RAM size, and
hard disk capacity of its computers.
3. Convert these binary numbers to decimal numbers.
a. 1010
b. 110011
c. 110.01
d. 111111
14 Chapter 0 Introduction to Computers and Programming Languages

4. Convert these decimal numbers to binary numbers.


a. 35
b. 125
c. 567
d. 98
5. What is the maximum decimal number you can represent in 4 bits? 16 bits?
N bits?
6. If a computer has 128 MB of RAM, how many bytes are there?
7. How do high-level programming languages differ from low-level
programming languages?
8. Consider a hypothetical programming language called Kona. Using Kona,
you can write a program to compute and print out the sum of 20 integers
entered by the user:
let sum = 0;

repeat 20 times [
let X = next input;
add X to sum;
]

printout sum;

Is Kona a high-level language? Why or why not?


Other documents randomly have
different content
must not keep a thing back from her. How did you happen to meet—
Mr. Galt this afternoon?”
“That's what you want to know?”
“Yes, dear—that's all. Surely, there can be no reason why your
own dear mother should not know a little thing like that. Surely he—
Mr. Galt—couldn't have told you not to tell me?”
The child was still for a moment. He folded his little arms over his
knee, clinched his hands, and sat avoiding her insistent eyes.
“Wait!” he said, finally. “I want to go to Granny.”
“You want to go to Granny, and leave your mother?” she asked,
deeply perplexed. .
“Just a minute,” he said, as he crawled over her and got down on
the floor. “I'll be back. I'll be right back, mother, dear.”
“It is something you will tell her, but can't tell me!” Dora cried out,
in half-assumed reproach. “Why, Lionel?”
“I'll be back,” he said, evasively. “There is no hurry.” And she
heard the patter of his bare feet along the corridor to his
grandmother's room.
Mrs. Barry always retired early, and she was now in her bed, but
very wide awake. Something in the incident had set her to thinking
on new lines. “Can it be? Can it be?” she kept asking herself, in great
excitement. “Why didn't I think of it?”
“Granny!” she heard Lionel call out from the dark, doorway.
“Yes, dear, what is it?” she asked.
“I want to come to your bed a minute—just a minute.”
“All right, come on, darling; don't stumble over anything.”
She heard him groping through the dark, and then felt his little
hands on her wrinkled face.
“Granny,” he said, a tremor in his voice, “you told me if anybody
ever said anything mean about my mother, that I must not let her
know about it—never at all.”
“Yes, darling, that would be a nice, brave little man, for you
wouldn't want to make her sad, would you?”
“Well, I had a terrible fight with Grover Weston over in Mr. Galt's
yard. Grover said a nasty, mean thing about her. You told me not to
let her know anything like that, and so did Mr. Galt, but mamma is
begging me so hard.”
“Oh!” The old woman lifted the boy over her into the bed, and put
her arms about him tenderly. “You can tell Granny about it, and then
if she thinks best perhaps you may tell your mother.”
He complied, and the wondering old woman, as she lay with the
child in her arms, heard the whole beautiful story in every detail,
even to Galt's display of affection, and as she listened cold tears
welled up in her old eyes and trickled down the furrows of her
cheeks to her pillow. When it was over, she led the child back to his
mother.
“Don't ask him any more about it. Wait,” she said, in an
undertone, and with a significant gesture in the direction of her
room. “Don't spoil a beautiful thing. God bless him! he is right—
young as he is, he is right! The very angels of heaven are closing his
sweet lips to-night. Don't bother him.”
When Lionel was asleep Dora anxiously crept into her mother's
room. A lamp was now burning on a table, but Dora blew it out, and
went and sat on the edge of her mother's bed.
“I know your secret now,” Mrs. Barry faltered, with a suppressed
sob in her pillow. “All these years I have wondered over your great
trouble, and why you were not more open with me about it, but
Lionel has made it clear. I understand now.”
“Did Kenneth Galt tell my child that—” Dora cried out, in a rasping
undertone. “Did he dare to—”
“No, no, not that!” the old woman corrected. “He simply betrayed
himself in his conduct toward the boy. Listen! Lionel need never
suspect that you know what he did, but you must be told the truth.
It is too beautiful for you to miss.”
She told the whole story as it had come from the child's lips,
together with other things she had culled as to happenings between
him and his father on former occasions.
“Let them both alone,” she added, fervently, as she concluded.
“The little fellow, nameless and cast out as he is, has of himself won
the love God gave him the right to. It is his. Let him keep it, and I
pray Heaven that it may drag that haughty spirit down into the mire
of repentance. I've thought it all over. I remember the date well. I
know now why he deserted you; he couldn't face public exposure
just at that particular time. His temptation was great, and he fell. I
believe he loved you then, and that he does yet.”
“Does yet!” Dora sneered, and she put a protesting hand out to
her mother's as it lay on the coverlet. “Don't say that. He couldn't
now—after all this time.”
“But he does, he does—a thousand times more than he did, too,”
the old woman insisted. “He hasn't married; he is leading a lonely,
morbid life. He-is longing for you—though he may still dread public
opinion—and is adoring the child. He may resist longer, but in the
end he will succumb and crawl to your feet and beg for forgiveness.
Watch my prophecy. He'll do it!—he'll do it!”
“You don't know, mother,” Dora sighed, and she stood up and
moved away in the darkness. “You don't know.”
Dora went back to her room and stood looking down at her
sleeping child. Suddenly her eyes filled and her breast heaved high.
“Mother's little champion!” she cried, and she knelt down by the
bed, covered her face, and wept.
CHAPTER XIII

T
HE July sun beat fiercely on the tin slate roofs of the houses
forming square of Stafford. It was noon, business was at a
standstill. The clerks and typewriters in Walton's bank yawning
and fanning themselves heat. The only occupied individual in the
building was the banker himself, who was crouched over his desk in
his little office making calculations on a pad of paper with a pencil.
Toby Lassiter was at the window of the receiving-teller when an old
man came in at the folding-screen door and asked if he might see
Mr. Walton personally. It was Stephen Whipple, and he carried a
travelling-bag in his hand; he was covered with dust, and marked in
the creases of his face by drifts of fine cinders.
“I'll see, sir, if you'll wait a minute,” Toby answered, with his best
window-manners; then he went to his employer, and returned to
pilot the caller back to the office.
“Stranded on a trip and wants a check cashed without
identification,” was Toby's mental comment as he led the way. “Well,
he's come to the wrong man, as he will mighty soon find out.”
Whipple gave a searching glance at the man who was rising from
the desk with impatiently lifted brows. He put his bag down at his
feet, but failed to extend his hand, as Walton evidently expected him
to do.
“Take a seat, sir, take a seat,” and the banker motioned to a chair
near the desk.
“Thanks.” The Westerner kicked his bag along toward the chair,
and sat down rather clumsily. He took out an enormous
handkerchief, also considerably begrimed, and mopped his perspiring
face.
“You've got a hot town, sir,” Whipple said, introductively.
“Some say so, and some say not,” Walton replied, succinctly.
“Well, sir,” he continued, “is there anything I can do for you? The
reason I make so bold as to ask is because my clerk said you wanted
to see me personally.”
“Yes, it is of a sort of personal nature; at least, I reckon, you
might call it that,” and the merchant reached down and caught the
handle of his bag for no obvious reason than that he wanted to
move it to a point equidistant between his two splaying feet. Then
he looked up, and there was a decided flush of embarrassment in his
face, which extended down to the soiled collar on his pudgy neck.
The banker, ever quick at the reading of countenances, came to the
conclusion that some sort of unbusiness-like request in regard to
needed funds was forthcoming, and he was already framing his
refusal.
“Well, sir—well, sir?” he said.
“The truth of the matter is that it is of such a personal nature that
it is purty hard to know how to get started at it,” Whipple finally got
out. “Of course, I am a stranger to you, and I've come, too, without
any letters of introduction or papers of identification, and—is there
any danger of anybody listening?”
“None whatever—none on earth!” Walton sniffed, impatiently. “You
can talk at the top of your voice if you want to; the walls are thick;
besides, I don't have secrets, and I don't know as I am in the
market for any.”
“No, of course not, Mr. Walton.” The flush in the visitor's face was
dying out and giving place to an expression of rather anxious rigidity.
“Well, I am glad we won't be overheard, at any rate, for I want to
talk to you in behalf of your son.”
“Oh, that's it, huh? I see! I see!” And Walton swept the form
before him with eyes in which the lights of anger were slowly but
positively kindling. “It is about him, is it? Well, wait till I send this
letter to the mail. I'll be back, sir. I'll be back.”
“All right, Mr. Walton. There's no hurry.”
With the letter in his hand the banker rose as if from the sheer
heat of the growing anger within him and went out. Standing in the
door of the main counting-room he caught Lassiter's eye and
signalled him to approach. Giving him the letter, Walton said: “Mail
that, and then come back and keep a peeled eye on that fat chap at
my desk. Do you remember what I said when that three thousand
dollars came from nowhere in particular by express awhile back,
along with the mealy-mouthed yarn from Fred about changing his
ways, and all that gush?”
“Yes, sir, I think so,” answered the startled Toby. “You said you
thought—”
“That it was a deep-laid plan amongst him and some other
sharpers to hoodwink me; and I told you, Toby, that I'd be willing to
bet money that it wouldn't be many days before somebody would
hike along this way to talk it over—some go-between, you
understand. Well, he's in there now, setting humped over his satchel
like a spider watching a fly. He thinks I'm the fly. I want to know
what he's got to say. I want to see his hand, you know, and I come
out here to take a whiff of air and steady myself so I wouldn't blurt
out what I thought too quick and drive him away. Keep your eye on
him after he leaves me, Toby, and see which way he goes. He looks
to me like some shyster lawyer who has taken up the matter and
thinks he is smart enough to fool me. Somebody has invested three
thousand in this scheme, and the deal is to be clinched this morning.
Huh! I'll sorter tote 'im along, Toby, and see if I can get onto his
game,” and, with a sly and yet nervous wink, Walton turned away.
“Yes, sir; all right now, sir,” he said, breezily, as he returned to his
desk and lowered himself into his chair. “We've got this room all to
ourselves, and are as snug as a bug in a rug, as the fellow said.
Now, fire ahead.”
“Of course, it must be a sort o' disagreeable subject for you to talk
about,” Whipple began, awkwardly, “and I'll admit to you, Mr.
Walton, that I thought over it a powerful long time before I finally
made up my mind to come.”
“Oh yes, of course,” Walton said, pulling his whiskers with his long
hand—“of course, you naturally would.”
“Especially as Fred had no idea of what I had in view,” the
Westerner said. “You see, I had to act wholly on my own
responsibility.”
“Yes, I see—I see, sir.” It was only by an effort that Walton kept a
sarcastic ring of irritation out of his voice, and he stroked into the
roots of his beard a smile of contempt at such puerile attempts to
deceive.
“And that's what makes the whole thing so hard on me,” the
merchant went on. “You see, I took it on myself to act for Fred in, I
might say, actual opposition to his wishes and judgment.”
Whipple then proceeded to give a full and accurate account of his
first introduction to Fred and all that had happened to him since,
withholding only his own name and the name of the town he was
from. And while he talked, pausing to wipe his wet brow at times, or
to clear his shaky voice, the banker watched him as a cat might a
mouse. He held a pencil in his long, steady fingers, and kept the
point of it on a pad of paper, raising his shrewd glance and lowering
it as suited his fancy. Had he been an artist, old Simon might have
sketched what to his understanding was the most subtly designing
face he had ever seen. Here was a man, he told himself, who
resorted even to the emotional methods of a ranting revivalist to
gain his nefarious aims. It was a wonderful conception, but it wofully
missed its mark, for it was being applied to a man who had no
emotions. It was being applied to a man, too, who was as eagerly
on the lookout for new tricks as a biologist for a new species of
insect. What a weakling the fellow was, for a man of that age, and
what fun it would be to suddenly undeceive him—let him know the
manner of man he was attempting, in such a shallow way, to bunco!
“Yes, I decided not to wait longer,” Whipple concluded, with a
sigh. “I didn't intend to act till the remaining three thousand was
paid; but, as I say, I—”
“It is only two, according to my calculations.” Walton thought he
had tripped him up, and smiled knowingly.
“Fred said he felt that another thousand, at least, was due as
interest at the rate you usually get.”
“Oh, I see; he's certainly liberal.” Walton smiled at his joke, and
bent his head over his pad to hide it.
“As I say,” the merchant resumed, “I intended to wait till the debt
was entirely paid, but things took a sudden turn that I didn't expect.
I offered to advance the money to Fred, but he wouldn't take it.”
“Oh, he wouldn't take it!” Walton said, with a hurried regret that
Toby was not present to enjoy the feast of stupidity being spread
before him. “I see; he didn't want it. That's a little bit like him.”
Simon's amusement showed itself now in his voice rather than in the
visage which he managed to keep unruffled. “But you say things had
sorter taken a twist around?”
“Yes; he was brave enough, and bearing up mighty well till me
and him took a trip, as much for pleasure as anything else, to New
York, and we passed through this very town, and—”
“So you passed through here?” Walton interrupted, and then to
himself he added: “I knew it. I knew Fred was hanging about Atlanta
and sending money to that woman. Huh, his fat agent is certainly
giving the snap away!”
“Yes, we passed through here one night, and, as our train was
delayed below town by a wreck ahead of us, Fred got out and
walked around. He was gone till after midnight, and when he came
back to the Pullman where I was I noticed that he was powerfully
upset, and begun to suspect that maybe this was his old home. He
started to tell me about it then, but I stopped him, and it was not till
we had been to New York and got back home that he finally told me
your name and where you lived. As I said, he has not been the same
since then, and, to be honest with you, Mr. Walton, I don't know of
anything in the world that will restore his peace of mind, except—”
“Except having me send for him,” Simon suddenly let himself go,
“and kill the fatted bull-yearling, and put a dinky-dinky cap on his
brow, and give him a key to the vault, and start in, hit or miss,
exactly where me and him left off!”
“You are hard on him, Mr. Walton,” Whipple gasped, fairly
staggered by the unexpected retort—“much harder, I must say, than
I had hoped to find you. He declared that you wasn't the sort that
would forgive easily, but, having been a father once myself, I didn't
believe you would, after hearing about your boy's life since he left
you, refuse to—”
“See here!” Walton interrupted, laying down his pencil and staring
at the visitor from eyes which fairly snapped with blended triumph
and rage, “you've held the floor long enough; now step aside and let
me take it. I don't know as I ever had the luck to run across just
such a specimen as you are. You've evidently had very little to do
with business men. You seem to have as little common sense as a
mountain school-teacher or a young preacher on his first circuit.
Here you come with a long, roundabout, hatched-up tale that is so
thin and full of holes that a body could throw a straw hat through it.
I'd have you understand that this here house is a bank. My own
granddaddy would have to be identified, if he was alive, before he
could cash a check at that front window, and yet here you come—
pitapat, pitapat, as unconcerned as a house-cat looking for a place
to lie down—back into my private quarters, and propose something
that may, or may not, involve every dollar I own on the top-side of
the earth. You do all that without even taking the trouble to hint at
who you are or where you hail from, and—”
“I'm not afraid to give you my name!” the merchant gasped, taken
wholly off his guard by the withering attack. “It is Stephen Whipple,
sir—W-h-i-double p-l-e, Whipple!” he spelled, and he leaned forward
and pointed a stiff finger at Walton's pad. “Write it down. It might
get away from you.”
“Are you plumb sure it ain't Jenkins?” the banker grinned,
significantly.
“No; nor Jones, nor Smith, nor Brown. It's Whipple—Stephen
Whipple. Put it down on your paper. Huh, I'm not ashamed of it!”
“All right, there you are, in big letters.” Walton laughed, still
victoriously, as he pencilled the name on the pad. “Now, one other
formality, please—your postoffice address?”
“My post-office—” Whipple hesitated. His astounded gaze went
down; he was all of a quiver, even to his bushy eyebrows.
“Why, it's this way—this way—” he stammered, and, raising his
helpless eyes to the banker's taunting ones, he came to a dead halt.
“I think it must be,” Walton chuckled. “In fact, it mighty nigh
always is that way when a feller gits in a corner. But surely, out of all
the places in the United States, you could think of some town,
railroad station, or cross-roads store. A word as uncommon as
Whipple would be hard for me to think of in a pinch. It seemed to
come handy to you. Maybe you've used it before, or had some dead
friend by that name.”
“You are not fair, sir!” The merchant was becoming exasperated by
the human riddle before him. “I told you I had come against your
son's knowledge or wish. He has kept his whereabouts from you up
to now, and I have no moral right to let it out. I reckon he is afraid
you will hound him down before he has a chance to pay back what
he owes you. The Lord knows, he has plenty of reason for being
cautious, for, if I am any judge, you are as hard and unforgiving as a
stone wall.”
“I haven't seen any reason to forgive him, or bother one way or
another about it,” old Simon hurled into the flushed face before him.
“I don't see any difference between the way me and him stand now
and six years ago. I reckon he thinks I'm on my last legs, and that
the three thousand he got by some hook or crook—or from some
crook—would be well invested as a gum-stickum plaster to put over
my eyes before I am put under ground. After he had staked that
much, he thought some oily-tongued friend of his might come and
reconnoitre and report favorable. Well, you've reconnoitred, Mr.—Mr.
Whipstock, and you can go back to Atlanta and tell him it is no go.
You may tell him I am much obliged to you all—whoever your gang
is—for the three thousand on account. I may be making a mistake
now by shooting off my mouth so quick, for if I had worked my
cards right I might have secured another payment by dropping a
tear or two; but it is worth something to say what I've said in the
way I've said it.”
“So you don't believe what I have told you?” Whipple gasped, in
astonishment.
“Not a blessed word—not a syllable,” Walton laughed, and he
threw himself back in his chair in sheer enjoyment of his visitor's
discomfiture.
“You don't believe he is in my employment—you don't believe he
earned the money by faithful work which he sent you—you don't
believe—” Whipple paused, at the end of his resources.
“No, I don't believe even that,” Walton jested. “But I'll tell you one
thing, and I mean it. I don't intend to have you coming around
bothering me with this matter any more at all. It is strictly my affair,
anyway. That boy was a bad egg when he was here, and from the
looks of you and your game I can't see that he has improved a dang
bit. I don't say I'd arrest him, neither; half the debt has been paid, if
it was paid for a sneaking reason, and he can rove where he will. He
is a good riddance. I used to bother about what might become of
him, but I don't now.”
“Say, look me in the eye!” Whipple suddenly demanded, and with
a fierceness that almost sent a shock of surprise through the banker.
“You've not believed what I have told you, it seems, because you
thought I was after your dirty money. Hard cash is the only thing
you can believe in, I see, and so I am going to use some of it to
convince you. You have no faith in your son—the only child God
gave you, and who is now honoring your gray hairs as they don't
deserve to be honored, but, thank Heaven! I believe in him from
head to foot. Before I left Atlanta, this morning, I prepared myself
for some sort of emergency like this.”
Whipple took out a long envelope and threw it on the desk under
the banker's eyes. “That contains three thousand dollars—six bills of
five hundred each. Take them! Your boy's debt is paid in full. I may
have spoiled his chances with you by coming here against his
knowledge, but he shall not lose by it. If I live to get back home I
shall provide for him in my will. I may look like a faker, but I flatter
myself—from all I have heard of you—that I am worth more to-day
in the financial world than you could be if you could live another
twenty-five years. Good-day, sir.”
CHAPTER XIV

T
AKING up his satchel, the merchant strode heavily from the
room. Doubting if he had heard aright, Walton tore open the
envelope and took out the bills. He spread them on the desk;
he fumbled them with quivering fingers; he took out a big
magnifying glass and essayed to examine them one by one, but his
excitement and perturbation rendered it impossible. Dropping his
hand on his call-bell, he gave a sharp ring, and Toby Lassiter came
in quickly. Brushing the money toward his clerk, Walton said:
“See if they are counterfeit. By gum!”
The clerk examined them with the glass while Walton watched him
with staring eyes.
“They seem to me to be all right, Mr. Walton,” Toby said,
wonderingly, as he laid the bills down.
“I reckon they are—my Lord, I reckon they are!” the banker said,
in his throat. “Credit it on my private account, Toby. Credit me with
three—my Lord, I didn't think—I had no idea that the dang fellow—
no, I'll attend to the money. Toby, you run out and see where he
goes. He may make for a hotel, or he may—but hurry!”
Twenty minutes later Toby came back and found Walton still at his
desk, the money before him; his face had taken on an ashen tinge,
the eye he raised had a lacklustre expression.
“Well?” he said, eagerly.
“I missed him for the first few minutes,” the clerk said. “He was on
the way to the train. I took the belt-line down. He was on the car
ahead. I was just in time to see him board the Atlanta special.”
“So he's gone?”
“Yes, he's gone, Mr. Walton.”
The old man stared helplessly for a minute into the puzzled face of
his clerk, and then he drew the pad to him on which he had written
the name of his caller.
“Me 'n' him had a tiff,” he said. “We had a sort o' tiff—I reckon you
might call it that—after he had told me a long cock-and-bull tale
about Fred reforming, and I laughed at him. I reckon I was rough.
Then he threw this money at me all in a chunk to settle off the boy's
account, and said it might talk plainer than he had. Toby, it don't
look exactly like a fake. Fakes ain't worked that way. You see, it was
all up between me and him, and there wasn't a thing he could gain
by it, and yet he yanked out this wad and threw it at me like so
much waste paper. He refused to say where he lives, but here's his
name. Fred wrote that the fellow he was with was a merchant, and a
big one at that. I wonder if there is any way of finding out just who
and what the dang fool is?”
“You say you didn't get his address?” Toby inquired, as he
helplessly stroked his colorless face and sparse mustache.
“No.” The banker uttered something like a moan of self-disgust.
“He intimated that he kept it back to keep me from running the boy
down. I reckon I made a big fool of myself in the presence of a man
that may have unlimited capital for all I know. That's where my
judgment slipped a cog for once, I reckon. I set in to believe he was
out after my money, and went a little mite over the limit. He didn't
look rich, covered with dust like he was, but he may be—he may be
all Fred has claimed. Can you think of any way, Toby, to get a report
on him?”
“I might take Bradstreet's by States,” the clerk suggested, “and
run through all the towns and cities far and near.”
“It would take a month to go through that big book,” Walton said,
dejectedly, “and I want to know to-day, right off. If—if I've made a
break as big as that, and—and gone and insulted a man who has
befriended my boy, and one who, in fact, says he intends to provide
for him liberally, why, it would be nothing but good business to make
what amend lies in my power. If the boy really has built himself up,
and made good connections, and the like, why, you see, Toby, I
ought not to be the first—the very first—to—to damage his interests.
What I said, in my rough way, you see, might have a tendency to
sort o' make this Whipple—if he is all right—think twice before
helping out the son of a man who rode as high a horse as I was
astride of just now. I must have a report on him, I tell you.”
“I'll go through the book, Mr. Walton,” the clerk said. “It wouldn't
take so awful long. I would only have to run through the W's, you
know, and needn't look in the little places. If he is in the wholesale
line, he must be in a town of over ten thousand.”
“That's a fact, that's a fact,” Walton agreed. “I reckon he didn't
think of that when he gave me his name, though I acknowledge I
kinder gouged it out of him when he was good and hot. Go bring the
book here and set at my desk. I'll not let the rest bother you. My
Lord! my Lord! What a mess!”
All that afternoon the clerk bent over the huge volume with its
closely printed columns on very thin paper. The closing hour came.
The typewriters and clerks went home and the front door was shut,
but still Toby read, patiently running the point of his pencil down
column after column. Night came on, and less than half of the book
still remained to be scanned.
“Go home to supper and come back,” Walton said, a strange light
burning in his shrewd eyes. “I'll meet you here. I want this thing
settled. I don't believe I could sleep with the doubt on my mind as
to whether that man was fooling me or not. It is a big thing—a
powerful big thing. If Fred has made himself of enough importance
to have a man like that come a long distance in his behalf, why, you
see, I ought to know about it, that's all—I ought to know about it.”
“Yes, you ought to know, Mr. Walton,” Lassiter said, as he laid a
blotter between the pages and reached for his hat. They went out
together and walked side by side to the corner, where the clerk had
to turn off.
“You sort o' believed in Fred all along, Toby,” the banker said,
tentatively—“that is, you used to talk him up to some extent.”
“I thought he was in earnest about what he wrote in that last
good-bye letter, Mr. Walton. It made a deep impression on me. It
sounded perfectly straight. And awhile back, when his other letter
came, bringing all that cash, I was more sure than ever. Even when
you said you believed it was a trick, somehow I couldn't exactly look
at it that way.”
“Well, see if you can locate this Whipple,” Walton said, and,
turning off, he trudged heavily homeward through the gathering
shadows.
He was on his way back to the bank about nine o'clock when he
saw Toby coming toward him. The clerk was walking rapidly,
swinging his long arms to and fro like pendulums.
“Well, well?” Walton exclaimed, as they met face to face on the
sidewalk in the flare of a gas-light.
“I have found him!” Toby chuckled. “There is no mistake. Stephen
Whipple is a whopping big wholesale grocer at Gate City, Oklahoma.
He's rated at over a million, with credit at the top notch.”
“You don't say!” A negro laborer with a bag of flour on his
shoulder was passing close by, and Walton laid his hand warmingly
on the arm of his clerk and drew him slowly along.
“You don't say!” he repeated, under his breath, as he clutched
Toby's thin arm, “and I talked to him like a dog—like a hound-dog. I
did that, when he could buy and sell me over and over. I sneered at
him, and just as good as called him a thief, when he was right then
befriending the son I'd cast off. Say, Toby, you've got a sight more
sense than I have; what do you think I ought to do about it?”
“I really don't know, Mr. Walton,” Toby replied, awkwardly. “Maybe
it would be a good idea for you to go out there. From the way Fred
wrote, it stands to reason he'd be glad to see you, anyway, and—”
“I couldn't do that, Toby,” Walton said, under his breath. “After the
stand I took and have held all these years, I couldn't go running
after him. I could do some things, but I couldn't do that. Besides,
you see, Whipple would know we'd looked up his standing, and think
I'd come because he was rich. But, say, I have an idea, Toby. Don't
you think you could get on the train and go out there and take a
look around?”
“Why, yes, if you advise it, Mr. Walton.”
“And you could go and hang about, in a quiet, know-nothing way,
without letting Fred see you, I reckon?”
“Easy enough, Mr. Walton, in a bustling place like that.”
“Well, then, I'll tell you what you do. Pack your grip to-night, and
take the eight-thirty train in the morning. Put up at some out-of-the-
way hotel, and lie low and pick up what information you can. Don't
go about Whipple's place of business; if Fred saw you, it would spoil
it all. I'll defray your expenses. You deserve a trip, anyway. Of
course, even if the boy has made such a good, comfortable nest for
himself out there, that woman business is still hanging over him, and
he wouldn't feel exactly like facing Stafford folks right now. But I
reckon he's been doing an honest man's part by her along with his
rise. He's been providing for her and the child pretty well, I'll be
bound. And in case he does come back, even on a visit, we'll help
him smooth over the matter as far as is in our power. He ain't the
first young chap that's let his blood get the upper hand. Some of the
great men of history have made like slips along at the start. Yes,
we'll try to manage that some way. We might even get her and her
mother to move off somewhere. I don't know—I only say it might be
done. Folks in a plight of that sort will do most anything when they
are paid, and it looks like Fred won't go a-begging. Now, good-bye,
Toby. You've got a job of detective work before you, but I believe
you'll be smart enough to put it through.”
“I'll do my best, Mr. Walton,” the clerk said. “Goodbye.”
CHAPTER XV

I
T was a delightfully cool and crisp morning for midsummer, and
Doctor Dearing was on the lawn between his house and Galt's,
when he noticed that the railroad president had come out into
his own grounds for a smoke. The two exchanged greetings through
cordial signals, and Galt crossed over and joined his friend.
“What news from New York?” he asked, as he flicked the ashes
from his cigar.
“They will be here to-morrow,” Dearing replied. “Madge has been
homesick for fully two weeks; but Uncle Tom made her stay longer,
hoping that she would become more interested in what was going
on. They have had all sorts of attentions paid them, but he writes
me that he has never been worried so much in his life over her. He
says she enjoyed the first two weeks thoroughly, but lately she has
been actually depressed. He tried everything imaginable, but home
was what she wanted and would have.”
“And so they are coming?” Galt said, reflectively.
“Yes, they are on the way now. After all, what better could one
ask for than a snug retreat like this in hot weather? Madge is fond of
home. She doesn't care for giddy social things among a lot of
money-spending Yankees, and I admire her taste.”
“Yes, so do I,” Galt answered, and he smoked steadily, his eyes
bent on the ground. .
“I have an unpleasant job on hand,” Dearing remarked. “I have
delayed it several times, but I have decided to do it to-day and have
it over with.”
“What is it?” Galt asked.
“It is a slight operation I have to perform on little Lionel.”
“Operation? Lionel?” Galt started, and then checked himself and
stared blankly. “I didn't know there was anything at all wrong with
him.”
“Oh, it is only a slight and common thing with children,” Dearing
explained. “Enlarged tonsils and adenoidal growth which must be
removed. Outwardly the little chap is as sound as a dollar, and, so
far, his wonderful strength has fought the thing off; but for a child so
nervous as he is, and high strung and imaginative, it might, later on
affect him seriously. Neglected cases have brought on permanent
deafness and lung trouble. It is inherited, as a rule; you, yourself,
had something of that sort, I think you told me.”
“Yes, yes,” Galt replied. Deep down within him something seemed
to clutch his vitals. In the ear of his naked soul an accusing voice
was sounding: “Inherited! Inherited!” The word rang out like a threat
from the Infinite—from the vast mystery of life which had of late
been so tenaciously closing around him. Even the pain Lionel was to
undergo was the outcome of another's sin.
“Oh, it is a very simple operation,” Dearing went on, “and in any
ordinary case I shouldn't give it a second thought; but, by George, I
have become attached to that little chap. He is the pluckiest little
man I ever knew. I had an exhibition of his grit one day that was
ahead of anything I ever saw in a child. He had fallen, and his upper
teeth had cut a deep gash in his tongue. They sent for me, and I
saw that I'd have to take a stitch in it to close the ugly gap. It was a
ticklish job, and I hardly saw how I could do it, for I didn't want to
use an anaesthetic. But I talked to him just as I would to a man, and
he promised me he wouldn't cry. He didn't. I give you my word, old
man, he didn't whimper as the needle went through, and even while
I was tying the thread; but I could see from his big, strained eyes
that it hurt him like rips. A child with grit like that, Kenneth, is bound
to make a stir in the world. I have noticed that you like him too, and
I am glad you do. The truth is, darn you, you are taking my place!
I'm jealous; he thinks you are a regular king. He is always talking
about you.”
“When do you think you will do the—the operation?” Galt faltered,
as he averted his shrinking glance from Dearing's face.
“Why, I want to do it right off. It is like this: his mother knows it
has to be done, and has agreed to leave it entirely to me; but she is
very nervous over it. She has a vein of morbid superstition running
through her. She fancies that some disaster is bound, sooner or later,
to happen to him—in fact, as she has often put it to me, she hardly
believes that a just God would allow such a sensitive and ambitious
child to grow up to a full comprehension of his humiliation.
“I see—I see what you mean,” Galt managed to say, and his soul
seemed to writhe anew as he stood trying to make his words sound
casual.
“So I thought,” the doctor went on, “that I'd like, if possible, to get
it over without her knowledge, or without her mother knowing of it.
Nervous people standing around, half frightened out of their wits, at
such a time, unsteady my hand and upset me generally. Now, as I
have everything in readiness up-stairs, I think, when Lionel comes
over this morning, as I've asked him to do, I'll talk him into it. Young
Doctor Beaman, my new assistant, is up-stairs sterilizing my
instruments, and he will give the chloroform. You see, it would be a
pleasant surprise and a relief to those doting women to suddenly
find out that the thing they have made such a fuss about is over and
no harm done.” Galt made no reply. He had seen a trim little figure
darting across the lower end of the lawn, and saw a flash of golden
tresses in the sunlight, and knew that Lionel was coming—and to
what? Galt suppressed an inward groan. The unsuspecting child was
bounding along, joyous and full of life, to the grim, inexplicable
snare which had been set for him. Young as he was, he was to be
asked to be firm and brave, that his little form might take on the
semblance of death and submit to the knife, a thing at the thought
of which even strong men had quailed. And what might, after all, be
the as yet unrevealed outcome? One case in every ten thousand, at
least, failed to survive the artificial sleep, owing to this or that
overlooked internal defect. Would this child of malignant misfortune
be that one?
Lionel drew near, sweeping the two men with merry eyes of
welcome. There was an instant's hesitation as to which to greet first,
and then instinct seemed to swerve him toward Galt, his hand
outstretched. With a queer throb of appreciation, the father took it
and felt it pulsate in his clasp.
“Come here, Lionel, my boy,” Dearing said, with affected lightness
of manner. “You remember what I said one day about those ugly
lumps down there in your little throat which are going to get bigger
and bigger, till after a while you can't eat any jam and cake? You
wouldn't like that, would you?”
“I remember.” Lionel passed his tapering hand over his white
throat. “I can feel them when I swallow.”
“And that is why you have those bad dreams, and jump in your
sleep, and think you are falling,” Dearing added, adroitly. “You know
you promised to let me get them out.”
“Oh, not to-day!” the boy protested, throwing a wistful glance up
at the unclouded sky. “I was going to build a really-really house out
of the bricks at the barn. I have a stove-pipe for a smoke-stack. I'll
show you both. Come with me! Oh, it's great!”
“Not to-day. Lionel, listen.” Dearing drew the boy close to him, and
tenderly stroked back his hair from his fine brow. “Mamma, you
know, is terribly nervous about it. Women are that way, aren't they?
Men and boys, like us, know better. She can hardly sleep at night for
thinking about it—even a little thing like that. We can do it now, and
I can run over and tell her you are sleeping like a kitten in my big
bed up-stairs, and she and Granny will be so glad. It won't hurt a
bit, you know, for the medicine will make you sleep through it all.” A
shadow of deep disappointment came into Lionel's expressive eyes.
The warm color of life in his face faded into tense gravity, and they
saw him clasp his little hands and wring them undecidedly.
“And you think to-day is the best time?” he faltered, on the edge
of refusal.
“The very best of all, Lionel,” Dearing said, gently. “You wouldn't
be afraid of me, would you?”
The child stared dumbly. To Galt's accusing sense the world had
never held a more desolate sentient being than this incipient
repetition of himself. The child had proved that he knew no physical
fear. To what, then, did he owe this evident clutch of horror? Could it
be due to some psychic warning of approaching danger, or was the
sensitive child telepathically governed by the morbid fears which, at
that moment, were raging in the heart of his father?
“Come, that's a good, nice boy!” Dearing urged. “I see you are
going to be a brave little man.”
“I'm not afraid it will hurt,” Lionel faltered, “but I don't like to be
put to—to sleep.”
“But it must be so, my boy,” the doctor said. “Come on. Mamma
will see us in a minute and smell a mouse.” For a moment yet the
child stood undecided, his gaze alternately on the two faces before
him. Suddenly, while they waited and his eyes were resting in
strange appeal on Galt, he asked:
“Will you come, too?”
A shock as if from some unknown force went through the man
addressed, but, seeing no alternative, he answered:
“If you wish it, yes, of course.”
“And you think I ought to—to do it?”
“Yes,” Galt nodded, his head rocking like that of an automaton.
“The doctor knows best.”
“Well, then, I'll go,” the boy sighed, with another wistful look over
the lawn. “I'll go.”
As they were entering the house, by some strange mandate of
fate or instinct the boy again took his father's hand, and Galt held it
as they began to ascend the broad, walnut stairs. Argue as he would
that the operation was only a most ordinary thing, to Galt's morbid
state of mind it assumed the shape of a tragedy staged and enacted
by the very imps of darkness.
On the way up the boy tripped on the stair-carpeting and slipped
and fell face downward. He was unhurt, but Galt raised him in his
arms and bore him up the remainder of the steps into a big, light
room off the corridor.
“Here we are, Doctor Beaman!” Dearing cheerily called out to a
slender, beardless young man, who, with a towel in hand, was
bending over some polished instruments on the bureau. “This is the
little chap who never cries when he is hurt. He is a regular soldier, I
tell you!”
“No, I'm not afraid,” the boy said, as he stood alone in the centre
of the room; but still, as his father noted, there was a certain
contradictory rigidity of his features which he had never remarked
before.
Galt told himself that the child's evident dread, vague as it was,
was also an inheritance; for he recalled how he himself had once
taken ether to have a slight operation performed. He had been a
man in years at the time, and yet the effect on his mind as to what
might be the outcome had been most depressing. That day, as he
was doing now, he had looked upon the drug-induced sleep as a
dangerous approach to death; and now, as then, he gravely feared
that the tiny thread of reduced vitality might be torn asunder. He
stood dumb with accusing horror as the two doctors hastily made
their grewsome arrangements, such as securing warm water, fresh
towels and sheets, which, in their very whiteness, suggested a
shroud.
The noise made as they drew a narrow table across the
resounding floor into the best light between the two windows jarred
harshly on his tense nerves. These things were grim enough, but the
wan isolation of the waiting child, as he stood with that war against
fear and shame of fear going on in his great, fathomless eyes, so
like those of his artist-mother—that appealing little figure, nameless,
disowned among men, was stamped on the retina of Galt's eye for
the remainder of his life.
“Now, take off your waist and collar and necktie,” Dearing said to
Lionel—“that will be enough. We'll have you all right in a jiffy. You
are not afraid now, are you?”
Galt's heart sank like a plummet, for the child's lips moved, but no
sound issued. The little fellow turned his face away as he began to
undress. He removed the flowing necktie, but his little fingers could
not unfasten the stiff linen collar.
“Help him, Kenneth,” Dearing said. “My hands are full.”
Galt obeyed, his fingers coming into contact with the cold chin of
the child and the soft flesh of his neck. He felt like snatching the boy
from the damnable spot, as a mother might her young from the
claws of a wild beast. Yet, outwardly calm, he drew the sleeves of
the child's blouse off and laid it on a chair.
“Now we are ready for you, young man,” Dearing said, lightly. “I
see you are not afraid I'll hurt you.”
“No, I know it won't hurt,” Lionel said, “but—”
“Don't you begin butting me,” Dearing laughed. “You are not a
goat like the one that butted Grover Weston heels over head the
other day.”
“If I shouldn't wake up—I mean if I really shouldn't, you know,”
Lionel finished, with a faint effort to smile at the doctor's jest, “won't
you please not tell my mother too quick? She gets frightened so
easily, and, you see, if I didn't wake up—if I never woke again—”
“Ah, come off!” Dearing laughed, as he turned to his assistant.
“Doctor, this kid hints that we don't know our business.”
“But if I didn't wake, if I didn't!” Lionel insisted, “you'd not scare
her, would you? And—and”—his lower lip quivered—“wouldn't you
tell her that I wasn't a bit afraid, and that I didn't cry, and—wait!
wait! Won't you tell her that it didn't hurt a single bit, not even a
little teensy bit?”
“Yes, yes,” Dearing said, and, considerably taken aback, he stared
at Galt rather than at the insistent speaker. “I'll tell her you are the
best boy in the world—the best, the bravest, and the sweetest. And
God knows I'll mean it,” he finished, in a lower tone to Galt. “I've
seen thousands of kids, Kenneth, but this one gets nearer me than
all the rest put together. I swear I am almost tempted to throw the
darn job up. But, you see, it has to be done. Doctor,” turning to his
assistant, “put him on the table, and I'll tickle his nose and make
him laugh. We'll make him have the funniest dreams he ever had.”
Doctor Beaman went to the boy and held out his arms, and Lionel
was lifted to the table and stretched out on the crisp sheet which
had been spread over it. Just then, happening to look round,
Dearing saw Galt's face, and hastily stepped to his side. “My Lord!”
he whispered, “I see this thing is going against you, old man. You
are nauseated; you look faint. Many men are that way—young
students sometimes have to give up surgery for that reason. It is
nothing to be ashamed of. You like the little chap, and your
sympathies are worked up, that's all. But, really, I don't think you
ought to stay. I become nervous if others are, and I must have a
free hand. Besides, if you were to keel over in a faint at an
important moment I couldn't look after you. You'd better run down-
stairs and take a whiff of air. I'll call you when it is over.”
“Is he going?—must he go?” Lionel asked, as he turned his head
and saw Galt moving to the door. “Yes,” Dearing said, “but only
down-stairs.”
“Oh,” the child exclaimed, regretfully, and averted his face, “I
thought he could stay!”
Down into the still silence of the great hall Galt went. There was
something heartlessly maddening in the calm, yellow sunlight on the
grass, which he could see through the doorway. The birds in the
trees, as they flitted about with twigs in their mouths and chirped in
glee, seemed mocking voices of despair from the deliberate tyranny
of the universe.
“God have mercy and spare him!” the man cried out from the
depths of his agony. “Spare him, O God, spare him!”
Unconscious of the incongruous prayer which had fallen from his
lips, he turned into the drawing-room, on the left of the hall, and
sank into an easy-chair, covering his face with his stiff hands.
Suddenly he heard a light step on the veranda, and, raising his eyes,
he saw Dora standing in the hall, glancing wildly and excitedly about
her. Possessed by the fear that she might call out, and thus make
her presence known at that most crucial moment, he rose and
hastened to her. She did not see him till he was close at her side,
and then she turned and their eyes met.
“Where is Lionel—where is my child?” she panted.
He stood staring at her, unable to formulate a reply, and, brushing
past him with an air of contempt, which he read all too clearly, she
turned to the stairs, and started to ascend.
“Oh, you mustn't—you really mustn't!” he called out in protest,
and he put a detaining hand on her arm.
Shrinking from his touch, she stared at him piteously.
“Then they really are doing it!” she cried. “They are up there
operating on my child! I knew it when Doctor Beaman drove up, and
Doctor Wynn came and asked Lionel to play over here.”
Galt made no denial. He stood beside her, swept out of himself by
the sheer power of her astounding beauty, as he now beheld it for
the first time since their parting. In his wildest stretch of fancy as to
what the years might have brought her, he had not dreamed that
she had become such a flower among women. There was a
seductive maturity of intellect in her faultless face. The strange,
appealing, and yet unreadable lights of genius were burning in her
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookball.com

You might also like