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

Download Full A comprehensive introduction to object oriented programming with Java 1st Edition C. Thomas Wu PDF All Chapters

oriented

Uploaded by

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

Download Full A comprehensive introduction to object oriented programming with Java 1st Edition C. Thomas Wu PDF All Chapters

oriented

Uploaded by

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

Download Full ebookname - Read Now at ebookname.

com

A comprehensive introduction to object oriented


programming with Java 1st Edition C. Thomas Wu

https://ebookname.com/product/a-comprehensive-introduction-
to-object-oriented-programming-with-java-1st-edition-c-
thomas-wu/

OR CLICK BUTTON

DOWLOAD EBOOK

Discover More Ebook - Explore Now at ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Object Oriented Programming With C 4th Edition E.


Balagurusamy

https://ebookname.com/product/object-oriented-programming-with-c-4th-
edition-e-balagurusamy/

ebookname.com

Microsoft Visual C 2010 An Introduction to Object Oriented


Programming 4th Edition Joyce Farrell

https://ebookname.com/product/microsoft-visual-c-2010-an-introduction-
to-object-oriented-programming-4th-edition-joyce-farrell/

ebookname.com

Introduction to Object Oriented Programming An 3rd Edition


Timothy Budd

https://ebookname.com/product/introduction-to-object-oriented-
programming-an-3rd-edition-timothy-budd/

ebookname.com

British Economic Development in South East Asia 1880 1939


Volume 1 Agriculture 1st Edition David Sunderland (Editor)

https://ebookname.com/product/british-economic-development-in-south-
east-asia-1880-1939-volume-1-agriculture-1st-edition-david-sunderland-
editor/
ebookname.com
Environmental Bioengineering Volume 11 1st Edition
Svetlana Yu. Selivanovskaya Ph.D.

https://ebookname.com/product/environmental-bioengineering-
volume-11-1st-edition-svetlana-yu-selivanovskaya-ph-d/

ebookname.com

THE SEEDERS The Return Of The Gods 1st Edition Elena


Danaan.

https://ebookname.com/product/the-seeders-the-return-of-the-gods-1st-
edition-elena-danaan/

ebookname.com

Teaching and Learning in Further Education Diversity and


Change 3rd Edition Prue Huddleston

https://ebookname.com/product/teaching-and-learning-in-further-
education-diversity-and-change-3rd-edition-prue-huddleston/

ebookname.com

Africa and the International Criminal Court 1st Edition


Gerhard Werle

https://ebookname.com/product/africa-and-the-international-criminal-
court-1st-edition-gerhard-werle/

ebookname.com

Politics of urban runoff nature technology and the


sustainable city 1st Edition Andrew Karvonen

https://ebookname.com/product/politics-of-urban-runoff-nature-
technology-and-the-sustainable-city-1st-edition-andrew-karvonen/

ebookname.com
Advanced Characterization Techniques for Thin Film Solar
Cells 1st Edition Uwe Rau

https://ebookname.com/product/advanced-characterization-techniques-
for-thin-film-solar-cells-1st-edition-uwe-rau/

ebookname.com
wu23399_fm.qxd 1/10/07 11:53 Page i

A Comprehensive Introduction
to Object-Oriented Programming
TM
with Java

C.Thomas Wu
Naval Postgraduate School
wu23399_fm.qxd 1/10/07 11:53 Page ii

A COMPREHENSIVE INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING WITH JAVA

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

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

This book is printed on acid-free paper.

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

ISBN 978–0–07–352339–2
MHID 0–07–352339–9

Publisher: Alan R. Apt


Executive Marketing Manager: Michael Weitz
Senior Project Manager: Sheila M. Frank
Lead Production Supervisor: Sandy Ludovissy
Associate Media Producer: Christina Nelson
Designer: Rick D. Noel
Cover Designer: Elise Lansdon
(USE) Cover Image: breaking wave on foaming ocean surface, ®Ron Dahlquist/Getty Images
Compositor: ICC Macmillan Inc.
Typeface: 10.5/12 Times Roman
Printer: R. R. Donnelley Crawfordsville, IN

Library of Congress Cataloging-in-Publication Data

Wu, C. Thomas.
A comprehensive introduction to object-oriented programming with Java / C. Thomas
Wu. – 1st ed.
p. cm.
ISBN 978–0–07–352339–2 — ISBN 0–07–352339–9
1. Object-oriented programming (Computer science) 2. Java (Computer program
language) I. Title.

QA76.64.W77 2008
005.117–dc22

2006048064

www.mhhe.com
wu23399_fm.qxd 1/10/07 11:53 Page iii

To my family
wu23399_fm.qxd 1/10/07 11:53 Page iv
wu23399_fm.qxd 1/10/07 11:53 Page v

Contents

Preface xiii
Key Differences from the Standard Edition xiii
Book Organization xiv
Hallmark Features of the Text xviii

0 Introduction to Computers and


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

1 Introduction to Object-Oriented Programming and


Software Development 15

1.1 Classes and Objects 16


1.2 Messages and Methods 18
1.3 Class and Instance Data Values 20
1.4 Inheritance 23
1.5 Software Engineering and Software
Life Cycle 24

v
wu23399_fm.qxd 1/10/07 11:53 Page vi

vi Contents

2 Getting Started with Java 29

2.1 The First Java Program 30


2.2 Program Components 39
2.3 Edit-Compile-Run Cycle 49
2.4 Sample Java Standard Classes 52
2.5 Sample Development 67

3 Numerical Data 81

3.1 Variables 82
3.2 Arithmetic Expressions 90
3.3 Constants 95
3.4 Displaying Numerical Values 97
3.5 Getting Numerical Input 103
3.6 The Math Class 109
3.7 Random Number Generation 113
3.8 The GregorianCalendar Class 115
3.9 Sample Development 120
3.10 Numerical Representation (Optional) 131

4 Defining Your Own Classes—Part 1 145

4.1 First Example: Defining and Using a Class 146


4.2 Second Example: Defining and Using Multiple Classes 156
4.3 Matching Arguments and Parameters 160
4.4 Passing Objects to a Method 162
4.5 Constructors 167
4.6 Information Hiding and Visibility Modifiers 172
4.7 Class Constants 175
4.8 Local Variables 183
4.9 Calling Methods of the Same Class 185
4.10 Changing Any Class to a Main Class 189
4.11 Sample Development 190
wu23399_fm.qxd 1/10/07 11:53 Page vii

Contents vii

5 Selection Statements 213

5.1 The if Statement 214


5.2 Nested if Statements 225
5.3 Boolean Expressions and Variables 231
5.4 Comparing Objects 239
5.5 The switch Statement 244
5.6 Drawing Graphics 248
5.7 Enumerated Constants 258
5.8 Sample Development 264

6 Repetition Statements 295

6.1 The while Statement 296


6.2 Pitfalls in Writing Repetition Statements 305
6.3 The do–while Statement 311
6.4 Loop-and-a-Half Repetition Control 315
6.5 The for Statement 319
6.6 Nested for Statements 324
6.7 Formatting Output 326
6.8 Loan Tables 331
6.9 Estimating the Execution Time 334
6.10 Recursive Methods (Optional) 338
6.11 Sample Development 343

7 Defining Your Own Classes—Part 2 365

7.1 Returning an Object from a Method 366


7.2 The Reserved Word this 370
7.3 Overloaded Methods and Constructors 378
7.4 Class Variables and Methods 383
wu23399_fm.qxd 1/10/07 11:53 Page viii

viii Contents

7.5 Call-by-Value Parameter Passing 387


7.6 Organizing Classes into a Package 394
7.7 Using Javadoc Comments for Class Documentation 395
7.8 The Complete Fraction Class 400
7.9 Sample Development 410

8 Exceptions and Assertions 437

8.1 Catching Exceptions 438


8.2 Throwing Exceptions and Multiple catch Blocks 445
8.3 Propagating Exceptions 450
8.4 Types of Exceptions 458
8.5 Programmer-Defined Exceptions 461
8.6 Assertions 463
8.7 Sample Development 469

9 Characters and Strings 487

9.1 Characters 488


9.2 Strings 491
9.3 Pattern Matching and Regular Expression 502
9.4 The Pattern and Matcher Classes 509
9.5 Comparing Strings 513
9.6 StringBuffer and StringBuilder 515
9.7 Sample Development 521

10 Arrays and Collections 543

10.1 Array Basics 544


10.2 Arrays of Objects 555
10.3 The For-Each Loop 565
wu23399_fm.qxd 1/12/07 13:15 Page ix

Contents ix

10.4 Passing Arrays to Methods 569


10.5 Two-Dimensional Arrays 576
10.6 Lists and Maps 583
10.7 Sample Development 596

11 Sorting and Searching 619

11.1 Searching 620


11.2 Sorting 624
11.3 Heapsort 632
11.4 Sample Development 645

12 File Input and Output 669

12.1 File and JFileChooser Objects 670


12.2 Low-Level File I/O 679
12.3 High-Level File I/O 684
12.4 Object I/O 693
12.5 Sample Development 700

13 Inheritance and Polymorphism 713

13.1 A Simple Example 714


13.2 Defining Classes with Inheritance 717
13.3 Using Classes Effectively with Polymorphism 721
13.4 Inheritance and Member Accessibility 724
13.5 Inheritance and Constructors 729
13.6 Abstract Superclasses and Abstract Methods 733
13.7 Inheritance versus Interface 738
13.8 Sample Development 739
wu23399_fm.qxd 1/10/07 11:53 Page x

x Contents

14 GUI and Event-Driven Programming 765

14.1 Simple GUI I/O with JOptionPane 768


14.2 Customizing Frame Windows 771
14.3 GUI Programming Basics 777
14.4 Text-Related GUI Components 787
14.5 Layout Managers 798
14.6 Effective Use of Nested Panels 808
14.7 Other GUI Components 817
14.8 Menus 835
14.9 Handling Mouse Events 839

15 Recursive Algorithms 859

15.1 Basic Elements of Recursion 860


15.2 Directory Listing 861
15.3 Anagram 863
15.4 Towers of Hanoi 866
15.5 Quicksort 868
15.6 When Not to Use Recursion 873

16 Memory Allocation Schemes and


Linked Data Structures 879
16.1 Contiguous Memory Allocation Scheme 881
16.2 Noncontiguous Memory Allocation Scheme 886
16.3 Manipulating Linked Lists 890
16.4 Linked Lists of Objects 903
16.5 Sample Development 908
wu23399_fm.qxd 1/10/07 11:53 Page xi

Contents xi

17 Generics and Type Safety 945

17.1 Generic Classes 946


17.2 Generics and Collections 961
17.3 Generics, Inheritance, and Java Interface 969
17.4 Additional Topics and Pitfalls 974

18 List ADT 981

18.1 The List ADT 982


18.2 The List Interface 988
18.3 The Array Implementation of the List ADT 992
18.4 The Linked-List Implementation
of the List ADT 1001
18.5 The Linked Implementation
with the Head Node 1018
18.6 The Iterator Design Pattern 1022
18.7 Sample Development 1027

19 Stack ADT 1035

19.1 The Stack ADT 1036


19.2 The Stack Interface 1040
19.3 The Array Implementation 1042
19.4 The Linked-List Implementation 1047
19.5 Implementation Using NPSList 1052
19.6 Sample Applications: Matching HTML Tags 1053
19.7 Sample Applications: Solving
a Maze with Backtracking 1060
wu23399_fm.qxd 1/10/07 11:53 Page xii

xii Contents

20 Queue ADT 1069

20.1 The Queue ADT 1070


20.2 The Queue Interface 1073
20.3 The Array Implementation 1075
20.4 The Linked-List Implementation 1082
20.5 Implementation Using NPSList 1088
20.6 Priority Queue 1089

Appendix A 1099

Appendix B 1107

Appendix C 1133

Appendix D 1155

Index 1163
wu23399_fm.qxd 1/10/07 11:53 Page xiii

Preface

T his book is an in-depth introduction to object-oriented programming using


the Java programming language. In addition to covering traditional topics for a CS1
course, some of the more advanced topics such as recursion and linked lists are in-
cluded to provide a comprehensive coverage of beginning to intermediate-level ma-
terials. There are more materials in the book than what are normally covered in a
typical CS1 course. An instructor may want to teach some of the chapters on data
structures in an advanced CS1 course. Topics covered in Chapters 16 to 20 are also
suitable for use in a CS2 course.

Key Differences from the Standard Edition


This comprehensive edition is based on An Introduction to Object-Oriented Pro-
gramming with Java, Fourth Edition. The key differences between this comprehen-
sive version and the fourth edition standard version are as follows:
1. Data Structures Chapters. Chapter 16 covers topics on managing linked
nodes. Using this as the foundation, Chapters 18 through 20 present three ab-
stract data types (ADTs) List, Stack, and Queue, respectively. For all three
ADTs, both array-based and linked-list implementations are shown, and their
relative advantages and disadvantages are discussed.
2. More Discussion on Java 5.0 Features. Many of the new Java 5.0 features
are explained and used in the sample programs. They include the enumerator
type, the for-each loop construct, auto boxing and unboxing, and the generics.
One complete chapter (Chapter 17) is dedicated to the generics.
3. Exclusive Use of Console Input and Output. All the GUI related topics,
including the JOptionPane class, are moved to Chapter 14. Sample programs
before Chapter 14 use the standard console input (Scanner) and output
(System.out). Those who want to use JOptionPane for simple input and output
can do so easily by covering Section 14.1 before Chapter 3.
xiii
wu23399_fm.qxd 1/10/07 11:53 Page xiv

xiv Preface

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

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

0
1

4
5

6
7

8 9 10
*Note: Some examples use arrays,
11 12 13 14* 15 16 but the use of arrays is not an
integral part of the examples.
These examples can be modified
to those that do not use arrays.
17 18 Many topics from the early part
of the chapter can be introduced
19 20 as early as after Chapter 2.
wu23399_fm.qxd 1/10/07 11:54 Page xv

Preface xv

Brief Chapter Summary


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

xvi Preface

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

Preface xvii

• Chapter 13 discusses inheritance and polymorphism and how to use them ef-
fectively in program design. The effect of inheritance for member accessibil-
ity and constructors is explained. We also explain the purpose of abstract
classes and abstract methods.
• Chapter 14 covers GUI and event-driven programming. Only the Swing-
based GUI components are covered in this chapter. We show how to use the
JOptionPane class for a very simple GUI-based input and output. GUI com-
ponents introduced in this chapter include JButton, JLabel, ImageIcon,
JTextField, JTextArea, and menu-related classes. We describe the effective use
of nested panels and layout managers. Handling of mouse events is described
and illustrated in the sample programs. Those who do not teach GUI can skip
this chapter altogether. Those who teach GUI can introduce the beginning part
of the chapter as early as after Chapter 2.
• Chapter 15 covers recursion. Because we want to show the examples where
the use of recursion really shines, we did not include any recursive algorithm
(other than those used for explanation purposes) that really should be written
nonrecursively.
• Chapter 16 covers contiguous and noncontiguous memory allocation schemes
and introduces the concept of linked lists. Ample examples are provided to
illustrate the manipulation of linked lists of primitive data types and linked
lists of objects. This chapter lays the necessary foundation for the students to
learn different techniques for implementing the abstract data types covered in
Chapters 18 through 20.
• Chapter 17 covers new Java 5.0 generics in detail. The chapter describes how
generic classes are defined and how the type safety is supported by generics.
A concrete example of using generics is shown by defining a simple linked list
with generic nodes.
• Chapter 18 introduces the concept of abstract data types (ADT) and covers
the List ADT. Key features of the List ADT are explained and two implemen-
tations using an array and a linked list are shown. The iterator pattern to tra-
verse the elements in the List ADT is introduced.
• Chapter 19 covers the Stack ADT. Key features of the Stack ADT are ex-
plained and two implementations using an array and a linked list are shown.
Sample applications that use stacks are described.
• Chapter 20 covers the Queue ADT. Key features of the Stack ADT are ex-
plained and two implementations using an array and a linked list are shown.
A special type of queue called a priority queue is also intoduced in this
chapter.
wu23399_fm.qxd 1/10/07 11:54 Page xviii

xviii Preface

Hallmark Features of the Text

Problem Solving

Sample Development Programs


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

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

Overall Plan
Our first task is to map out the overall plan for development. We will identify classes nec-
essary for the program and the steps we will follow to implement the program.We begin
with the outline of program logic. For a simple program such as this one, it is kind of obvi-
ous; but to practice the incremental development, let’s put down the outline of program
flow explicitly. We can express the program flow as having three tasks:

program 1. Get the user’s first, middle, and last names.


tasks
2. Extract the initials to formulate the monogram.
3. Output the monogram.
Having identified the three major tasks of the program, we will now identify the
classes we can use to implement the three tasks. First, we need an object to handle the
input. At this point, we have learned about only the Scanner class, so we will use it
here. Second, we need an object to display the result. Again, we will use System.out, as
it is the only one we know at this point for displaying a string value. For the string

Development Exercises Development Exercises


give students an opportunity For the following exercises, use the incremental development methodology to
to practice incremental implement the program. For each exercise, identify the program tasks, create a
design document with class descriptions, and draw the program diagram. Map
development. out the development steps at the start. Present any design alternatives and
justify your selection. Be sure to perform adequate testing at the end of each
development step.
8. In the sample development, we developed the user module of the keyless
entry system. For this exercise, implement the administrative module that
allows the system administrator to add and delete Resident objects and
modify information on existing Resident objects. The module will also allow
the user to open a list from a file and save the list to a file. Is it proper to
implement the administrative module by using one class? Wouldn’t it be a
better design if we used multiple classes with each class doing a single,
well-defined task?
9. Write an application that maintains the membership lists of five social clubs
in a dormitory. The five social clubs are the Computer Science Club, Biology
Club, Billiard Club, No Sleep Club, and Wine Tasting Club. Use the Dorm
wu23399_fm.qxd 1/10/07 11:55 Page xix

Preface xix

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

/*

Chapter 2 Sample Program: Displaying a Window

File: Ch2Sample1.java

*/

import javax.swing.*;

class Ch2Sample1 {

public static void main(String[] args) {

JFrame myWindow;

myWindow = new JFrame();

myWindow.setSize(300, 200);
myWindow.setTitle("My First Java Program");
myWindow.setVisible(true);
}
}

Good practices on object-


oriented design are
discussed throughout
User module Dorm Resident
the book and illustrated
through numerous
sample programs. Door

Administrative Dorm Resident


module

A helper class A class we One or more classes


provided to us implement we implement

Figure 8.8 Program diagrams for the user and administrative modules. Notice the same Dorm and
Resident classes are used in both programs. User and administrative modules will include one or more
classes (at least one is programmer-defined).
wu23399_fm.qxd 1/10/07 11:55 Page xx

xx Preface

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

Numerical Data Object

int number1, number2; Professor alan, turing;


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

number1 alan

number2 turing

int number1, number2; Professor alan, turing;


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

number1 237 alan

number2 turing

:Professor

int number1, number2; Professor alan, turing;


number1 = 237; alan = new Professor();

number2 = number1; turing = alan;

number1 237 alan

number2 237 turing

:Professor

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

Lucid diagrams are used effectively to explain myList


data structures and abstract data types.
0 1 2 3
Before “cat” “ape” “dog” “bee”

add(1, “gnu”)

myList

0 1 2 3 4
After “cat” “gnu” “ape” “dog” “bee”

myList

0 1 2 3
Before “cat” “ape” “dog” “bee”

throws
add(5, “gnu”) <index-out-of-bounds-exception>

myList

0 1 2 3
“cat” “ape” “dog” “bee” No structural
After
change to the list

Figure 18.2 Sample version 2 add operations on myList.


wu23399_fm.qxd 1/10/07 11:55 Page xxi

Preface xxi

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

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

Tips, Hints, and Pitfalls


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

We didn’t write

Fraction f1, f2;


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

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

You Might Want to Know


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

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

xxii Preface

Supplements for Instructors and Students


On-Line Learning Center is located at www.mhhe.com/wu

For Instructors
• Complete set of PowerPoints, including lecture notes and figures.

• Complete solutions for the exercises


• Example Bank—Additional examples, which are searchable by topic, are
provided online in a “bank” for instructors.
• Homework Manager/Test Bank—Conceptual review questions are stored in
this electronic question bank and can be assigned as exam questions or home-
work.
• Online labs which accompany this text, can be used in a closed lab, open lab,
or for assigned programming projects.
wu23399_fm.qxd 1/10/07 11:55 Page xxiii

Preface xxiii

For Students
• Compiler How Tos provide tutorials on how to get up and running on the
most popular compilers to aid students in using IDEs.

• Interactive Quizzes allow students to test what they learn and get immediate
feedback.
• Source code for all example programs in the book.
• Answers to quick check exercises.
• Glossary of key terms.
• Recent News links relevant to computer science.
• Additional Topics such as more on swing and an introduction to data structures.

Acknowledgments
First, I would like to thank the following reviewers for their comments, suggestions,
and encouragement.

Wu Focus Group—Jackson Hole, WY


Elizabeth Adams, James Madison University
GianMario Besana, Depaul University
Michael Buckley, State University of New York, Buffalo
James Cross, Auburn University
Priscilla Dodds, Georgia Perimeter College
Christopher Eliot, University of Massachusetts-Amherst
Joanne Houlahan, John Hopkins University
Len Myers, California Polytechnic State University, San Luis Obispo
Hal Perkins, University of Washington
William Shea, Kansas State University
Marge Skubic, University of Missouri, Columbia
Bill Sverdlik, Eastern Michigan University
Suzanne Westbrook, University of Arizona
wu23399_fm.qxd 1/10/07 11:56 Page xxiv

xxiv Preface

Reviewers
Ajith, Abraham, Oklahoma State University
Elizabeth Adams, James Madison University
David L. Atkins, University of Oregon
GianMario Besana, DePaul University
Robert P. Burton, Brigham Young University
Michael Buckley, State University of New York, Buffalo
Rama Chakrapani, Tennessee Technological University
Teresa Cole, Boise State University
James Cross, Auburn University
Priscilla Dodds, Georgia Perimeter College
Kossi Delali Edoh, Montclair State University
Christopher Eliot, University of Massachusetts-Amherst
Michael Floeser, Rochester Institute of Technology
Joanne Houlahan, John Hopkins University
Michael N. Huhns, University of South Carolina
Eliot Jacobson, University of California, Santa Barbara
Martin Kendall, Montgomery Community College
Mike Litman, Western Illinois University
Len Myers, California Polytechnic State University, San Luis Obispo
Jun Ni, University of Iowa
Robert Noonan, College of William and Mary
Jason S. O’Neal, Mississippi College
Hal Perkins, University of Washington
Gerald Ross, Lane Community College
William Shea, Kansas State University
Jason John Schwarz, North Carolina State University
Marge Skubic, University of Missouri, Columbia
Bill Sverdlik, Eastern Michigan University
Peter Stanchev, Kettering University
Krishnaprasad Thirunarayan, Wright State University
David Vineyard, Kettering University
Suzanne Westbrook, University of Arizona
Melissa Wiggins, Mississippi College
Zhiguang Xu, Valdosta State University.

The following reviewers have provided feedback on the chapters new to this
comprehensive edition:

Eric Matson, Wright State University


Tim Margush, University of Akron
Roxanne Canosa, Rochester Institute of Technology
Ivan Bajic, San Diego State University
Carolyn Miller, North Carolina State
Sunil Prabhakar, Purdue University
Weining Zhang, University of Texas, San Antonio
wu23399_fm.qxd 1/10/07 11:56 Page xxv

Preface xxv

Personal Story
In September, 2001, I changed my name for personal reasons. Prof C. Thomas
Wu is now Prof Thomas W. Otani. To maintain continuity and not to confuse peo-
ple, we continue to publish the book under my former name. For those who
care to find out a little about my personal history can do so by visiting my web-
site (www.drcaffeine.com).
Other documents randomly have
different content
– Hallgasson meg. Pár éve kinoz.

– Igen Lőrinczre akadt… ki…


– Ne végezze be. Ne sértsen meg, mert minékünk, értse meg jól,
egy élet folyamára barátságban kell maradnunk. Lássa, könyörületes
vagyok magával, pedig maga kegyetlen volt velem. Lőrincz szeret,
igen szeret – s felemelkedett nyergén, derekát kiegyenesítette és
diadalmasan nézett Gáborra; a megsértett asszony kettős diadala
beszélt a tekintetéből.
Az nagy megnyugvásomra van, hogy ezt én mondom el
magának először. Tudom, hogy Lőrincz, ki gyengédebb, mint maga s
gyengédebb, mint én – nem szólott még magának e tárgyról. Én
elmondom, mert úgy vélem, ez a kötelességem…
– És… és? – kérdte Gábor halotthalványan.
– A mi az én érzelmeimet illeti, azt engedje meg, hogy ma éppen
olyan kevéssé tárjam fel maga előtt, mint azelőtt tettem. Azelőtt nem
akarta megismerni gondolat- és érzésvilágomat, most nem fogja.
– Szereti tehát?
– Nem tudom… ma még nem hiszem. Lássa, annyi a közös
magukban, hogy nem tudom, melyik a Lőrincz, melyik maga.
És e perczben valami lehetetlen, valami szédítően merész – és
ügyetlen gondolat fogamzott meg Gábor agyában. Azt hitte, (és
nemcsak logikája, de még lázongó érzései is erre vitték) csak úgy
mentheti meg Lőrinczet, ha maga-magát dobja oda zsákmányul. És
– a pillanat hatása alatt úgy érezte, hogy ez áldozattal tán még
önmaga is nyerni fog.
– Lolly – szeret? Akar nőm lenni? – kérdte határozott hangon, de
oly határozottan, mint csak az kérdhette, ki már e themát hónapok,
évek óta rágva, végre konkluzióra jutott. Úgy érezte, mázsás kő
esett le szivéről e kérdéssel, úgy érezte, újra bizalommal nézhet az
élet elé.
– Nem, nem szeretem – felelt most Lolly épp oly határozott
hangon. – Lássa, sajnálom, hogy oly elővigyázatlan volt. Így hát
elrontotta visszonyunkat egy élet folyamára. Vége – vége. Mennyire
bánom, mennyire fáj. De hát hogy lehetnénk meg már most, egy
ilyen nyilatkozat után, ezentúl egy fedél alatt… utaink szétváltak,
szegény barátom, így Niffor Lőrincz neje csak nem lehet Márfay
Gábor testvére… ki szereti!
– Lolly, Lolly… bocsásson meg, – kiáltott Gábor a kétségbeesés
hangján.
– Az Isten áldja meg… felejtsen el… ezt kívánom magának csak.
És elvágtatott, ott hagyta Gábort egyedül. De egyedül egy élet
folyamára, kifosztva családjától, elvéve életczélját, jövőjének minden
útját eltorlaszolva, ledobva a mélységbe, könyörület és szánalom
nélkül…
8.

Gábor hazaérve bezárkózott.


Így hát vége mindennek. Hiszen mindenkép a lehető
legrosszabbul, legügyetlenebbül cselekedett. Nem csak, hogy
szerelmét, mely – óh emberi szív rejtelmei! – most sokkal nagyobb
intenzivitással ébredt fel lelkében, vesztette el, hanem testvérét is.
Hogy lépjen most már Lőrincz elé? Hogy magyarázza el néki, hogy
nemcsak az önmaga, hanem az ő érdekében is így kellett, hogy
cselekedjen. Ha nem szól, minden önmaga ellen beszél, ha szól –
önmaga. Mit tegyen?…
Így tehát már többé Lőrincz szerencsétlen szerelme ellen nem
dolgozhat. Nincs joga hozzá. Hiszen megkérte. Így méltán azt
vethetné szemére: – Azért beszélsz szerelmem ellen, hogy egyszer
még te vehessed el.
Így hát még testvérét se tudta megmenteni. Megmenteni!…
Elvesztette, hisz ő az oka, hogy így a pusztulás ösvényére lépett.
És ő akarta volna egész törzsét, ezt az egész társadalmat itt
megmenteni?!… Gyenge báb, érzi, olyan, mint Niki bácsi vagy
akármelyik közülök. Nincs erő, energia benne… Életképtelen ő is és
vele a többiek.
9.

Egész éjjel nem aludt, kora hajnalba arra határozta el magát,


hogy azonnal elutazik az Alföldre, Ádámékhoz. Csak édes anyjától
búcsúzott el. Felhasználta az alkalmat, hogy Lőrincz reggel
átlovagolt Tomiékhoz s így tőle nem búcsúzott el. Nem akarta látni,
nem birta volna látni. Azt mondta édes anyjának, hogy alföldi birtokát
akarja rendezni s ezért hívja le gyámja magához.
Édes anyja megcsókolta homlokát s szomorúan így szólt:
– Tégy úgy, a hogy gondolod fiam, nehezemre esik pedig most,
ha akár egy napra is távozol mellőlem – öreg vagyok – s attól félek,
(hisz abban a korban vagytok) egyszer csak végleg kirepültök
szárnyaim alul.
– Édes anyám… soká voltam fészek nélkül nagyon – susogta
halkan és elhallgatott. Végtelen szomorúság vett erőt lelkén,
érezte… úgy érezte, nem lesz többé anyjával, nem lehet többé vele
abban a viszonyban, mint volt. Ha Lőrincz elveszi Lollyt – idegen
lesz hozzá ő is, mint a többiek. És anyjának Lőrinczczel kell
maradnia… neki nagyobb szüksége lesz reá, mint neki. Igen… ez a
két nagy sötét szem, a mely annyit szenvedett s szenvedése oly
gyengéddé tette, nem fog többé oly szomorúan tekinteni reá, mint
most. Ez a kéz, a mely végig simítja a homlokát… hideg leszen
hozzá. Ez az ajak, a mely most ajkait érinti, elveszti bensőségét.
Szeretett volna leborulni anyja előtt s elrejteni fejét ölében és
sírni, sírni…
És az öreg asszony – ki csupa érzés volt, ki érezte fia lelki
állapotát, nem tudta, mi marja, de tudta, hogy boldogtalan. Szeretett
volna oda hajolni reá… s kikérdeni, mije fáj, megkérdeni, adhat-e
balzsamot lelkére, tehet-e érte valamit. De hogyan? És eszélyes lett
volna megint Lollyra vinni a szót? Azt hitte, ez volt oka fia bánatának.
Úgy hitte, az ilyen sebet legjobb hegedni hagyni s nem nyúlni hozzá.
Így hát nem szólt egyik se semmit.
Ott ültek egymás mellett némán… keresve tárgyat, nem hallva
egyebet e perczben, mint a szivük dobogását. Pedig nehéz volt az
egymás hallgatását elviselni.
Lenn végre kocsirobogás.
– Előállott a kocsim, mennem kell, – mondta Gábor s lassan
felkelt helyéről, keresve egy szót, a melybe mindent bele tudjon
foglalni, a mit e perczben érez, anélkül hogy valamit mondana, a
miből édes anyja a közelgő veszedelmet kiérezné.
De hát a szem mindezt még jobban kifejezte. Hallgatva
megcsókolta kezét, aztán ajkait. Édes anyja hevesen a kebléhez
szorította fiát. Soká, némán, összeforrott ajakkal csüngtek egymás
keblén.
Az öreg asszony zokogott… aztán egyszerre kitépve magát fia
karjai közül, csillogó könnyes szemmel mosolyogni igyekezett.
– De milyen gyerek vagyok én vén asszony létemre – hiszen pár
nap mulva látlak megint… Ugy-e?
Gábor nem birt szólani. Némán, szinte szédülve, ingó lábakkal az
ajtó felé haladt, ott megfordult, visszanézett, anyja tekintetét kereste.
– Gábor… akarsz nékem tán valamit mondani? Szólj, mi bajod?
– kérdte az öreg asszony rekedt hangon, megremegve. De már
ekkor fia hirtelen, gyors mozdulattal kirohant az ajtón.
Csak a léptei kopogása hallik, aztán ez is elhal. Most a kocsi
dübörög lenn a kavicsos udvaron… Egy fordulat s az is eltűnik.
És az öreg asszony egyedül maradt.
És az öreg asszony egyedűl maradt.
10.

– Ez aztán a meglepetés öcsém. Tán csak nem untad meg már a


brinza-kosztot – fogadta Ádám nagy örömmel s nevetve Gábort.
– Nem bátyám, csak egy kis búzakenyérre vágytam megint –
mondta Gábor és mosolygott, annyi hét óta először.
– Kapsz mindent, a mit szemed, szád kiván. Paraszt szívet, meg
paraszt konyhát… Ugy-e Cziczellém.
– Ki-ki azt kap nálunk, a mit érdemel – mondta a lány kezet
nyújtva Gábornak. – Te néked a kezünket nyújtjuk? – mondta
szeliden mosolyogva reá.
– Épp erre van szükségem… Csak is erre, – felelt Gábor
hevesen.
– Gyere be fiam s beszélj, látom sok mondani valód van, te meg
lányom láss a reggeli után, öcsémet kiéheztették ott fenn az
ostyepka birodalmában.
A két férfi bement a kis dohányzóba. Letelepedtek a kandalló
mellé, pár perczig mindkettő hallgatott. Aztán Gábor gyorsan, szinte
hadarva mondta el e pár rövid hónap történetét, de nem titkolva el
semmit, még szerelmi tragédiájukat sem.
Ádám végig hallgatta, egyszer se szólt a szavába, csak lassan
pipált s csak azt nézte, a mint a csibukjának a füstje lassan karikázik
a légben.
– Tehát – szólalt meg, hogy Gábor elhallgatott – így végződött a
felsőmagyarországi hadjáratunk. Hm… Vajjon az öreg Gábor mit
szólna, ha hallana ezekről a másvilágon.
– De hát mi lesz így velem?
– Teveled? Te persze atyád végrendeletére gondolsz. Akkor tán
még lehetett volna valamit tenni. Most már késő. Hallgass reám.
Atyád tévedett… most már, hogy itt lenn jártál nálunk, elmondhatom
azt, a mit előbb nem mertem volna néked elmondani…
– Beszélj, – mondta Gábor rekedten az izgatottságtól.
– De mit beszéljek hiába, nézd az Alföldet, ott vannak a
parasztjai, azoké a jövő, mert magyar a világnézletük, magyar az
érzésük. Valamennyinek az anyaföldön áll a lába, és felfelé tekint.
Magyar nem hajtja meg fejét még Istene előtt sem, még azzal is
emelt fővel beszél. Ennek energiájában – mely legerősebb a világon
– szívósságában bízok. Hiába akarták az utolsó évek őrült
nemzetgazdaságával tönkre tenni, hiába nyomták az egyetlen
igazán magyar nemzetgazdasági faktort, a földet, csak gyarapodott s
lerázta válláról a terheket. Él fajunk s élni fog, mert erős és életre
képesebb mind a többinél. És hiába, az fogja Pestre is rányomni
bélyegét, mint már rá is nyomta az irodalmait müvészetére, hisz az
Arany, a Petőfi hatása érzik lépten nyomon. Nézz ki, látod ezt a
rengő buzavetést, – mondta feltárva ablakát – ezt magyar kezek
vetették ide, itt a magyar föld szivét hallhatod verni… ide jere. Én
nem teszek semmit, csak nézem őket s vállaikra támaszkodva
megyek az egyensúly egyenes útján. Ebben élek, ezekkel élek s
úszom az áramlattal… Értesz?
Gábor úgy érezte, mintha álomból ébredne. Derült arczczal,
nyugodtan felkelt s gyámja vállaira támaszkodva, szinte mámorosan
szívta be magába a magyar föld áldott illatát!
11.

A magyar faj megismerését Erzsébeten keresztül kezdte meg.


Ezer kérdést intézett hozzá, akárcsak a vak a vezetőjéhez, midőn
lehullott szeméről a hályog és látni kezd. Mint ki még a tárgyakat
csak tapintja, látva alig ismeri meg.
– Mondd Erzsébet és te nem vagy soha nyugtalan, ideges?
– Valahogy csak lesz, sehogy még nem volt, így mondják a
falunkban.
– De ha valamit kivánsz, akkor mit csinálsz?
– Megvárom, hogy az a valami beteljesedjék. Ha jó, örülök neki,
ha rossz, akkor is elég időm marad búsulni felette, ha már
megtörtént.
– Szerettél már?
A leány elpirult, de azért nyugodtan felelt,
– Különös kérdés. Igen,
– Szeretsz még?
– Igen, még mindig.
– S ha az a valaki nem vesz el – teszem fel? – kérdte Gábor
nyugtalan szemmel vizsgálva tekintetét.
– Akkor – mondta a leány s lehajolt, hogy egy mezei virágot
letépjen – akkor azon fogok igyekezni, hogy egyéb vágyaimat is
mind elöljem azzal az egygyel, a melyben a többi mind benne
foglaltatott.
– Miért?
– Mert akkor a boldogsághoz így kell eljutnom.
– Hisz ez a lemondás.
– Nem, ez a vágytalan boldogság, az a melyről kedves poétám
Czóbel Minka a verseiben beszél. Én az ő tanítványa vagyok.
Szeretem, mert éppen a filozófiájában magyar. Magyar és ezért
evolvált, mint a hogy papa mondja. Igaza van, a vágytalan
boldogság a legtisztább a világon.
– Nagyon okos vagy, de ezt nem értem.
Furcsa volt, új volt néki, a mit a leány mondott.
12.

Másnap két táviratot kapott. Az egyik anyjától jött:


«Lőrincz tegnap jegyezte el Klienigstein Lollyt, az esküvő
szeptemberben lesz. Reménylem, mielőbb haza jösz. Lőrincz
ügyeinek rendezésében segítségedre szorulunk. Ádáméknak sok
szépet, ölel csókol
Anyád.»
A másik: «Ma jegyeztem el Lollyt. Bocsásd meg szerelmemet.
Szeretem, nem tudok nélküle élni. Szeretlek – s barátságodra
szorulok. Gyere minél előbb haza. Elvár… vár
Testvéred.»
És midőn Gábor a két táviratot elolvasta, feltekintett. Szobájából
az udvarra látott. Egy nagy cseresznyefa alatt állott Erzsébet. Egész
arcza nyugalmat lehelt. Sötétkék szemei ragyogtak, telt, kissé
napbarnított arczán, nyoma se volt a kételynek, ajkain szinte kevély
mosoly, egész lénye lelki egyensulyát fejezte ki. Mögötte a puszta
széles lapja, rajta fehér házak, csendes fehér gulyák s mind e felett
a magyar ég végtelen kékje.
13.

Este Ádám cselédjei holdvilágnál csépeltek. Ádám, Erzsébet és


Gábor vacsora után, a verandán telepedtek le. Föl hozzájuk
hallatszott a munkások dala. Rossz termés volt az idén, rozsda
marta az úgy is megritkult gabonát, de azért a részesek daloltak s
daluk életboldogságról beszélt.
Lassan ők is hármasban lementek a géphez… Lőrincz
házasságáról beszéltek, de azért másra gondolt mind a három.
– De, hát én velem mi lesz? – szólalt meg egyszerre Gábor.
– Te… szólalt meg atyja helyet Erzsébet – te köztünk, velünk
maradsz. Megismered a Tisza partját.
– De hát én fenyvesekben nőttem fel!
– Meg kell ezentúl a mi fűzfáinkkal is elégedned… Bánod a
cserét?
– Nem én, szinte azt hiszem, soha nem is láttam fenyőfát.
– Látsz majd ezentúl is egyszer évente, karácsonykor – nevetett
Ádám.
A cséplőgéphez értek. Csodálatosan hatottak a holdfénynél az
ide alá iramló fehér árnyak, a melyeknek erős határozott lépéséből
azonban ki lehetett érezni, hogy biz ezek igazi emberek s nem
fantomok, hiszen itt még a holdvilágnál is tesz és alkot az ember. A
kis gép vígan dudolt, derűlt volt a marokverők nótája:

«Én Istenem, Istenem,


Mire van a szerelem?
Szivárványos az ég alja,
Nem jól van a fejem alja…
Gyere babám, igazítsd meg,
A jó Isten áldjon meg.»

Erzsébet egy marokverő lánynyal elkezdte a kévéket hordani.


Fehér batiszt ruhája nem ütött el az otthon szőtt gyolcs ruháktól.
Ádám ugyanazt a nyelvet beszélte, mint annak a gazdának a szava,
kihez szólott.
– Lesz gabonánk István?
– Kevesebb jóval mint tavaly.
– Szorult a szeme?
– Tavaly volt elég, a jövő meg Isten kezében van.
– Abban, Gábor, a magyarok Istenében – mondta Ádám
Gáborhoz fordulva s rátette a fiú vállára a kezét. Erzsébet már ott
volt mellettük.
– Nem megy – nevette – ha gazda lánya lennék, nem venne el
senki. Rossz marokverő vagyok.
– Hát a magyarok Istene annak teremtette a báró kisasszonyt a
mi – mondta István gazda, figyelve, a mit azok beszéltek – tán majd
csak esztán se feledkezik meg róla.
14.

Egész augusztust gyámjával töltötte Gábor. Lőrincz esküvőjéről


csak Nifforné írt szorgalmasan, változatlan pontossággal, minden
két-három nap levelet Gábornak. Az esküvő Niffor Tomiéknál lesz
szeptember 15-én. A lakodalom nagyszerűnek igérkezik, Bécsből is
jönnek sokan, az esküvőt nagy caroussel előzi majd meg (furcsa
gondolat!), természetesen Ádámékat is elvárjuk az
ünnepélyességekre. Legalább alkalom lesz Ádámnak Erzsébetet
bemutatni. Igen – legjobb alkalom lesz erre – mondta utána Gábor.
«Vőfély, négy lesz, te – és Klienigstein Hanzi vezetitek a
menyasszonyt, aztán a két Bálványossy fiú (hogy Miczi jóvá tegye
így a Júlián esett sérelmet), a menyasszony uszályát Tomi két fia
fogja vinni apród-ruhában. Nyoszolyólányok: Bálványossy Julie s két
vagy három bécsi comtesse, a násznagyi tisztet meg Niffor Tomi,
Czobor Ádám és Niki bácsi töltik be, hogy így családjaink mind
képviselve legyenek.»
Így írt meg az öreg grófné majd mindent, a mi előadta magát –
csakhogy a szive érzéseit ne kellessen megírnia. És Gábor is csak a
faktumokat olvasta a levélből s nem akart mellé semmit, de semmit
gondolni.
– Tán már az esküvő ténye is csak mint rideg, száraz elvont
esemény tűnt fel előtte? Csak ha Lőrinczre gondolt, akkor áradt túl
érzéssel is lelke, akkor szeretett volna még tenni, akkor ébredt fel
lelkében a régi tettvágy.
Lolly?… Csak az utolsó két találkozás Lollyja lebegett szemei
előtt. Elragadóan, szépen, de hidegen – szívtelenűl.
15.

Egy augusztusi estén történt. Ádám Tisza-Füredre ment. Gábor


egyedül maradt Erzsébettel. Kinn ültek a terasseon s csendes
szívvel azt hallgatták… hogy tér nyugalomra az egész falu. Most épp
a gulya kolompja hallik, a kert alatt halad el…
– Milyen jó is a nyugalom… – mondta Gábor messze nézve.
– Kivált annak, a kinek az otthonában van a nyugalma is.
– Más nyugalmat el se képzelek…
– És oda fenn… nem szerettél köztük…
– Testem, lelkem ide húz. Nem vagyok én közéjük való. Aztán
meg amott az egészben önmagamat láttam… Meg fáradt is vagyok.
Az én véremben nincs meg már a küzdelem vágya.
– Pedig szép, szép lehet egy eszméért lelkesülni, azért tenni! Én
sajnálom, hogy nem férfinak születtem…
– De hisz így van vágyad…
– Csak tréfálok. Jó így, így a legjobb…
S a leány csak mosolygott nyugodtan. Arczán nyoma sincs a
bánatnak, küzdelemnek. Szinte egy vonása sem árulja el azt, hogy
van valami ott túl annak a falunak a határán is, s hogy ott
körömszakadtáig foly a küzdelem és ennek a küzdelemnek a neve:
élet. És mégis úgy érezte, ez a leány megértette azt, a mit alig ismer.
És nem félhet semmitől, mert passzivitásában el hagyja maga felett
rohanni a lét s nemlét esélyeit és nem fél sem egyik, sem másiktól,
mert – mint mondja – s mint a hogy Gábor érzi is rajta – vágyai
nincsenek.
– És – kérdte Gábor valami titkos ösztöntől megkapva – ha
szeretni fogsz, hová lesz nyugalmad?
– Abba helyezem, akit szeretni fogok…
– És te csak boldog szerelmet képzelsz?
– Csak. Mert azt, ki engem nem szeret – azt én se tudnám
szeretni, érzem…
S a leány nyugodtan, biztosan mondta ezt, érzett rajta, hogy ez
így lesz, hogy ez máskép nem is lehetséges…
Párbeszédüket egy szolga zavarta meg, ki oda lépett a leányhoz
s valamit súgott a fülébe. Gábor észrevette, hogy az megrezdült,
aztán felveszi kalapját, feláll s elindul a falu irányába.
– Hová mész?
– A faluba, egy betegem, egy szegény öreg asszony haldoklik,
ahhoz.
– Mehetek veled?
– Jere.
Elindultak. Az est már tökéletesen leszállt. A nyugati ég
hamvaskék alapjából azért még kiváltak a fehér házak. Az estharang
is szólott, a hazatérők csizmái is csak kopogtak a járdán. – Mintha itt
most minden ember boldog lenne – mondta Gábor – ki hinné, hogy e
pár házon túl valaki haldoklik?
A leányra nézett, az nem sietett, annak nem változott az
arczkifejezése. Szívtelen talán?…
Beléptek a házba. Az asszony ott feküdt a vaczkon. Igen
szegény lehetett s nagyon öreg. Egy pár rozoga bútor volt csak a
házában, a melynek alacsonyak voltak a gerendái, piczinyek az
ablakai. Az ágy mellett egy szál fagygyúgyertya volt, – de volt ott egy
nagy csokor virág is. Olyan mint a milyeneket Erzsébet szokott kötni.
Az asszony nem tudott már beszélni. De a mint meglátta a
«Miasszonyunkat», megtört fényű szemei még felvillantak. Szinte az
élet tért vissza beléjük.
A leány nyugodtan mosolyogva leült ágyára, megigazította fejét,
takaróját s végig símította homlokán a kezét. Gábor leült a szoba
sarkában egy rozoga székre s nézett. Erzsébet nyugodt hangon
beszélt az asszonynak. Elmondta a kis udvar száz baját. Mindegyik
szárnyasról tudott hírt adni az öreg néninek.
– Tudod Terka, az a kisebb gyöngytyukom rosszul költ. Mind
összetörte a tojásait. Most hozattam Pestről egy másikat… az öreg
tyúk meg megdöglött.
Az öreg asszony sajnálkozva nézett fel.
– Azt a kappant meg, a melyik a kis csirkékkel járt, megczibálta
multkor a czirmos.
Az öreg asszony úgy látszik mind ismerte őket, nagy figyelemmel
hallgatta a szavait. Erzsébet csak beszélt, nyugodt arczczal. Az öreg
asszony szemei meg mind üvegesebbek, mind merevebbek
lesznek… egyszer csak egyet sóhajtott – meghalt.
A leány csak mosolygott szelíden tovább. Odahajolt reá,
lenyomta tágra nyilt szempilláit, aztán felvette a nagy bokrétát az
asztalról s virágokkal hintette be az öreg asszonyt, ki folyton
mosolygott ott a fehér virágok alatt.
A házban erős virágillat terjengett.
A leány még egyszer körülnézett, aztán lábujjhegyen, ujját ajkára
emelve, kiszaladt a szobából. Gábor követte.
– Furcsa – mondta aztán hosszú hallgatás után – nálatok a halál
jobban hasonlít az élethez, mint oda fenn az élet maga…
És oly jól esett néki, hogy e perczben a leány nyugodtan a
szemébe tekint.
16.

Este, hogy Ádám hazajött, soká beszélgettek még a délutáni


jelenetről.
– Látod Gábor, ime a magyar superioritása minden faj felett. A
fantázia és a rationálismus fakultásai közötti összhang és egyensúly
teszi őt a világ egyik legerőteljesebb népévé. Ez az asszony
nyugodtan halt meg, mert tudta, nem rossz helyre jut a földbe (van-e
a parasztnak kedvesebb helye a világon?) s mert tudta, hogy a halál
se nem jó, se nem rossz, hanem a lét szükségképeni és bizonyos
vége. És így van népünk az elemi csapásokkal is. Jégverés után,
akkor, midőn a be nem biztosított «urak» jajgatva lamentálnak tele
hét határt, a parasztgazda, ki tán többet vesztett, mert mindennapi
kenyere is vele ment az elpusztult terméssel, nyugodtan hazamegy s
ujra dolgozni kezd, mintha semmi se történt volna.
– Hisz ez jóformán a keletiek «málese».
– Csakhogy, ha a keleti ember háza leég, hát nem panaszkodik s
igaz, hogy így kiált fel: «máles» – Allah adta, Allah elvette: a magyar
paraszt se fog panaszkodni, csakhogy azonnal a leégett ház ujra
építéséhez fog. A magyar parasztban a keletiek fiatal fatalismusába
már a nyugati népek tettvágya van beoltva… legfőbb elve: élni az
életet. Így mondja azt még typikus vallásában, a nazarénizmusban
is, bár itt hozzá teszi: «ha már egyszer ránk van mérve. Hisz a halál
nem veszedelem, az élet meg kötelesség». Ha valamivel több
rationalismus lenne bennök, sajnálnák itt hagyni a földi javakat, ha
pedig valamivel több fantázia mint kéne, rettegnének az
ismeretlentől. Nincs a magyarban semmi túlságos, harmonikus a
nyelve, az észjárása, a filozofiája, még a vallása is… Ezért jó itt,
nagyon jó.
De azért Gábor csak pár napig maradt. Mind jobban áthasonulva
magyarrá, «turán» lett belőle, mint a hogy Ádám szokta mondani.
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!

ebookname.com

You might also like