100% found this document useful (3 votes)
8 views

Programming in Java Sachin Malhotra pdf download

The document provides information about the book 'Programming in Java' by Sachin Malhotra and Saurabh Choudhary, detailing its content, features, and updates in the second edition. It covers Java programming concepts, including object-oriented principles, advanced topics, and practical examples, while also offering resources for students and instructors. The book is aimed at undergraduate and postgraduate students in computer science and engineering, as well as professionals seeking to enhance their Java skills.

Uploaded by

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

Programming in Java Sachin Malhotra pdf download

The document provides information about the book 'Programming in Java' by Sachin Malhotra and Saurabh Choudhary, detailing its content, features, and updates in the second edition. It covers Java programming concepts, including object-oriented principles, advanced topics, and practical examples, while also offering resources for students and instructors. The book is aimed at undergraduate and postgraduate students in computer science and engineering, as well as professionals seeking to enhance their Java skills.

Uploaded by

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

Programming in Java Sachin Malhotra pdf download

https://textbookfull.com/product/programming-in-java-sachin-
malhotra/

Download more ebook from https://textbookfull.com


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

Java Programming Joyce Farrell

https://textbookfull.com/product/java-programming-joyce-farrell/

Java Programming Joyce Farrell

https://textbookfull.com/product/java-programming-joyce-
farrell-2/

Computer Graphics Programming in OpenGL with Java


Gordon

https://textbookfull.com/product/computer-graphics-programming-
in-opengl-with-java-gordon/

Murach s Java Programming Joel Murach

https://textbookfull.com/product/murach-s-java-programming-joel-
murach/
Learning Java An Introduction to Real World Programming
with Java Marc Loy

https://textbookfull.com/product/learning-java-an-introduction-
to-real-world-programming-with-java-marc-loy/

Learning Java Beginning programming with java for


dummies First Edition John Bach

https://textbookfull.com/product/learning-java-beginning-
programming-with-java-for-dummies-first-edition-john-bach/

Java Network Programming Fourth Edition Harold Elliotte

https://textbookfull.com/product/java-network-programming-fourth-
edition-harold-elliotte/

Java Performance In Depth Advice for Tuning and


Programming Java 8 11 and Beyond 2nd Edition Scott Oaks

https://textbookfull.com/product/java-performance-in-depth-
advice-for-tuning-and-programming-java-8-11-and-beyond-2nd-
edition-scott-oaks/

Introduction to Programming in Java An


Interdisciplinary Approach 2nd Edition Robert Sedgewick

https://textbookfull.com/product/introduction-to-programming-in-
java-an-interdisciplinary-approach-2nd-edition-robert-sedgewick/
Programming in
Java
Second Edition

SACHIN MALHOTRA
Associate Professor
IMS, Ghaziabad

SAURABH CHOUDHARY
Formerly, Head
IT Department
IMS, Ghaziabad

1
3
Oxford University Press is a department of the University of Oxford.
It furthers the University’s objective of excellence in research, scholarship,
and education by publishing worldwide. Oxford is a registered trade mark of
Oxford University Press in the UK and in certain other countries.

Published in India by
Oxford University Press
YMCA Library Building, 1 Jai Singh Road, New Delhi 110001, India

© Oxford University Press 2010, 2014

The moral rights of the author/s have been asserted.

First Edition published in 2010


Second Edition published in 2014

All rights reserved. No part of this publication may be reproduced, stored in


a retrieval system, or transmitted, in any form or by any means, without the
prior permission in writing of Oxford University Press, or as expressly permitted
by law, by licence, or under terms agreed with the appropriate reprographics
rights organization. Enquiries concerning reproduction outside the scope of the
above should be sent to the Rights Department, Oxford University Press, at the
address above.

You must not circulate this work in any other form


and you must impose this same condition on any acquirer.

ISBN-13: 978-0-19-809485-2
ISBN-10: 0-19-809485-X

Typeset in Times New Roman


by Sukuvisa Enterprises
Printed in India by Yash Printographics, Noida 201301
Dedicated
to
Our Parents
About the Authors

Sachin Malhotra is currently Associate Professor in the IT department of IMS Ghaziabad. He has more
than a decade long experience in mentoring students on developing Java applications as well as training
practising professionals in the field of Java. He has also designed and conducted various corporate
trainings in Java and networking.
Saurabh Choudhary is currently a practising IT consultant and corporate trainer. He has more than 12
years of experience in industry, academia, and consultancy. He has worked on positions of eminence
at IMS Ghaziabad as Head of IT department and Dean Academics (University Campus). His areas of
expertise include Java, Database Management System, and Information Systems.

Testimonials
From pervasive computing to communications industry, medical science to aerospace, Java is
gaining a foothold in every domain. Programming in Java has been written to arouse the interest
even in a novice computer programmer to an expert, craving to sharpen his programming skills.
Pankaj Verma | Senior Software Engineer | OSI Inc.
It is definitely the best textbook on Java that I have run into. I highly recommend it.
Sachin Dhama | Team Lead | Accenture
Java is a very powerful language for developing enterprise applications. I am hopeful that this
book will provide a basic building platform for Java programmers to enhance their knowledge.
Awadhesh Kumar Katiyar | Technical Lead | HCL Technologies Ltd.
Java enables users to develop applications on the Internet for servers, desktops computers, and small
handheld devices. The future of computing is being influenced by the Internet, and Java promises to
play a big part in it. This book is perfect for those who are seeking a clear understanding of Java. It
should allow the readers to create codes that are a lot clearer and are far more effective than before.
Saurabh Moondhra | Sr. Technical Consultant | SGT Inc
This is the most interesting Java programming book for beginners; at the same time, it is equally
good for intermediate readers as well. This should be your first Java book if you are learning
from scratch.
Pankaj Jain | Senior Manager | Bank of America
When you go through this book, you will gain confidence after completing each chapter. The
authors have written it in such a simple way covering each and every aspect of Java that anyone
can learn how to develop effective codes.
Rajeev Varshney | Lead Consultant | HCL NZ Ltd.
Preface to the First Edition

Java was primarily designed as a platform-independent language for usage in small consumer
electronic devices. It was derived from C++ but with a lot of difference. Java’s platform
independence originally addressed the problem that applications for embedded devices must
run on a wide variety of hardware. But since the Internet was emerging at the same time, Java
soon got adopted as an Internet language because of its portable nature. Major Internet browsers
such as Netscape Navigator and Microsoft Internet Explorer became Java-compatible, as it
effectively addressed the concerns for security by providing a firewall between web applications
and the computer. Eventually it became a standard programming language and is now being
used for creating a variety of applications including standalone applications, web applications,
enterprise-wide applications, and mobile games.
It can therefore be inferred that since its inception, Java has emerged as the most important
programming language. As the domain of Java is quite vast and a bit more complex than other
programming languages such as C, C++, and Visual Basic, it is observed that students and novice
programmers strive hard to comprehend its core concepts. Hence, a need for a book in this area,
which is both concise and simple, is a necessity.
About the Book
The book encapsulates the concepts of the latest version of Java, i.e. Java 6, encompassing a
comprehensive coverage of curriculum and industry expectations. It is useful for the students of
undergraduate and postgraduate courses of computer science and engineering and information
technology disciplines as well as for the instructors at various levels.
The book provides a thorough understanding of the basic concepts of object-oriented
programming principles and gradually moves on to the advanced concepts in Java. It includes
numerous examples, line-by-line description of examples, figures, explanation of concepts, and
key notes. Review questions and programming exercises are included as chapter-end exercises
to assess the learning outcomes. Every topic in the book is supported by examples followed
by an output and explanation. It also offers an appendix on general interview questions which
provides students an insight into the current requirements of the industry and allows them to
prepare accordingly.
The main features of this book include the following:
  an exhaustive coverage of Java features such as operators, classes, objects, inheritance,

packages, and exception handling


  comprehensive discussion on the latest features of Java such as enumerations, generics,

logging API, console class, StringBuilder class, NetworkInterface class, and assertions
  latest features combined with core concepts such as multithreading, applets, AWT, and

swings
  an introduction to the advanced concepts in Java such as servlets, RMI, and JDBC
Preface to theLab
Appendix A: Lab Manual—Java First Edition XIxi
Exercises

ACKNOWLEDGEMENTS
Several people have been instrumental throughout this tiring yet wonderful journey. First of all,
we would like to express our sincere gratitude to our families without whose support, patience,
and cooperation, this would not have been possible and we would not have been what we are
today. We are very thankful to Dr R. K. Bharadwaj, Head of our institution, for his inspirational
thoughts which inculcated urgency for writing this book. We are also thankful to our colleagues
for their endless support and suggestions during the entire process of writing this book.
Sachin Malhotra
Saurabh Choudhary
Preface to the Second Edition

Java is an easy-to-learn, versatile, robust, portable, and secure language with rich user interfaces.
It has set up new benchmarks in the software development world ranging from desktop to web-
based enterprise applications to mobile and embedded applications. Since its inception in 1995,
it has come a long way by continuously evolving itself and in the process, changing the style of
programming the world over. Java is not only found in laptops or data centres, it is also widely
used in cell phones, SIM cards, smart cards, printers, routers and switches, set-top boxes, ATMs,
and navigation systems, to name a few. According to Oracle, a staggering 1.1 billion desktops
and 3 billion cell phones are based on Java.
This second edition of Programming in Java confirms to Java Standard Edition 7, the latest
release since Oracle took over Sun Microsystems. It is significant in the sense that the last update
was six years back and this major release comes bundled with plenty of enhancements which were
overdue. To list a few noticeable enhancements, Java 7 includes support for strings in switch and
try-with-resources statements, improved multi-catch, binary numeric literals, numeric literals
with underscores, new APIs in NIO such as path and files, automatic resource management, and
much more. All the new topics are appropriately explained with suitable examples.
New to the Second Edition
This revised edition has been updated thoroughly with greater topical coverage as well as more
programming examples in every chapter, in addition to the confirmation to Java 7. Practically
every chapter, with the exception of Chapter 11, has been revisited to refine the text as much as
possible. The most noticeable changes are as follows:
  New practical programming examples to show how Java is used in practice.

 Enhanced coverage of servlets and JDBC along with an introduction to JSP, Java beans,

Jar files and enterprise Java beans


 Enhanced coverage of swing components like JTree, JTable, layered pane, JDesktopPane,

internal frames, JColorChooser, JFileChooser, and JEditorPane


 New classes of java.nio package and project coin language enhancements

  Enhanced coverage of utility classes

 Appendix B contains more interview questions to help students prepare for their interviews.

 The second edition is supplemented with a rich online resource centre that contains chapter-

wise PPTs for teachers and additional practical programming examples for students.
Key Features
The most prominent feature of this book has been the line-by-line explanation section under
each program. They facilitate in-depth understanding of the whole program. We have retained
this feature in the second edition as it has been well appreciated by the users. Other noticeable
features include the following:
Preface to the Second Edition vii

  A recap of object-oriented programming concepts before introducing the concepts of Java


 Plenty of user-friendly programs and key notes at appropriate places to highlight important
concepts
 A variety of end-chapter exercises that includes subjective as well as objective questions
Extended Chapter Material
The second edition includes the following changes:
Chapter 1, Introduction to OOP: Enhanced coverage of UML and its application in pictorial
representation of OOP concepts.
Chapter 2, Getting Started with Java: New sections about the features of Java 7 and how
to install JDK 1.7.
Chapter 3, Java Programming Constructs: Numeric literals with underscores, binary
numeric literals, and how to use strings in switch statements.
Chapter 4, Classes and Objects: New topics such as inner classes, variable length arguments,
arrays as return values from methods, and objects as arguments to and return type from methods.
It contains a practical problem on complex numbers to demonstrate how OOP concepts can be
put to practise.
Chapter 5, Inheritance: New section that highlights the differences between shadowing and
overriding. At the end of the chapter, there is a practical programming example on circle and
cylinder class.
Chapter 6, Interfaces, Packages, and Enumeration: Practical problem on banking concepts
to demonstrate the usage of packages in creating applications.
Chapter 7, Exception, Assertions, and Logging: try-with-resources and catching multiple
exceptions features which are new enhancements of Java 7.
Chapter 8, Multithreading in Java: Concrete practical example to show the use of threads
in applications.
Chapter 9, Input/Output, Serialization, and Cloning: New classes included in java.nio
package and how to perform cloning of objects.
Chapter 10, Generics, java.util and other API: Utility classes like Random class, Runtime
class, Observer and Observable and reflection API.
Chapter 12, Applets: how to use threads and images in applets. The practical problem at the
end of the chapter explains how to display a digital clock.
Chapter 13, Event Handling in Java: Practical programming example that explains how to
create a cartoon on applet and performs its event handling. This is actually a series of examples
with gradual and step-by-step revision in all of them in order to enhance their functionality and
then eliminate their drawbacks.
Chapter 14, Abstract Window Toolkit: Mini project like programming example on CityMap
Applet. The applet shows the map of a city from top angle with five buttons, namely, Hospitals,
Shopping Malls, Police station, Post Office, and Stadium. If a user presses the Hospital button,
all the hospitals are shown on the map with a specific color and likewise for Malls, Police station,
Post office and Stadium.
Chapter 15, Swing: Explanation of new classes with examples and also includes a practical
programming example to create a mini text editor.
Chapter 16, Introduction to Advanced Java: Introductory sections on JSP, Java Beans, Jar
files and enterprise Java beans with lots of examples apart from enhanced coverage of servlets
and JDBC. This chapter also encompasses a login application built using servlets and database
to demonstrate how to create and use a web application.
viii Preface to the Second Edition

Content and Structure


This book comprises 16 chapters and two appendices. A brief outline of each chapter is as follows.
Chapter 1 focuses on the object-oriented concepts and principles. It provides real life mapping
of concepts and principles besides depicting them pictorially. In addition to this, the chapter also
provides an introduction to Unified Modeling Language (UML), which is a modeling language
to show classes, objects, and their relationship with other objects.
Chapter 2 introduces Java and its evolution from its inception to its current state. Besides
introducing the features of Java, it also tells you about the structure of JDK (Java Development
Kit) and the enhancements made to Java in its latest versions. It describes how to install and run
the JDK that is in turn required for executing a Java program.
Chapter 3 describes the basic programming constructs used in Java such as variables, data
types, identifiers, etc. Java reserved keywords are also depicted in this chapter. The operators
(arithmetic, relational, boolean, etc.) that act on variables are also explained in this chapter. For
each set of operators, we have provided sufficient examples along with their explanation and
output. Apart from variables and operators, this chapter focuses on statements like if and other
loops available in Java (for, while, do…while, and for...each).
Chapter 4 deals with classes and objects. A lot of practical problems and their solutions
have been discussed in this chapter. It begins with how to define classes, objects, and method
creation. Method overloading is also discussed. Later, it emphasizes on the differences between
instance variables/methods and class variables and methods. Finally, a discussion about arrays,
this keyword, and command-line arguments is also provided.
Chapter 5 focuses on inheritance and its uses. How it is realized in Java is discussed in this
chapter. Apart from this, polymorphism concepts are visualized through method overriding and
super keyword. How practical programming problems are solved through super keyword forms
a major part of this chapter. Towards the end of the chapter, some related concepts like abstract
classes are also discussed.
Chapter 6 covers interfaces, packages, and enumeration. It highlights the differences between
abstract classes and interfaces and their practical usages with examples. The role of packages in
Java and their creation and usage is also discussed. In-depth coverage of a predefined package
java.lang is included in this chapter along with some of the famous classes such as String,
StringBuffer, StringBuilder, and Wrapper classes.
Chapter 7 discusses exceptions in detail. Apart from explaining in detail the five keywords
(try, catch, throw, throws, and finally) used in handling exceptions, it also discusses how a user
can create his own exceptions and handle them. Concepts such as exception, encapsulation, and
enrichment are also explained in this chapter. Besides these, the new facilities provided by Java
like assertions and logging are also discussed.
Chapter 8 covers multithreading concepts, its states, priorities, etc. It also discusses in detail
the inter-thread communication and synchronization concepts. Methods like wait(), notify(), and
notifyAll() have also been discussed.
Chapter 9 emphasizes on the essentials of I/O concepts like how standard input can be taken
and how output is delivered to the standard output. A few main classes of the java.io package
are discussed with examples and their usages. Console class, used for taking user input, is also
discussed. What is the use of making objects persistent and how will it be done is discussed
towards the end of the chapter.
Chapter 10 discusses the java.util package in detail. The interfaces like Map, Set, and List
etc have been discussed in detail as well as their subclasses like LinkedList, ArrayList, Vector,
HashSet, HashMap, TreeMap, etc. Java 5 introduced a new feature named ‘Generics’ which
Preface to the Second Edition ix

forms the core of the java.util package. This concept along with its application has been covered
in detail.
Chapter 11 explains how network programming can be done in Java. In-depth coverage of
sockets is extended in this chapter. Client and server concept is illustrated by the programs
created. TCP and UDP clients and server and their interactions are demonstrated. The concept
of multithreading is merged with socket and illustrated to create server programs. Some main
classes such as URL, URL connection, and network interface (new feature) are also discussed.
Chapter 12 focuses on applets, its lifecycle, methods, etc. and how they are different from
applications. Besides providing an in-depth coverage of java.applet package, some of the
classes of java.awt package are also discussed as they are very useful in creating applets such
as Graphics class, Font class, Color class, and FontMetric class. All these classes are discussed
and supported by an example for each of them.
Chapter 13 talks about event handling in Java. Basically for creating effective GUI applications,
we need to handle events and this forms the basis of this chapter. The event handling model is
not only discussed but applied throughout the chapter. All the approaches to event handling have
been discussed such as Listener interfaces, Adapter classes, inner classes, and anonymous inner
classes.
Chapter 14 focuses on GUI creation through java.awt package. It has an in-depth coverage
of containers and components. Containers like Frame, Window, etc. and components like Label,
Button, TextField, Choice, Checkbox, List, etc. are discussed in detail. How the components can
be arranged in a container is also discussed, e.g. BorderLayout, GridBagLayout, and GridLayout.
Chapter 15 shows how to create more advanced and lightweight GUI applications in Java.
More advanced layouts like SpringLayout have been discussed. Lightweight components like
JButton, JLabel, JCheckBox, JToggleButton, JList, JScrollPane, JTabbedPane, etc. have been
discussed. How to create Dialogs is also discussed. The pluggable look and feel of Java is
explained in detail.
Chapter 16 focuses on advanced Java concepts such as servlets, JDBC, and RMI. An
introduction to the advanced technologies has been discussed. This chapter is equipped with
numerous figures showing how to install the necessary softwares required for executing an
advanced Java program. The chapter also provides a step-by-step and simplified approach on
how to learn advanced concepts.
Appendix A on practical lab problems will facilitate better understanding of the concepts
explained in the book. Appendix B includes a list of interview questions along with their answers
that provides an overview of the industry scenario and their requirements.

ACKNOWLEDGEMENTS
Several people have been instrumental throughout this tiring yet wonderful journey. First of all, we
would like to express our sincere gratitude to our families without whose support, patience, and
cooperation, this would not have been possible and we would not have been what we are today.
We are also thankful to our colleagues and friends for their endless support and suggestions
during the entire process of writing this book. Lastly, we would also like to thank all our readers
/students who have supported us, encouraged us, and provided feedback to us regularly which
has helped us in shaping this edition.
Sachin Malhotra
Saurabh Choudhary
Brief Contents
Preface to the Second Edition vi
Preface to the First Edition x
Detailed Contents xiii
1. Introduction to OOP 1
2. Getting Started With Java 12
3. Java Programming Constructs 42
4. Classes and Objects 74
5. Inheritance 132
6. Interfaces, Packages, and Enumeration 156
7. Exception, Assertions, and Logging 199
8. Multithreading in Java 224
9. Input/Output, Serialization and Cloning 256
10. Generics, java.util and other API 296
11. Network Programming 336
12. Applets 354
13. Event Handling in Java 394
14. Abstract Window Toolkit 429
15. Swing 495
16. Introduction to Advanced Java 553
Appendix A: Lab Manual 628
Appendix B: Interview Questions 650
Index 657
Detailed Contents
Preface to the Second Edition vi
Preface to the First Edition x

1. Introduction to OOP 1 2.6.6 Java is Multithreaded 20


2.6.7 Other Features 20
1.1 Introduction 1
2.7 Program Structure 21
1.2 Need of Object-Oriented
Programming 2 2.7.1 How to Execute a Java
Program 21
1.2.1 Procedural Languages 2
2.7.2 Why Save as Example.Java? 22
1.2.2 Object-Oriented Modeling 2
2.7.3 Explanation 22
1.3 Principles of Object-Oriented
2.8 Java Improvements 23
Languages 3
2.8.1 Java 5.0 Features 23
1.3.1 Classes 3
2.8.3 Java 6 Features 25
1.3.2 Objects 3
2.8.4 Java 7 Features 26
1.3.3 Abstraction 3
2.8.4 Brief Comparison of Different
1.3.4 Inheritance 4
Releases 27
1.3.5 Encapsulation 4
2.9 Differences between Java and C++ 28
1.3.6 Polymorphism 5
2.10 Installation of JDK 1.7 29
1.4 Procedural Language vs OOP 5
2.10.1 Getting Started With the JDK 29
1.5 OOAD Using UML 6
2.10.2 JDK Installation Notes 29
1.6 Applications of OOP 9
2.10.3 Exploring the JDK 37
2. Getting Started With Java 12 2.11 Integrated Development
Environment 39
2.1 Introduction 12
2.2 History of Java 13 3. Java Programming Constructs 42
2.3 Java’s Journey: From Embedded Systems
3.1 Variables 42
To Middle-Tier Applications 13
3.2 Primitive Data Types 42
2.4 Java Essentials 14
3.3 Identifier 44
2.5 Java Virtual Machine 15 3.3.1 Rules for Naming 44
2.6 Java Features 16 3.3.2 Naming Convention 44
2.6.1 Platform Independence 16 3.3.3 Keywords 45
2.6.2 Object Oriented 16 3.4 Literals 45
2.6.3 Both Compiled and Interpreted 17 3.5 Operators 48
2.6.4 Java is Robust 18 3.5.1 Binary Operators 48
2.6.5 Java Language Security 3.5.2 Unary Operators 54
Features 18 3.5.3 Ternary Operator 54
xiv Detailed Contents

3.6 Expressions 55 4.9 this Keyword 103


3.7 Precedence Rules and 4.10 Arrays 105
Associativity 55 4.10.1 One-Dimensional Arrays 105
3.8 Primitive Type Conversion 4.10.2 Two-Dimensional Arrays 110
and Casting 57 4.10.3 Using for-each With Arrays 115
3.9 Flow of Control 61 4.10.4 Passing Arrays to Methods 115
3.9.1 Conditional Statements 62 4.10.5 Returning Arrays from
3.9.2 Loops 65 Methods 116
3.9.3 Branching Mechanism 68 4.10.6 Variable Arguments 117
4.11 Command-line Arguments 118
4. Classes and Objects 74 4.12 Nested Classes 119
4.1 Classes 74 4.12.1 Inner Class 119
4.2 Objects 75 4.12.2 Static Nested Class 122
4.2.1 Difference between Objects 4.12.3 Why Do We Create Nested
and Classes 76 Classes? 124
4.2.2 Why Should We Use 4.13 Practical Problem: Complex
Objects and Classes? 76 Number Program 124
4.3 Class Declaration in Java 77
4.3.1 Class Body 78 5. Inheritance 132
4.4 Creating Objects 79 5.1 Inheritance vs Aggregation 132
4.4.1 Declaring an Object 79 5.1.1 Types of Inheritance 133
4.4.2 Instantiating an Object 79 5.1.2 Deriving Classes Using
4.4.3 Initializing an Object 80 Extends Keyword 135
4.5 Methods 82 5.2 Overriding Method 137
4.5.1 Why Use Methods? 82 5.3 super Keyword 141
4.5.2 Method Types 82 5.4 final Keyword 146
4.5.3 Method Declaration 83 5.5 Abstract Class 147
4.5.3 Instance Method Invocation 86 5.6 Shadowing vs Overriding 149
4.5.4 Method Overloading 87 5.7 Practical Problem: Circle
4.6 Constructors 90 and Cylinder Class 151
4.6.1 Parameterized Constructors 93
6. Interfaces, Packages, and
4.6.2 Constructor Overloading 94
Enumeration 156
4.7 Cleaning Up Unused Objects 96
4.7.1 The Garbage Collector 96 6.1 Interfaces 156
4.7.2 Finalization 97 6.1.1 Variables in Interface 158
4.7.3 Advantages and Disadvantages 97 6.1.2 Extending Interfaces 160
4.8 Class Variable and 6.1.3 Interface vs Abstract Classes 160
Methods—Static Keyword 97 6.2 Packages 161
4.8.1 Static Variables 98 6.2.1 Creating Packages 162
4.8.2 Static Methods 99 6.2.2 Using Packages 164
4.8.3 Static Initialization Block 101 6.2.3 Access Protection 168
Detailed Contents xv

6.3 java.lang Package 169 8.4 Main Thread 227


6.3.1 java.lang.Object Class 169 8.5 Creation of New Threads 228
6.3.2 Java Wrapper Classes 170 8.5.1 By Inheriting the Thread
6.3.3 String Class 174 Class 228
6.3.4 StringBuffer Class 179 8.5.2 Implementing the Runnable
6.3.5 StringBuilder Class 180 Interface 231
6.3.6 Splitting Strings 181 8.6 Thread.State in Java 234
6.4 Enum Type 183 8.6.1 Thread States 235
6.4.1 Using Conditional Statements with 8.7 Thread Priority 240
an Enumerated Variable 185 8.8 Multithreading—Using isAlive()
6.4.2 Using for Loop for Accessing and join() 243
Values 185 8.9 Synchronization 245
6.4.3 Attributes and Methods Within 8.9.1 Synchronized Methods 246
Enumeration 186 8.9.2 Synchronized Statements 246
6.5 Practical Problem: Banking 8.10 Suspending and Resuming Threads 246
Example 187 8.11 Communication between
Threads 248
7. Exception, Assertions, 8.12 Practical Problem: Time
and Logging 199 Clock Example 251
7.1 Introduction 199
7.1.1 Exception Types 201 9. Input/Output, Serialization
and Cloning 256
7.2 Exception Handling Techniques 202
7.2.1 try…catch 203 9.1 Introduction 256
7.2.2 throw Keyword 206 9.1.1 java.io.InputStream and
7.2.3 throws 207 java io.OutputStream 257
7.2.4 finally Block 209 9.2 java.io.File Class 258
7.2.5 try-with-resources 9.3 Reading and Writing Data 261
Statement 210 9.3.1 Reading/Writing Files Using Byte
7.2.6 Multi Catch 212 Stream 261
7.2.7 Improved Exception Handling 9.3.2 Reading/Writing Console
in Java 7 213 (User Input) 264
7.3 User-Defined Exception 215 9.3.3 Reading/Writing Files Using
7.4 Exception Encapsulation Character Stream 269
and Enrichment 216 9.3.4 Reading/Writing Using Buffered
7.5 Assertions 217 Byte Stream Classes 270
7.6 Logging 219 9.3.5 Reading/Writing Using Buffered
Character Stream Classes 272
8. Multithreading in Java 224
9.4 Randomly Accessing a File 273
8.1 Introduction 224 9.5 Reading and Writing Files
8.2 Multithreading in Java 225 Using New I/O Package 276
8.3 java.lang.Thread 225 9.6 Java 7 Nio Enhancements 278
xvi Detailed Contents

9.7 Serialization 283 12. Applets 354


9.8 Cloning 285 12.1 Introduction 354
12.2 Applet Class 355
10. Generics, java.util and other API 296
12.3 Applet Structure 356
10.1 Introduction 296 12.4 Example Applet Program 357
10.2 Generics 301 12.4.1 How to Run an Applet? 358
10.2.1 Using Generics in Arguments and 12.5 Applet Life Cycle 359
Return Types 304 12.6 Common Methods Used in
10.2.2 Wildcards 304 Displaying the Output 361
10.2.3 Bounded Wildcards 306 12.7 paint(), update(), and repaint() 364
10.2.4 Defining Your Own 12.7.1 paint() Method 364
Generic Classes 307 12.7.2 update() Method 365
10.3 Linked List 309 12.7.3 repaint() Method 366
10.4 Set 311 12.8 More About Applet Tag 366
10.4.1 Hashset Class 312 12.9 getDocumentbase() and
10.4.2 Treeset Class 314 getCodebase() Methods 369
10.5 Maps 315 12.10 Appletcontext Interface 370
10.5.1 Hashmap Class 315 12.10.1 Communication between Two
Applets 371
10.5.2 Treemap Class 317
12.11 How To Use An Audio Clip? 372
10.6 Collections Class 318
12.12 Images in Applet 373
10.7 Legacy Classes and Interfaces 319
12.12.1 Mediatracker Class 375
10.7.1 Difference between Vector
12.13 Graphics Class 377
and Arraylist 319
12.13.1 An Example Applet Using
10.7.2 Difference between Enumerations
Graphics 379
and Iterator 320
12.14 Color 380
10.8 Utility Classes: Random Class 320
12.15 Font 382
10.8.1 Observer and Observable 322
12.16 Fontmetrics 386
10.9 Runtime Class 326
12.17 Practical Problem: Digital Clock 390
10.10 Reflection API 328
13. Event Handling in Java 394
11. Network Programming 336
13.1 Introduction 394
11.1 Introduction 336 13.2 Event Delegation Model 395
11.1.1 TCP/IP Protocol Suite 336 13.3 java.awt.Event Description 395
11.2 Sockets 337 13.3.1 Event Classes 395
11.2.1 TCP Client and Server 338 13.4 Sources of Events 404
11.2.2 UDP Client and Server 342 13.5 Event Listeners 404
11.3 URL Class 344 13.6 How Does The Model Work? 406
11.4 Multithreaded Sockets 346 13.7 Adapter Classes 410
11.5 Network Interface 349 13.7.1 How To Use Adapter Classes 410
Detailed Contents xvii

13.7.2 Adapter Classes in Java 412 15. Swing 495


13.8 Inner Classes in Event Handling 413
15.1 Introduction 495
13.9 Practical Problem: Cartoon
15.1.1 Features of Swing 496
Applet 416
15.1.2 Differences between
13.9.1 Smiling Cartoon With Blinking Swing and AWT 496
Eyes (Part 1) 416
15.2 JFrame 497
13.9.2 Smiling Cartoon With Blinking
15.3 JApplet 500
Eyes (Part 2) 420
15.4 JPanel 501
13.9.3 Smiling Cartoon (Part 3) 423
15.5 Components in Swings 502
14. Abstract Window Toolkit 429 15.6 Layout Managers 506
15.6.1 Springlayout 506
14.1 Introduction 429 15.6.2 Boxlayout 509
14.1.1 Why Awt? 429 15.7 JList and JScrollPane 510
14.1.2 java.awt Package 430 15.8 Split Pane 513
14.2 Components and Containers 432 15.9 JTabbedPane 514
14.2.1 Component 432 15.10 JTree 516
14.2.2 Components as Event 15.11 JTable 521
Generator 433 15.12 Dialog Box 525
14.3 Button 434 15.13 JFileChooser 529
14.4 Label 437 15.14 JColorChooser 530
14.5 Checkbox 438 15.15 Pluggable Look and Feel 531
14.6 Radio Buttons 441 15.16 Inner Frames 539
14.7 List Boxes 444 15.17 Practical Problem: Mini Editor 545
14.8 Choice Boxes 448
16. Introduction to Advanced Java 553
14.9 Textfield and Textarea 451
14.10 Container Class 455 16.1 Introduction to J2ee 553
14.10.1 Panels 455 16.2 Database Handling Using JDBC 553
14.10.2 Window 456 16.2.1 Load the Driver 554
16.2.2 Establish Connection 556
14.10.3 Frame 456
16.2.3 Create Statement 556
14.11 Layouts 458
16.2.4 Execute Query 557
14.11.1 FlowLayout 459
16.2.5 Iterate Resultset 557
14.11.2 BorderLayout 462
16.2.6 Scrollable Resultset 559
14.11.3 CardLayout 465
16.2.7 Transactions 560
14.11.4 GridLayout 469 16.3 Servlets 562
14.11.5 GridbagLayout 471 16.3.1 Lifecycle of Servlets 562
14.12 Menu 478 16.3.2 First Servlet 563
14.13 Scrollbar 483 16.3.3 Reading Client Data 567
14.14 Practical Problem: City 16.3.4 Http Redirects 571
Map Applet 487 16.3.5 Cookies 572
xviii Detailed Contents

16.3.6 Session Management 574 16.7.1 Creating a Jar File 605


16.4 Practical Problem: Login Application 577 16.7.2 Viewing the Contents of
16.5 Introduction to Java a Jar File 606
Server Pages 589 16.7.3 Extracting the Contents
16.5.1 JSP Life Cycle 589 of Jar 607
16.5.2 Steps in JSP Page Execution 590 16.7.4 Manifest Files 607
16.5.3 JSP Elements 590 16.8 Remote Method Invocation 609
16.5.4 Placing Your JSP in the 16.8.1 RMI Networking Model 609
Webserver 593
16.8.2 Creating an Rmi Application 610
16.6 Java Beans 597
16.9 Introduction to EJB 613
16.6.1 Properties of a Bean 597
16.9.1 Types of EJB 614
16.6.2 Using Beans Through JSP 601
16.6.3 Calculatebean Example 602 16.9.2 EJB Architecture 615
16.7 Jar Files 605 16.10 Hello World—EJB Example 616

Appendix A: Lab Manual 628


Appendix B: Interview Questions 650
Index 657
Introduction to
OOP 1
Beauty is our weapon against nature; by it we make objects, giving them limit,
symmetry, proportion. Beauty halts and freezes the melting flux of nature.
Camille Paglia

After reading this chapter, the readers will be able to


 know what is object-oriented programming

 understand the principles of OOP

 understand how is OOP different from procedural languages

 comprehend the problems in procedural programming and how OOP overcomes them

 learn the applications of OOP

 use UML notations

1.1 INTRODUCTION
Object-oriented programming (OOP) is one of the most interesting and useful innovations in
software development. OOP has strong historical roots in programming paradigms and practices.
It addresses the problems commonly known as the software crisis. Software have become
inherently complex which has led to many problems within the development of large software
projects. Many software have failed in the past. The term ‘software crisis’ describes software
failure in terms of
 Exceeding software budget
 Software not meeting clients’ requirements
 Bugs in the software
OOP is a programming paradigm which deals with the concepts of object to build programs
and software applications. It is modeled around the real world. The world we live in is full of
objects. Every object has a well-defined identity, attributes, and behavior. Objects exhibit the
same behavior in programming. The features of object-oriented programming also map closely
to the real-world features like inheritance, abstraction, encapsulation, and polymorphism. We
will discuss them later in the chapter.
2 Programming in Java

1.2 NEED OF OBJECT-ORIENTED PROGRAMMING


There were certain limitations in earlier programming approaches and to overcome these
limitations, a new programming approach was required. We first need to know what these
limitations were.
1.2.1 Procedural Languages
In procedural languages, such as C, FORTRAN, and PASCAL, a program is a list of instructions.
The programmer creates a list of instructions to write a very small program. As the length of a
program increases, its complexity increases making it difficult to maintain a very large program.
In the structured programming, this problem can be overcome by dividing a large program into
different functions or modules, but this gives birth to other problems. Large programs can still
become increasingly complex. There are two main problems in procedural language—(i) the
functions have unrestricted access to global data and (ii) they provide poor mapping to the real
world.
Here are some other problems in the procedural languages. Computer languages generally
have built-in data types: integers, character, float, and so on. It is very difficult to create a new
data type or a user-defined data type. For example, if we want to work with dates or complex
numbers, then it becomes very difficult to work with built-in types. Creating our own data types is
a feature called extensibility: we can extend the capabilities of a language. Procedural languages
are not extensible. In the traditional languages, it is hard to write and maintain complex results.
1.2.2 Object-Oriented Modeling
In the physical world, we deal with objects like person, plane, or car. Such objects are not like
data and functions. In the complex real-world situations, we have objects which have some
attributes and behavior. We deal with similar objects in OOP. Objects are defined by their unique
identity, state, and behavior. The state of an object is identified by the value of its attributes and
behavior by methods.
Attributes
Attributes define the data for an object. Every object has some attributes. Different types of
objects contain different attributes or characteristics. For example, the attributes of a student
object are name, roll number, and subject; and the attributes for a car object would be color,
engine power, number of seats, etc. These attributes will have specific values, such as Peter (for
name) or 23 (for roll number).
Behavior
The response of an object when subjected to stimulation is called its behavior. Behavior defines
what can be done with the objects and may manipulate the attributes of an object. For example,
if a manager orders an employee to do some task, then he responds either by doing it or not
doing it. The wings of a fan start moving only when the fan is switched ON. Behavior actually
determines the way an object interacts with other objects. We can say that behavior is synonym
to functions or methods: we call a function to perform some task. For example, an Employee
class will have functions such as adding an employee, updating an employee details, etc.
Introduction to OOP 3

Note If we try to represent the CPU of a computer in OOP terminology, then CPU is the object.
The CPU is responsible for fetching the instructions and executing them. So fetching and
executing are two possible functions (methods or behavior) of CPU. The place (attributes)
where CPU stores the retrieved instructions, values and result of the execution (registers) will
then be the attributes of the CPU.

1.3 PRINCIPLES OF OBJECT-ORIENTED LANGUAGES


OOP languages follow certain principles such as class, object, and abstraction. These principles
map very closely to the real world.
1.3.1 Classes
A class is defined as the blueprint for an object. It serves as a plan or a template. The description
of a number of similar objects is also called a class. An object is not created by just defining a
class. It has to be created explicitly. Classes are logical in nature. For example, furniture does
not have any existence but tables and chairs do exist. A class is also defined as a new data type,
a user-defined type which contains two things: data members and methods.
1.3.2 Objects
Objects are defined as the instances of a class, e.g. table, chair are all instances of the class
Furniture. Objects of a class will have same attributes and behavior which are defined in that
class. The only difference between objects would be the value of attributes, which may vary.
Objects (in real life as well as programming) can be physical, conceptual, or software. Objects
have unique identity, state, and behavior. There may be several types of objects:
 Creator objects: Humans, Employees, Students, Animal

 Physical objects: Car, Bus, Plane

 Objects in computer system: Monitor, Keyboard, Mouse, CPU, Memory

1.3.3 Abstraction
Can you classify the following items?
 Elephant  CD player

 Television  Chair

 Table  Tiger

How many classes do you identify here? The obvious answer anybody would give is three, i.e.,
Animal, Furniture, and Electronic items. But how do you come to this conclusion? Well, we
grouped similar items like Elephant and Tiger and focused on the generic characteristics rather
than specific characteristics. This is called abstraction. Everything in this world can be classified
as living or non-living and that would be the highest level of abstraction.
Another well-known analogy for abstraction is a car. We drive cars without knowing the
internal details about how the engine works and how the car stops on applying brakes. We are
happy with the abstraction provided to us, e.g., brakes, steering, etc. and we interact with them.
In real life, human beings manage complexity by abstracting details away. In programming,
we manage complexity by concentrating only on the essential characteristics and suppressing
implementation details.
4 Programming in Java

1.3.4 Inheritance
Inheritance is the way to adopt the characteristics of one class into another class. Here we have
two types of classes: base class and subclass. There exists a parent–child relationship among
the classes. When a class inherits another class, it has all the properties of the base class and it
adds some new properties of its own. We can categorize vehicles into car, bus, scooter, ships,
planes, etc. The class of animals can be divided into mammals, amphibians, birds, and so on.
The principle of dividing a class into subclass is that each subclass shares common
characteristics with the class from where they are inherited or derived. Cars, scooters, planes,
and ships all have an engine and a speedometer. These are the characteristics of vehicles. Each
subclass has its own characteristic feature, e.g., motorcycles have disk braking system, while
planes have hydraulic braking system. A car can run only on the surface, while a plane can fly
in air and a ship sails over water (see Fig. 1.1).

Vehicle

Road vehicle Air vehicle Water vehicle

Bus Motor bike Aeroplane Boat

Fig. 1.1 Inheritance

Inheritance aids in reusability. When we create a class, it can be distributed to other


programmers which they can use in their programs. This is called reusability. Suppose someone
wants to make a program for a calculator, he can use a predefined class for arithmetic operations,
and then he need not define all the methods for these operations. This is similar to using library
functions in procedural language. In OOP, this can be done using the inheritance feature. A
programmer can use a base class with or without modifying it. He can derive a child class from
a parent class and then add some additional features to his class.
1.3.5 Encapsulation
Encapsulation is one of the features of object-oriented methodology. The process of binding
the data procedures into objects to hide them from
the outside world is called encapsulation (see Fig.
1.2). It provides us the power to restrict anyone from
directly altering the data. Encapsulation is also known Method
as data hiding. An access to the data has to be through
the methods of the class. The data is hidden from the Method Data
outside world and as a result, it is protected. The details Accessing
that are not useful for other objects should be hidden data Method
from them. This is called encapsulation. For example,
an object that does the calculation must provide an
interface to obtain the result. However, the internal
coding used to calculate need not be made available Fig. 1.2 Diagrammatic Illustration of a
to the requesting object. Class to Show Encapsulation
Introduction to OOP 5

1.3.6 Polymorphism
Polymorphism simply means many forms. It can be defined as the same thing being used in
different forms. For example, there are certain bacteria that exhibit in more than one morphological
form. In programming, polymorphism is of two types: compile-time and runtime polymorphism.
Runtime polymorphism, also known as dynamic binding or late binding, is used to determine
which method to invoke at runtime. The binding of method call to its method is done at runtime
and hence the term late binding is used. In case of compile-time polymorphism, the compiler
determines which method (from all the overloaded methods) will be executed. The binding of
method call to the method is done at compile time. So the decision is made early and hence
the term early binding. Compile-time polymorphism in Java is implemented by overloading
and runtime polymorphism by overriding. In overloading, a method has the same name with
different signatures. (A signature is the list of formal argument that is passed to the method.)
In overriding, a method is defined in subclass with the same name and same signature as that
of parent class. This distinction between compile-time and runtime polymorphism is of method
invocation. Compile-time polymorphism is also implemented by operator overloading which
is a feature present in C++ but not in Java. Operator overloading allows the user to define new
meanings for that operator so that it can be used in different ways. The operator (+) in Java is
however an exception as it can be used for addition of two integers as well as concatenation of
two strings or an integer with a string. This operator is overloaded by the language itself and
the Java programmer cannot overload any operator.

1.4 PROCEDURAL LANGUAGE VS OOP


Table 1.1 highlights some of the major differences between procedural and object-oriented
programming languages.
Table 1.1 Procedural Language vs OOP
Procedural Language OOP
 Separate data from functions that operate on them.  Encapsulate data and methods in a class.
 Not suitable for defining abstract types.  Suitable for defining abstract types.
 Debugging is difficult.  Debugging is easier.
 Difficult to implement change.  Easier to manage and implement change.
 Not suitable for larger programs and applications.  Suitable for larger programs and applications.
 Analysis and design not so easy.  Analysis and design made easier.
 Faster.  Slower.
 Less flexible.  Highly flexible.
 Data and procedure based.  Object oriented.
 Less reusable.  More reusable.
 Only data and procedures are there.  Inheritance, encapsulation, and polymorphism are the
key features.
 Use top-down approach.  Use bottom-up approach.
 Only a function call another.  Object communication is there.
 Example: C, Basic, FORTRAN.  Example: JAVA, C++, VB.NET, C#.NET.
6 Programming in Java

1.5 OOAD USING UML


An object-oriented system comprises of objects. The behavior of a system results from its objects
and their interactions. Interaction between objects involves sending messages to each other.
Every object is capable of receiving messages, processing them, and sending to other objects.
Object-oriented Analysis and Design (OOAD)
It is an approach that models software as a group of interacting objects. A model is a description
of the system that we intend to build. Each object is characterized by its class having its own state
(attributes) and behavior. Object-oriented analysis (OOA) analyzes the functional requirements
of a system and focuses on what the system should do. Object-oriented design (OOD) focuses on
how the system does it. The most popular modeling language for OOAD is the unified modeling
language (UML).
UML is a standard language for OOAD. It contains graphical notations for all entities (class,
object, etc.) used in the object-oriented languages along with the relationship that exists among
them. These notations are used to create models. UML helps in visualizing the system, thereby
reducing complexity and improving software quality. The notations used for class and object are
shown in Fig. 1.3. For example, consider an Employee class with attributes name, designation,
salary, etc. and operations such as addEmployee, deleteEmployee, and searchEmployee.
The notation for employee class and its object is as follows:

Employee Class
name
address
designation Attributes
salary

addEmployee
deleteEmployee Behavior
searchEmployee

Fig. 1.3 UML Notation for Class


The notation for an object is very much similar to the class notation. The class name underlined
and followed by a colon represents an object (Fig. 1.4).

:Employee Object
name=peter
address=NY
designation=manager Attributes
salary=10000

addEmployee
deleteEmployee
searchEmployee

Fig. 1.4 UML Notation for Object


Introduction to OOP 7

An instance of a class can be related to any number of instances of other class known as
multiplicity of the relation. One-to-one, one-to-many, and many-to-many are different types
of multiplicities that exist among objects. The multiplicities along with their examples and
respective notations are shown below. Figure 1.5(a) illustrates the generic notation for representing
multiplicity in object-oriented analysis and design. One-to-one mapping is shown as a straight
line between the two classes. Figure 1.5(b) shows the UML notation for demonstrating the one-
to-one mapping. The 1..1 multiplicity depicted on the straight line (both ends) indicates a single
instance of a class is associated with single instance of other class. Figure 1.5 shows that each
country has a president and a president is associated with a country.

Country has Country 1.1 has 1.1


President President

(a) (b)

Fig. 1.5 One-to-one Relationship

A country has many states and many states belong to a country. So there exists a one-to-many
relationship between the two. This relationship is shown in Fig. 1.6. Part (a) of this figure shows
the generic notation where a solid dot is indicated on the many side and both classes are joined
by a straight line. Figure 1.6(b) shows the UML notation where 1..* indicates the one to many
relationship between country and states. On the country end, a 1..1 multiplicity is placed to
indicate one country and on states end, a 1..* is placed to indicate many states.

has 1..1 has 1..*


Country States Country States

(a) (b)

Fig. 1.6 One-to-many Relationship

Let us take another example to explain many-to-many relationship. A teacher teaches many
students and a student can be taught by many teachers. There exists a many-to-many relationship
between them. Many-to-many relationship (Generic notation in OOAD) are represented by
placing solid dots on both ends joined by a straight line as shown in Fig. 1.7(a). The respective
notation in UML is shown in Fig. 1.7(b) where 1..* on both ends is used to signify many-to-
many relationship.

teaches 1..* teaches 1..*


Teacher Student Teacher Student

(a) (b)

Fig. 1.7 Many-to-many Relationship


8 Programming in Java

Besides multiplicity of relations, the relationships can be of various types: inheritance,


aggregation, composition. These relationships can be denoted in UML with links and associations.
The links represent the connection between the objects and associations represent groups of links
between classes. If a class inherits another class, then there exists a parent-child relationship
between them. This relationship is depicted in UML as shown in Fig. 1.8. For example, Shape
is the superclass, and the subclasses of Shape can take any shape, e.g., Square, Triangle, etc.

Shape

Triangle Square

Fig. 1.8 UML Diagram Depicting Inheritance


The above diagram can be extended to depict the OOP principle of polymorphism. Every shape
will have a method named area() which would calculate the area of that shape. The implementation
of area() method would be different for different shapes. For example, the formula for calculating
area of a triangle is different from a square. So the implementation is different but the name of
the method is same. This is polymorphism (one name many implementations). In Fig 1.9 below,
the area() method is overridden by Triangle and Square classes.

Shape

area( )

Triangle Square Rectangle

area( ) area( ) area( )

Fig. 1.9 UML Diagram Depicting Polymorphism

Another kind of relationship that exists among objects is the part-of-relationship. When a
particular object is a part of another object then we say that it is aggregation. For example, car is
Introduction to OOP 9

an aggregation of many objects: engine, door, etc. and engine in turn is an aggregation of many
objects, e.g., cylinder, piston, valves, etc. as shown in Fig. 1.10(a). A special kind of aggregation
is composition where one object owns other objects. If the owner object does not exist, the
owned objects also ceases to exist. For example, the human body is a very good example of
composition. It is a composition of different organs. The hands, feet, and internal organs such
as the lung and intestine are also parts of the body owned by the body.

Car

Human body
Engine Door

Cylinder Radiator Liver Lungs

(a) (b)

Fig. 1.10 (a) Aggregation and (b) Composition

1.6 APPLICATIONS OF OOP


The basic thought behind object-oriented language is to make an object by combining data and
functions as a single unit and then operate on that data. In procedural approach, the focus is on
business process and the data needed to support the process. For example, in the last decade, a
problem bothered every programmer, popularly known as the Y2K problem. Everybody related
to the computer industry was afraid of what will happen past midnight 31 December 1999. The
problem arises due to the writing convention of the year attribute. In early programming days,
a programmer wrote a year in two digits, so there was a problem to distinguish the year 1900
from 2000 because if we write only the last two digits of a year, the computer cannot differentiate
between the two. Nobody perceived this problem and used the date and year code as and when
required, thus aggravating the problem. The solution to this problem was to analyze multiple
lines of codes everywhere and change the year to four digits rather than two. It seems simple to
change the state variable of year but analyzing a code of several thousands of lines to find how
many times you have used date in your code is not an easy task.
If object-oriented programming language had been used, we could have created a Date class
with day, month, and year attributes in it. Wherever the date functionality would be required,
10 Programming in Java

a Date object would be created and used. At a later point of time, if a change is required, for
example, the year of Date class needs to be changed to four digits, then this change would be
incorporated in the class only and this change would automatically be reflected in all the objects
of the Date class whenever they are created and used. So, the change would have to be done at
one place only, i.e., the class and wherever the objects of the class are being used, the changes
would be reflected automatically. There is no need to analyze the whole code and change it.
In OOP, we access data with the help of objects, so it is very easy to overcome a problem
without modifying the whole system. Likewise, OOP is used in various fields, such as
 Real-time systems  Neural networks

 Artificial intelligence  Database management

 Expert systems

SUMMARY
Object-oriented languages have become an ubiquitous large projects, a technique known as OOAD is used.
standard for programming. They have been derived Object-oriented analysis and design deals with how a
from the real world. OOP revolves around objects and system is modeled. OOA deals with what the system
classes. A class is defined as a group of objects with should do and OOD deals with how the system
similar attributes and behavior. OOP is a programming achieves what has been specified by OOA.
paradigm which deals with the concepts of objects to OOAD is realized with the help of a language known
develop software applications. Certain principles have as UML. UML stands for unified modeling language;
been laid down by OOP which are followed by every it is a standard language used for visualizing the
OOP language. These principles are: inheritance, software. An abstract model is created for the entire
abstraction, encapsulation, and polymorphism. software using graphical notations provided by UML.
We have presented a detailed comparison of
procedural and object-oriented languages. For building

EXERCISES
Objective Questions
1. In an object model, which one of the following is (c) Polymorphism (d) None of the above
true? 4. Which one of the following terms must relate to
(a) Abstraction, encapsulation, and multitasking polymorphism?
are the major principles (a) Static allocation (b) Static typing
(b) Hierarchy, concurrency, and typing are the
(c) Dynamic binding (d) Dynamic allocation
major principles
5. Providing access to an object only through its
(c) Abstraction, encapsulation, and polymor-
phism are the major principles member functions, while keeping the details
(d) Typing is the major principle private is called
(a) Information hiding (b) Encapsulation
2. Which one of the following is not an object-
(c) Modularity (d) Inheritance
oriented language?
(a) Simula (b) Java 6. The concept of derived classes is involved in
(c) C++ (d) C (a) Inheritance
3. The ability to hide many different implementations (b) Encapsulation
behind an interface is. (c) Data hiding
(a) Abstraction (b) Inheritance (d) Abstract data types
Introduction to OOP 11

7. Inheritance is a way to (d) All the above


(a) Organize data 9. Which of the following is true about class?
(b) Pass arguments to objects of classes (a) Class possesses data and methods
(c) Add features to existing classes without (b) Classes are physical in nature
rewriting them (c) Collection of similar type of objects is a class
(d) Improve data-hiding and encapsulation (d) Both (a) and (c)
8. UML is used for 10. Which of the following is true about procedural
(a) Creating models languages?
(b) Representing classes, objects and their (a) Debugging is easier
(b) analysis and design is easy
relationships pictorially
(c) less reusable
(c) Reducing complexity and improving software
(d) difficult to implement changes
quality

Review Questions
1. Explain the importance of object-oriented pro- 4. Write short notes on: (a) inheritance, (b) poly-
gramming languages. morphism, (c) abstraction, (d) encapsulation.
2. Explain the difference between class and object. 5. Differentiate between runtime and compite-time
3. Differentiate between procedural languages and polymorphism.
OOP languages.

Programming Exercises
1. Identify the relevant classes along with their A hospital wants to keep track of scheduled
attributes for the following: A departmental store appointments of a patient with his doctor. When
needs to maintain an inventory of cosmetic items a patient is given an appointment, he should be
which might be found there. You should include given a confirmation that states the time and date
female as well as male cosmetic items. Keep of appointment along with the doctor’s name.
information on all items such as item name, Meanwhile the doctor should also be informed
category, manufacturer, cost, date purchased, about the patient details. Each doctor has one
and serial number. weekday as off-day and no patients should be
2. Identify the relevant classes along with their assigned to a doctor on that day.
attributes from the following problem specification:

Answers to Objective Questions


1. (c) 2. (d) 3. (c) 4. (c)
5. (b) 6. (a) 7. (c) 8. (d)
9. (d) 10. (c) and (d)
Getting Started
with Java 2
The road of life can only reveal itself as it is traveled; each turn in the road reveals a
surprise. Man’s future is hidden. Anon

After reading this chapter, the readers will be able to


 know the history of Java

 understand the features of Java and its runtime environment

 know the basic structure of a Java program

 know the details about JDK installation

 understand various constituents of JDK and its development environments

2.1 INTRODUCTION
Java is a popular and powerful language. Although it is a very simple language, there are a
number of subtleties that can trip up less-experienced programmers. Java is an object-oriented
programming language with a built-in application programming interface (API) that can handle
graphical user interfaces (GUI) used to create applications or applets. Java provides a rich set
of APIs apart from being platform-independent.
Much of the syntax in Java is similar to C and C++. One of the major differences between
Java and other languages is that it does not have pointers. However, the biggest difference is that
you are forced to write object-oriented code in Java. Procedural code is embedded in objects.
In Java, we distinguish between applications and applets, applications being programs that
perform functions similar to those written in other programming languages and applets are
programs that are meant to be embedded in a web page and downloaded over the Internet.
When a program is compiled, a byte code is generated which can be executed on any platform,
provided the runtime environment exists on the destination platform.
This chapter guides the readers to a step-by-step introduction to Java programming. An
important thrust of this chapter is to cover the features of Java from an object-oriented perspective.
It also gives an insight about the installation of Java runtime environment and the various
integrated development environments (IDEs) of Java.
This chapter also focusses on the different versions of Java (including the latest Java 7) and
the Core API’s (Java 7 is also known as Java 1.7).
Random documents with unrelated
content Scribd suggests to you:
every sense of the word this Miss Parker was! What if she, Erskine's
mother, had been gifted with foresight, in those early years, had
been able to conceive of the possibilities hidden in that uncouth, silly
country girl, and had encouraged in Erskine the interest which she
then awakened? Or, failing in that, what if she had simply kept her
hand off and let things take their course? Would this woman with
her beautiful face and gracious ways and cultivated mind and heart
have become Erskine's wife, and her daughter? How extraordinary
that it should have been Mamie Parker who had touched her life
again, when she had labored so hard to be free from her, and had
succeeded! And it was Mamie Parker who had come to the rescue of
a desperately friendless girl who ought at this moment to be
sheltered in their own home! And then she was back in the meshes
of it all again!

She arose at length and began to move softly about her room
through the darkness. She must stay in the darkness, otherwise
Erskine might discover a light and insist upon being admitted. Very
softly she drew back her curtains and looked out upon the moonless
night. There were countless stars, but they gleamed from far away
and looked even more indifferent than usual to what was going on
below them. Softly she drew a chair beside the open casement and
sat down to try the effect of the cool night air upon her throbbing
head. If she could only get quiet enough to think! But those two
conflicting thoughts were still pounding away in her brain: "Erskine
must be told." "Erskine must not be told!"

Yet she made progress, and a discovery. It was beginning to


humiliate her to the very dust to discover that there was a sense in
which she wanted to tell him! No, not that, either; but she wanted
him to know; and she wanted this because she desired to have Irene
dethroned!

There were no tears shed during those hours. The victim had
gone beyond tears. Her throat felt dry and parched and her eyes
burned, as one in a fever. She was beginning to realize that this
might be a conflict between right and wrong, and that her own
personality was engaged in it. The clock struck two, struck three,
and still that mother sat gazing out on the singularly quiet night.
Twice during that time she heard Erskine come with soft footsteps,
evidently to listen at her door.

"Mamma," he said, speaking low, but so distinctly that she knew


he reasoned that if she were awake she would certainly hear him. It
seemed to her that he must hear the throbbing of her heart as she
waited. A wild desire possessed her to fling wide the door and bid
him come in and listen while she said to him: "The woman you have
taken to your heart, to love and cherish forever, is false to the truth,
false to every sense of honor, false even to her own child!"

She clutched at the arms of her chair, to keep her, and held her
breath that it make no sound.

Erskine went on tiptoe back to his room, and his mother, who had
almost spent her physical strength, sank limply back into her chair.
But before the clock struck again she had got to her knees. All the
while she had been conscious of a strange reluctance about going to
God with this trouble. Accustomed as she was, and had been ever
since she became a praying woman, to taking all things, small as
well as great, to Him, it had seemed strange even to herself that she
held back.

Not that she had said that she would not pray, she had simply
shrunken back with a half-frightened "Not yet, I am not ready yet;
let me think." But she reached the moment when she understood
that she must have help and must have it at once, and that only God
could give it.

She knelt long; at first speaking no words, not thinking words.


Then she broke into short, half-sobbing ejaculations: "Lord, show me
the way. Christ, son of Mary, son of God, help me!" And then the
habit of years asserted itself and the sorely shaken woman entered
wholly within the refuge and poured out her soul in prayer.
When she arose from her knees, the rosy tints of a new day were
beginning to flush the east. She drew her shades and went back to
her bed and slept. Some things had been settled for her; she need
not think about them any more.

The woman who a few hours later appeared at the breakfast


table in a white morning dress and with her hair carefully arranged,
showed little trace of her night's vigil, though her son regarded her
searchingly.

"I am thankful to see you here," he said. "I was quite worried
about you last night. It is so unusual not to meet you at dinner and
have a little chat with you. You did not even give a fellow a chance
to say good-night! I was sure that something was wrong." His wife
laughed.

"Erskine cannot get away from the idea that he is his mother's
nursemaid," she said lightly. "And he is a real 'Miss Nancy' for
worrying. Such a night as he gave me, merely because you did not
choose to come down to dinner! He must have trotted out to your
door to listen twenty times, at least."

"Twice, anyway," said Erskine, gayly. "Never mind, though; she is


all right this morning, and that is more than I dared to hope." But he
watched her closely.

"What tired you so, mamma? Or rather, who did? Irene said you
had company all the afternoon."

"Yes, an old acquaintance. I don't think you could guess who it


was."

"Not at least without seeing her. Was she also an old


acquaintance of mine?"

"I think you will remember her; at least you will, her brother. It
was Miss Parker."
"'Miss Parker?' Not Mamie? How interesting! Why didn't you keep
her to dinner? I should like to have met her. Is she 'Miss Parker' still,
after all these years? That is rather surprising, isn't it? She must be
thirty or more. And what about her brother? I haven't heard
anything of him to speak of, since I left college."

"Who are these interesting people who seem to have just sprung
into existence again?" Irene asked. "I have never heard of Mamie
Parker, have I? Is she an old sweetheart of yours?"

"Hardly!" Erskine laughed carelessly. "There was a time during my


college life that her brother and I were rather intimate; then we
drifted apart; he was a good fellow, though. What about him,
mamma?"

"Something that greatly surprised me. Had you supposed him to


be of the material that makes missionaries? That is what he has
become: a foreign missionary. He went out to China about seven
years ago, purely in a commercial way. He represented a New York
business house, but he carried letters of introduction to our
missionaries located there, and became intimate with them and so
interested in their work that, after a time, he gave up his business
entirely and became a missionary teacher."

"Is it possible!" said Erskine. "I think he is the last one I should
have chosen for such a future; from our class, I mean. Though he
was a fine fellow with a big unselfish heart. Didn't I always insist
upon that, mamma, in the days when you did not like him very well?
Weren't there such days? I have almost forgotten."

"I don't think I considered him remarkable," Mrs. Burnham said.


"Though I remember that Alice saw possibilities in him. She liked
him for being so good to his sister."

"And he is really in China! How does his sister like that?"


"So well that she is going out to be with him for a year, and
perhaps longer. She is in daily expectation of receiving a summons
from a party of missionaries with whom she is to travel. She is very
enthusiastic about it; sees ways in which she can further the work. I
should not be at all surprised if she remained there and made it her
life work."

Erskine Burnham looked curiously at his mother, as if to


determine whether she was really in earnest, then threw back his
head and laughed.

"Mamie Parker a missionary in China!" he exploded, "or anywhere


else! my imagination isn't equal to such a flight as that."

"She has changed wonderfully, Erskine. At first I could not make


myself believe that she was really the Mamie Parker we used to
know. Yet as I studied her closely I could see a suggestion of the
girlish face. She was pretty, you remember, but I did not think her
face gave promise of the beauty it has now. However, she is more
than beautiful. She is an educated cultivated woman."

"Educated?" Erskine repeated the word incredulously.

"She went back to school, Erskine, the winter after she visited her
brother, and prepared for college. She is a Smith graduate, think of
it! As for culture, I don't think I ever met a more perfect-appearing
lady than she has become."

"Dear me!" said Irene with a but slightly suppressed yawn, "what
a paragon she must be; I'm glad I didn't meet her. I detest
paragons. Now, if you, sir, can stop talking about her long enough to
consider it, have the goodness to tell me at what time I may expect
you in town this afternoon? We are to be at the Durands' at five,
remember. Don't you dare to tell me you must be excused, for I
have simply set my heart on having you with me."
But Erskine could not so readily be made to forget his anxieties.
He put off a direct answer to his wife, and followed his mother to
her room to press his inquiries tenderly.

"Are you sure that you are all right this morning, and that it was
only weariness which kept you so close a prisoner last night? There
is something about you that I don't quite like; there are heavy rings
under your eyes, and you are paler than usual. Did you sleep well?"

"Not very," she said after a moment's hesitation. "I was—


restless."

He studied her face and spoke with tender reproach.

"Mommie, something troubles you. Am I not to know it?"

She had no recourse but to speak truth.


CHAPTER XIX
ALONE

She laid a tender motherly hand on his arm as she said:—

"Something has been troubling me, Erskine, something that I


cannot explain, because there is a sense in which it is not my trouble
at all, but has to do with others. For a time I was very much
perplexed, but I have settled it now, what my share in it should be,
so that it need not perplex me any more."

She knew that the truth was deceiving him, but it satisfied him.
He believed that Mamie Parker's troubles, whatever they were, had
been brought for his mother to share. His face cleared a little, but he
felt it his duty to administer a loving admonition.

"Remember your one weakness, mamma; there was always in


your nature a temptation to 'bear one another's burdens' too literally.
If there is any way in which I can help without infringing on
confidences, you will let me, of course?"

She was able to smile as she assured him that she would. Despite
her night of vigil she felt strong. Her part had been revealed to her.
She was to keep Irene's secret, to suffer and to act in her stead; and
to shield her son's name and home as much as lay in her power. A
miserable travesty of a home it looked to her; still, it was all he had,
and for a time at least it could be kept sacred in Erskine's eyes. She
had no faith in a perpetual concealment; such skeletons, she
believed, were always unearthed sooner or later—often in
unexpected and mysterious ways. How remarkable, for instance, it
was that, of all the young women in the world who might have
discovered and befriended the deserted child it should have been
their old acquaintance Mamie Parker! Still, this morning, she could
thank God that she need not be the one to unearth this secret.

Of course the child must be planned for—there was no danger


that Ruth would forget her—but it had become very clear to her that
nothing but disaster could result from an enforced acknowledgement
of her by the mother at this late day. If Irene wanted her—if her
heart had turned toward her child in the slightest, or, failing in heart,
if her conscience had impelled her to make the least small effort to
repair some of the mischief, then, indeed, Ruth would have braved
public opinion, gossip, Erskine's pain and shame, everything to help
her. And she could do it understandingly. Had not Ruth Erskine,
away back in her girlhood, helped her father in his tardy right-doing?

It is true that, even at this late day, her face flushed with pain
and shame over the thought of the manner in which she had done
this, at first; still, she had done it. And later, had she not herself
taken the initiative and opened the way for her husband to do his
belated duty? Who could know better than she the cost of such
effort? But there was one infinite difference between past
experiences and present problems. Both her father and her husband,
when the crucial test came, had a foundation of moral strength to
build upon; while Irene—

Ruth Burnham knew that she had tried very hard to find some
lighting up of the story. She had thoroughly probed Mamie Parker to
discover whether or not through the years the mother had made
some sign which proved that she at least knew of the continued
existence of her daughter; but there had been absolutely no proof
that she had ever thought of her six months' old baby again! Ruth
had to turn quickly away from that subject as one that would not
bear dwelling on. The idea that a mother had actually and
deliberately abandoned her baby, roused such a sense of revolt in
this woman's heart that there were times when she told herself that
she could not breathe in the same house with such a creature.
Miss Parker herself had seemed able to appreciate this feeling. At
least she had given no hint that she expected or hoped anything
whatever from the mother, and frankly owned that she had avoided
meeting her on occasions when there would have been opportunity.
She had not felt, she said simply, that anything could be gained by
coming in contact with her. And all her plea had been that Erskine's
mother should in some way interest herself in the welfare of the
lonely girl.

She was very lonely, now, more so by far than she used to be,
Miss Parker had said in a voice that trembled. Then she had waited a
few minutes to regain self-control before she explained that her
mother had to a very great extent taken the place of mother to the
little one.

"She used to spend her vacations with us," she said, "and mother
fell into the habit of looking after her clothes and her comfort in
every way, just as though she were a daughter; and the child loved
mother with a devotion that is uncommon in one so young. Of
course she cannot but miss her sadly."

"Have you lately lost your mother?" Ruth had inquired, and her
tone had been so full of tender sympathy that Miss Parker had
explained in detail how it was that she had only her brother left.
That was why she was going out to him, so that they might be
together, at least for a time, since they were all that was left of
home.

Jim had not married; his sister sometimes feared that he never
would. Didn't Mrs. Burnham think that was a calamity for a man?

"I used to think so," Ruth had replied, as one who did not realize
that she was speaking aloud, and then she had started and flushed
over the thought of what she might thus be revealing; and the flush
had deepened as she remembered what this woman already knew of
her son's wife. But Miss Parker had not once glanced in her
direction, and made no sign that she had heard. She went on,
quietly, talking about her brother. Men, she thought, were different
in that respect from women. A woman need never marry in order to
be comfortable, or to be cared for; but there were ways in which the
average man was helpless and almost homeless without the one
woman to care for him, selected from all the world. This was so
different from the usual putting of the subject that Mrs. Burnham
had felt impelled to smile. Yet as she looked at the beautiful woman
opposite her she admitted that her brother's home would certainly
be brightened by her presence. Still, it was a long way to go to make
a home for a brother.

"Do you have any thought of remaining there," she had asked. "I
mean, of making it a permanent home?"

Miss Parker did not know. She had not allowed herself to look
ahead very far. There were so many changes in life that it did not
seem wise to try to plan. She should like to remain there, like it very
much, she believed; that is, if she could help in the work. She was
sure that she could help Jim; at least, she could take care of him,
and give him more time to do his work; and Jim was a success. Still,
there were times when she was sorry that she had planned in this
way, on Maybelle's account. Even now, if she could make a change,
could delay a little, without incommoding her brother, she would do
so; but Jim had made plans in view of her coming that would
seriously inconvenience him if she did not go.

Yes, there had been changes, sad changes since her plans were
made. Mr. Somerville, who was a frail man and hopelessly careless of
himself, had contracted a cold, a few months ago, that had settled
on his lungs; and it was now evident to all but that poor little girl
that she would, before long, be fatherless.

Oh, she would be cared for, no doubt, so far as her body was
concerned. She was at school, and it was a good school, as good,
perhaps, as any of them. At least she, and her mother, had been at
infinite pains to discover it; still, it was school, and not home, and
poor Maybelle had never been quite happy there. The teachers were
kind, but cold and unsympathetic. They did not understand the child,
and they almost openly disapproved of her father. He went every
day to see her, but the time was coming when he would no longer
be able to do so, and she dreaded to think what Maybelle would do
when this truth dawned upon her.

In these and many other ways had Miss Parker made it apparent
to Mrs. Burnham that her hope lay in winning the woman who had
been so much to her, to become this deserted and lonely child's
friend and guardian.

This was the problem therefore which occupied Ruth Burnham's


chief thought for a number of days following Miss Parker's visit. Only
one decision with regard to it had been reached: that she would do
what she could; but what that would be, she was unable to
determine. Her way seemed hedged in with difficulties which had
not occurred to her during those first awful hours. How, for instance,
was she, a stranger, with no claim to other than a stranger's interest
that she could press, to present herself before a young woman who
was under the care of her own father, and beg to be taken as a
friend and adviser?

Then, too, she shrank exceedingly from meeting the father;


meeting and talking with a man who had been Irene's husband! his
very presence on the earth seemed an insult to her son! What
explanation could she possibly make to him as to her interest in his
daughter? Would her name tell him anything? What did he know of
the after history of the mother of his child? If he was acquainted
with her present name, might he not look upon the coming of her
husband's mother as an added insult? For, after all, he was a decent
man, decent enough for a woman like Mamie Parker to acknowledge
his acquaintance; and he had done what he could for his deserted
child. She could not even find that he had been seriously to blame
for the child's desertion; therefore he might well resent this tardy
coming to his aid.
Going back step by step over her interview with Miss Parker, Ruth
found that there were many questions which she had failed to ask;
and among them was this important one as to the father's
knowledge of Irene's present name and home. It seemed almost
necessary to wait and write to Miss Parker before attempting
anything. Yet she shrank morbidly from this; it seemed like opening
the whole horror afresh.

If there were actual need on the part of the girl, such as could be
met by money, her way would have been clearer. But of this she had
thought at once, and Miss Parker had almost dignifiedly declined her
help.

"Dear Mrs. Burnham, I consider it my privilege to look after


Maybelle in all such ways; we have done it for years, mother and I
together, and now it seems almost like her trust to me. It has been a
real comfort to see that the child was provided with such little
luxuries of the toilet, for instance, as I longed for and could not
have. We were much straitened in my girlhood, and I have been
living my life over again in this young girl; though she is much less
silly than I was. I must not be deprived of this privilege, Mrs.
Burnham; indeed I have her father's permission to do for her
whatever I think wise; he trusts me fully; and I have no one else,
now, to think about."

So that avenue seemed closed. Ruth, thinking about it almost


irritably as the complications grew upon her, told herself that it
would have been wiser for Mamie Parker to plan to stay away from
China and attend to all the rest of it; she could do it better than any
one else.

She wrote to Miss Parker at last, a careful letter, re-written several


times lest it tell too much between lines.

That young woman had evidently taken it for granted that the
Burnham family were supplied with the main facts in this tragedy,
and had found it hard to rally from her astonishment at finding the
mother in ignorance. Ruth knew that she believed that Erskine was
not. She longed to tell her that this was false, yet held her pen. Did
not this infringe upon her solemn covenant with God to shield her
daughter-in-law as much as right would permit? Yet, was it right to
let her son's good name be smirched unnecessarily in the eyes of
this woman who had known him in his spotless youth?

At last she wrote this:—

"Since our interview I have been through a bitter experience


trying to decide as to my duty in certain directions. I believe
now that I have reached a decision, and feel that I am not
called upon to tear down with my own hands the fair home
which my son believes he has begun to build. He is God's own
servant, and God will see to it that he understands all that he
must understand. I believe that I may leave it with Him."

She waited eagerly for a reply to this letter; it came in the


form of a telegram.

"I am to sail on Saturday. My poor little girl is alone. Father


buried yesterday. Have written.

"M. M. Parker."
CHAPTER XX
THEY HATED MYSTERY

Mrs. Ruth Burnham was settled in a drawing-room car,


surrounded by every comfort and luxury that money and modern
ideas can furnish for a long journey; and her son Erskine stood
looking down on her with a face only half satisfied.

It occurred to him as a matter of astonishment that, with the


single exception of her one trip homeward, after her ministrations to
Alice, and while he was abroad, his mother had not, since he could
remember, taken a journey without him. And here she was, starting
for New York, and planning for a stay of indefinite length, while he
was remaining at home. He did not wholly like it.

"It does not seem quite right, mamma," he said, with a smile that
had almost wistfulness in it. "I am not used to seeing you off, you
know. It seems as though I should be going along to look after your
comfort."

"You have already done that, Erskine; I am sure a queen could


not be more carefully provided for."

"And you have really no idea when you are coming home?"

"I could not plan for it, dear. Your Aunt Flossy is a woman of
many schemes, you know, and it is long since I visited her; not since
you and I were there together, years ago."

"It was always 'you and I together,'" he said, discontentedly, as


though he almost resented this sudden independence of him.
"And this other—person—whoever she is, you will not let her
absorb you? I can see how she will wear you out, without me to
manage for you. She is imperious and selfish, of course."

His mother smiled on him tenderly, and a little sadly. "How did
you learn that, Erskine?"

"Oh, by intuition; or common sense. She would not expect an


entire stranger to take a long and tiresome journey in her behalf if
she were not."

"I don't think she knows anything about the journey, or the
stranger, my son."

"Then it is all Miss Parker's fault?" and he frowned. "She has not
grown like her brother; not as he used to be, at least. Why doesn't
she stay at home and attend to her own affairs, since they are of so
much importance? That sounds ugly, I know, but I don't like to lend
you, mommie, indeed I don't. You belong to me; and besides, there
seems to be an air of mystery about the whole matter, and I hate
mystery; at least between us."

It was at that moment that the call of "all aboard" sounded, and
Erskine gave his mother a hasty last kiss and made flying leaps
toward the platform.

It was a relief to have him go. His mother also hated mystery;
and despite her attempts at frankness, no one was more conscious
than she of the part that she had not told.

She had shown Erskine the telegram and made at the time the
very brief explanation which it had taken her hours to arrange.

"It is a protégé of Miss Parker's, Erskine, for whom she has


bespoken my sympathy and help. The girl is quite alone, her father
has just died; and since I have been long promising your Aunt
Flossy, and they are in the same city, I think I ought to take this time
for my visit."

"A protégé," Erskine had repeated with lifted eyebrows. "A


relative? Is she responsible for her? How can one shift such
responsibilities as that, especially upon a stranger?"

"She is not related to Miss Parker," his mother had replied, and
was glad that at the moment she had been bending over a drawer,
so that her burning face was partially hidden. If Erskine only knew
whose responsibilities had been shifted! It was that thought which
burned her face.

"She is not!" he had replied in an exclamatory tone. "Then why in


the name of common sense should she,"—and then, his mother had
determined what she would say further.

"Erskine,"—her face was still bent over that bureau drawer—"the


peculiar circumstances connected with this child were explained to
me by Miss Parker in confidence, and of course I cannot speak of
them; further than to tell you that she considers the girl as a trust."

"Well," Erskine had said, after waiting a moment for more words
that had not come, "I don't half like it, mamma. I am sure of that;
and if it were not for your making this long-promised visit to Aunt
Flossy, I should not consent to your going. As it is, rushing off at an
hour's notice, in response to an ordinary telegram, as though
somebody had a right to order you around, seems absurd. I shall
write to Aunt Flossy not to let your heart run away with your
judgment. I am really afraid you are being imposed upon, mamma.
Remember, we know nothing about these Parkers."

After his mother had watched, with the nervous tremors with
which one watches when all that one has is jumping from a moving
train—until Erskine was lifting his hat to her from safe ground, and
her train was gliding away from him, she drew a deep breath of
relief; not only from that immediate tension, but all the hours which
had preceded it. Every moment since the arrival of that telegram
had been a nervous strain to her, because of the things that she
must say, and the things that she must not say.

Irene, especially, had taxed her honesty and ingenuity to the


utmost. From the first moment, the young woman had been curious
and painstaking in trying to satisfy herself.

"The idea!" she would exclaim. "It seems to me that is asking a


great deal of an old woman; and Erskine says this Miss Parker is only
a passing acquaintance. What possible claim can she have on you?
Why is she so interested in this girl? Do you understand it? It looks
as though there was a love affair, somewhere, doesn't it? She is an
old maid, of course. You can depend upon it that she was in love
with that girl's father!"

There was a side to this woman which Ruth in her secret soul
called coarse. So far as she knew, it was a phase of her character
that was never exhibited to Erskine.

With her fine regard for truth, and her contempt of anything like
subterfuge, Mrs. Burnham found it hard to satisfy the curious
questioner, and yet keep back that part of the truth which she must
not tell. She could not but be glad when the strain was over.

Not once had she mentioned the name of the girl. It had been a
continual terror to her lest she should be asked it; but though Irene
asked every possible question that might throw light on the mystery,
she had been mercifully preserved from thinking of names. Mrs.
Burnham had learned from Miss Parker that the first name, Maybelle,
would reveal nothing; it had been chosen by the father for his still
nameless child, months after the mother's desertion; and chosen for
no better reason than that Baby had come in the month of May, and
was a "little beauty." But the name of Somerville might at least have
startled Irene, had she heard it; and her mother-in-law determined
that she should not. Having resolved upon silence as the right
course, the more absolute it could be, the better for all concerned.
So it was not until the train was fairly under way, speeding
eastward at thirty miles an hour, that Ruth felt free to draw a long
breath and rest her overstrained nerves. Her mind wandered back
through the years, lured there by the thought of Flossy. It was years
since they two had been alone together, but just at this time Flossy's
husband had taken a hurried business trip abroad.

"It is really providential that I am at home," Flossy had written, in


response to her old friend's letter, telling that she might soon visit
her. "Evan wanted me to go with him, brief as his stay is to be; and I
should have done so, but for the illness of a very dear friend who
seemed to need me; to think that if I had gone, I might have missed
you!"

Dear Flossy! what a rarely wise little woman she had become!
astonishing them all, not by her sweetness,—they had always been
sure of that,—but by her strength and skill as a Christian worker. No
young woman left to herself in a dangerous world could have a
safer, more helpful friend than Flossy Shipley Roberts. Yet Ruth,
even as she thought this comforting thought, remembered that the
duty thrust upon her of guarding the hateful secrets of others must
prevent her from speaking plainly even to Flossy.

However, she found reticence with Flossy easier than it had been
with Irene. Joyfully glad to get possession of her old friend was Mrs.
Roberts, and athrob with eagerness to hear all that she had to tell
her, and sympathetic about the minutest details; yet in nothing did
she show her perfect breeding and rare tact more distinctly than in
the questions that she did not ask, concerning things that Ruth did
not choose to tell.

She told very little.

"You know, Flossy, I have been planning to come to you for a


long, long time."
"I certainly do!" interrupted Flossy, with an air that obliged Ruth
to stop and laugh.

"But the reason I am here just at this time is because a protégé


of my friend—the young woman who sailed last week for China—has
just lost her father and is alone in this great city, so far as relatives
or very close friends are concerned, and I am commissioned to try to
comfort her."

"And I know, dear Ruth, how certainly you will succeed," was Mrs.
Roberts's comment and her only one.

A little later she asked: "Where do you find your charge, Ruth? Is
she a young girl, did you say? Delightful! I hope you will let me
help? Oh, no, I must not go with you on your first visit, of course.
One new face at a time is enough for the poor child to meet."

Ruth blessed her in her heart for the delicate reserve which would
not let her question even about the woman who had gone to China.
After Irene's baldly put inference she shrank from trying to explain
Miss Parker's interest in the girl.

It was on the morning after her arrival in town that Mrs. Burnham
sat waiting in the reception room of a dignified, many-storied house,
which, she told herself, had everywhere about it the unmistakable
boarding-school air.

She had sent up her card, but was uncertain how much it would
tell, or whether she should be allowed to see the person on whom
she had called. As matters had turned out it seemed unfortunate
that she had so long delayed her visit to Mrs. Roberts. If she could
have been introduced here by Miss Parker in person, it might have
been better for all concerned. As it was, she felt strangely out of
place and embarrassed. She had not been able to decide just how
she would account for her extreme interest in this stranger. It was
especially embarrassing to remember that she must account for it
even to the girl herself. While she waited, she went back in memory
to that other waiting, in a boarding-house parlor, when she had
called to see Mamie Parker. What eventful years had intervened, and
what changes they had wrought! How mistaken she, Ruth Burnham,
had been about many things, notably her estimate of Mamie Parker.
Had she been able with prophetic insight to get a vision of the
woman Mamie was to be, would it have made a difference, a radical
difference with all their lives? Then she flushed to her temples as
she remembered that such thoughts were almost an insult to her
son.

Just then the door opened and there entered Madame Sternheim,
the head of the "Young Ladies' Fashionable School."

Madame Sternheim was dignified and correct in every movement


and word, and was as cold as ice.

Yes, Miss Somerville was with them, of course. Her poor father
had left her in their charge, and a serious responsibility she found it.
Oh, yes, Miss Parker, before she left, had spoken of some one by the
name of—of Burnham—she referred to the card which she held in
her hand—who might write, or be heard from in some way. She
seemed not to be at all sure that any one would call.

Yes, certainly, the circumstances were peculiar and had been all
the time. The poor father—it was by no means a pleasant thing to
have to speak plainly of the dead, but it was sometimes necessary,
and perhaps Mrs.—yes, thank you, Mrs. Burnham, knew that he was
not in every respect the fit guardian for a young woman?

Oh, yes, Miss Parker had been most kind, most attentive; Miss
Somerville owed her a deep debt of gratitude, certainly.

It seemed a strange—"Providence—shall we call it?" that took


Miss Parker away to China at just the time when it would appear
that her self-assumed charge needed her the most. She, Madame
Sternheim, had never professed to understand the situation. Miss
Parker, she believed, was not even remotely related to the girl, not
even a relative of the relatives—was she? Yet her interest in the child
and her father had been unaccountably deep. There had always
seemed to her to be an air of mystery about the whole matter.
Madame Sternheim did not like mystery; in fact she might say that
she shrank from it. Did Mrs. Burnham understand that Miss Parker
knew personally any of the family connection?

Ruth was angry with herself that she must blush and almost
stammer over so simple a question.

No, that was what Madame Sternheim had been led to infer. The
relatives were all in England, were they not? It seemed strange that
the girl was not to go out to them; but then, her poor father—Had
Mrs. Burnham been personally acquainted with the father? Well, she
knew of him probably? which was perhaps quite enough. Miss
Parker's unaccountable interest in him was beyond understanding,
until one remembered that no one could tell on what the human
heart would anchor, especially a woman's heart. She had never
thought that Mr. Somerville was especially—but then he, poor man,
was gone; they need not speak of such things now. And Miss Parker,
too, was gone—to China! That was unaccountable. If love for the girl
had been what had prompted her attentions all these years, why,
the poor child was doubly in need of it now. She had been deeply
attached to her father despite the fact that—

"Ah," Madame Sternheim broke off quickly, as the door slowly


opened, to say:—

"Here she is, Mrs. Burnham, to speak for herself."


CHAPTER XXI
"A STUDY"

A tall, pale girl with delicate features and great brown eyes and a
wealth of gold-brown hair.

"A study in black and white," was the phrase that floated through
Ruth's mind as she looked at her. The girl was in deep mourning
unrelieved even by a touch of white, and her face was intensely
pale. Yet there was something about her, a nameless something,
that claimed instant interest, and Mrs. Burnham, who, ever since she
had heard of the girl's existence, had been struggling with an
unreasonable desire to hate her, felt instantly drawn toward her. She
felt rather than realized that, whatever might have been Irene's
appearance in girlhood, the two had nothing in common now, for her
eyes.

"I have heard your name," the pale girl said, much as she might
have addressed a book agent, "but I did not know that you were
coming to New York."

"My dear," broke in Madame Sternheim, reproof in her tone, "I am


sure it is very kind in Mrs.—yes, Mrs. Burnham to take all this trouble
for your sake. She tells me that she is not related to you in any way,
and it is certainly quite unusual for strangers to be so kind."

"It is very kind," the girl said coldly, and stood irresolute
apparently as to what she should do or say next; while Ruth, sorry
for her and for herself and unreasonably annoyed with Madame
Sternheim, was at a loss how to proceed.

The Madame came to her aid, addressing the young girl.


"Do be seated, my dear, and make yourself at least look
comfortable." There was a strong emphasis laid upon the word
"look" and the reproof in the tone was still marked, as she
continued:—

"Mrs. Burnham will naturally want to have a talk with you, and
learn what little you may be able to explain to her about this sad
matter, although I am too fully aware that it will be very
unsatisfactory." Then she turned to Ruth.

"With your permission, dear madam, I will retire and leave my


charge in your care for the present. I assure you it is a great relief to
me to find that there is some one willing to share with me this heavy
responsibility."

The girl turned at this, and with slow, languid steps preceded the
Madame to the door, which she held open for her to pass, and
bowed respectfully as she did so. Then, waiting until a turn in the
hall hid the lady from sight she carefully closed the door.

Ruth, meantime, was watching her with a half-terrified


fascination. She was so calm, so self-possessed, so utterly without
feeling of any sort, apparently. What was to be said to her? and
what good could come in any way from that which now began to
look like interference? She was not in the least prepared for the
sudden change which the closing of that door seemed to make.

The girl turned with an impetuous movement and seemed to fly,


rather than walk, over the space between them, and, flinging herself
in a crushed little heap in front of her guest, hid her face on Mrs.
Burnham's lap and burst into a passion of weeping.

"Poor little girl!" Ruth said softly, and laid her hand tenderly on
the bowed head. There seemed no other word that could be spoken
until the storm of weeping had in a degree subsided.
"Oh, do forgive me!" the child said, after a minute, but without
raising her head. "I did not mean to cry, I meant to control myself; I
thought I could, through it all, but I am so wretched! and she—she
freezes me! she wants me to be resigned, and to remember how
much better off I am than some other girls who have no one to look
after them, and it doesn't help me one bit. I am so glad that you
have come! You are Aunt Mamie's friend, so you can't be like
Madame Sternheim; and you won't tell me that Aunt Mamie isn't
related to me in the most distant degree and in the nature of things
cannot be, will you? I can see that you are not like the Madame the
least bit in the world, and I am glad, glad! Oh! I am a very wicked
girl! I ought not to have said that; she is good, she is very good; and
she is patient with my faults and follies; and yet—there are times
when I almost hate her! Oh, dear! what will you think of me? I don't
act like this very often; I don't cry often—I don't cry at all! but now I
must, or I shall die!"

Then followed another outburst of passionate weeping.

"Cry as much as you want to, dear child," Ruth said. "It is only
natural, and will do you good."

All the time her hand was moving over the tumbled masses of
hair, making quiet, soothing passes.

After a little the girl sat up and brushed away the tears. "I can't
think what made me," she said. "Only you reminded me of Aunt
Mamie, and then—it all came back. I don't know what I am to do; it
seems to me that I cannot live without her, but I have got to; and
without—everybody. It does seem sometimes as though there was
never another girl in the world so utterly alone; but Madame
Sternheim says there are, hundreds of them, even in this city! I am
so sorry for them all! I wish they could die and go to heaven. I wish
I could, with papa. But Madame Sternheim says—" she stopped
abruptly and struggled for self-control, and spoke almost fiercely.
"I won't tell you what she says about my father, nor think about
it. It isn't true, and if it were, she—"

Ruth felt a curious feeling of indignation rising against Mamie


Parker. How could she have deserted this child? so soon, at least,
after her bereavement? Surely she needed her more than the
brother did, who had been alone for years! Then came a great gust
of shame and shook her heart. Why should Mamie Parker, a stranger,
be expected to show compassion for this lonely girl when her own
family, her own mother—But that would not bear thinking about.

"Poor little girl!" she said again, with infinite tenderness. "Will you
take me for a friend? I will do the best I can to be a true one."

"Oh, thank you," the child said impulsively. "I am so glad, so glad
for you! and only last night I thought I could never be glad about
anything again! Aunt Mamie had to go, of course, at the time
appointed. It isn't like other journeys, you know; they have to sail
when they are told; missionaries do, I mean. That is,—oh, you
understand. But Aunt Mamie felt very badly about leaving me; and
she said she thought you would love me; but of course I couldn't
see why you should. It isn't that I am not cared for, Mrs. Burnham. I
have been with Madame Sternheim for six years and I am sure that I
have every care and attention that a girl possibly could; she has
always made that plain to me; but—She did not like papa, Mrs.
Burnham. She never did; and she—almost spoke against him, even
to me! Could a girl ever care very much for one who talked and felt
as she did about the dearest, kindest, most loving papa that ever
lived? oh!"

She clenched her hands, and the tears threatened to choke her;
but she put them back with a strong will, and even faintly smiled.

"I shall not cry again," she said. "Madame thinks it is wicked. Mrs.
Burnham, I wish you could have known my papa. He was—I mean
he was not—oh, I don't know how to say it; and I am not sure that I
want to say it, ever. He was good to me always; a girl like me
couldn't have had a better father; and I don't know how to live in
this world without him. It kills me to have to stay all the time among
people who say always; 'Your poor father!' and shake their heads
and look as though they could say volumes of ugly things about him
if they chose. They shall not! I will not have people talking about my
father! the dearest, the best! a great deal better than the self-
righteous creatures made of icicles that they admire!"

Ruth was amazed at the suppressed fury of her tones, and at her
eyes which, but a moment before dim with weeping, now blazed
with indignation. Evidently the child had passed through a severe
mental strain.

"Don't, dear," she said gently. "No one could be so cruel as to


want to speak against your father. I am glad you love him so dearly;
he can always help you. You will not want to disappoint him in any
way, you know."

The girl looked at her searchingly as one startled. This was


evidently a new thought; it took hold of her heart. A softened light
came into her unusually expressive eyes and after a moment she
said very gently:—

"No one ever said anything to me like that, before. It helps."

They made great strides toward intimacy even in that first


morning. So great that when Ruth, pitying the girl's loneliness and
evident dread of the people by whom she was surrounded, proposed
that she send for her to come and take dinner with Mrs. Roberts and
herself, she caught at the suggestion with an eagerness which
showed what a relief it was to her; and then almost immediately
demurred.

"But I ought not to presume in that way. I am certain the


Madame will think so. Will not your friend think it very strange in
me, a stranger, to intrude upon her home?"
"Wait until you see her," Ruth said, smiling. "Mrs. Roberts and I
are very old friends, and I am almost as much at home in her house
as I am in my own."

As she spoke, she felt a sudden stricture at her heart over those
commonplace words. Was she not in these later days almost more at
home in Flossy's house than in her own?

But Maybelle's face had gloomed over.

"I think I must not go, Mrs. Burnham," she said. "I suppose I
ought not to wish, or even be willing to go; I am sure Madame
Sternheim will be shocked at the idea. I am in deep mourning, you
know, and my loss is so recent."

Unconsciously the child had imitated the prim decorum of her


Mentor, and it had changed her entire face.

Ruth leaned forward impulsively and kissed her, while she spoke
with a smile:—

"Dear child, be yourself, and not Madame Sternheim. Adopt me,


will you, and let me attend to the decorum part, and all the rest.
Mrs. Roberts is quite alone, save for me; her husband is away on a
business trip, and her children have scattered for the vacation; so
we shall be very quiet, we three; and there is no reason in the world
why you should not come to us. I want you to know Mrs. Roberts;
she is anxious to see you, and would have come with me this
morning, if she had not thought it better that you and I should make
each other's acquaintance first. As for you, you will love her the first
time you look at her. Shall I speak to Madame Sternheim myself
about it?"

When this was done, Madame Sternheim was discovered to be


graciousness itself. She might be doubtful as to Mrs. Burnham's
place in the world, her knowledge of people being limited and very
local, but the name of Mrs. Evan Roberts called for instant approval,
and to know that Mrs. Burnham was her friend and guest was
sufficient passport for her. It was very kind and thoughtful in dear
Mrs. Roberts, she was sure, to send for the poor child; and very like
her too, if all that the Madame had heard concerning her was true.
Did Mrs. Burnham know that her friend had the name of always
doing the most delicate kindnesses that no one else would have
thought of? She was really a wonderful woman? Madame Sternheim
had long wanted to know her. They need not trouble to send the
dear child home, she herself was going out this evening, and would
have pleasure in calling for Miss Somerville at ten o'clock.

"Isn't it beautiful here?" Maybelle said, a few hours later, as she


sank among the cushions of a "Sleepy Hollow" and feasted her
beauty-loving eyes on the harmonies of Mrs. Roberts's living-room.
"It is like a poem, or no, a picture; that is what it is like, Mrs.
Burnham; one of papa's pictures. How he would have loved this
room! He was always making sketches of sweet, dear, home rooms,
and there was always a beautiful mother in them with a baby in her
arms. I think my mother must have been very beautiful, for it was
always the same face, and I know it was intended for mamma,
though he never told me so; I could not talk with papa about her,
ever, it made him cry. Don't you think it is dreadful to see a man cry?
When I started the tears in his dear blue eyes, I always felt like a
wretch! and for that reason I gave up trying to say anything about
mamma, though I should so love to have heard every little thing
about her. Papa must simply have adored her, but I have had to
dream her out for myself. I have spent hours and hours over it,
studying papa's sketches, you know, and trying to clothe them with
flesh. I believe I know just how she looked. Sometimes she would
grow so real to me that I almost expected her to hold out her arms
and clasp me to them. I was a wee baby, you know, when mamma
went away."
CHAPTER XXII
A LOYAL HEART

The friendship so strangely started between Mrs. Burnham and


the girl thrust upon her conscience, grew apace. As Ruth had
surmised, her old friend Flossy had lost none of her charm with
young people, and she won Maybelle's fascinated interest from the
first moment of their meeting; an interest that developed rapidly into
love.

When Mrs. Roberts's young people came home—an event that


Ruth, at least, had dreaded for Maybelle's sake—it was found that
the charm was increased. Ruth, in writing to Erskine about them,
which she did at some length, had added: "I might have saved you
much of this description, by simply saying that the children are very
like their mother. Even Erskine, tall and muscular as he is, a
thorough boy in every sense of the word, and a manly one, yet has
that indefinable indescribable charm about him that our little Flossy
always had and always will have, should she live to be a hundred,
bless her! what a blessing she would be to this old world if she
should. Do you realize, dear, that he is your namesake, as well as
mine? At first I was not sure that I wanted another Erskine,—there is
but one to me, you know,—but Erskine Roberts is such a splendid
repetition of the family name that we cannot but be proud of him."

But she gave no description of Maybelle, and mentioned her


name as little as possible. She shrank almost painfully from the
thought of writing about this girl to one who ought to be deeply
interested in her,—as in the nature of the case Erskine should be if
he knew,—and yet looked upon her as an intruder, almost resenting
his mother's efforts in her behalf.
But if she kept silence about her to Erskine, she atoned for it in
the amount of time and thought that she bestowed upon the child.
As the weeks passed and she grew to better understand this child-
woman with whom she had to deal, she found herself bestowing
upon her a wealth of love and tenderness that she had not supposed
any but her very own could call out. And her love was returned in
royal measure. However much Maybelle might admire and love Mrs.
Roberts and enjoy her son and daughters, she had given the wealth
of her heart unreservedly to Mrs. Burnham. "Next to Aunt Mamie I
love you best of all the world," she would declare as she patted
Ruth's shoulder with a loving little touch that was peculiarly her own.
"It ought always to be Aunt Mamie first, you know, because she—
she mothered me all those years when I was hungry for a mother.
Dear Mrs. Burnham, if she were your daughter and I could be your
granddaughter, would not that be perfect? But that couldn't be, of
course, for Aunt Mamie loved her own dear mother better than any
other mother in the world; and she was a dear; I loved her very
much, but—how many different kinds of love there can be in the
same heart!" she broke off to say, with the air of a dreamy
philosopher, "Different kinds of loves and different kinds of unloves,
ever so many of them! the heart is a curious country, isn't it?"

By that time Mrs. Burnham had come to understand Miss Parker's


absorbed interest in the girl, which continued unabated even amid
the absorbing interests of a strange land. She wrote long loving
letters to the child of her adoption, and long earnest ones to Mrs.
Burnham about her.

"There have been times," she wrote, "when I have almost


regretted that I left the dear girl all alone and came away out here
where weeks must intervene before I can hear from her. I felt this
especially after I found that my brother, although very glad indeed to
welcome me, had made interests here about which I knew nothing,
one that is to help make a home for him in the near future, so that
so far as care and companionship are concerned he could have done
very well without me. When I first began to understand the situation
here, I was puzzled, and just a little bit troubled over the question
why I had been allowed to come, or rather left to think that to come
was the only right course, when apparently I was much more
needed at home on that dear child's account, than here. But after
reading Maybelle's letter I understood that it was in order to leave
the way clear and plain for her to your dear heart; you can do so
much more for her than I can ever hope to. How blissful the darling
is over her new friendships and interests! I am glad that you have
kidnapped her loyal little heart, just as I knew you would."

"Poor girl!" Mrs. Burnham said softly to herself after reading this
letter. "She has one of those hungry hearts that Maybelle talks
about; and she fancied that her brother could fill it, instead of being
quite satisfied with his generous corner of it! I wonder if it can be
possible that she cared for the child's father, as the Madame hints?
That would account for—but there is nothing to be accounted for;
one could not help loving Maybelle. I must tell Miss Parker that she
is always to have the first place in that 'curious' heart, while I am
enthroned as second. Dear simpleton!" Then, as the thought crossed
her mind, not for the first time, that the one who should hold that
first place might be named Erskine, the uneasy conviction shook her
that in such event certain ugly truths would have to be revealed.

But she put the thought from her as soon as possible. She could
not plan for the future, and for the present, Maybelle and Erskine
Roberts were simply comrades heartily enjoying each other's society,
as her own Erskine and Alice Warder had done, without apparently
other thoughts than those shared with them by Marian Roberts, who
was Erskine's twin.

Ruth wrote to Miss Parker that same evening, giving her a


detailed account of one of her talks with Maybelle.

"You may well call hers a 'loyal heart,' my friend," she wrote. "You
should hear the pathetic way in which the child talks about you by
the hour! Yesterday she said to me:—
"'Sometimes I used to wish that I could call Aunt Mamie, mother.
She is the only woman that I ever had such a thought about; I
suppose it was because she came close enough to give me an idea
of what a real mother would be. I mean to keep her always for my
heart-mother. There can be heart-mothers, you know, and in some
ways they are almost as dear as real ones. Oh, I wonder if you know
how a girl like me sometimes longs and longs for a real mother! I
think it is the only possession that I ever envied. Sometimes, Mrs.
Burnham, I have been fiercely jealous for hours together, so that I
almost hated the girls who chattered about their mothers. Wasn't
that dreadful! Oh, I cannot think what would have become of me
long before this, if I had not had Aunt Mamie.'"

Thus much Ruth Burnham wrote, and stayed her pen. Was it
necessary for her to tell all this? To lay bare even to this woman,
who knew so much, the depths of a suffering young heart, thereby
revealing the magnitude of the mother's sin against it? And that
mother was her daughter, her son's wife! She wanted to write it;
there were times when she wanted to shout it out to all the world,
just what manner of woman was being sheltered by her name and
home. She knew that she would never do it, but ought not Mamie
Parker who had mothered the child, to understand? She thought
long, she shed a few struggling tears that seemed to burn her face;
the hurt at her heart was too deep for tears, and then she hid her
face on the writing table and talked with God.

The end of it was that she tore the sheet across and threw the
fragments into her grate. And wrote again:—

"You may well call hers a 'loyal heart,' my friend; she loves with a
depth that seems to me unusual in one so young; and she has
enthroned you at her heart's very centre. I want to say, just here,
that I do not think she overestimates what you have done for her; I
believe you have saved her to herself."
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like