Starting Out with Java: From Control Structures through Objects (6th Edition) Gaddis instant download
Starting Out with Java: From Control Structures through Objects (6th Edition) Gaddis instant download
https://textbookfull.com/product/starting-out-with-java-from-
control-structures-through-objects-6th-edition-gaddis/
https://textbookfull.com/product/starting-out-with-java-from-
control-structures-through-objects-whats-new-in-computer-
science-7th-edition-gaddis/
https://textbookfull.com/product/starting-out-with-c-from-
control-structures-through-objects-brief-edition-9-e-tony-gaddis/
https://textbookfull.com/product/starting-out-with-c-from-
control-structures-through-objects-second-custom-edition-for-
penn-state-university-tony-gaddis/
https://textbookfull.com/product/starting-out-with-python-gaddis/
Starting Out With Visual Basic (8th Edition) Tony
Gaddis
https://textbookfull.com/product/starting-out-with-visual-
basic-8th-edition-tony-gaddis/
https://textbookfull.com/product/objects-nothing-out-of-the-
ordinary-1st-edition-korman/
https://textbookfull.com/product/big-java-early-objects-7th-
edition-cay-s-horstmann/
https://textbookfull.com/product/making-it-in-real-estate-
starting-out-as-a-developer-2nd-edition-john-mcnellis/
Starting Out with
Java
TM
Java
TM
Tony Gaddis
Haywood Community College
Copyright © 2016 by Pearson Education, Inc. or its affiliates. All Rights Reserved. Printed in the United States of America.
This publication is protected by copyright, and permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical,
photocopying, recording, or otherwise. For information regarding permissions, request forms and the appropriate contacts
within the Pearson Education Global Rights & Permissions department, please visit www.pearsoned.com/permissions/.
Many of the designations by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those
designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed in
initial caps or all caps.
Unless otherwise indicated herein, any third-party trademarks that may appear in this work are the property of their
respective owners and any references to third-party trademarks, logos or other trade dress are for demonstrative or
descriptive purposes only. Such references are not intended to imply any sponsorship, endorsement, authorization, or
promotion of Pearson’s products by the owners of such marks, or any relationship between the owner and Pearson
Education, Inc. or its affiliates, authors, licensees or distributors.
Microsoft and/or its respective suppliers make no representations about the suitability of the information contained in the
documents and related graphics published as part of the services for any purpose. All such documents and related graphics
are provided “as is” without warranty of any kind. Microsoft and/or its respective suppliers hereby disclaim all warranties
and conditions with regard to this information, including all warranties and conditions of merchantability. Whether
express, implied or statutory, fitness for a particular purpose, title and non-infringement. In no event shall microsoft and/or
its respective suppliers be liable for any special, indirect or consequential damages or any damages whatsoever resulting
from loss of use, data or profits, whether in an action of contract. Negligence or other tortious action, arising out of or in
connection with the use or performance of information available from the services.
The documents and related graphics contained herein could include technical inaccuracies or typographical errors changes are
periodically added to the information herein. Microsoft and/or its respective suppliers may make improvements and/or
changes in the product(s) and/or the program(s) described herein at any time partial screen shots may be viewed in full within
the software version specified.
Microsoft® Windows®, and Microsoft Office® are registered trademarks of the Microsoft Corporation in the U.S.A. and
other countries. This book is not sponsored or endorsed by or affiliated with the Microsoft Corporation.
10 9 8 7 6 5 4 3 2 1
ISBN-13: 978-0-13-395705-1
ISBN-10: 0-13-395705-5
Contents in Brief
Preface xxiii
Chapter 1 Introduction to Computers and Java 1
Chapter 2 Java Fundamentals 27
Chapter 3 Decision Structures 111
Chapter 4 Loops and Files 189
Chapter 5 Methods 269
Chapter 6 A First Look at Classes 319
Chapter 7 Arrays and the ArrayList Class 405
Chapter 8 A Second Look at Classes and Objects 495
Chapter 9 Text Processing and More about Wrapper Classes 559
Chapter 10 Inheritance 613
Chapter 11 Exceptions and Advanced File I/O 703
Chapter 12 A First Look at GUI Applications 761
Chapter 13 Advanced GUI Applications 849
Chapter 14 Applets and More 917
Chapter 15 Creating GUI Applications with JavaFX and Scene Builder 991
Chapter 16 Recursion 1047
Chapter 17 Databases 1075
Index 1171
Appendixes A–M Companion Website
Case Studies 1–7 Companion Website
v
This page intentionally left blank
Contents
Preface xxiii
Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Class Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.4 Primitive Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
The Integer Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Floating-Point Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
The boolean Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
The char Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Variable Assignment and Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Variables Hold Only One Value at a Time . . . . . . . . . . . . . . . . . . . . . . . . 53
2.5 Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Integer Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Grouping with Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
The Math Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.6 Combined Assignment Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
2.7 Conversion between Primitive Data Types . . . . . . . . . . . . . . . . . . . . . . 65
Mixed Integer Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Other Mixed Mathematical Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 68
2.8 Creating Named Constants with final . . . . . . . . . . . . . . . . . . . . . . . . 69
2.9 The String Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Objects Are Created from Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
The String Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Primitive Type Variables and Class Type Variables . . . . . . . . . . . . . . . . . . 71
Creating a String Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
2.10 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
2.11 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
2.12 Programming Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
2.13 Reading Keyboard Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Reading a Character . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Mixing Calls to nextLine with Calls to Other Scanner Methods . . . . . . . . 88
2.14 Dialog Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Displaying Message Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Displaying Input Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
An Example Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Converting String Input to Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
2.15 Common Errors to Avoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Review Questions and Exercises 100
Programming Challenges 105
Index 1171
Companion Website:
Appendix A Working with Records and Random Access Files
Appendix B The ASCII/Unicode Characters
Appendix C Operator Precedence and Associativity
Appendix D Java Key Words
Appendix E Installing the JDK and JDK Documentation
Appendix F Using the javadoc Utility
Appendix G More about the Math Class
Appendix H Packages
Appendix I More about JOptionPane Dialog Boxes
Appendix J Answers to Checkpoints
Appendix K Answers to Odd-Numbered Review Questions
xx Contents
Chapter 15
Using Scene Builder to Create the Kilometer Converter GUI, p. 998
Learning More About the Main Application Class, p. 1010
Writing the Main Application Class For the Kilometer Converter GUI, p. 1011
Learning More About the Controller Class, p. 1013
Registering the Controller Class with the Application’s GUI, p. 1014
JavaFX RadioButtons, p. 1019
JavaFX CheckBoxes, p. 1027
The Retail Price Calculator Problem, p. 1042
W elcome to Starting Out with Java: From Control Structures through Objects,
Sixth Edition. This book is intended for a one-semester or a two-quarter CS1
course. Although it is written for students with no prior programming background, even
experienced students will benefit from its depth of detail.
xxiii
xxiv Preface
· A New Section on Anonymous Inner Classes: Chapter 10 now has a new section that
introduces anonymous inner classes.
· Default Methods: In this edition, Chapter 10 provides new material on default meth-
ods in interfaces, a new feature in Java 8.
Depend On
Chapter 7
Chapter 17
Arrays and the
Databases
ArrayList Class
*Some examples in
Chapter 17 use GUIs,
which are introduced
in Chapter 12.
Chapter 9 Chapter 8 Chapter 12
Chapter 16
Text Processing and A Second Look at A First Look at GUI
Recursion
Wrapper Classes Classes and Objects Applications
*Some examples in
Chapter 16 are applets,
which are introduced
Depends On in Chapter 14. Depends On
Chapter 10 Chapter 14
Depends On
Inheritance Applets and More
Chapter 15 Chapter 11
Creating GUI Applications
with JavaFX and Scene Exceptions and
Builder Advanced File I/O Chapter 13
Advanced GUI
Applications
Chapter 2: Java Fundamentals. This chapter gets students started in Java by introduc-
ing data types, identifiers, variable declarations, constants, comments, program output, and
simple arithmetic operations. The conventions of programming style are also introduced.
Students learn to read console input with the Scanner class and with dialog boxes using
JOptionPane.
xxvi Preface
Chapter 4: Loops and Files. This chapter covers Java’s repetition control structures. The
while loop, do-while loop, and for loop are taught, along with common uses for these
devices. Counters, accumulators, running totals, sentinels, and other application-related
topics are discussed. Simple file operations for reading and writing text files are included.
Chapter 5: Methods. In this chapter students learn how to write void methods, value-
returning methods, and methods that do and do not accept arguments. The concept of
functional decomposition is discussed.
Chapter 7: Arrays and the ArrayList Class. In this chapter students learn to create
and work with single and multi-dimensional arrays. Numerous array-processing tech-
niques are demonstrated, such as summing the elements in an array, finding the highest and
lowest values, and sequentially searching an array. Other topics, including ragged arrays
and variable-length arguments (varargs), are also discussed. The ArrayList class is intro-
duced, and Java’s generic types are briefly discussed and demonstrated.
Chapter 8: A Second Look at Classes and Objects. This chapter shows students how
to write classes with added capabilities. Static methods and fields, interaction between
objects, passing objects as arguments, and returning objects from methods are discussed.
Aggregation and the “has a” relationship is covered, as well as enumerated types. A section
on object-oriented design shows how to use CRC cards to determine the collaborations
among classes.
Chapter 9: Text Processing and More about Wrapper Classes. This chapter dis-
cusses the numeric and Character wrapper classes. Methods for converting numbers to
strings, testing the case of characters, and converting the case of characters are covered.
Autoboxing and unboxing are also discussed. More String class methods are covered,
including using the split method to tokenize strings. The chapter also covers the
StringBuilder and StringTokenizer classes.
Preface xxvii
Chapter 10: Inheritance. The study of classes continues in this chapter with the subjects
of inheritance and polymorphism. The topics covered include superclasses, subclasses, how
constructors work in inheritance, method overriding, polymorphism and dynamic binding,
protected and package access, class hierarchies, abstract classes, abstract methods, anony-
mous inner classes, interfaces, and lambda expressions.
Chapter 11: Exceptions and Advanced File I/O. In this chapter students learn to
develop enhanced error trapping techniques using exceptions. Handling exceptions is cov-
ered, as well as developing and throwing custom exceptions. The chapter discusses advanced
techniques for working with sequential access, random access, text, and binary files.
Chapter 12: A First Look at GUI Applications. This chapter presents the basics of
developing GUI applications with Swing. Fundamental Swing components and the basic
concepts of event-driven programming are covered.
Chapter 13: Advanced GUI Applications. This chapter continues the study of GUI
application development with Swing. More advanced components, menu systems, and
look-and-feel are covered.
Chapter 14: Applets and More. In this chapter students apply their knowledge of GUI
development to the creation of applets. In addition to using Swing applet classes, AWT
classes are discussed for portability. Drawing simple graphical shapes is discussed.
Chapter 15: Creating GUI Applications with JavaFX and Scene Builder. This
chapter introduces JavaFX, which is the next generation library for creating graphical
applications in Java. This chapter also shows how to use Scene Builder, a free screen designer
from Oracle, to visually design GUIs. This chapter is written in such a way that it is inde-
pendent from the existing chapters on Swing and AWT. You can choose to skip chapters 12,
13, and 14, and go straight to Chapter 15, or cover all of the GUI chapters.
Chapter 17: Databases. This chapter introduces the student to database programming.
The basic concepts of database management systems and SQL are first introduced. Then the
student learns to use JDBC to write database applications in Java. Relational data is cov-
ered, and numerous example programs are presented throughout the chapter.
Example Programs. The text has an abundant number of complete and partial example
programs, each designed to highlight the current topic. In most cases the programs are prac-
tical, real-world examples.
Program Output. Each example program is followed by a sample of its output, which
shows students how the program functions.
Note: Notes appear at several places throughout the text. They are short explanations
of interesting or often misunderstood points relevant to the topic at hand.
Tip: Tips advise the student on the best techniques for approaching different program-
ming problems and appear regularly throughout the text.
Warning! Warnings caution students about certain Java features, programming tech-
niques, or practices that can lead to malfunctioning programs or lost data.
VideoNotes. A series of videos, developed specifically for this book, are available at www.
pearsonhighered.com/gaddis. Icons appear throughout the text alerting the student to videos
VideoNote
about specific topics.
Case Studies. Case studies that simulate real-world business applications are intro-
duced throughout the text and are provided on the book’s resource page at www.pearson-
highered.com/gaddis.
Common Errors to Avoid. Each chapter provides a list of common errors and explana-
tions of how to avoid them.
Review Questions and Exercises. Each chapter presents a thorough and diverse set of
review questions and exercises. They include Multiple Choice and True/False, Find the
Error, Algorithm Workbench, and Short Answer.
Random documents with unrelated
content Scribd suggests to you:
"They serve who stand and wait." It is easier to be busy than to be
quiet. When Peter was "young," he went whither he would; but
when he got "old," he went whither he would not. What a contrast
between the young, restless, ardent, energetic Peter, going whither
he would, and the old, matured, subdued, experienced Peter, going
whither he would not! What a mercy to have the will broken!—to be
able to say from the heart, "What Thou wilt—as Thou wilt—where
Thou wilt—when Thou wilt"—"not my will, but Thine, O Lord, be
done"!
"Follow Me!" Precious words! May they be engraved on our hearts,
beloved reader! Then shall we be steady in our course and effective
in our service. We shall not be distracted or unhinged by the
thoughts and opinions of men. It may happen that we shall get very
few to understand us or to sympathize with us—few to approve or
appreciate our work. It matters not. The Master knows all about it. If
a master tells one of his servants distinctly to go and do a certain
thing, or occupy a certain post, it is his business to go and do that
thing, or occupy that post, no matter what his fellow-servants may
think. They may tell him that he ought to be somewhere else, or to
do something else. A proper servant will heed them not; he knows
his master's mind, and has to do his master's work.
Would it were more thus with all the Lord's servants! Would that we
all knew more distinctly, and carried out more decidedly, the Master's
will respecting us! Peter had his path, and John had his. James had
his work, and Paul had his. So it was of old: the Gershonite had his
work, and the Merarite had his; and if the one had interfered with
the other, the work would not have been done. The tabernacle was
carried forward, or set up, by each man doing his own proper work.
Thus it is in this our day. God has varied workmen in His house and
in His vineyard; and the original terms of service are that the Holy
Spirit divideth to every one as He will. He has quarrymen, stone-
squarers, masons, and builders. Are all quarrymen? Surely not. But
each has his work to do, and the building is carried forward by each
one doing his own appointed work. Should a quarryman despise a
builder, or a builder look down with contempt upon a quarryman?
Assuredly not. The Master wants them both; and whenever the one
would interfere with the other (as, alas, we are apt to do), the
faithful correcting word falls on the ear, "What is that to thee? follow
thou Me."
JERICHO AND ACHOR
OR
PRIVILEGE AND RESPONSIBILITY
(Read Joshua vi., vii.)
The Christian reader will do well to turn, first of all, to the two
chapters named above, and give them a careful reading. They
furnish a very striking and impressive record of the double effect of
God's presence with His people. In chapter vi. we are taught that
the divine Presence ensured victory over the power of the enemy. In
chapter vii. we learn that the divine Presence demanded judgment
upon evil in the bosom of the congregation. The ruins of Jericho
demonstrate the one; the great heap of stones in the valley of Achor
attests the other.
Now, these two things must never be separated. We see them
vividly illustrated in every page of the history of God's people, both
in the Old and in the New Testament. The self-same Presence that
secures victory demands holiness. Let us never forget this. Yea, let
us keep it ever in the remembrance of our hearts. It has an
individual as well as a collective application. If we are to walk with
God, or, rather, if He is to walk with us, we must judge and put away
everything inconsistent with His holy presence. He cannot sanction
unjudged evil in His people. He can pardon, heal, restore, and bless;
but He is intolerant of evil. "Our God is a consuming fire." "The time
is come that judgment must begin at the house of God."
Should the thought of this discourage or depress any true-hearted
child of God, or servant of Christ? Certainly not. It should neither
discourage nor depress, but it should make us very watchful over
our hearts, very careful as to our ways, our habits of thought and
conversation. We have nothing to fear while God is with us, but He
cannot possibly sanction evil in His people; and every true lover of
holiness will heartily bless Him for this. Could we possibly desire it to
be otherwise? Would we wish the standard of holiness to be lowered
at all? God forbid. All those who love His name can give thanks at
the remembrance of His holiness, and rejoice in the truth that
holiness becometh His house forever? "Be ye holy, for I am holy." It
is not by any means on the pharisaic principle, wrapped up in the
words, "Stand by thyself; I am holier than thou." Thank God, it is
not this. It is not a question of what we are, but of what He is. Our
character and conduct are to be formed by the truth of what God is.
Marvelous grace! Precious privilege!
God must have His people like Himself. If they forget this, He will
surely remind them of it. If He, in infinite grace, links His name and
His glory with us, it behooves us to look well to our habits and ways,
lest we bring any reproach on that name. Is this legal bondage? Nay,
it is the holiest liberty. We may rest perfectly assured of this, that we
are never further removed from legality than when treading that
path of true holiness which becomes all those who bear the name of
Christ. "Having therefore these promises, dearly beloved, let us
cleanse ourselves from all filthiness of the flesh and spirit, perfecting
holiness in the fear of God."
This great truth holds good at all times. We see it in the ruins of
Jericho. We read it in the valley of Achor. What was it that caused
the frowning walls and towering bulwarks of Jericho to fall down at
the sound of rams' horns and the shout of the people? The presence
of Jehovah. And it mattered not if it was but the city of Jericho or
the whole land of Canaan, before that invincible Presence.
But what means the humiliating defeat before the insignificant city of
Ai? How comes it to pass that the hosts of Israel, so recently
triumphant at Jericho, have to flee ignominiously before a mere
handful of men at Ai? Ah, the answer tells a sorrowful tale! Here it
is; let us harken to it, and ponder it in the deepest depths of our
heart. Let us seek to profit by it. Let us be solemnly warned by it. It
has been written for our admonition. The Holy Ghost has taken the
pains to record it for our learning. Woe be to the one who turns a
deaf ear to the warning voice!
"But the children of Israel committed a trespass in the accursed
thing: for Achan, the son of Carmi, the son of Zabdi, the son of
Zerah, of the tribe of Judah, took of the accursed thing: and the
anger of the Lord was kindled against"—whom? Achan merely? or
his household, or his family, or his tribe? Nay, but "against the
children of Israel"! The whole assembly was involved in the evil. How
was this? The divine presence imparted a unity to the whole
assembly; it bound them all together in such a manner as to involve
all in the sin of the one. It was one assembly, and hence it was
impossible for any one to take independent ground. The sin of each
was the sin of all, because God was in their midst, and He could not
countenance unjudged evil. The whole congregation was involved,
and had to clear itself of the evil ere Jehovah could lead it on to
victory. Had He allowed them to triumph at Ai, it would have argued
that He was indifferent to the sin of His people, and that He could
give the sanction of His presence to "an accursed thing," which were
simply blasphemy against His holy name.
"And Joshua sent men from Jericho to Ai, which is beside Beth-aven,
on the east side of Bethel, and spake unto them, saying, Go up and
view the country. And the men went up and viewed Ai. And they
returned to Joshua, and said unto him, Let not all the people go up;
but let about two or three thousand men go up and smite Ai;"—
more easily said than done;—"and make not all the people to labor
thither; for they are but few"—yet quite too many for Israel with an
Achan in the camp. "So there went up thither of the people about
three thousand men; and they fled before the men of Ai. And the
men of Ai smote of them about thirty and six men: for they chased
them from before the gate even unto Shebarim, and smote them in
the going down: wherefore the hearts of the people melted, and
became as water.
"And Joshua rent his clothes, and fell to the earth upon his face
before the ark of the Lord until the eventide, he and the elders of
Israel, and put dust upon their heads."
Here was a strange and unlooked-for experience. "And Joshua said,
Alas, O Lord God, wherefore hast Thou at all brought this people
over Jordan, to deliver us into the hand of the Amorites, to destroy
us? would to God we had been content, and dwelt on the other side
Jordan! O Lord, what shall I say when Israel turneth their backs
before their enemies? For the Canaanites and all the inhabitants of
the land shall hear of it, and shall environ us round, and cut off our
name from the earth: and what wilt Thou do unto Thy great name?"
Joshua, that beloved and honored servant of God, did not see, did
not understand, that it was the very glory of that "great name"
which necessitated the defeat at Ai, just as it had achieved the
victory at Jericho. But there were other elements in that glory
besides power. There was holiness, and that holiness rendered it
impossible for Him to lend the sanction of His presence where there
was unjudged evil. Joshua should have concluded that there was
something wrong in the condition of the people. He ought to have
known that the hindrance was with Israel, and not with Jehovah.
The same grace that had given them victory at Jericho would have
given it at Ai, if things were right. But, alas, they were not right; and
hence defeat, and not victory, was the order of the day. How could
there be victory with an accursed thing in the camp? Impossible!
Israel must judge the evil, or Jehovah must judge Israel. To have
given them a victory at Ai would have been a reproach and a
dishonor to the One whose name was called upon them. The divine
presence absolutely demanded judgment upon the evil; and until
that was executed, further progress in the conquest of Canaan was
out of the question. "Be ye clean that bear the vessels of the Lord."
"Holiness becometh Thy house, O Lord, for ever."
"And the Lord said unto Joshua, Get thee up; wherefore liest thou
thus upon thy face? Israel hath sinned,"—not merely Achan,—"and
they have also transgressed My covenant which I commanded them:
for they have even taken of the accursed thing, and have also
stolen, and dissembled also, and they have put it even among their
own stuff. Therefore the children of Israel could not stand before
their enemies, but turned their backs before their enemies, because
they were accursed: neither will I be with you any more, except ye
destroy the accursed from among you."
This is peculiarly solemn. The whole congregation is held responsible
for the evil. "A little leaven leaveneth the whole lump." Unbelief may
inquire how all are involved in the sin of one; but the word of God
definitely settles the question—"Israel hath sinned"—"they have
taken"—"they have stolen"—"they have dissembled." The assembly
was one; one in privilege, one in responsibility. As such, the sin of
one was the sin of all, and all were called upon to clear themselves
thoroughly by putting away the accursed thing from among them.
There was not a single member of that large congregation who was
not affected by Achan's sin. This may seem strange to mere nature,
but such is the solemn and weighty truth of God. It was true in the
assembly of Israel of old, and assuredly it is not less true in the
Church of God now. No one could take independent ground in the
assembly of Israel; how much less can he take it in the Church of
God? There were over six hundred thousand people who, to speak
after the manner of men, were wholly ignorant of what Achan had
done; and yet God's word to Joshua was, "Israel hath sinned." All
were involved; all were affected; and all had to clear themselves ere
Jehovah could again lead them on to victory. The presence of God in
the midst of the Assembly formed the unity of all; and the presence
of the Holy Ghost in the Church of God, the body of Christ now on
the earth, binds all up in one divine, indissoluble unity. Hence, to talk
of independency is to deny the very foundation-truth of the Church
of God, and to prove beyond all question that we understand neither
its nature nor its unity as set forth on the page of inspiration.
And if evil creeps into an assembly, how is it to be met? Here it is:
"Up, sanctify the people, and say, Sanctify yourselves against to-
morrow: for thus saith the Lord God of Israel, There is an accursed
thing in the midst of thee, O Israel: thou canst not stand before
thine enemies, until ye take away the accursed thing from among
you." Were they one in privilege? Were they one in the enjoyment of
the glory and strength which the divine Presence secured? Were
they one in the splendid triumph at Jericho? Who would deny all
this? Who would wish to deny it? Why, then, seek to question their
oneness in responsibility—their oneness in respect to the evil in their
midst, and all its humbling consequences? Surely, if there was unity
in anything, there was unity in everything. If Jehovah was the God
of Israel, He was the God of all, the God of each; and this grand and
glorious fact was the solid basis both of their high privileges and
their holy responsibilities. How could evil exist in such an assembly,
and a single member be unaffected by it? How could there be an
accursed thing in their very midst, and a single member not be
defiled? Impossible. We may reason and argue about it until the
tongue cleaves to the roof of the mouth, but all the reasoning and
argument in the world cannot touch the truth of God, and that truth
declares that "a little leaven leaveneth the whole lump."
But how is the evil to be discovered? The presence of God reveals it.
The self-same power that had leveled the walls of Jericho, detected,
revealed and judged the sin of Achan. It was the double effect of the
same blessed Presence, and Israel was called to share in the one as
well as in the other. To attempt to separate the two is folly,
ignorance, or wickedness. It cannot be done, and ought not to be
attempted.
PART II.
We must ever remember, that, in the history of God's ways with His
people, privilege and responsibility are intimately bound up together.
To talk of privilege, or think of enjoying it, while neglecting the
responsibility, is a gross delusion. No true lover of holiness could
think for a moment of separating them; nay, he must ever delight in
strengthening and perpetuating the precious link.
Thus, for example, in Israel's case, who could estimate aright the
high privilege of having Jehovah dwelling in their midst? By day and
by night, there He was, to guide and guard, shield and shelter them;
to meet their every need, to give them bread from heaven, and
bring them forth water out of the rock. His presence was a
safeguard against every foe; no weapon formed against them could
prosper; not a dog might move his tongue against them; they were
at once invulnerable and invincible; with God in their midst they had
nothing whatever to fear. He charged Himself with all their wants,
whether great or small. He looked after their garments, that they
might not wax old; He looked after their feet, that they might not
swell; He covered them with the shield of His favor, so that no arrow
might touch them; He stood between them and every foe, and flung
back in the enemy's face every accusation.
Thus much as to the high privilege. But mark the corresponding and
connected responsibility. See how both are indissolubly bound up
together in the following weighty words: "For the Lord thy God
walketh in the midst of thy camp, to deliver thee, and to give up
thine enemies before thee: therefore shall thy camp be holy; that He
see no unclean thing in thee, and turn away from thee."
Precious privilege! Solemn responsibility! Who would dare to dissolve
the hallowed connection? Had Jehovah deigned to come down into
their midst, and walk with them, and tabernacle among them? Had
He, in infinite grace, condescended to be their traveling companion?
Was He there for the exigence of every hour? Yes, blessed be His
name. If so, then what did His presence demand? We have seen
something of what His presence secured; but what did it demand?
Holiness! Israel's whole conduct was to be regulated by the great
fact of the divine Presence in their midst. Not only their great public
national institutions, but their most private habits, were to be
brought under the controlling influence of Jehovah's presence with
them. He regulated what they were to eat, what they were to wear,
how they were to carry themselves in all the scenes, circumstances
and relationships of daily life. By night and by day, sleeping and
waking, sitting in the house or walking by the way, alone or in
company, He looked after them. Nothing was to be allowed in any
wise inconsistent with the holiness and purity which became the
presence of the Holy One of Israel.
Was all this irksome? Were the privileges irksome? Was it irksome to
be fed, clothed, guided, guarded and cared for in every possible
way? Was it irksome to repose beneath the overshadowing wings of
the God of Israel? Surely not. Why, then, should it be irksome to
keep their persons, their habits and their dwellings clean? Must not
every true heart, every upright mind, every tender conscience,
accept as thoroughly the responsibility which the divine Presence
necessarily involves as the privileges which it infallibly secures? Yea,
rather must we not rank the very responsibility itself among our
richest and rarest privileges? Unquestionably. Every true lover of
holiness will esteem it a signal mercy—a very high order of blessing
—to walk in company with One whose presence detects and
condemns every form of evil. "Thy testimonies are very sure;
holiness becometh Thy house, O Lord, for ever."
The foregoing train of thought will enable us in some measure to
understand the history of Achan, in Josh. vii.—a history solemn and
impressive in the highest degree—a history which utters in our
hearing, with deepest emphasis, words which our careless hearts are
only too ready to forget, "God is greatly to be feared in the assembly
of His saints, and to be had in reverence of all them that are about
Him." Had Achan remembered this, it would have taught him the
holy necessity of nipping in the very bud the covetousness of his
heart, and thus have spared the whole assembly the humiliating
defeat at Ai, and all the consequent sorrow and discipline. How
terrible to think of one man, for the sake of a little personal gain,
which at best could last but for a moment, plunging a whole
congregation into the deepest trouble! and, what was worse than all,
dishonoring and grieving that blessed One who had deigned, in His
infinite goodness, to take up His abode in their midst! How well it
would be if each one of us, when tempted to commit any secret sin,
would just pause and ask himself the question, "How can I do this
thing, and grieve the Holy Spirit of God who dwells in me, and bring
leaven into the assembly of God's people?" We ought to remember
that our private walk has a direct bearing upon all the members of
the body. We are either helping or hindering the blessing of all. We
are none of us independent atoms; we are members of a body
incorporated by the presence of the Holy Ghost; and if we are
walking in a loose, carnal, worldly, self-indulgent spirit, we are
grieving the Spirit, and injuring all the members. "But God hath
tempered the body together ... that there should be no schism in the
body; but that the members should have the same care one for
another. And whether one member suffer, all the members suffer
with it; or one member be honored, all the members rejoice with it"
(1 Cor. xii. 24-26).
It may seem hard, to some, to grasp this great practical truth—hard
to see how our private condition and conduct can affect our fellow-
members; but the simple and obvious fact is, we must either admit
this, or maintain the unscriptural and foolish notion that each
Christian is an independent person, having no connection with the
whole body of believers. If he be a member of a body, all the
members of which are bound together, and linked with the Head by
the personal indwelling of the Holy Ghost, then, verily, it follows that
his walk and ways affect all his fellow-members just as really as, if
any member of the human body suffers, all the other members feel
it. If there is anything wrong with the hand, the foot feels it. How is
this? Because the head feels it. The communication, in every
instance, is with the head first, and from the head to the members.
Now, though Achan was not a member of a body, but merely of a
congregation, yet we see how his private conduct affected the whole
assembly. This is all the more striking, inasmuch as the great truth
of the one body was not unfolded, and could not be until—
redemption being a grand, accomplished fact—the Head took His
seat on the throne of God, and sent down the Holy Ghost to form
the body, and link it, by His personal presence and indwelling, to the
Head in heaven. If the secret sin of Achan affected every member of
the congregation of Israel, how much more (may we not say?) doth
the secret sin of any member of the body of Christ affect all the
members thereof!
Let us never forget this weighty truth. May we keep it ever in the
remembrance of our hearts, that so we may see the urgent need of
a careful, tender, holy walk; that we may not dishonor our glorious
Head, grieve the blessed indwelling Spirit, or injure the feeblest
member of that body of which, by the sovereign grace of God and
the precious blood of Christ, we form a part.
But we must proceed with our subject, and in so doing call the
special attention of the reader to the way in which the sin of Achan
was traced home to him. It is all most solemn. He had little idea
whose eye was resting upon him when he was carrying on his secret
wickedness. He would, no doubt, think himself all right, and very
successful, when he had the money and the garment safely hidden
in his tent. Fatal, guilty, wretched treasure! Unhappy man! How
dreadful is the love of money! How terrible is the blinding power of
sin! It hardens the heart, deadens the conscience, darkens the
understanding, ruins the soul, and in the case before us brought
defeat and disaster upon the whole people of which he formed a
part.
"And the Lord said unto Joshua, Get thee up; wherefore liest thou
thus upon thy face?" There is a time for lying on the face, and there
is a time for standing on our feet; a time for devout prostration, and
a time for decided action. The instructed soul will know the time for
each. "Israel hath sinned, and they have also transgressed My
covenant which I commanded them; for they have even taken of the
accursed thing, and have also stolen, and dissembled also, and they
have put it even among their own stuff. Therefore the children of
Israel could not stand before their enemies, but turned their backs
before their enemies, because they were accursed: neither will I be
with you any more, except ye destroy the accursed from among you.
Up, sanctify the people, and say, Sanctify yourselves against to-
morrow: for thus saith the Lord God of Israel, There is an accursed
thing in the midst of thee, O Israel: thou canst not stand before
thine enemies, until ye take away the accursed thing from among
you."
How peculiarly solemn is all this! how very arresting! how soul-
subduing! God's people—those who bear His name, and profess to
hold His truth, who stand identified with Him in this world—must be
holy. He cannot lend the sanction of His presence to that which is
unholy or impure. Those who enjoy the high privilege of being
associated with God are solemnly responsible to keep themselves
unspotted from the world, else He must take down the rod of
discipline and do His strange work in their midst. "Be ye clean that
bear the vessels of the Lord."
"Thou canst not stand before thine enemies, until ye take away the
accursed thing from among you. In the morning therefore ye shall
be brought according to your tribes: and it shall be, that the tribe
which the Lord taketh shall come according to the families thereof;
and the family which the Lord shall take shall come by households;
and the household which the Lord shall take shall come man by
man."
Ah, this was coming to close quarters! The sinner might seek to
persuade himself that discovery was impossible; he might cherish
the fond hope of escaping amid the many thousands of Israel.
Miserable delusion! He might be sure his sin would find him out. The
self-same Presence that secured individual blessing, secured with
equal fidelity the detection of the most secret individual sin. Escape
was impossible. If Jehovah was in the midst of His people to lay
Jericho in ruins at their feet, He was there also to lay bare, in its
deepest roots, the sin of the congregation, and to bring forth the
sinner from his hiding-place to bear the penalty of his wickedness.
How searching are God's ways! First, the twelve tribes are
summoned, that the transgressor might be manifested. Then, one
tribe is fixed upon. Nearer still! the family is fixed upon! And yet
nearer! the very household is actually singled out; and, last of all,
"man by man!" Thus, out of six hundred thousand people, the all-
searching eye of Jehovah reads the sinner through and through, and
marks him off before the assembled thousands of Israel.
"And it shall be that he that is taken with the accursed thing shall be
burnt with fire, he and all that he hath: because he hath
transgressed the covenant of the Lord, and because he hath
wrought folly in Israel.
"So Joshua rose up early in the morning, and brought Israel by their
tribes; and the tribe of Judah was taken: and he brought the family
of Judah; and he took the family of the Zarhites: and he brought the
family of the Zarhites man by man; and Zabdi was taken: and he
brought his household man by man; and Achan, the son of Carmi,
the son of Zabdi, the son of Zerah, of the tribe of Judah, was taken."
"Our God is a consuming fire." He cannot tolerate evil in the ways of
His people. This accounts for the solemn scene before us. The
natural mind may reason about all this—it may marvel why the
taking of a little money and a garment from amid the spoils of a
doomed city should involve such awful consequences and entail such
a severe punishment. But the natural mind is incapable of
understanding the ways of God. And may we not ask the objector,
How could God sanction evil in His people? How could He go on with
it? What was to be done with it? If He was about to execute
judgment upon the seven nations of Canaan, could He possibly be
indifferent to sin in His people? Most assuredly not. His word is, "You
only have I known of all the families of the earth; therefore will I
punish you for your iniquities." The very fact of His taking them into
relationship with Himself was the ground of His dealing with them in
holy discipline.
It is the height of folly for man to reason about the severity of divine
judgment, or the apparent lack of proportion between the sin and
the punishment. All such reasoning is false and impious. What was it
that brought in all the misery, the sorrow, the desolation, the
sickness, pain, and death—all the untold horrors of the last six
thousand years? What was the source of it all? Just the one little act
—as man would call it—of eating a bit of fruit? But this little act was
that terrible thing called sin—yea, rebellion—against God! And what
was needed to atone for this? How was it to be met? What stands
over against it as the only adequate expression of the judgment of a
holy God?—What? The burning in the valley of Achor? Nay. The
everlasting burnings of hell? Nay; something far deeper and more
solemn still. What? The cross of the Son of God! The awful mystery
of the death of Christ!—that terrible cry, "My God, My God, why hast
Thou forsaken Me?" Let men remember this, and cease to reason.
PART III.
PART IV.
THE ATONEMENT,
which is here presented in its two grand aspects, first, Godward; and
secondly, usward. The apostle declares that Christ hath appeared "to
put away sin;" and also "to bear the sins of many." This is a
distinction of the utmost importance, and one not sufficiently
understood or attended to, Christ has put away sin by the sacrifice
of Himself. He has glorified God in reference to the question of sin in
its very broadest aspect. This He has done altogether irrespective of
the question of persons or the forgiveness of the sins of individuals.
Even though every soul, from the days of Adam down to the very
last generation, were to reject the proffered mercy of God, yet would
it hold good that the atoning death of Christ had put away sin—had
destroyed the power of Satan—had perfectly glorified God, and laid
the deep and solid foundation on which all the divine counsels and
purposes can rest for ever.
It is to this fact that the Baptist refers in these memorable words,
"Behold the Lamb of God, which taketh away the sin of the world"
(John i. 29). The Lamb of God has wrought a work in virtue of which
every trace of sin shall be obliterated from the creation of God. He
has perfectly vindicated God in the very midst of a scene in which
He had been so grossly dishonored, in which His character had been
traduced and His majesty insulted. He came to do this at all cost,
even at the sacrifice of Himself. He sacrificed Himself in order to
maintain, in view of heaven, earth and hell, the glory of God. He has
wrought a work by the which God is infinitely more glorified than if
sin had not entered at all. God shall reap a richer harvest by far in
the fields of redemption than ever He could have reaped in the fields
of an unfallen creation.
It is well that the reader should deeply ponder this glorious aspect of
the atoning death of Christ. We are apt to think that the very highest
view we can take of the cross is that which involves the question of
our forgiveness and salvation. This is a grave mistake. That question
is divinely settled, as we shall seek to show; for the less is always
included in the greater. But let us remember that our side of the
atonement is the less, God's side of it the greater. It was infinitely
more important that God should be glorified than that we should be
saved. Both ends have been gained, blessed be God, and gained by
one and the same work, the precious atonement of Christ; but we
must never forget that the glory of God is of far greater moment
than the salvation of men; and further, that we never can have so
clear a sense of the latter as when we see it flowing from the former.
It is when we see that God has been perfectly and for ever glorified
in the death of Christ, that we can really enter into the divine
perfectness of our salvation. In point of fact, both are so intimately
bound up together that they cannot be separated; but still God's
part in the Cross of Christ must ever get its own proper
preeminence. The glory of God was ever uppermost in the devoted
heart of the Lord Jesus Christ. For this He lived, for this He died. He
came into this world for the express purpose of glorifying God, and
from this great and holy object He never swerved a moment from
the manger to the cross. True it is—blessedly true—that in carrying
out this object He has perfectly met our case; but the divine glory
ruled Him in life and in death.
Now it is on the ground of atonement, looked at in this its higher
aspect, that God has been dealing with the world in patient grace,
mercy and forbearance for well nigh six thousand years. He sends
His rain and His sunbeams upon the evil and upon the good, upon
the just and the unjust. It is in virtue of the atonement of Christ—
though despised and rejected—that the infidel and the atheist live,
and enjoy God's daily mercies; yea, the very breath that they spend
in opposing the revelation and denying the existence of God they
owe to Him in whom they live, move and have their being. We speak
not here, by any means, of the forgiveness of sins, or of the soul's
salvation. This is another question altogether, and to it we shall refer
presently. But, looking at man in reference to his life in this world,
and looking at the world in which he lives, it is the Cross which
forms the basis of God's merciful dealing with both the one and the
other.
Furthermore, it is on the ground of the atonement of Christ, in this
same aspect of it, that the evangelist can go forth "into all the world,
and preach glad tidings to every creature." He can declare the
blessed truth that God has been glorified as to sin—His claims
satisfied—His majesty vindicated—His law magnified—His attributes
harmonized. He can proclaim the precious message that God can
now be just and yet the justifier of any poor ungodly sinner that
believes in Jesus. There is no hindrance, no barrier of any kind
whatsoever. The preacher of the gospel is not to be cramped by any
dogmas of theology. He has to do with the large, loving heart of
God, which, in virtue of atonement, can flow forth to every creature
beneath the canopy of heaven. He can say to each and to all—and
say it without reserve—"Come!" Nay, more, he is bound to "beseech"
them to come. "We pray you in Christ's stead, be ye reconciled to
God." Such is the proper language of the evangelist, the herald of
the cross, the ambassador of Christ. He knows no less a range than
the wide, wide world; and he is called to drop his message into the
ear of every creature under heaven.
And why? Because "Christ hath put away sin by the sacrifice of
Himself." He has, by His most precious death, changed completely
the ground of God's dealings with man and with the world, so that,
instead of having to deal with them on the ground of sin, He can
deal on the ground of atonement.
Finally, it is in virtue of the atonement, in this broad and lofty aspect,
that every vestige of sin, and every trace of the serpent shall be
obliterated from the wide universe of God. Then shall be seen the
full force of that passage above referred to, "The Lamb of God,
which taketh away the sin of the world."
Thus much as to what we may call the primary aspect of the atoning
death of Christ—an aspect which cannot be too thoughtfully studied.
A clear understanding of this weighty point would tend to remove a
great deal of difficulty and misunderstanding in reference to the full
and free preaching of the gospel. Many of the Lord's honored
servants find themselves hindered in the presentation of the glad
tidings of salvation, simply because they do not see this wide aspect
of the atonement. They confine the death of Christ merely to its
bearing upon the sins of God's elect; and they therefore deem it
wrong to preach the gospel to all, or to invite, yea to beseech and
entreat, all to come.
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.
textbookfull.com