eTextbook 978-0134285436 Java Foundations: Introduction to Program Design and Data Structures (4th Edition) instant download
eTextbook 978-0134285436 Java Foundations: Introduction to Program Design and Data Structures (4th Edition) instant download
https://ebookmass.com/product/etextbook-978-0134285436-java-
foundations-introduction-to-program-design-and-data-
structures-4th-edition/
https://ebookmass.com/product/c-programming-program-design-including-
data-structures-8th-edition-d-s-malik/
https://ebookmass.com/product/etextbook-978-1285856872-c-programming-
from-problem-analysis-to-program-design/
https://ebookmass.com/product/etextbook-978-0134448237-c-how-to-
program-10th-edition/
https://ebookmass.com/product/starting-out-with-java-from-control-
structures-through-data-structures-3rd-edition-ebook-pdf/
Data structures and algorithm analysis in Java 3rd ed
Edition Mark Allen Weiss
https://ebookmass.com/product/data-structures-and-algorithm-analysis-
in-java-3rd-ed-edition-mark-allen-weiss/
https://ebookmass.com/product/etextbook-978-1305575073-introduction-
to-health-care/
https://ebookmass.com/product/etextbook-978-1305969766-introduction-
to-criminal-justice/
https://ebookmass.com/product/etextbook-978-1305251472-introduction-
to-process-technology/
https://ebookmass.com/product/etextbook-978-0135121030-police-
administration-structures-processes-and-behavior/
Preface
Welcome to Java Foundations. This book is designed to serve as the primary resource for a two- or three-term
introductory course sequence, ranging from the most basic programming concepts to the design and implementation
of complex data structures. This unified approach makes the important introductory sequence more cohesive and
accessible for students.
We’ve borrowed the best elements from the industry-leading text Java Software Solutions for the introductory material,
reworked to complement the design and vision of the overall text. For example, instead of having graphics sections
spread throughout many chapters, the coverage of graphical user interfaces is accomplished in a well-organized
chapter of its own.
In the later chapters, the exploration of collections and data structures is modeled after the coverage in Java Software
Structures, but has been reworked to flow cleanly from the introductory material. The result is a comprehensive,
cohesive, and seamless exploration of programming concepts.
We appreciate the feedback we’ve received about this book and are pleased that it continues to serve so well as an
introductory text. The following modifications have been made to improve the presentation of particular topics and
the overall flow:
Added an application in Chapter 18 that animates the sort algorithms to compare efficiency.
Added an introduction to thread processing as part of the new sort animation example.
Revised the discussion of binary search trees to provide a more comprehensive introduction.
Your feedback indicated that you did not want to see the discussion of Swing completely replaced by JavaFX coverage,
so we’ve kept the Swing content and added a new JavaFX chapter. Eventually, JavaFX will replace Swing, but with the
huge amount of code relying on it, knowledge of Swing will be important for quite a while.
In the third edition, we had established the following flow when discussing collections:
The feedback has indicated that this modification was well received and we have continued and reinforced its use. It
clarifies the distinction between the way the Java API supports a particular collection and the way it might be
implemented from scratch. It makes it easier for instructors to point out limitations of the API implementations in a
compare-and-contrast fashion. This approach also allows an instructor, on a case-by-case basis, to simply introduce a
collection without exploring implementation details if desired.
We think these modifications build upon the strong pedagogy established by previous editions and give instructors
more opportunity and flexibility to cover topics as they choose.
Chapter Breakdown
Chapter 1 (Introduction) introduces the Java programming language and the basics of program
development. It contains an introduction to object-oriented development, including an overview of
concepts and terminology. This chapter contains broad introductory material that can be covered while
students become familiar with their development environment.
Chapter 2 (Data and Expressions) explores some of the basic types of data used in a Java program and the
use of expressions to perform calculations. It discusses the conversion of data from one type to another,
and how to read input interactively from the user with the help of the Scanner class.
Chapter 3 (Using Classes and Objects) explores the use of predefined classes and the objects that can be
created from them. Classes and objects are used to manipulate character strings, produce random numbers,
perform complex calculations, and format output. Packages, enumerated types, and wrapper classes are
also discussed.
Chapter 4 (Conditionals and Loops) covers the use of boolean expressions to make decisions. All related
statements for conditionals and loops are discussed, including the enhanced version of the for loop. The
Scanner class is revisited for iterative input parsing and reading text files.
Chapter 5 (Writing Classes) explores the basic issues related to writing classes and methods. Topics include
instance data, visibility, scope, method parameters, and return types. Constructors, method design, static
data, and method overloading are covered as well. Testing and debugging are now covered in this chapter
as well.
Chapter 6 (Graphical User Interfaces) is a thorough exploration of Java GUI processing, focusing on
components, events, and listeners. Many types of components and events are discussed using numerous
GUI examples. Additionally, layout managers, containment hierarchies, borders, tooltips, and mnemonics
are introduced.
Chapter 7 (Arrays) contains extensive coverage of arrays and array processing. Topics include bounds
checking, initializer lists, command-line arguments, variable-length parameter lists, and multidimensional
arrays.
Chapter 8 (Inheritance) covers class derivations and associated concepts such as class hierarchies,
overriding, and visibility. Strong emphasis is put on the proper use of inheritance and its role in software
design.
Chapter 9 (Polymorphism) explores the concept of binding and how it relates to polymorphism. Then we
examine how polymorphic references can be accomplished using either inheritance or interfaces. Design
issues related to polymorphism are examined as well.
Chapter 10 (Exceptions) covers exception handling and the effects of uncaught exceptions. The try-catch
statement is examined, as well as a discussion of exception propagation. The chapter also explores the use
of exceptions when dealing with input and output, and examines an example that writes a text file.
Chapter 11 (Analysis of Algorithms) lays the foundation for determining the efficiency of an algorithm and
explains the important criteria that allow a developer to compare one algorithm to another in proper ways.
Our emphasis in this chapter is understanding the important concepts more than getting mired in heavy
math or formality.
Chapter 12 (Introduction to Collections—Stacks) establishes the concept of a collection, stressing the need
to separate the interface from the implementation. It also conceptually introduces a stack, then explores an
array-based implementation of a stack.
Chapter 13 (Linked Structures - Stacks) discusses the use of references to create linked data structures. It
explores the basic issues regarding the management of linked lists, and then defines an alternative
implementation of a stack (introduced in Chapter 3) using an underlying linked data structure.
Chapter 14 (Queues) explores the concept and implementation of a first-in, first-out queue. Radix sort is
discussed as an example of using queues effectively. The implementation options covered include an
underlying linked list as well as both fixed and circular arrays.
Chapter 15 (Lists) covers three types of lists: ordered, unordered, and indexed. These three types of lists
are compared and contrasted, with discussion of the operations that they share and those that are unique
to each type. Inheritance is used appropriately in the design of the various types of lists, which are
implemented using both array-based and linked representations.
Chapter 16 (Iterators) is a new chapter that isolates the concepts and implementation of iterators, which
are so important to collections. The expanded discussion drives home the need to separate the iterator
functionality from the details of any particular collection.
Chapter 17 (Recursion) is a general introduction to the concept of recursion and how recursive solutions
can be elegant. It explores the implementation details of recursion and discusses the basic idea of analyzing
recursive algorithms.
Chapter 18 (Searching and Sorting) discusses the linear and binary search algorithms, as well as the
algorithms for several sorts: selection sort, insertion sort, bubble sort, quick sort, and merge sort.
Programming issues related to searching and sorting, such as using the Comparable interface as the basis of
comparing objects, are stressed in this chapter. An application uses animation to demonstrate the efficiency
of sorting algorithms. The comparator interface is examined and demonstrated as well.
Chapter 19 (Trees) provides an overview of trees, establishing key terminology and concepts. It discusses
various implementation approaches and uses a binary tree to represent and evaluate an arithmetic
expression.
Chapter 20 (Binary Search Trees) builds off of the basic concepts established in Chapter 10 to define a
classic binary search tree. A linked implementation of a binary search tree is examined, followed by a
discussion of how the balance in the tree nodes is key to its performance. That leads to exploring AVL and
red/black implementations of binary search trees.
Chapter 21 (Heaps and Priority Queues) explores the concept, use, and implementations of heaps and
specifically their relationship to priority queues. A heap sort is used as an example of its usefulness as well.
Both linked and array-based implementations are explored.
Chapter 22 (Sets and Maps) explores these two types of collections and their importance to the Java
Collections API.
Chapter 23 (Multi-way Search Trees) is a natural extension of the discussion of the previous chapters. The
concepts of 2-3 trees, 2-4 trees, and general B-trees are examined and implementation options are
discussed.
Chapter 24 (Graphs) explores the concept of undirected and directed graphs and establishes important
terminology. It examines several common graph algorithms and discusses implementation options,
including adjacency matrices.
Chapter 21 (Databases) explores the concept of databases and their management, and discusses the basics
of SQL queries. It then explores the techniques for establishing a connection between a Java program and a
database, and the API used to interact with it.
Chapter 21 (JavaFX) presents several examples using the new JavaFX framework for GUIs and graphics. A
comparison of the Swing and JavaFX approaches is followed by an introduction to several JavaFX elements.
The JavaFX Scene Builder application is explored as well.
Supplements
The following instructor resources can be found at Pearson Education’s Instructor Resource Center:
Test bank
To obtain access, please visit www.pearsonhighered.com/irc or contact your local Pearson Education sales
representative.
Contents
1. Preface vii
2. Credits xxx
3. VideoNotes xxxii
4. Chapter 1. Introduction 1
1. A Java Program 3
2. Comments 5
4. White Space 9
3. Development Environments 15
5. Errors 17
2. String Concatenation 36
3. Escape Sequences 40
1. Variables 41
3. Constants 46
2. Characters 48
3. Booleans 50
4. 2.4 Expressions 51
1. Arithmetic Operators 51
2. Operator Precedence 52
4. Assignment Operators 57
1. Conversion Techniques 60
1. Aliases 78
3. 3.3 Packages 83
1. Autoboxing 102
2. Parameters 196
3. Aggregation 206
1. Reviews 225
4. Sliders 267
6. Timers 277
1. Borders 317
2. Generics 487
1. Javadoc 496
1. Threads 694
1. B*-Trees 867
2. B+-Trees 867
1. Traversals 880
1. Insert 917
3. Update 922
3. Conversions 984
1. Chaining 1053
But now his firmness was put to the severest test. Letters arrived
from his family, containing the bitterest reproaches. He was even
accused of want of parental care and gross neglect of his wife and
home. This was indeed hard to bear. La Fayette was deeply in love
with his winsome and affectionate wife. But with an unselfishness
which amounted to the sublimity of heroism, his young wife
restrained her tears, lest he should be blamed, and bravely
determined to bear the parting uncomplainingly. Such a heroine as
she afterwards proved herself to be made her a truly worthy
companion for her hero-husband.
Letters came, also, under kingly authority, forbidding his
embarkation for America, threatening severe displeasure in case of
disobedience. Sovereign displeasure, La Fayette was well aware,
meant liability to the confiscation of all his property, and public
disgrace. Feigning obedience, La Fayette returned to Bordeaux, and
wrote to the ministry, requesting permission to carry out his plans,
representing the benefits which France would derive by the wresting
of this coveted land from proud England. But the king was not
prepared to excite the wrath of his powerful neighbor, and no reply
was sent directly to La Fayette, though he was made to understand,
through friends, that his petition had been refused.
He shortly afterwards received orders to proceed to Marseilles,
and join himself to the Duke d’Ayen, who was going into Italy. La
Fayette now determined to brave all hazards. He accordingly
departed ostensibly for Marseilles, but soon changed his route and
went directly to Passage, and there embarked on his gallant ship
Victory, and unfurled the sails, pointing the prow of his vessel
towards the land of liberty. As soon as it was ascertained that La
Fayette had gone, despatches were sent to arrest him at the West
Indies. But La Fayette, suspecting this, ordered his captain to steer
directly for America.
His wearisome voyage lasted for two months. Seasickness added
its discomforts to the anxieties, regrets, and aspiring longings which
made keen warfare in his saddened heart. Would his wife forgive
him for this seeming desertion? Would his country renounce him?
Would his unselfish and magnanimous sacrifice avail in the cause of
liberty, which was the ruling passion of his life? Weak with sickness
and tempest-tossed, he addressed to his wife these pathetic letters:
—
Again he writes:—
“June 19.
“I landed at Charleston, after having sailed for several days along
a coast swarming with hostile vessels. On my arrival here every one
told me that my ship would undoubtedly be taken, because two
English frigates had blockaded the harbor. I even sent, both by land
and by sea, orders to the captain to put the men on shore, and burn
the vessels, if he had still the power of doing so. Eh bien! by a most
extraordinary piece of good fortune, a sudden gale of wind having
blown away the frigates for a short time, my vessel arrived at
noonday, without having encountered friend or foe. At Charleston I
have met General Howe, a general officer now engaged in service.
The governor of the state is expected this evening from the country.
All the persons with whom I wished to be acquainted have shown
me the greatest attention and politeness—not European politeness
merely. I can only feel gratitude for the reception tendered me,
although I have not yet thought proper to enter into any details
respecting my future prospects and arrangements. I wish to see the
Congress first. I hope to set out in two days for Philadelphia, which
is a land journey of more than two hundred and fifty leagues. We
shall divide into small parties. I have already purchased horses and
light carriages for this purpose.
“I shall now speak to you, my love, about the country and its
inhabitants, who are as agreeable as my enthusiasm led me to
imagine. Simplicity of manner, kindness of heart, love of country and
of liberty, and a delightful state of equality are universal. The richest
and the poorest men are completely on a level; and, although there
are some immense fortunes in this country, I may challenge any one
to point out the slightest difference in their respective manner
toward each other. I first saw and judged of a country life at Major
Huger’s house. I am at present in this city, where I notice a
resemblance to English customs, except that I find more simplicity
here than in England.
“Charleston is one of the best built, handsomest, and most
agreeable cities that I have ever seen. The American women are
very pretty, and have great simplicity of character. The extreme
neatness of their appearance is truly delightful. Cleanliness is
everywhere even more studiously regarded here than in England.
What gave me most pleasure is to see how completely the citizens
are all brethren of one family. In America there appear to be none
poor, and none even who can be called peasants. Each citizen has
some property, and all citizens have the same rights as the richest
individual or landed proprietor in the country. The inns are very
different from those in Europe; the host and hostess sit at table with
you, and do the honors of a comfortable meal, and when you depart
you pay your bill without being obliged to fee attendants. If you
dislike going to inns, you always find country houses, in which you
will be received as a good American, with the same attention that
you expect to find at a friend’s house in Europe.
“My own reception has been peculiarly agreeable. To have been
merely my travelling companion suffices to secure the kindest
welcome. I have just passed five hours at a large dinner, given in
compliment to me by an individual of this town. Generals Howe and
Moultrie, and several officers of my suite, were present. We drank
each other’s health, and endeavored to talk English, which I am
beginning to speak a little. I shall pay a visit to-morrow, with these
gentlemen, to the governor of the state, and make the last
arrangements for my departure. The next day the commanding
officer here will take me to see the town and its environs, and I shall
then set out to join the army.
“From the agreeable life I lead in this country, from the sympathy
which makes me feel as much at ease with the inhabitants as if I
had known them twenty years, the similarity between their manner
of thinking and my own, my love of glory and liberty, you might
imagine that I am very happy; but you are not with me, my dearest
love; my friends are not with me; and there is no happiness for me
when far away from you and them. I often ask you if you still love,
but I put that question still more often to myself, and my heart ever
answers yes. I trust that my heart does not deceive me. I am
inexpressibly anxious to hear from you, and hope to find some
letters at Philadelphia. My only fear is lest the privateer which was to
bring them to me may have been captured on her way. Although I
can easily imagine that I have excited the special displeasure of the
English, by taking the liberty of coming hither in spite of them and
landing before their very face, yet I must confess that we shall be
even more than on a par if they succeed in catching that vessel, the
object of my fondest hopes, by which I am expecting to receive your
letters.
“I entreat you to send me both long and frequent letters. You are
not sufficiently conscious of the joy with which I shall receive them.
Embrace, most tenderly, my Henriette; may I add, embrace our
children! The father of those poor children is a wanderer, but he is,
nevertheless, a good, honest man, a good father, warmly attached to
his family, and a good husband also, for he loves his wife most
tenderly. The night is far advanced, the heat intense, and I am
devoured by mosquitoes; but the best countries, as you perceive,
have their inconveniences. Adieu, my love, adieu.”
Again La Fayette writes to his wife from Petersburg, Va., July 17,
1777:—
“I am now eight days’ journey from Philadelphia, in the beautiful
state of Virginia. All fatigue is over, and I fear that my martial labors
will be very light if it be true that General Howe has left New York, to
go I know not whither. But all the accounts I receive are so
uncertain that I cannot form any fixed opinion until I reach my
destination.
“You must have learned the particulars of the beginning of my
journey. You know that I set out in a brilliant manner, in a carriage,
and I must now tell you that we are all on horseback,—having
broken the carriage according to my usual praiseworthy custom,—
and I expect soon to write to you that we have arrived on foot. The
journey is somewhat fatiguing; but, although several of my
comrades have suffered a great deal, I have scarcely, myself, been
conscious of fatigue. The captain, who takes charge of this letter, will
perhaps pay you a visit. I beg you, in that case, to receive him with
great kindness.
“The farther I advance to the north, the better pleased I am with
the country and its inhabitants. There is no attention or kindness
that I do not receive, although many scarcely know who I am. But I
will write all this to you more in detail from Philadelphia.”
As soon as La Fayette arrived in Philadelphia, he presented himself
before Congress, then in session. The moment was inauspicious. Mr.
Deane had given so many foreigners the same promises, that
Congress found itself in a very embarrassing situation. Many of these
foreigners were brave men, and true, who had come to America with
philanthropic motives, but others were mere adventurers, and
Congress therefore received the young Marquis de La Fayette with
coldness and indifference, which he illy deserved, and which in the
light of after events proved a mortifying mistake. La Fayette laid his
stipulations with Mr. Deane before Congress, but, with surprise and
chagrin, he was informed by the chairman of the Committee on
Foreign Affairs that there was little hope that his request would be
granted.
Imagine the feelings of the noble young marquis of nineteen. He
had sacrificed home, family, friends, and fortune, to give his aid to
this struggling nation, and his immense personal sacrifices were thus
insultingly thrown into his face. What blindness in Congress! What
heroic magnanimity in La Fayette! Pride and patriotism battled in his
sensitive soul. But unselfish patriotism conquered, and never does
he appear more truly great than at this moment. Seizing a pen, he
writes to Congress this brief but immortal note:—
“After the sacrifices I have made, I have a right to exact two
favors: one is, to serve at my own expense; the other is, to serve as
a volunteer.”
Astonished at such unprecedented generosity, and conscious of
their mistake in classing the young marquis with other foreigners,
who were actuated by selfish avarice and love of adventure,
Congress accordingly passed the following preamble and resolution
on the 31st of July, 1777:—
ebookmasss.com