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

Java Java Java Object Oriented Problem Solving 3rd Edition Ralph Morelli Ralph Walde instant download

The document provides information about the third edition of 'Java, Java, Java: Object-Oriented Problem Solving' by Ralph Morelli and Ralph Walde, which is available for download under a Creative Commons license. This edition emphasizes an 'objects first' approach to programming and includes updates such as new chapters on user interfaces and advanced topics like networking and data structures. The book is designed for introductory computer science courses and includes exercises, UML diagrams, and a companion website for additional resources.

Uploaded by

elesighilda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
12 views

Java Java Java Object Oriented Problem Solving 3rd Edition Ralph Morelli Ralph Walde instant download

The document provides information about the third edition of 'Java, Java, Java: Object-Oriented Problem Solving' by Ralph Morelli and Ralph Walde, which is available for download under a Creative Commons license. This edition emphasizes an 'objects first' approach to programming and includes updates such as new chapters on user interfaces and advanced topics like networking and data structures. The book is designed for introductory computer science courses and includes exercises, UML diagrams, and a companion website for additional resources.

Uploaded by

elesighilda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Java Java Java Object Oriented Problem Solving

3rd Edition Ralph Morelli Ralph Walde pdf


download

https://ebookmeta.com/product/java-java-java-object-oriented-
problem-solving-3rd-edition-ralph-morelli-ralph-walde/

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

Beginning Java 17 Fundamentals Object Oriented


Programming in Java 17 3rd Edition Kishori Sharan

https://ebookmeta.com/product/beginning-java-17-fundamentals-
object-oriented-programming-in-java-17-3rd-edition-kishori-
sharan/

Beginning Java 17 Fundamentals: Object-Oriented


Programming in Java 17 3rd Edition Kishori Sharan

https://ebookmeta.com/product/beginning-java-17-fundamentals-
object-oriented-programming-in-java-17-3rd-edition-kishori-
sharan-2/

Functional Interfaces in Java Fundamentals and Examples


1st Edition Ralph Lecessi

https://ebookmeta.com/product/functional-interfaces-in-java-
fundamentals-and-examples-1st-edition-ralph-lecessi/

Theatre Histories An Introduction 2nd Edition Phillip B


Zarrilli

https://ebookmeta.com/product/theatre-histories-an-
introduction-2nd-edition-phillip-b-zarrilli/
Popular Culture Introductory Perspectives 4th Edition
Marcel Danesi

https://ebookmeta.com/product/popular-culture-introductory-
perspectives-4th-edition-marcel-danesi/

The Colliding Worlds of Mina Lee 1st Edition Oh

https://ebookmeta.com/product/the-colliding-worlds-of-mina-
lee-1st-edition-oh/

Addicted Notes from the Belly of the Beast 3rd Edition


Lorna Crozier Editor Patrick Lane Editor

https://ebookmeta.com/product/addicted-notes-from-the-belly-of-
the-beast-3rd-edition-lorna-crozier-editor-patrick-lane-editor/

Genetics for Smart Kids A Little Scientist s Guide to


Cells DNA Genes and More Future Geniuses Book 3 Pazos
Carlos

https://ebookmeta.com/product/genetics-for-smart-kids-a-little-
scientist-s-guide-to-cells-dna-genes-and-more-future-geniuses-
book-3-pazos-carlos/

Alpha Geek Trent 1st Edition Milly Taiden

https://ebookmeta.com/product/alpha-geek-trent-1st-edition-milly-
taiden/
Poems Mostly of the Sea 1st Edition Jenne Kaivo

https://ebookmeta.com/product/poems-mostly-of-the-sea-1st-
edition-jenne-kaivo/
Java, Java, Java
Object-Oriented Problem Solving
Third Edition

R. Morelli and R. Walde


Trinity College
Hartford, CT
June 25, 2017
This work is licensed under a
Creative Commons Attribution 4.0 International License (CC BY 4.0).

This book was previously published by


Pearson Education, Inc.
Preface to the Open Source
Edition

Java, Java, Java, 3e was previously published by Pearson Education, Inc.


The first edition (2000) and the second edition (2003) were published by
Prentice-Hall. In 2010 Pearson Education, Inc. reassigned the copyright to
the authors, and we are happy now to be able to make the book available
under an open source license.
This PDF edition of the book is available under a Creative Commons
Attribution 4.0 International License, which allows the book to be used,
modified, and shared with attribution:
(https://creativecommons.org/licenses/by/4.0/).

– Ralph Morelli and Ralph Walde


– Hartford, CT
– December 30, 2016

i
ii
Preface to the Third Edition

We have designed this third edition of Java, Java, Java to be suitable for
a typical Introduction to Computer Science (CS1) course or for a slightly
more advanced Java as a Second Language course. This edition retains the
“objects first” approach to programming and problem solving that was
characteristic of the first two editions. Throughout the text we emphasize
careful coverage of Java language features, introductory programming
concepts, and object-oriented design principles.
The third edition retains many of the features of the first two editions,
including:

• Early Introduction of Objects

• Emphasis on Object Oriented Design (OOD)

• Unified Modeling Language (UML) Diagrams

• Self-study Exercises with Answers

• Programming, Debugging, and Design Tips.

• From the Java Library Sections

• Object-Oriented Design Sections

• End-of-Chapter Exercises

• Companion Web Site, with Power Points and other Resources

The In the Laboratory sections from the first two editions have been moved
onto the book’s Companion Web Site. Table 1 shows the Table of Contents
for the third edition.

What’s New in the Third Edition


The third edition has the following substantive changes:

• Although the book retains its emphasis on a “running example”


that is revisited in several chapters, the CyberPet examples have
been replaced with a collection of games and puzzle examples. The
CyberPet examples from earlier editions will be available on the
Companion Web Site.

iii
iv

Table 1: Table of Contents for the Third Edition.

Chapter Topic
Chapter 0 Computers, Objects, and Java (revised)
Chapter 1 Java Program Design and Development
Chapter 2 Objects: Defining, Creating, and Using
Chapter 3 Methods: Communicating with Objects (revised)
Chapter 4 Input/Output: Designing the User Interface (new)
Chapter 5 Java Data and Operators
Chapter 6 Control Structures
Chapter 7 Strings and String Processing
Chapter 8 Inheritance and Polymorphism (new)
Chapter 9 Arrays and Array Processing
Chapter 10 Exceptions: When Things Go Wrong
Chapter 11 Files and Streams
Chapter 12 Recursive Problem Solving
Chapter 13 Graphical User Interfaces
Chapter 14 Threads and Concurrent Programming
Chapter 15 Sockets and Networking (expanded)
Chapter 16 Data Structures: Lists, Stacks, and
Queues (revised and expanded)

• Chapters 0 (Computers, Objects, and Java) and 1 (Java Program De-


sign and Development) have been substantially reorganized and
rewritten. The new presentation is designed to reduce the pace
with which new concepts are introduced. The treatment of object-
oriented (OO) and UML concepts has also been simplified, and some
of the more challenging OO topics, such as polymorphism, have
been moved to a new Chapter 8.
• The new Java 1.5 Scanner class is introduced in Chapter 2 and is
used to perform simple input operations.
• Chapter 4 (Input/Output: Designing the User Interface) has been
completely written. Rather than relying primarily on applet inter-
faces, as in the second edition, this new chapter provides indepen-
dent introductions to both a command-line interface and a graphi-
cal user interface (GUI). Instructors can choose the type of interface
that best suits their teaching style. The command-line interface is
based on the BufferedReader class and is used throughout the
rest of the text. The GUI is designed to work with either graphi-
cal applications or applets. Both approaches are carefully presented
to highlight the fundamentals of user-interface design. The chapter
concludes with an optional section that introduces file I/O using the
new Scanner class.
• Much of the discussion of inheritance and polymorphism, which
was previously woven through the first five chapters in the second
edition, has been integrated into a new Chapter 8.
• An optional graphics track is woven throughout the text. Beginning
with simple examples in Chapters 1 and 2, this track also includes
v

some of the examples that were previously presented in Chapter 10


of the second edition.

• Chapter 15, on Sockets and Networking, is expanded to cover some


of the more advanced Java technologies that have emerged, includ-
ing servlets and Java Server Pages.

• Chapter 16, on Data Structures, has been refocused on how to use


data structures. It makes greater use of Java’s Collection Framework,
including the LinkedList and Stack classes and the List inter-
face. It has been expanded to cover some advanced data structures,
such as sets, maps, and binary search trees.

The Essentials Edition


An Essentials Edition of the third edition, which will include Chapters 0-
12, will be published as a separate title. The Essentials Edition will cover
those topics (Chapters 0-9) that are covered in almost all introductory
(CS1) courses, but it will also include topics (Exceptions, File I/O, and
Recursion) that many CS1 instructors have requested.

Why Start with Objects?


The Third Edition still takes an objects-early approach to teaching Java,
with the assumption that teaching beginners the “big picture” early gives
them more time to master the principles of object-oriented programming.
This approach seems now to have gained in popularity as more and more
instructors have begun to appreciate the advantages of the object-oriented
perspective.
Object Orientation (OO) is a fundamental problem solving and design
concept, not just another language detail that should be relegated to the
middle or the end of the book (or course). If OO concepts are introduced
late, it is much too easy to skip over them when push comes to shove in
the course.
The first time I taught Java in our CS1 course I followed the same ap-
proach I had been taking in teaching C and C++ — namely, start with the
basic language features and structured programming concepts and then,
somewhere around midterm, introduce object orientation. This approach
was familiar, for it was one taken in most of the textbooks then available
in both Java and C++.
One problem with this approach was that many students failed to get
the big picture. They could understand loops, if-else constructs, and arith-
metic expressions, but they had difficulty decomposing a programming
problem into a well-organized Java program. Also, it seemed that this
procedural approach failed to take advantage of the strengths of Java’s
object orientation. Why teach an object-oriented language if you’re going
to treat it like C or Pascal?
I was reminded of a similar situation that existed when Pascal was the
predominant CS1 language. Back then the main hurdle for beginners was
procedural abstraction — learning the basic mechanisms of procedure call
vi

and parameter passing and learning how to design programs as a collec-


tion of procedures. Oh! Pascal!, my favorite introductory text, was typical
of a “procedures early” approach. It covered procedures and parameters
in Chapter 2, right after covering the assignment and I/O constructs in
Chapter 1. It then covered program design and organization in Chap-
ter 3. It didn’t get into loops, if-else, and other structured programming
concepts until Chapter 4 and beyond.
Today, the main hurdle for beginners is the concept of object abstraction.
Beginning programmers must be able to see a program as a collection of
interacting objects and must learn how to decompose programming prob-
lems into well-designed objects. Object orientation subsumes both proce-
dural abstraction and structured programming concepts from the Pascal
days. Teaching objects-early takes a top-down approach to these three im-
portant concepts. The sooner you begin to introduce objects and classes,
the better the chances that students will master the important principles
of object orientation.
Java is a good language for introducing object orientation. Its object
model is better organized than C++. In C++ it is easy to “work around”
or completely ignore OO features and treat the language like C. In Java
there are good opportunities for motivating the discussion of object orien-
tation. For example, it’s almost impossible to discuss GUI-based Java ap-
plications without discussing inheritance and polymorphism. Thus rather
than using contrived examples of OO concepts, instructors can use some
of Java’s basic features — the class library, Swing and GUI components —
to motivate these discussions in a natural way.

Organization of the Text


The book is still organized into three main parts. Part I (Chapters 0-4) in-
troduces the basic concepts of object orientation and the basic features of
the Java language. Part II (Chapters 5-9) focuses on remaining language el-
ements, including data types, control structures, string and array process-
ing, and inheritance and polymorphism. Part III (Chapters 10-16) covers
advanced topics, including exceptions, file I/O, recursion, GUIs, threads
and concurrent programming, sockets and networking, data structures,
servlets, and Java Server Pages.
The first two parts make up the topics that are typically covered in an
introductory CS1 course. The chapters in Part III are self-contained and
can be selectively added to the end of a CS1 course if time permits.
The first part (Chapters 0 through 4) introduces the basic concepts of
object orientation, including objects, classes, methods, parameter passing,
information hiding, and a little taste of inheritance, and polymorphism.
The primary focus in these chapters is on introducing the basic idea that
an object-oriented program is a collection of objects that communicate and
cooperate with each other to solve problems. Java language elements are
introduced as needed to reinforce this idea. Students are given the basic
building blocks for constructing Java programs from scratch.
Although the programs in the first few chapters have limited function-
ality in terms of control structures and data types, the priority is placed
vii

Table 2: A one-semester course.

Weeks Topics Chapters


1 Object Orientation, UML Chapter 0
Program Design and Development Chapter 1
2-3 Objects and Class Definitions Chapter 2
Methods and Parameters Chapter 3
Selection structure (if-else)
4 User Interfaces and I/O Chapter 4
5 Data Types and Operators Chapter 5
6–7 Control Structures (Loops) Chapter 6
Structured Programming
8 String Processing (loops) Chapter 7
9 Inheritance and Polymorphism Chapter 8
10 Array Processing Chapter 9
11 Recursion Chapter 12
12 Advanced Topic (Exceptions) Chapter 10
13 Advanced Topic (GUIs) Chapter 11
Advanced Topic (Threads) Chapter 15

on how objects are constructed and how they interact with each other
through method calls and parameter passing.
The second part (Chapters 5 through 9) focuses on the remaining lan-
guage elements, including data types and operators (Chapter 5), control
structures (Chapter 6), strings (Chapter 7), and arrays (Chapter 9). It
also provides thorough coverage of inheritance and polymorphism, the
primary mechanisms of object orientation: (Chapter 8).
Part three (Chapters 10 through 16) covers a variety of advanced topics
(Table 1). Topics from these chapters can be used selectively depending
on instructor and student interest.
Throughout the book, key concepts are introduced through simple,
easy-to-grasp examples. Many of the concepts are used to create a set
of games, which are used as a running example throughout the text. Our
pedagogical approach focuses on design. Rather than starting of with lan-
guage details, programming examples are carefully developed with an
emphasis on the principles of object-oriented design.
Table2 provides an example syllabus from our one-semester CS1
course. Our semester is 13 weeks (plus one reading week during which
classes do not meet). We pick and choose from among the advanced topics
during the last two weeks of the course, depending on the interests and
skill levels of the students.

Ralph Morelli
June 25, 2017
viii
Contents

0 Computers, Objects, and Java 1


0.1 Welcome . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
0.2 What Is a Computer? . . . . . . . . . . . . . . . . . . . . . . . 2
0.3 Networks, the Internet and the World Wide Web . . . . . . . 4
0.4 Why Study Programming? . . . . . . . . . . . . . . . . . . . . 6
0.5 Programming Languages . . . . . . . . . . . . . . . . . . . . 7
0.6 Why Java? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
0.7 What Is Object-Oriented Programming? . . . . . . . . . . . . 11

1 Java Program Design and Development 23


1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.2 Designing Good Programs . . . . . . . . . . . . . . . . . . . . 24
1.3 Designing a Riddle Program . . . . . . . . . . . . . . . . . . . 26
1.4 Java Language Elements . . . . . . . . . . . . . . . . . . . . . 34
1.5 Editing, Compiling, and Running a Java Program . . . . . . 48
1.6 From the Java Library: System and
PrintStream . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

2 Objects: Using, Creating, and Defining 61


2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.2 Using String Objects . . . . . . . . . . . . . . . . . . . . . . 62
2.3 Drawing Shapes with a Graphics Object (Optional) . . . . 66
2.4 Class Definition . . . . . . . . . . . . . . . . . . . . . . . . . . 69
2.5 CASE STUDY: Simulating a Two-Person Game . . . . . . . . 76
2.6 From the Java Library: java.util.Scanner. . . . . . . . . 90

3 Methods: Communicating with Objects 101


3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
3.2 Passing Information to an Object . . . . . . . . . . . . . . . . 102
3.3 Constructor Methods . . . . . . . . . . . . . . . . . . . . . . . 109
3.4 Retrieving Information from an Object . . . . . . . . . . . . . 114
3.5 Passing a Value and Passing a Reference . . . . . . . . . . . . 118
3.6 Flow of Control: Control Structures . . . . . . . . . . . . . . . 121
3.7 Testing an Improved OneRowNim . . . . . . . . . . . . . . . . 130
3.8 From the Java Library java.lang.Object . . . . . . . . . 135
3.9 Object-Oriented Design: Inheritance and Polymorphism . . 136
3.10 Drawing Lines and Defining Graphical Methods (Optional) 138

4 Input/Output: Designing the User Interface 149


4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

ix
x CONTENTS

4.2 The User Interface . . . . . . . . . . . . . . . . . . . . . . . . . 150


4.3 A Command-Line Interface . . . . . . . . . . . . . . . . . . . 151
4.4 A Graphical User Interface (GUI) . . . . . . . . . . . . . . . . 160
4.5 Case Study: The One Row Nim Game . . . . . . . . . . . . . 176
4.6 From the Java Library: java.io.File
and File Input (Optional) . . . . . . . . . . . . . . . . . . . . . 183

5 Java Data and Operators 197


5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
5.2 Boolean Data and Operators . . . . . . . . . . . . . . . . . . . 199
5.3 Numeric Data and Operators . . . . . . . . . . . . . . . . . . 205
5.4 From the Java Library java.lang.Math . . . . . . . . . . . 216
5.5 Numeric Processing Examples . . . . . . . . . . . . . . . . . 217
5.6 From the Java Library
java.text.NumberFormat . . . . . . . . . . . . . . . . . . 229
5.7 Character Data and Operators . . . . . . . . . . . . . . . . . . 231
5.8 Example: Character Conversions . . . . . . . . . . . . . . . . 235
5.9 Problem Solving = Representation + Action . . . . . . . . . . 237

6 Control Structures 241


6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
6.2 Flow of Control: Repetition Structures . . . . . . . . . . . . . 242
6.3 Counting Loops . . . . . . . . . . . . . . . . . . . . . . . . . . 243
6.4 Example: Car Loan . . . . . . . . . . . . . . . . . . . . . . . . 252
6.5 Graphics Example: Drawing a Checkerboard . . . . . . . . . 255
6.6 Conditional Loops . . . . . . . . . . . . . . . . . . . . . . . . 259
6.7 Example: Computing Averages . . . . . . . . . . . . . . . . . 266
6.8 Example: Data Validation . . . . . . . . . . . . . . . . . . . . 270
6.9 Principles of Loop Design . . . . . . . . . . . . . . . . . . . . 270
6.10 The switch Multiway Selection Structure . . . . . . . . . . . 273
6.11 OBJECT-ORIENTED DESIGN:
Structured Programming . . . . . . . . . . . . . . . . . . . . . 277

7 Strings and String Processing 297


7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
7.2 String Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
7.3 Finding Things Within a String . . . . . . . . . . . . . . . . . 304
7.4 Example: Keyword Search . . . . . . . . . . . . . . . . . . . . 306
7.5 From the Java Library: java.lang.StringBuffer . . . . . . . . . 308
7.6 Retrieving Parts of Strings . . . . . . . . . . . . . . . . . . . . 310
7.7 Example: Processing Names and Passwords . . . . . . . . . 312
7.8 Processing Each Character in a String . . . . . . . . . . . . 313
7.9 Comparing Strings . . . . . . . . . . . . . . . . . . . . . . . . 317
7.10 From the Java Library:
java.util.StringTokenizer . . . . . . . . . . . . . . . . . . . . . 323
7.11 Handling Text in a Graphics Context
(Optional) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324

8 Inheritance and Polymorphism 337


8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
8.2 Java’s Inheritance Mechanism . . . . . . . . . . . . . . . . . . 338
CONTENTS xi

8.3 Abstract Classes, Interfaces,


and Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . 347
8.4 Example: A Toggle Button . . . . . . . . . . . . . . . . . . . . 353
8.5 Example: The Cipher Class Hierarchy . . . . . . . . . . . . . 357
8.6 Case Study: A Two Player Game Hierarchy . . . . . . . . . . 363
8.7 Principles Of Object-Oriented Design . . . . . . . . . . . . . 384

9 Arrays and Array Processing 393


9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
9.2 One-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . 394
9.3 Simple Array Examples . . . . . . . . . . . . . . . . . . . . . 401
9.4 Example: Counting Frequencies of Letters . . . . . . . . . . . 403
9.5 Array Algorithms: Sorting . . . . . . . . . . . . . . . . . . . . 406
9.6 Array Algorithms: Searching . . . . . . . . . . . . . . . . . . 414
9.7 Two-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . 417
9.8 Multidimensional Arrays (Optional) . . . . . . . . . . . . . . 426
9.9 OBJECT-ORIENTED DESIGN:
Polymorphic Sorting (Optional) . . . . . . . . . . . . . . . . . 428
9.10 From the Java Library: java.util.Vector . . . . . . . . . . . . . 430
9.11 Case Study: An N-Player Computer Game . . . . . . . . . . 431
9.12 A GUI-Based Game (Optional Graphics) . . . . . . . . . . . . 437

10 Exceptions: When Things Go Wrong 459


10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
10.2 Handling Exceptional Conditions . . . . . . . . . . . . . . . . 460
10.3 Java’s Exception Hierarchy . . . . . . . . . . . . . . . . . . . 462
10.4 Handling Exceptions Within a Program . . . . . . . . . . . . 466
10.5 Error Handling and Robust
Program Design . . . . . . . . . . . . . . . . . . . . . . . . . . 477
10.6 Creating and Throwing Your Own
Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
10.7 From the Java Library: JOptionPane . . . . . . . . . . . . . 489

11 Files and Streams: Input/Output Techniques 499


11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
11.2 Streams and Files . . . . . . . . . . . . . . . . . . . . . . . . . 500
11.3 CASE STUDY: Reading and Writing Text Files . . . . . . . . 505
11.4 The File Class . . . . . . . . . . . . . . . . . . . . . . . . . . 518
11.5 Example: Reading and Writing Binary Files . . . . . . . . . . 521
11.6 Object Serialization: Reading and Writing Objects . . . . . . 530
11.7 From the Java Library
javax.swing.JFileChooser . . . . . . . . . . . . . . . . 535
11.8 Using File Data in Programs . . . . . . . . . . . . . . . . . . . 536

12 Recursive Problem Solving 545


12.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
12.2 Recursive Definition . . . . . . . . . . . . . . . . . . . . . . . 549
12.3 Recursive String Methods . . . . . . . . . . . . . . . . . . . . 551
12.4 Recursive Array Processing . . . . . . . . . . . . . . . . . . . 563
12.5 Example: Drawing (Recursive) Fractals . . . . . . . . . . . . 569
xii CONTENTS

12.6 OBJECT-ORIENTED DESIGN:


Tail Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
12.7 OBJECT-ORIENTED DESIGN:
Recursion or Iteration? . . . . . . . . . . . . . . . . . . . . . . 574
12.8 From the Java Library:
javax.swing.JComboBox . . . . . . . . . . . . . . . . . . . . . 577

13 Graphical User Interfaces 591


13.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
13.2 Java GUIs: From AWT to Swing . . . . . . . . . . . . . . . . . 592
13.3 The Swing Component Set . . . . . . . . . . . . . . . . . . . . 595
13.4 OBJECT-ORIENTED DESIGN:
Model-View-Controller Architecture . . . . . . . . . . . . . . 596
13.5 The Java Event Model . . . . . . . . . . . . . . . . . . . . . . 598
13.6 CASE STUDY: Designing a Basic GUI . . . . . . . . . . . . . 602
13.7 Containers and Layout Managers . . . . . . . . . . . . . . . . 614
13.8 Checkboxes, Radio Buttons, and Borders . . . . . . . . . . . 620
13.9 Menus and Scroll Panes . . . . . . . . . . . . . . . . . . . . . 629

14 Threads and Concurrent Programming 643


14.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644
14.2 What Is a Thread? . . . . . . . . . . . . . . . . . . . . . . . . . 644
14.3 From the Java Library: java.lang.Thread . . . . . . . . . 648
14.4 Thread States and Life Cycle . . . . . . . . . . . . . . . . . . . 654
14.5 Using Threads to Improve
Interface Responsiveness . . . . . . . . . . . . . . . . 656
14.6 CASE STUDY: Cooperating Threads . . . . . . . . . . . . . . 664
14.7 CASE STUDY: The Game of Pong . . . . . . . . . . . . . . . . 679

15 Sockets and Networking 693


15.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694
15.2 An Overview of Networks . . . . . . . . . . . . . . . . . . . . 694
15.3 Using Multimedia Network Resources for a Graphical Pro-
gram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700
15.4 From the Java Library: java.net.URL . . . . . . . . . . . . 701
15.5 The Slide Show Program . . . . . . . . . . . . . . . . . . . . . 704
15.6 Adding Text Network Resources for an
Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708
15.7 Client/Server Communication via Sockets . . . . . . . . . . 719
15.8 CASE STUDY: Generic Client/Server Classes . . . . . . . . . 724
15.9 Playing One Row Nim Over the Network . . . . . . . . . . . 732
15.10Java Network Security Restrictions . . . . . . . . . . . . . . . 741
15.11Java Servlets and Java Server Pages . . . . . . . . . . . . . . . 742

16 Data Structures: Lists, Stacks, and Queues 757


16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758
16.2 The Linked List Data Structure . . . . . . . . . . . . . . . . . 758
16.3 OBJECT-ORIENTED DESIGN:
The List Abstract Data Type (ADT) . . . . . . . . . . . . . . . 770
16.4 The Stack ADT . . . . . . . . . . . . . . . . . . . . . . . . . . . 776
16.5 The Queue ADT . . . . . . . . . . . . . . . . . . . . . . . . . . 778
CONTENTS xiii

16.6 From the Java Library: The Java Collections Framework


and Generic Types . . . . . . . . . . . . . . . . . . . . . . . . 782
16.7 Using the Set and Map Interfaces . . . . . . . . . . . . . . . 785
16.8 The Binary Search Tree Data Structure . . . . . . . . . . . . . 789

A Coding Conventions 801

B The Java Development Kit 809

C The ASCII and Unicode Character Sets 819

D Java Keywords 821

E Operator Precedence Hierarchy 823

F Java Inner Classes 825

G Java Autoboxing and Enumeration 831

H Java and UML Resources 837


Discovering Diverse Content Through
Random Scribd Documents
“But what was I to do?” he asked of Barakah, to whom, as an old
friend, he took his troubles. “Their cries had fired my spirit. I could
not keep silent. Na’imah tells me not to worry, yet I feel most guilty.”
Yûsuf, too, was downcast and repentant.
“We have been like fools,” he sighed, “wasting in vanity the precious
hours we might have spent with him—as if we thought that he
would live for ever. Now the end draws near, we can but beat our
breasts and curse our folly.”
When Barakah went to the old palace to inquire, she was struck by
the despairing looks of all the servants. A eunuch with a very woeful
smile conducted her to Fitnah Khânum, who exclaimed at sight of
her:
“The praise to Allah, thou art come! Our lord has asked for thee.
Murjânah was just going to dispatch a messenger. Come! Come at
once! There is no time to lose. He has refused to take a potion
which I had prepared. He will not let a charm be hung upon him. He
resigns his life to Allah. It is the end.”
Murjânah Khânum sat beside the bed, holding the old man’s hand.
About the walls crouched many black-robed women, waiting in
silence, like a flock of vultures.
“Here is the wife of Yûsuf,” said Murjânah, giving place to Barakah.
The Pasha spoke in French. His voice was faint.
“Madame,” he said, “I am about to die, and I am glad to be allowed
to say adieu to you. Very often have I thought of you and of your life
among us. I feel a very grave responsibility. I trust that you have
been, upon the whole, content?”
Barakah declared herself quite happy, and he said, “Thank God!”
“But you will not leave us yet; you will recover,” she exclaimed.
“No, no, my cherished daughter. My last hour has sounded. I have
lived to see my life-work all undone. The Christians always sought a
war with El Islâm. We kept a calm face under insults, even made
concessions, as one gives a rabid dog a stick to worry.” For a
moment the worn face resumed its light of humour. “But now the
war has come.... Those rash fanatics!...”
There rose a murmur in the room.
“The Grand Mufti comes,” announced Murjânah Khânum.
“Forgive me, dear madame. It is an old and cherished friend,” the
dying man suspired, with a faint smile. “Adieu! Adieu!”
And Barakah, with all the women save Murjânah Khânum, hurried
out into the passage. At the door a tall and stately man brushed past
her. His head was so erect beneath the massive turban, his long
robe fell so straight from well-squared shoulders, that it astonished
her to see his beard as white as snow. He passed into the room. The
door was shut.
A minute later, Murjânah Khânum uttered a loud cry; the Mufti came
forth sobbing, with head bowed; the black-cowled women scurried
shrieking to the death-room, where they instantly began the dance
of death. They leapt and pirouetted, waving arms above their heads,
with frenzied cries. Barakah was gazing horror-stricken at the sight,
when some one took her hand and whispered, “Come away!”
It was Murjânah.
“I cannot bear these customs,” she confessed. “The women of the
country keep them in defiance of religion. It is useless to protest;
one has to suffer. I am very tired, my dear; for I have not slept for
many nights. Indeed, my weariness and grief are such that I can
hardly look for rest save in the grave.”
Barakah took coffee in Murjânah’s room, and tried to comfort her.
She too was sad. But her despair was turned to joy when that same
day Muhammad rushed into her arms. He had been called by
telegram. She held him back from her and gazed at him until he
blushed and hung his head. The uniform, the high-crowned fez, the
sword, the snowy gloves, embellished him. When she had gazed her
fill, she made him tell her of the camp, his friends, his duties; and,
started on that theme, he talked for hours.
“If only I could be transferred to the Canal!” he sighed. “That is the
real centre of the war. The fighting where I am is empty show, and I
am kept from taking part in it. Day after day, I have to teach
recruits, dull fellâhîn, who know not right from left. Instruction
seems to make them stupider. I beat and beat them, till my arm
aches. By my sword and valour, I could often kill them! Think, O my
mother!—El Islâm is menaced, armed infidels have set foot in our
land, and these men, Muslims, will not learn their exercises!”
His mother laughed at his impetuosity. She told his grandfather’s last
words to her, and how he feared the English would take hold of
Egypt.
“There is no fear of that, in sh´Allah!” cried Muhammad. “Our
faithful host will sweep them off like fleas. I wish I had been there to
reassure the dear one. May Our Lord have mercy on him!”
The funeral of Muhammad Pasha Sâlih was among the greatest ever
known, although the town was empty. The harassed population
flocked to pay respect to one who had denounced Arâbi—a
demonstration which could not be punished since sons of the dead
man—nay, half his family—acclaimed the tyrant. In the front of the
procession were led sheep and bullocks to be slaughtered at the
tomb, their meat distributed among the needy in the name of the
deceased. Then came hired chanters of the Corân, then half the
male inhabitants of Cairo, walking, flanked by two thin lines of
soldiers, then the male relations, then a choir of boys shrieking an
ode in honour of the Prophet. Immediately behind these moved the
lidless coffin, carried on men’s shoulders, with its coloured pall, and
then the females of the family in shuttered carriages. A crowd of
black-cowled women of the city, whose wailing sounded bird-like in
the open air, brought up the rear.
The train, a mile long, wound out in the blinding sunlight over the
sandhill to the city of the dead, from which at its approach the kites
and crows went up, affrighted. There ensued a period of forced
inaction, which to Barakah in the haramlik at the mausoleum
seemed interminable. The ceaseless chanting in the tomb, the
wailing of the crowd outside, attacked her nerves. Muhammad was
to leave again that evening, and every minute she was parted from
him seemed an hour. He was kept upon the men’s side of the tomb;
nor would she see him till they reached the house again; she had
first to drive home in the stuffy carriage with Na´imah and two of
the late Pasha’s daughters. It was maddening.
In fact, she saw him only for a moment, ere he ran to catch his
train. She wept a little at the disappointment, but his visit had
relieved her of a weight of sorrow. She had only to dispatch a
telegram and he would come again. Moreover, she was now quite
certain he was not in danger.
When told by Yûsuf that her drives must cease, because the horses
had been taken for the army, she did not complain, but hired a
donkey when she had to pay a call; nor could the prospect of a
famine frighten her. Her mind had rest. Each evening brought the
news of an Egyptian victory. The English would be driven out. Her
son was safe. Once more she joked and dreamt with Umm ed-
Dahak.
CHAPTER XXXII
At Kafr ed-Dowâr Muhammad was kept drilling conscripts, relieving
older officers who were required for actual fighting. Almost every
day he heard the boom of cannon, the stirring noises of attack and
skirmish; and often in his leisure moments he would perch in some
high nook and watch the flashes, the white puffs of smoke,
dispersed upon the green of level fields between the sea-coast
sandhills and the lake—a pretty sight. Beyond the plain of water
skimmed by white-winged birds the town of Alexandria basked in
sunlit haze. Upon the land-plain doves were wheeling round
deserted villages, kites and vultures hovered high in air. Franks from
the seaport rode out in the rearward of the English troops, and from
the vantage-point of dykes and hillocks watched the operations
through their field-glasses. The assaults, as he had told his mother,
were not serious; mere “fantaziyeh” the old soldiers called them.
The aim of the assailants was to keep a portion of Arâbi’s troops
from joining the main army on the banks of the Canal, where war
was being waged in bitter earnest. Muhammad fretted at his dull
employment. The atmosphere of strife, the bugle-calls, the march of
men, no longer satisfied him as at first. He wished to fight, and
begged the general-in-chief, who favoured him, being a close friend
of his uncle Hamdi, to move him to some post of danger. The great
one laughed and patted him upon the back.
“We cannot spare thee yet from the recruits,” he said. “That work is
useful, and it must be done. Think, thou hast given us a thousand
soldiers, none like them for rigidity and speed of motion.”
Muhammad hated the recruits, who still were driven in by hundreds
every day—men past their prime, and boys dragged from the
wretched villages, and active rogues caught hiding in some ditch or
patch of cane. The land had been already drained; the dregs were
called for. And they were stupid, dazed, those fellâhîn; a flock of
sheep has more intelligence! Muhammad, for whom soldiering was a
religion and every detail of the drill had sanctity, was driven frantic
by their apathy, their foolish stare. Dancing with fury, he reviled their
mothers and beat them with his cane about the ears.
“By the Prophet, they are pigs!” he told the son of Ghandûr, who
served him in his tent and hung upon his every word. “Here is El
Islâm in danger; they are Muslims; yet they yawn and gape if asked
to hold a gun. Ah! if I had a hundred Turks instead of them!”
The son of Ghandûr, who to please Muhammad would himself have
put his head into a cannon’s mouth, was horrified at the behaviour
of the conscripts. That they could fail to see the light of inspiration
on Muhammad’s brow was proof sufficient of their utter baseness.
For the same reason he despised the generals. Muhammad was
more gifted for command than they, and yet they kept him ever at
this menial task. Had Muhammad—or his foster-brother even—
owned the leadership, Iskenderîyeh would long since have fallen,
and all the English have been pushed into the sea. He dared to
proffer this opinion to his lord one evening. But Muhammad in his
wisdom answered:
“No, we cannot take the town, for this good reason, that a portion of
their fleet, unseen from here, commands it, and would pour in shells
to our destruction.”
Ali received this information with head bowed and thanks to God. He
prayed the Maker of the World to put some mind in the recruits in
order that they too might profit by such high instruction.
It was usual at that time for officers to handle soldiers roughly on
parade, caning them upon the head and shoulders, kicking them,
and heaping on them every species of abuse. Muhammad might be
called indulgent as commanders went; but he was over-much in
earnest. His outbreaks lacked the touch of humour which endears.
Old soldiers might have borne them with a laugh for the sake of his
enthusiasm, which was very evident.
But these were men who had been driven from their homes like
cattle, at the goad’s point. For days they had been herded up in
pens in a provincial town, and there harangued by holy men and
maddened by religious shouting till they lost what little wits
remained to them and hardly knew a true believer from an infidel.
Arâbi had proclaimed the golden age; yet here they were
imprisoned, hounded, driven, and now subjected to the cuffs and
insults of a shameless boy. Huddling together, they looked on with
lowered brows, too scared to understand what the young Turk was
shouting. Arâbi had proclaimed the Turks abolished. Where was
reason? They gave forth inarticulate harsh cries like frightened
beasts.
Each squad Muhammad handled seemed more stupid than the last—
so stupid that one early morning an inspecting general advised him,
laughing, to give drill a rest, and take them to the trenches; they
were used to digging.
Muhammad felt the order as a whip-cut; he was furious. The general
despised his work as an instructor, whereas God knew what trouble
he had taken. It was all their fault. In the trenches he allowed them
to do nothing right, but shrieked out contradictory orders
emphasized by slashes of his cane. Slowly it dawned on them that
he was quite alone; the place was hidden by high banks from
supervision.
The daily pageant of attack was then in progress. The crackle of a
volley came from no great distance. Muhammad implored Allah to
direct the bullets so as to kill them all, for they were worse than
infidels. He did not notice the changed manner of their breathing,
nor the new fire which smouldered in their eyes.
At a blow across the face, accompanied by frightful insults, a burly
fellow seized Muhammad’s wrists and deftly tripped him. The boy lay
on his back bereft of speech. His captor knelt upon his belly, while
the others crowded round like cattle interested. He could feel their
breath.
“Hear, O my little son! Swear by the Sayyid Ahmad to be civil. It
were best for thee.”
Muhammad, with his pride undaunted, answered: “Sinful hog! I
swear to have thee thrashed with the nailed whip and then
decapitated. O Muslimîn! Do you not know that this is mutiny, an
awful crime?”
“Then we must finish him,” remarked his captor, with a sigh. “With
his own sword! Here! Quickly, while I stop his screeching.”
The speaker pressed his hand down on Muhammad’s mouth, while
another drew the sword and plunged it several times into the
prostrate form. They watched until the last convulsions ceased; then
piously observed: “Our Lord have mercy on him! There is no power
nor might save in Allah, the High, the Tremendous!”
“By Allah, he could bite!” observed his first assailant, shaking blood
from his right hand. The palm was bitten through. He stopped to
bandage it; and then they made a litter with their spades and so
conveyed the body back to camp with wailing.
“The darling of our souls is dead,” they chanted. “Slain by the
infidels, whom we repulsed. Our brother, Abdul Câder, too, is
wounded in the hand.”
The lie was quite transparent, yet it passed unquestioned. The high
commanders shrugged and let it go. There were a hundred men
concerned, with Allah knew how many sympathizers. They dreaded
a stampede of all the conscripts in the camp.
When Ali, mad with grief, demanded justice, he was told to hold his
tongue. The general was profoundly grieved; he shed some tears,
and swore that every honour should be paid to the remains. A
telegram was sent to Yûsuf Pasha announcing that his son had died
a martyr, and that the blessed body was upon its way to Cairo.
Within an hour of death it had been dressed for burial. It was carried
in a fine procession to the railway, where a special train—a
locomotive and an open truck—was waiting. The corpse was laid
down in the truck, and covered with some tent-cloth; and Ali sat
beside it, while the train sped hooting on past empty villages, where
only a few children played upon the dust-heaps, a few women stood
in doorways with hands shading eyes, past palm-groves and the
fields of cotton and of sugar-cane until the citadel rose up before
him in the evening sky.
CHAPTER XXXIII
The news was broken gently to the stricken mother. Yûsuf,
overcoming his own grief, came in at noon and sat an hour with her,
leading her up by little steps to view the glory that their son had
died a martyr for the Faith. When the announcement came at
length, the fortitude he had assumed gave way. He wept profusely.
But Barakah was tearless. She sat rigid, with pale eyes staring
vaguely in a face of stone. She asked that Ali, as soon as he arrived,
might be sent in to her; and that was all. Umm ed-Dahak came and
mumbled on her hand, moaning endearments which she did not
hear. Then Ali was announced. At the same instant dreadful wailing
filled the house. She drew her head-veil round her face (the
movement had become instinctive) when he fell before her, pouring
forth his awful story, concluding with the words: “The funeral sets
forth this minute, O my lady. His body will not keep with all those
wounds.”
And then her anguish passed the bounds of suffering; she moved
and looked and spoke, but felt no more.
Her women, half demented, danced around her. They tore their flesh
with finger-nails, defiled their faces, and raised an endless chant,
reviewing all the charms and virtues of the dear one, his mother’s
love, the blackness of the world, each verse concluding with a shriek
of “O calamity!” It was the triumph-song of death.
Robbed of the corpse, the funeral over, they thronged her chamber,
keeping up the ghastly round, the death-chant, in the hope to give
her tears. Her petrifaction filled them with dismay. To women who
accept with rapture all life’s chances, whose custom is to celebrate
each blow that strikes them and magnify it as a witness to the
power of God, her stony apathy appeared uncanny. They increased
their efforts, while Umm ed-Dahak poured into her ear a song of
memory designed to loose the frozen fountain of despair.
“She was the fairest daughter of the seed of Adam. See her now!
Her feet, her finger-tips dropped perfume. She had the grace of
flowers, the voice of turtles. Now behold her! In a moment blind and
deaf and dumb and paralyzed. And why? Alas, O thou who askest! it
is because the sunshine of her life is fled. We saw her follow his
dead body to the grave. As the cow pursues the calf that has been
reft from her, so did she follow blindly with a noise of lowing. She
has not even strength to beat her face. Her breath is painful, husky
like the voice of doves; its sound is all the sobbing of the childless
mother. Say, O beloved, what is in thy mind? Dost thou remember
his tarbûsh, his yellow slippers, the loveliness of all that touched his
body, which was perfumed amber? There was a little mole upon his
breast well known to thee. O Allah, waken memory, or grief will slay
her!”
Barakah saw and heard as in a trance. She thought herself in Hell,
bound fast and gagged while devils taunted her. She was tortured by
the memory of English winter evenings, of walking back from church
in the long train of orphans, the patter of their feet resounding sadly.
That dreariness appeared a state of bliss compared with this
luxurious life enclosed in heat. She longed for a cold wind, with rain
in it. Remembrance of a garden under sunset came to her; she saw
once more a cool verandah with long windows open on an English
drawing-room, and heard the earnest voice of Mrs. Cameron
entreating her to stay and save her soul. This was God’s
punishment. Her life from then till now had been all frowardness and
self-indulgence. While basking in it she had been aware that it was
baneful. A thousand awful faces rose to sneer, “We warned you!”
The glimpses she had had of horrid depths, the scenes of bloodshed
and the tales of cruelty, seemed now emphatic warnings of this end.
She had sunk downward till she had no faith nor virtue more than
beasts have. Her all was in her son, whom God had killed. Crushed,
maimed, defrauded, she was flung upon the earth, the scorn of men
and angels and the sport of fiends.
As by degrees her sense returned to her, she looked about her with
strange eyes and tried to think. But every effort was a sword that
pierced her heart. One morning, peering dully through her lattice,
she saw a gay pavilion in the yard, and leading to it rows of masts
with lanterns hung between. They were erected for the meytam, or
reception for the dead. She had seen them often when she visited
great houses; but now her mind attached no meaning to them. It
was two hours later, in the middle of the function, that her sense
returned. A mighty gust of grief, a cry of “O calamity!” swept
through the crowd of black-clad women in her great reception-room.
It roused her mind. She saw, and was alarmed. What was she
doing? What was all this crowd of people? Were they human?
The great saloon was full of women. The ladies sat up on the dais
with flourished handkerchiefs, beating their breasts, their faces, at
each burst of woe. Dependants crouched upon the ground and
rocked incessantly, with foaming lips. Some faces wore a hideous
fixed grin; some mouthed continually. The hired performers stood
and chanted with obscene contortions, or squatted on a mat and
wailed in chorus. The words “O my calamity,” recurring in a sort of
running chant without coherence, shook the assembly like a
tempest-blast. And all the while dainties were being handed round
by weeping servants, and accepted by the mourners as fresh cause
for grief.
An ague of intense repugnance seized on Barakah. She felt that she
must fly from this inferno, must keep the hope of flight before her
resolutely, or her soul was lost. It was as if a hostile hand
compressed her throat. She struggled, was determined to get free.
Towards that end she battled with instinctive cunning.
After the meytam, when she seemed exhausted, her brain,
enamoured of this hope, was planning madly.
“Take heart, O moon of moons,” the servants told her. “In sh´Allah
thou shalt bring forth sons instead of him.”
She strove to smile.
Her resolution was to leave her husband and her little daughter, the
comfortable house, the easy life, to stray alone and homeless, back
to Christian lands. There she would enter some religious order, and
spend the residue of life in prayer for Muslims.
Every one was kind. The tender sympathy of Yûsuf, though himself
hard stricken, might well have won her heart had she possessed
one. Her heart was dead and buried in the grave. The ladies and her
servants tried at first to cheer her; but when they found their efforts
useless, let her be. Only Umm ed-Dahak remained with her
constantly. Discreet as ever, she kept silence for long hours,
watching her mistress with a doleful mow. They thought her too
depressed to take a step unaided, had not the least suspicion of her
wish to flee. It was, besides, a time of national anxiety, when every
one who could went out to seek the news, and those imprisoned
listened to the noises of the street.
One day, in the full heat of noon, when men are sleepy, she sent out
the old woman on an errand; and went and kissed her child, Afîfah,
who was fast asleep. Then, having made sure that the slave-girls
were not moving, she returned to her own room and donned a
common habbarah, which she had sometimes worn when she went
out with Umm ed-Dahak. From the store of money Yûsuf had
entrusted to her she took sufficient to defray her fare to France, and
hung it in a bag around her neck.
Thus furnished, she stole out through the selamlik hall. No eunuch
challenged; the doorkeeper was snoring on his couch within the
entry. Beside him lay the best part of a water-melon.
CHAPTER XXXIV
Barakah had not made many steps outside the house before she was
completely lost. Although for sixteen years her home had been in
Cairo, she had never walked in the streets before. Which was the
way? She could not tell, but went on bravely, hoping for some guide.
At last she met a donkey-driver with a pleasant face. In answer to
her timid hail, he smiled delighted and praised his Maker for the
honour of her patronage. “To the railway station,” she enjoined at
mounting, and he answered “Ready!”
Away they went, arousing echoes in the stony alleys, the driver
shouting as he ran beside the ambling beast. Barakah felt
exhilarated by the change of motion, the little spice of danger when
they dashed round corners, or charged some group of wayfarers
with warning cries. The first stage of her flight would soon be over;
and once on board the train, she thought, escape was sure.
The streets were empty even for that hour. Scavenger dogs slept
undisturbed in every spot of shade. The persons they encountered
seemed to have no business, but stood about in groups conversing
glumly. On the wide, dusty square before the railway station groups
were many. A little crowd beset the station doors. These were all
closed, to Barakah’s amazement. The building looked deserted.
“Ask when the next train starts for the sea-coast,” she ordered her
attendant, who addressed a shout to persons standing near.
“The sea-coast? Allah knows! It may be never!” The reply was
shrugged. “A great fight has taken place. The end has come. The
English fell upon the camp at daybreak—yesterday or this morning,
Allah knows! The rebel army was dispersed like chaff. The leader—
the arch-traitor—escaped hither on an engine, and is in the town
now somewhere, herding with his kind. It is clearly seen how foully
he deceived us, seducing us from our allegiance with the promise of
success.”
“Praise be to Allah that his reign is ended,” said another. “If the
English were but true believers, one would bless them.”
“Nay, the tidings are not certain,” cried a third with anguish.
“As certain as the sun is hot upon my reins this minute. I have it
from a man who saw Arâbi. The rascal’s face was yellow as a
corpse.”
Barakah’s mind received no more than the initial statement. The way
that she had meant to take was closed against her.
“Whither, my lady?” asked the donkey-boy, with willing smile.
“Far, far away—towards the sea-coast. Anywhere!”
“Ready!” he laughed. “It is for thee to order. By Allah, we will go to
Gebel Câf if thou desire it.”
He smote his donkey, and they jogged along once more, out through
new suburbs to the open fields. The sun was an armed foe, the dust
a persecutor; her habbarah and face-veil made a sheath of fire. The
donkey-boy kept looking at her with compassion, smiling
encouragement whenever he could meet her gaze. He thought her
mad, and so indulged her fancy, assuring her that it would not take
long to reach the sea. But when she murmured of the heat and
wished to rest, he showed immense relief.
“That is the best,” he cried. “Wait till I find some pleasant shade for
thee. See, yonder is a tree. There thou shalt rest till the great heat is
past, and then, at thy command, we can resume the journey.”
Dismounting under leaves, she sank upon the ground and wept
despairingly. The tears, which bitter grief had failed to wring from
her, flowed freely for her impotence. Escape was hopeless. Her
project now appeared the last absurdity. The change of clothes, the
change of manners, now presented difficulties which she felt that
she would never have the strength to overcome. The donkey-boy’s
consoling words, his friendly grin, were teasing. She sent him to
fetch water from a village near at hand. He came back with a pitcher
and two slabs of bread; which so revived her spirit that she once
more saw beyond the moment and conceived a plan.
She would wait till nightfall and then seek the city of the dead, to die
on her son’s grave, if Allah willed it. At least she would spend all the
night in prayer imploring Allah’s mercy for him in the name of Christ.
She had sat a long while, cross-legged, gazing straight before her,
her hands locked in her lap, when a soft voice disturbed her. The
donkey-boy was plucking at her sleeve.
“The heat is spent,” he told her. “Best be moving! It is back into the
city,—not so?—thy command? Much better than to journey to the
sea, like this, without provision. Say, which way?”
Barakah pointed a direction listlessly. She had no wish to enter Cairo
before dark, so chose a long way round, among the fields.
Soon the sunset reddened all the plain, stretching their shadows far
before them on the dyke. The citadel upon its height was hotly
flushed one minute, the next ash-grey and lifeless like a skull. It
lived in her imagination as a monstrous spider which held her with
its web and drew her in.
The donkey-boy beside her prattled ceaselessly.
“O lady, I will not forsake thee—no, by the Prophet, never, till thy
mind is healed. Do I know the cemetery El Afîfi? Wallahi! I can guide
thee thither. Not a bad idea; for Allah comforts those who visit the
deceased. By the Sayyid Ahmad, thou art as my mother. May God
cut short my life if I desert thee in thy present state.”
The lad’s support was of some comfort to her.
In the first blue of night, when daylight lingers in the memory, they
were following a sandy road towards the city, when a noise as of the
sea arose behind them. The donkey-boy was first to hear it. He
stood still and listened, holding up his hand. It seemed approaching
on the road behind them. He looked puzzled; then suddenly let fall
his hands, and made a bound.
“It is the army! Come, O my lady! We must hide ourselves. Hold
fast!” He made the donkey gallop for a hundred yards, then led it
down into a patch of cane. Peeping out between the stems they saw
vague forms in clouds of dust approaching on the dyke above. The
roar became the jangle of accoutrements, the roll of heavy carriages
upon the road and murmuring voices.
Innumerable ranks of horsemen passed, dust-stained and weary,
with faces resolutely strained towards Cairo. Barakah saw them as
the figures of a dream. Their silhouette against the sky appeared
familiar. The words with which they cheered their tired horses rang
on memory.
“It is the English,” whispered her companion hoarsely.
“The English! Allah, help me!” murmured Barakah. Until that
moment she had lost remembrance of the war.
CHAPTER XXXV
The streets by night were full of people, in striking contrast with
their emptiness at noon that day. The mosques were all alight inside,
and from the glimpse which Barakah obtained through open
doorways appeared crowded.
She saw men making towards them through the press, embracing
precious bundles, with the look of fugitives.
“Their fear is of the English,” said the donkey-boy. “Who knows what
they will do by way of punishment?”
But the look on all the faces when a ray of light revealed them, the
note of the vast murmur lapping the whole city, was rather of relief
and comfort than anxiety. To hide away their treasures was a mere
precaution which only madmen would neglect in presence of a
conquering host; but men were thankful for the coming of the
English, which meant an end to anarchy and wild suspense.
“Wallahi, they are warriors,” one orator was declaiming at a street
corner. “The fight was far away at daybreak, and now behold them
here among us in the citadel. Wallahi, they are mighty! They smite
hard—one blow and all is said. Wallahi, they are not of those who
loiter. They appeared among us like a vision of the rising night; they
demanded the keys of our strong places as of right divine. The
people in the street stood still and gaped on them, rubbing their
eyes to ascertain that they were not asleep. May Allah make them
merciful. The praise to Allah!”
The donkey-boy, who had been looking at the lady’s eyes at frequent
intervals as if in expectation of a change of purpose, asked at
length:
“Whither shall I conduct thee, O my mistress? Is it not thy wish to
return to the house?”
“I have no house,” was her reply. “Did I not tell thee? To the El Afîfi
cemetery!”
“Not by night! Hear reason, O my lady!” he besought her. “Tell me
where thou dwellest, that I may conduct thee thither!”
“I go to the cemetery, as I told thee. It is necessary. If thou art
weary of my service, I will pay thee and go out alone.”
Barakah’s tone grew plaintive, almost tearful. The resolution in her
words was mere bravado. She knew that she was utterly dependent
on this friendly youth, whose company alone kept up her courage.
From the moment of her turning back she had felt stupid, useless,
relying on this boy to bring her to the cemetery, where she hoped to
die. It seemed a certainty that if she prayed her utmost, full as her
heart was, the vexed soul must leave the body, and the prayer by
sheer brute force become acceptable. At thought of being baulked of
her self-sacrifice, the boy’s help failing, she began to whimper.
“Nay, dearest lady, weep not!” he entreated. “By Allah, thou shalt
neither walk nor go alone. I will conduct thee thither; but it may be
necessary that we wait till morning, since the way is lonely and the
haunt of ginn. See here, before us is my mother’s house. Deign to
go in and rest awhile, and take refreshment, while I feed the
donkey. I will make inquiries. If it is possible to go to-night, I swear
to take thee. If not, thou canst rest here until the dawn.”
They had stopped before a doorway in a narrow alley. He went a
little way into the gloom and whispered:
“O my mother!”
“Is it thou, Selîm?” came back the answer.
“O my mother, come at once! I have a lady, a great lady in disguise.
She has run mad through grief in these bad times, and wants to go
out to the cemetery. Receive her in thy house a minute, feed her,
talk to calm her; while I discover if the way is safe.”
“The cemetery! Go not thither. Best come in and sleep.”
“The lady is distraught with grief. I reverence her like a parent. She
is absent from the world; she does not hear us. I think that she is
going to the tombs to pray. It were a good deed to conduct her
thither.”
“True, wallahi! May Allah heal her soul, the poor one! These be
dreadful times!”
A woman came out to the doorway, holding up an earthen lamp.
“Deign to enter, O my sweet,” she called seductively.
Selîm assisted his employer to dismount.
“Go in and rest,” he whispered. “My mother and my sister are alone
in there. Thou canst unveil. The dwellings of the poor are all
haramlik. In a little while I shall return and call thee from without. I
go but to make sure the ways are safe.”
The room in which she found herself was small and stuffy. It was
lighted only by the little lamp the woman carried. Barakah was glad
to loose her veil awhile. She refused the food, but drank the water,
which the women offered, and listened to their cordial blessings with
a sense of dreaming. Her prayer was that the boy might not decide
to wait till morning. Desire to reach the tomb at once absorbed her
life. Deprived of it, she would have had no further being. Her prayer
now took the Christian form, and now the Muslim; the two religions
growing tangled in her tired mind. At length the boy’s voice
sounded:
“Deign to come, O lady. The ways are thronged, they tell me, as in
Ragab. To-night is not as other nights, it is well seen.”
With praise to Allah she went out once more. But with its object now
assured, her mind grew dull. It was as if suspense alone had held it
wakeful. It lost the comprehension of its purpose, regained it with an
effort, and then let it go.
They passed beneath an ancient gateway. The city was behind them.
Still there was no solitude. Groups of people crossed the sand in all
directions. It was a moonless night. The many lanterns moving in
the darkness seemed reflections of the stars which shone like gems
of many facets in the silky sky. Barakah saw them both alike as
golden insects swarming in the cup of a great purple flower. At
moments, her head swimming, she mistook the earth for sky, and
had the sense of moving upside down.
“There is the cemetery,” said her guide. His whisper seemed to her a
long way off. Nor did she see the city of the dead till they were in its
streets, which loomed mysterious. The very stars looked sinister
above the frowning domes, from which a blacker darkness seemed
to emanate. The many crescents looked like horns against the sky.
Bats flitted past her; from the distance came a jackal’s howl. What
had she come to do there? She could not remember. “To pray,” she
told herself, but that meant nothing. She strove with all her might to
recollect. Then in a flash remembrance came to her; it bore her on,
excited, to the mausoleum. She dismounted, and then, upon the
threshold, she forgot once more. She entered, shuddering, too
dazed to question why the gate was left ajar, and turned instinctively
towards the women’s quarters. A step or two and she stood still in
deadly terror, hardly venturing to breathe. There was a light upon
the men’s side; beasts were tethered in the court; she heard a
sound of digging and men’s voices. Her thought was, “They expect
me, and have dug a grave.” As soon as fear would let her, she fled
back to where the guide was waiting.
“There are people. We must fly! Make haste!” she whispered.
He helped her to remount, and they retraced their steps. The solemn
thoughts which had possessed her mind gave place to rattle of dry
bones and impish laughter. A merry dance was going on within her
brain, as mad as could be, though her senses were quite clear—
clearer than ever they had been before, she knew exultantly. She
rode out from the place of tombs across the sandhills towards the
city.
“Hist!” said her companion suddenly, and stopped the donkey,
hanging on to its tail to prevent braying. “There are men without a
lantern—robbers! I hear voices.”
She strained her ears in the direction pointed.
“Am I not acknowledged sheykh of all the thieves?” some unseen
man amid the darkness was exclaiming angrily. “Was it not I alone
who had the wisdom to foresee that every man would seek to hide
his wealth this night? It is light work for you; they fly like conies at a
shout, leaving their treasure, and the light for you to count it. Why
then grumble that I sit here and receive the gold? Some one must
hold it for fair distribution. Say, have I ever wronged a man among
you of one small piaster? See, yonder comes another lantern. Go, do
your work, and say no more to me.”
“Stay, O my lady! For the love of Allah,” moaned Selîm. “They are
robbers, murderers, the worst of ruffians.”
But Barakah had urged the donkey forward; the laughter in her brain
deriding fear. She headed straight towards the voices, waving her
left arm and shouting madly. She heard a shriek of “The afrîtah!
Help, O Allah!” and saw men running as if fiends pursued them. Her
next sensation was a dive into the sand. The ass had stumbled.
Selîm assisted her to rise, and murmured reassuring words which
made her cry.
Remembrance of her little daughter overcame her. She had prayed
to Christ to guard her child before she recollected that the prayer
was useless. There was no mercy for disciples of the Arab prophet.
She reeled and would have fallen had not Selîm caught her. As it
was, she sank upon the ground, refusing to remount or take another
step.
The boy, resigned, sat down beside her, holding his donkey by the
halter-rope. They were upon the trodden plain below the citadel.
Lying upon her back, she saw a blackness rising till it took the shape
of bastions, walls, towers, surmounted by a dome and needle-
pointed minarets. Gazing at this and at the stars she fell asleep.
When she awoke it was still night. The donkey-boy was snoring on
the ground hard by. A chill and a strange silence hung about her.
The stars above were throbbing violently as if about to burst in
showers of light. Her grief returned upon her like an ague. “O Lord,
have mercy on me!” she exclaimed, and groaned aloud.
“What ails thee, O my sister?” said a voice so sweet, so unexpected
in its nearness, that it stopped her heart.

You might also like