100% found this document useful (16 votes)
129 views

Instant Download Java Methods A Ab Object oriented Programming and Data Structures Maria Litvin PDF All Chapters

Litvin

Uploaded by

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

Instant Download Java Methods A Ab Object oriented Programming and Data Structures Maria Litvin PDF All Chapters

Litvin

Uploaded by

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

Download the full version of the ebook at ebookname.

com

Java Methods A Ab Object oriented Programming and


Data Structures Maria Litvin

https://ebookname.com/product/java-methods-a-ab-object-
oriented-programming-and-data-structures-maria-litvin/

OR CLICK BUTTON

DOWNLOAD EBOOK

Download more ebook instantly today at https://ebookname.com


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

Object Oriented Data Structures Using Java Chip Weems

https://ebookname.com/product/object-oriented-data-structures-using-
java-chip-weems/

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/

ebookname.com

Object Oriented Programming Using C Fourth Edition Joyce


Farrell

https://ebookname.com/product/object-oriented-programming-using-c-
fourth-edition-joyce-farrell/

ebookname.com

Contexts of Metaphor Current Research in the Semantics


Pragmatics Interface 1st Edition M. Leezenberg

https://ebookname.com/product/contexts-of-metaphor-current-research-
in-the-semantics-pragmatics-interface-1st-edition-m-leezenberg/

ebookname.com
Modern Times India 1880s 1950s Environment Economy Culture
First Edition Sumit Sarkar

https://ebookname.com/product/modern-times-
india-1880s-1950s-environment-economy-culture-first-edition-sumit-
sarkar/
ebookname.com

The Political Philosophy of Zionism Trading Jewish Words


for a Hebraic Land 1st Edition Eyal Chowers

https://ebookname.com/product/the-political-philosophy-of-zionism-
trading-jewish-words-for-a-hebraic-land-1st-edition-eyal-chowers/

ebookname.com

The Siege Ljuba Merlina Bortolani

https://ebookname.com/product/the-siege-ljuba-merlina-bortolani/

ebookname.com

Decomposition methods for differential equations theory


and applications 1st Edition Juergen Geiser

https://ebookname.com/product/decomposition-methods-for-differential-
equations-theory-and-applications-1st-edition-juergen-geiser/

ebookname.com

The Examined Life Philosophical Meditations 1st Simon &


Schuster paperb. ed. Edition Robert Nozick

https://ebookname.com/product/the-examined-life-philosophical-
meditations-1st-simon-schuster-paperb-ed-edition-robert-nozick/

ebookname.com
Transcultural Cities Border Crossing and Placemaking isbn
9780415631426 1st Edition Jeffrey Hou

https://ebookname.com/product/transcultural-cities-border-crossing-
and-placemaking-isbn-9780415631426-1st-edition-jeffrey-hou/

ebookname.com
Java
Methods
A & AB
Object-Oriented Programming
and
Data Structures

Maria Litvin
Phillips Academy, Andover, Massachusetts

Gary Litvin
Skylight Software, Inc.

Skylight Publishing
Andover, Massachusetts
Skylight Publishing
9 Bartlet Street, Suite 70
Andover, MA 01810

web: http://www.skylit.com
e-mail: [email protected]
[email protected]

Copyright © 2006 by Maria Litvin, Gary Litvin, and


Skylight Publishing

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


stored in a retrieval system, or transmitted, in any form or by any means,
electronic, mechanical, photocopying, recording, or otherwise, without
the prior written permission of the authors and Skylight Publishing.

Library of Congress Control Number: 2005910949

ISBN 978-0-9727055-7-8

The names of commercially available software and products mentioned in this book are
used for identification purposes only and may be trademarks or registered trademarks
owned by corporations and other commercial entities. Skylight Publishing and the authors
have no affiliation with and disclaim any sponsorship or endorsement by any of these
products’ manufacturers or trademarks’ owners.

Sun, Sun Microsystems, Java, and Java logos are trademarks or registered trademarks of
Sun Microsystems, Inc. in the United States and other countries.

SCRABBLE® is the registered trademark of HASBRO in the United States and Canada and
of J.W. Spear and Sons, PLC, a subsidiary of Mattel, Inc., outside the United States and
Canada.

1 2 3 4 5 6 7 8 9 10 11 10 09 08 07 06

Printed in the United States of America


To Marg and Aaron
Brief Contents

Preface
How to Use This Book
Chapter 1 An Introduction to Hardware, Software, and the Internet
Chapter 2 An Introduction to Software Development
Chapter 3 Objects and Classes
Chapter 4 Algorithms
Chapter 5 Java Syntax and Style
Chapter 6 Data Types, Variables, and Arithmetic
Chapter 7 Boolean Expressions and if-else Statements
Chapter 8 Iterative Statements: while, for, do–while
Chapter 9 Implementing Classes and Using Objects
Chapter 10 Strings
Chapter 11 Class Hierarchies and Interfaces
Chapter 12 Arrays and ArrayLists
Chapter 13 Searching and Sorting
Chapter 14 Streams and Files
Chapter 15 Graphics
Chapter 16 GUI Components and Events
Chapter 17 Mouse, Keyboard, Sounds, and Images
Chapter 18 Big-O Analysis of Algorithms
Chapter 19 The Java Collections Framework
Chapter 20 Linked Lists
Chapter 21 Stacks and Queues
Continued

Draft. Copyright © 2006 by Skylight Publishing.


Chapter 22 Recursion Revisited
Chapter 23 Binary Trees
Chapter 24 Lookup Tables and Hashing
Chapter 25 Priority Queues
Chapter 26 Design Patterns
Appendix A The 17 Bits of Style
Appendix B Common Syntax Error Messages
Appendix C HTML Tutorial
Appendix D GUI Examples Index
Appendix E The EasyReader, EasyWriter, EasySound, EasyDate,
and EasyFormat Classes
Appendix F Computing in Context: Responsible, Ethical, and Effective
Computer Use
Index

Draft. Copyright © 2006 by Skylight Publishing.


Contents

Preface xvii

How to Use This Book xxi

Chapter 1. An Introduction to Hardware, Software, and the Internet 1


1.1 Prologue
1.2 Hardware Overview
1.2.1 The CPU
1.2.2 Memory
1.2.3 Secondary Storage Devices
1.2.4 Input and Output Devices
1.3 Software Overview
1.4 Representation of Information in Computer Memory
1.4.1 Numbers
1.4.2 Characters
1.5 The Internet
1.6 Summary
Exercises

Chapter 2. An Introduction to Software Development


2.1 Prologue
2.2 Compilers and Interpreters
2.3 Software Components and Packages
2.4 Lab: Three Ways to Say Hello
2.5 Object-Oriented Programming
2.6 Lab: More Ways to Say Hello
2.7 Summary
Exercises

Draft. Copyright © 2006 by Skylight Publishing.


viii CONTENTS

Chapter 3. Objects and Classes


3.1 Prologue
3.2 Case Study: First Steps
3.3 Classes
3.4 Fields, Constructors, and Methods
3.5 Case Study: First Steps Continued
3.6 Inheritance
3.7 Summary
Exercises

Chapter 4. Algorithms
4.1 Prologue
4.2 Properties of Algorithms
4.3 Iterations
4.4 Recursion
4.5 Case Study: Euclid’s GCF Algorithm
4.6 Working with Lists
4.7 Case Study: File Manager
4.8 Summary
Exercises

Chapter 5. Java Syntax and Style


5.1 Prologue
5.2 Using Comments
5.3 Reserved Words and Programmer-Defined Names
5.4 Syntax vs. Style
5.5 Statements, Blocks, Indentation
5.6 Lab: Correcting Syntax Errors
5.7 Summary
Exercises

Draft. Copyright © 2006 by Skylight Publishing.


CONTENTS ix

Chapter 6. Data Types, Variables, and Arithmetic


6.1 Prologue
6.2 Declaring Fields and Local Variables
6.3 Primitive Data Types
6.4 Strings
6.5 Constants
6.6 Scope of Variables
6.7 Arithmetic Expressions
6.8 Compound Assignment and Increment Operators
6.9 Converting Numbers and Objects into Strings
6.10 Lab: Pie Chart
6.11 Summary
Exercises

Chapter 7. Boolean Expressions and if-else Statements


7.1 Prologue
7.2 if–else Statements
7.3 boolean Data Type
7.4 Relational Operators
7.5 Logical Operators
7.6 Order of Operators
7.7 Short-Circuit Evaluation
7.8 if–else–if and Nested if–else
7.9 Case Study and Lab: Rolling Dice
7.10 The switch statement
7.11 Enumerated Data Types
7.12 Case Study and Lab: Rolling Dice Continued
7.13 Summary
Exercises

Chapter 8. Iterative Statements: while, for, do-while


8.1 Prologue
8.2 The while and for Loops
8.3 The do–while Loop
8.4 return and break in Loops
8.5 Nested Loops
8.6 Lab: Perfect Numbers
8.7 Summary
Exercises

Draft. Copyright © 2006 by Skylight Publishing.


x CONTENTS

Chapter 9. Implementing Classes and Using Objects


9.1 Prologue
9.2 Public and Private Features of a Class
9.3 Constructors
9.4 References to Objects
9.5 Defining Methods
9.6 Calling Methods and Accessing Fields
9.7 Passing Parameters to Constructors and Methods
9.8 return Statement
9.9 Case Study and Lab: Snack Bar
9.10 Overloaded Methods
9.11 Static Fields and Methods
9.12 Case Study and Lab: Snack Bar Continued
9.13 Summary
Exercises

Chapter 10. Strings


10.1 Prologue
10.2 Literal Strings
10.3 String Constructors and Immutability
10.4 String Methods
10.5 Converting Numbers into Strings and Strings into Numbers
10.6 Character Methods
10.7 Lab: Lipogrammer
10.8 The StringBuffer Class
10.9 Summary
Exercises

Chapter 11. Class Hierarchies and Interfaces


11.1 Prologue
11.2 Class Hierarchies and Polymorphism
11.3 Abstract Classes
11.4 Invoking Superclass’s Constructors
11.5 Calling Superclass’s Methods
11.6 Case Study: Dance Studio
11.7 Interfaces
11.8 Case Study: Dance Studio Continued
11.9 Summary
Exercises

Draft. Copyright © 2006 by Skylight Publishing.


CONTENTS xi

Chapter 12. Arrays and ArrayLists


12.1 Prologue
12.2 One-Dimensional Arrays
12.3 Lab: Fortune Teller
12.4 The ArrayList Class
12.5 ArrayList’s Constructors and Methods
12.6 ArrayList’s Pitfalls
12.7 Iterations and the “For Each” Loop
12.8 Inserting and Removing Elements
12.9 Lab: Creating an Index for a Document
12.10 Two-Dimensional Arrays
12.11 Case Study and Lab: Chomp
12.12 Summary
Exercises

Chapter 13. Searching and Sorting


13.1 Prologue
13.2 equals, compareTo, and compare
13.3 Sequential and Binary Search
13.4 Lab: Keeping Things in Order
13.5 Selection Sort
13.6 Insertion Sort
13.7 Mergesort
13.8 Quicksort
13.9 Lab: Benchmarks
13.10 The Arrays and Collections Classes
13.11 Summary
Exercises

Chapter 14. Streams and Files


14.1 Prologue
14.2 Pathnames and the java.io.File Class
14.3 Reading from a Text File
14.4 Writing to a Text File
14.5 Lab: Dictionary Maker
14.6 Summary
Exercises

Draft. Copyright © 2006 by Skylight Publishing.


xii CONTENTS

Chapter 15. Graphics


15.1 Prologue
15.2 paint, paintComponent, and repaint
15.3 Coordinates
15.4 Colors
15.5 Drawing Shapes
15.6 Fonts and Text
15.7 Case Study and Lab: Pieces of the Puzzle
15.8 Summary
Exercises

Chapter 16. GUI Components and Events


16.1 Prologue
16.2 Pluggable Look and Feel
16.3 Basic Swing Components and Their Events
16.4 Case Study and Lab: Speed Control
16.5 Pull-Down Menus
16.6 Layouts
16.7 Summary
Exercises

Chapter 17. Mouse, Keyboard, Sounds, and Images


17.1 Prologue
17.2 Mouse Events Handling
17.3 Keyboard Events Handling
17.4 Case Study and Lab: Drawing Editor
17.5 Lab: Cursor Keys
17.6 Sounds and Images
17.7 Summary
Exercises

Chapter 18. Big-O Analysis of Algorithms


18.1 Prologue
18.2 Big-O Notation
18.3 Sorting: a Big-O Review
18.4 Summary
Exercises

Draft. Copyright © 2006 by Skylight Publishing.


CONTENTS xiii

Chapter 19. The Java Collections Framework


19.1 Prologue
19.2 Collection<E> and Iterator<E>
19.3 Lists and ListIterator<E>
19.4 Stacks
19.5 Queues
19.6 Priority Queues
19.7 Sets
19.8 Maps
19.9 Case Study and Lab: Stock Exchange
19.10 Summary
Exercises

Chapter 20. Lists and Iterators


20.1 Prologue
20.2 Singly-Linked List
20.3 Traversals
20.4 Lab: Implementing a Singly-Linked List
20.5 Linked List with a Tail
20.6 Doubly-Linked List and Circular List
20.7 Lab: Teletext
20.8 Summary
Exercises

Chapter 21. Stacks and Queues


21.1 Prologue
21.2 Implementations of Stacks
21.3 Lab: Browsing
21.4 The Hardware Stack
21.5 Implementations of Queues
21.6 Case Study and Lab: Actors World
21.7 Summary
Exercises

Draft. Copyright © 2006 by Skylight Publishing.


xiv CONTENTS

Chapter 22. Recursion Revisited


22.1 Prologue
22.2 Three Examples
22.3 When Not to Use Recursion
22.4 Understanding and Debugging Recursive Methods
22.5 Lab: The Tower of Hanoi
22.6 Case Study and Lab: The Game of Hex
22.7 Summary
Exercises

Chapter 23. Binary Trees


23.1 Prologue
23.2 Implementation of Binary Trees
23.3 Traversals
23.4 Binary Search Trees
23.5 Lab: Morse Code
23.6 Case Study and Lab: Java Messenger
23.7 Summary
Exercises

Chapter 24. Lookup Tables and Hashing


24.1 Prologue
24.2 Lookup Tables
24.3 Lab: Cryptogram Solver
24.4 Hash Tables
24.5 java.util’s HashSet and HashMap
24.6 Lab: Search Engine
24.7 Summary
Exercises

Chapter 25. Heaps and Priority Queues


25.1 Prologue
25.2 Implementations of Priority Queues
25.3 Binary Trees: Non-Linked Representation
25.4 Heaps and Priority Queues
25.5 Lab: Heapsort
25.6 Summary
Exercises

Draft. Copyright © 2006 by Skylight Publishing.


CONTENTS xv

Chapter 26. Design Patterns


26.1 Prologue
26.2 Façade
26.3 Strategy
26.4 Singleton
26.5 Decorator
26.6 Composite
26.7 MVC (Model-View-Controller)
26.8 Summary
Exercises

Appendix A: The 17 Bits of Style


Appendix B: Common Syntax Error Messages
Appendix C: HTML Tutorial
Appendix D: GUI Examples Index
Appendix E: The EasyReader, EasyWriter, EasySound,
EasyDate, and EasyFormat Classes
Appendix F: Computing in Context: Responsible and Ethical
Computer Use

Index

Draft. Copyright © 2006 by Skylight Publishing.


xvi CONTENTS

Draft. Copyright © 2006 by Skylight Publishing.


Preface

This book offers a comprehensive introduction to the concepts and practices of


object-oriented programming in Java. It also introduces the most common data
structures and related algorithms and their implementations in the Java collections
framework. As the title implies, the book covers the material in the A- and AB-level
AP Computer Science course syllabus. This is equivalent to a two- or three-semester
college course sequence in introductory programming and data structures for
computer science majors. In addition to covering the AP curriculum in depth, we
introduce several topics that are not required for the AP exams, including file input
and output, graphics, graphical user interfaces, events handling in Java, and design
patterns. This additional material gives students a better sense of real-world Java
programming and enables them to undertake more realistic and engaging exercises
and labs.

This edition builds on our earlier books, Java Methods: An Introduction to Object-
Oriented Programming (Skylight Publishing, 2001) and Java Methods AB: Data
Structures (Skylight Publishing, 2003). In this edition we have organized all of the
material into one volume. Besides an upgrade to Java 5.0, we have made many
substantial changes that reflect the current thinking about object-oriented
programming (OOP) among computer science educators and professionals. We have
revised the sequence of topics for an earlier introduction of inheritance, class
hierarchies, interfaces, and polymorphism; enhanced the discussion of object-
oriented design; introduced new case studies and labs and updated and streamlined
those we decided to keep from the previous edition; recast almost all examples from
applets into applications; added a separate chapter on the Java collections framework;
and so on.

The book follows four main threads: OOP concepts and techniques, algorithms, Java
syntax and style, and Java libraries. As in the software engineering profession itself,
these threads are interwoven into an inseparable braid.

Our book strives to present the technical details while grounding them in clear
explanations of the underlying concepts. OOP has an extensive conceptual layer and
complex terminology. Fortunately, many OOP concepts are more straightforward
than the terminology makes them appear. The notions of objects (entities that
combine data elements and functions), classes (definitions of types of objects),
methods (functions that handle certain tasks), instantiation (creating an object of a
particular class), inheritance (one class extending the features of another class),

Draft. Copyright © 2006 by Skylight Publishing.


xviii PREFACE

encapsulation (hiding the implementation details of a class), polymorphism (calling


the correct methods automatically for specific objects disguised as more generic
types), and event-driven applications (where the operating system, the user, or events
in the program trigger certain actions) are actually quite intuitive.

We also emphasize good programming style, an element not mandated by formal


Java language specifications but essential for writing readable and professional
programs.

Our labs and case studies aim to demonstrate the most appropriate uses of the
programming techniques and data structures we cover. OOP is widely believed to
facilitate team work, software maintenance, and software reuse. While it is not
possible for an introductory textbook to present a large-scale real-world project as a
case study, the case studies and labs in this book offer a taste of how these OOP
benefits can play out in larger projects.

We assume that at least two or three class periods each week will be held in a
computer lab with students working independently or in small groups. The Student
“disk” (a zip file downloadable from the book’s web site) contains files for all the
case studies, labs, and exercises in the book; the Teacher’s “disk,” available to
teachers, provides complete solutions to all the labs and exercises.

Still, with all the examples and case studies, we leave a lot of work to you, the
student. This is not a Java-in-n-days book or an n-hours-to-complete book. It is a
book for learning essential concepts and technical skills at a comfortable pace, for
acquiring a repertoire of techniques and examples to work from, and for consulting
once in a while when you start writing your own Java programs professionally or for
fun.

Working through this book will not make you a Java expert right away — but it will
bring you to the level of an entry-level Java programmer with a better than average
understanding of the fundamental concepts. Object-oriented programming was
invented to make software development more accessible to beginners, and Java
Methods A & AB is written in that spirit.

Our sincere thanks to...

Our special thanks to Margaret Litvin for her thorough and thoughtful editing.

Without further delay, let us begin learning object-oriented programming in Java!

Draft. Copyright © 2006 by Skylight Publishing.


PREFACE xix

Draft. Copyright © 2006 by Skylight Publishing.


xx PREFACE

About the Authors

Maria Litvin has taught computer science and mathematics at Phillips Academy
in Andover, Massachusetts, since 1987. She is an Advanced Placement Computer
Science exam reader and question leader and, as a consultant for The College Board,
provides AP training for high school computer science teachers. Maria is a recipient
of the 1999 Siemens Award for Advanced Placement for Mathematics, Science, and
Technology for New England and of the 2003 RadioShack National Teacher Award.
Prior to joining Phillips Academy, Maria taught computer science at Boston
University. Maria is a co-author of C++ for You++: An Introduction to
Programming and Computer Science, which became one of the leading high school
textbooks for AP Computer Science courses, and of the earlier editions of Java
Methods and Java Methods AB. Maria is also the author of Be Prepared for the AP
Computer Science Exam in Java.

Gary Litvin is a co-author of C++ for You++, Java Methods, and Java Methods
AB and a contributor to the 2006 edition of Be Prepared for the AP Computer
Science Exam in Java. Gary has worked in many areas of software development
including artificial intelligence, pattern recognition, computer graphics, and neural
networks. As founder of Skylight Software, Inc., he developed SKYLIGHTS/GX,
one of the first visual programming tools for C and C++ programmers. Gary led in
the development of several state-of-the-art software products including interactive
touch screen development tools, OCR and handwritten character recognition systems,
and credit card fraud detection software.

Draft. Copyright © 2006 by Skylight Publishing.


How to Use This Book

The Java Methods A & AB companion web site —

http://www.skylit.com/javamethods

— is an integral part of this book. It contains four chapters and several appendices.
It also has a downloadable Student “disk” with all the student files for case studies,
labs, and exercises. Also on the book’s web site are “footnotes,” web links, errata,
supplemental papers, and syllabi and technical support information for teachers.

We have chosen to place Chapters 1, 14, 16, and 17 and the appendices on the web
either because they rely on many web links or because the material they cover is less
theoretical and handy to have online for reference.

The web symbol indicates a “footnote” that is on the book’s web site in the
alphabetical list of “footnote” links.

JM refers to the Java Methods student disk. For example, “you can find
HelloWorld.java in JM\Ch02\Hello” means the HelloWorld.java
file is located in the Ch02\Hello folder on your student disk.

This icon draws your attention to a lab exercise or a hands-on exploration of


an example.

“Parentheses” like these, in the margin, mark supplementary material


intended for a more inquisitive reader. This material either gives a glimpse
of things to come in subsequent chapters or adds technical details.

1. , 2. In exercises, a square indicates an “intermediate” question that may require


more thought or work than an ordinary question or exercise. A diamond
indicates an “advanced” question that could be treacherous or lead to
unexplored territory — proceed at your own risk.

A checkmark at the end of a question in an exercise means that a solution is


included on your student disk. We have included solutions to about one-
third of the exercises. They can be found in JM\SolutionsToExercises
(click on index.html).

Draft. Copyright © 2006 by Skylight Publishing.


xxii HOW TO USE THIS BOOK

A Teacher’s “disk” with complete solutions to all the exercises and labs is available
for downloading free of charge to teachers who use this book as a textbook in their
schools (click on the “Teachers’ Room” link at skylit.com/javamethods for
details).

(To a slightly different subject...)

How you use this book will depend on your background in computers. If you are
familiar with computers and programming, you can glance quickly at Chapters 1 and
2 to see whether they fill any gaps. Chapters 3 (Objects and Classes), 4
(Algorithms), and 5 (Java Syntax and Style) can be covered in any order, depending
on your taste. If you know C++, Chapters 6, 7, and 8 will be easy for you. But do
still look at them for the sake of the case studies and labs, which cover broader
concepts than the chapter headings imply. Chapters 14 (Streams and Files), 15
(Graphics), 16 (GUI Components and Events), and 17 (Mouse, Keyboard, Sounds,
and Images) are optional as far as the AP exams are concerned. Chapter 18 begins
the discussion of more advanced “AB” topics: big-O, the Java collections framework,
and data structures. The concluding chapter, Design Patterns, broadens the horizon,
but it is optional, too.

Draft. Copyright © 2006 by Skylight Publishing.


ch 001
1 An Introduction to Hardware,
Software, and the Internet
1.1 Prologue 2
1.2 Hardware Overview
1.2.1 The CPU
1.2.2 Memory
1.2.3 Secondary Storage Devices
1.2.4 Input and Output Devices
1.3 Software Overview
1.4 What Do Programmers Do?
1.5 Representation of Information in Computer Memory
1.4.1 Numbers
1.4.2 Characters
1.6 The Internet
1.7 Summary
Exercises 5

Draft. Copyright © 2006 by Skylight Publishing.


2 CHAPTER 1 ~ AN INTRODUCTION TO HARDWARE, SOFTWARE, AND THE INTERNET

1.1 Prologue
Have you ever opened that inconspicuous gray or black (or purple) box sitting on or
beside your desk, with tangled wires snaking out of it in all directions? If you do,
you might find a mostly empty box, with a power supply, a printed circuit board on
the bottom connected by tape cables to a small disk drive and a couple of other
devices neatly tucked away in their bays. And that’s all. But it brings you an entire
world.

The most important piece of a typical computer is the Central Processing Unit or
CPU. In a personal computer, the CPU is a microprocessor made from a tiny chip of
silicon, sometimes as small as half an inch square. Immensely precise manufacturing
processes etch a huge number of semiconductor devices, called transistors, into the
silicon wafer. Each transistor is a microscopic digital switch and together they
control, with almost perfect precision, billions of signals — little spikes of electricity
— that arise and disappear every second. The size of the spikes doesn’t matter, only
their presence or absence. The transistors in the CPU recognize only two states of a
signal, “on” or “off,” “high” or “low,” “1” or “0,” “true” or “false.” This is called
digital electronics, as opposed to analog electronics where the actual amplitudes of
signals carry information.

The transistors on a chip combine to form logical devices called gates. Gates
implement Boolean operations (named after the British mathematician George Boole,
1815-1864, boole who studied the properties of logical relations). For example, an
AND gate takes two inputs and combines them into one output signal. The output is
set to “true” if both the first and the second input are “true,” and to “false” otherwise
(Figure 1-1 (a)). In an OR gate, the output is set to “true” if either the first or the
second (or both) inputs are true (Figure 1-1 (b)). A NOT gate takes one input and
sets the output to its opposite (Figure 1-1 (c)). Note the special shapes used to denote
each type of gate.

These three basic types of gates can be combined to make other Boolean operations
and logical circuits. Figure 1-2, for example, shows how you can combine AND, OR
and NOT gates to make an XOR (“eXclusive OR”) operation. This operation sets the
output to “true” if exactly one of its two inputs is “true.” In the late 1940s, John von
Neumann, neumann a great mathematician and one of the founding fathers of computer
technology, showed that all arithmetic operations can be reduced to AND, OR, and
NOT logical operations.

Draft. Copyright © 2006 by Skylight Publishing.


CHAPTER 1 ~ AN INTRODUCTION TO HARDWARE, SOFTWARE, AND THE INTERNET 3

A A
A AND B A OR B A NOT A
B B

A B A AND B A B A OR B A NOT A
T T T T T T T F
T F F T F T F T
F T F F T T
F F F F F F

(a) (b) (c)


AND gate OR gate NOT gate

Figure 1-1. AND, OR, and NOT gates

B °
A XOR B

°
A B A XOR B
T T F
T F T
F T T
F F F

Figure 1-2. XOR circuit made of AND, OR and NOT gates

The microprocessor is protected by a small ceramic case mounted on a PC board


(Printed Circuit board) called the motherboard. Also on the motherboard are
memory chips. The computer memory is a uniform pool of storage units called bits.
A bit stores the smallest possible unit of information: “on” or “off,” “1” or “0.” For
practical reasons, bits are grouped into groups of eight, called bytes.

Draft. Copyright © 2006 by Skylight Publishing.


Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of Up from
Methodism
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

Title: Up from Methodism

Author: Herbert Asbury

Release date: March 2, 2024 [eBook #73085]

Language: English

Original publication: New York: Albert A. Knopf, Inc, 1926

Credits: Gísli Valgeirsson, David E. Brown, and the Online


Distributed Proofreading Team at https://www.pgdp.net
(This file was produced from images generously made
available by The Internet Archive)

*** START OF THE PROJECT GUTENBERG EBOOK UP FROM


METHODISM ***
ASBURY / UP FROM METHODISM
HERBERT ASBURY

UP FROM
METHODISM

ALFRED · A · KNOPF
NEW YORK
1926
Copyright 1926 by Alfred A. Knopf, Inc.

Manufactured in the United States of America


TO
STANLEY WALKER
CHAPTER I [Page 3]

HOME LIFE OF A BOY DESTINED FOR HEAVEN

CHAPTER II [Page 25]

THE MACHINERY OF SALVATION

CHAPTER III [Page 36]

TABOOS OF THE LORD’S DAY

CHAPTER IV [Page 56]

AGENTS OF GOD

CHAPTER V [Page 98]

A BAD BOY COMES TO JESUS

CHAPTER VI [Page 115]

NOTES ON A SAINTED RELATIVE

CHAPTER VII [Page 129]

DIVERSIONS OF AN ABANDONED SINNER

CHAPTER VIII [Page 168]


CONCLUSIONS OF A MAN GONE TO THE DEVIL
ASBURY / UP FROM METHODISM
HOME LIFE OF A BOY DESTINED FOR
HEAVEN
1
On my father’s side, according to my family belief, I am related to
Cotton Mather; on my mother’s side to Roger Williams. My great-
great-uncle was Francis Asbury, the first Bishop of the Methodist
Church to be ordained in America; his elder half-brother was my
great-great-grandfather, Thomas Asbury, who, disowned by his
father for various sins, ran away from the family cottage in England
and went to sea. Later he kidnapped Susan Jennings and married
her, and then settled in Virginia and so escaped the fate of the
Bishop, who doubtless went to the Methodist Heaven.
My great-grandfather was the Rev. Daniel Asbury of Fairfax County,
Va., an early pillar of Methodism and one of the great organizers of
the Church in the South. When a young man he went to North
Carolina, and in 1791 founded, in Lincoln County, the first Methodist
church west of the Catawba River. Later he was a Presiding Elder
and labored valiantly for the Wesleyan God. When but a boy he was
captured by the Indians and kept a prisoner for several years, and is
said to have converted the entire tribe to Christianity. Throughout his
whole life Sunday was his great day—he was born on Sunday,
converted on Sunday, captured by the Indians on Sunday, released
on Sunday, reached home on Sunday, was ordained as a minister on
Sunday, and on a Sunday married Nancy Morris in Brunswick
County, Va. His first child was born on Sunday and he died on
Sunday.
My grandfather was the Rev. William Asbury of North Carolina, a
local preacher who, for some reason that I have never known, quit
raising souls to Heaven and moved over into Mississippi, where he
had equally poor success raising coons and cotton. He married
Susan Lester Marks, member of an equally religious family. Several
of his seven sons were Methodist preachers, and my father, too,
would have assumed the cloth had not the Civil War come along. He
enlisted in the Confederate Army and became an officer of infantry,
and infantrymen do not make good preachers. At the close of the
War he studied Civil Engineering and then moved to Missouri, and
settled in Farmington, where I was born. He was county Surveyor of
my home county of St. Francois for more than thirty years, and City
Clerk of Farmington for twenty years. The exigencies of local politics
compelled him to attend services and take an active part in church
work, but I have no recollection of him as a religious man, although
he imposed religion upon his home and impressed upon his family
the necessity of Christian salvation.
I first suspected that he might not be as religious as reported when I
whacked him across the shins with a broomstick as he sat in the
yard one day nursing his rheumatism. He did not turn the other shin.
This was not long after we had moved from the cottage across the
street from the Masonic and Catholic cemeteries to our new house
on the other side of the town, near the mansions of our first families,
the Webers and the Cayces. Curiously enough, these graveyards
were side by side, although their occupants presumably went to
different Heavens. There was a high fence between them, and it was
not easy to dispose of the border-line burial plots; the Protestants felt
that a few Catholic demons might be able to crawl through or under
the fence, and the Catholics did not wish to have their mortal
remains so close to those of such benighted heathen as the
Methodists and the Presbyterians.
My mother’s people, the Prichards and the Blues, came originally
from North Carolina, Georgia and Tennessee, and were for the most
part devout Baptists, believing that in immersion alone was true
salvation. The strength of their religious convictions may be seen in
the fact that many of them never forgave my mother for marrying a
Methodist and transferring her letter to my father’s Church, forsaking
the austerities of her family faith. They considered the Methodists too
liberal! The true Baptist of those days was in a constant emotional
upheaval; his religion was a canker that ate deeper and deeper, and
he was able to find no relief; the more religious he became, the more
miserable he was. On the other hand, the Methodist enjoyed terrific
and periodical emotional explosions, and thereafter was generally
able to live for a few days in comparative calm. But the Baptist was
wrapped in gloom from the moment of his conversion until he was
called home to Jesus.
When my mother’s forbears came up from the South they settled
within a radius of twenty miles of Farmington, many of them in the
vicinity of Hazel Run and French Village. They were farmers, with a
sprinkling of small storekeepers, preachers and country doctors. My
mother’s father, Joseph Prichard, was a farmer, but he was very
religious and was renowned throughout the countryside around
French Village for his exploits as a faith healer; he could cure
toothache, remove warts and stop the flow of blood. His method was
merely to say: “It will be gone by the time you get home,” and
generally it was. He frequently removed warts from my own hands;
at least they vanished within a reasonable time after he had looked
at them and pronounced his incantations, and I regarded him with
awe.
There was a tradition in our family that my grandfather boasted
Indian blood in his veins, and although I do not think it was true, at
the time it gave me great pride and satisfaction; it invested me with
authority at such times as we played Indian and Wild West games.
He made a two-year trip overland to California during the 1849 gold
rush, without conspicuous success, and brought back with him the
musket with which we were given to understand he had slain
innumerable Indians. Two or three times a year his children and his
grandchildren, a vast horde all told, held family reunions at his
French Village farm, and the big moment of the day came in the
afternoon when all of the grandchildren trooped into the woods
behind the barn to watch Grandpa kill a squirrel. We stood in a half-
circle, almost overcome by awe, while my grandfather loaded his
gun with great care, pouring the correct amount of powder from his
powder horn and dumping the bullets from his pouch into the palm of
his hand, where he counted them carefully. And then he killed the
squirrel, while we stood behind him and marveled. He never failed;
he was an excellent rifle shot; in his ninety-first year, three years
before he died, he knocked a squirrel from a tree as easily as Davy
Crockett could have done it.
As a young man in Georgia and later in Missouri my grandfather
Prichard was famous as a leader of Baptist sing-songs. His favorite
hymn was “The Prodigal Son,” which he was wont to bellow with
fanatical fervor as he sat bolt upright in an uncomfortable, straight-
backed chair and directed the singing with a stick. He sang from an
old hymn book which had been in his family for many years, a
curious volume with the music printed in square notes. Many of the
hymns expressed sentiments that to-day, even in religious circles,
would be considered obscene. I recall one that said: “Oh, sinners!
My bowels do move with desire!”
I was constantly under the influence of my mother’s people, who did
what they could to overcome the pernicious influence of the
Methodists; they prevailed upon me to visit them and attend their
revivals and other religious meetings, and otherwise attempted to
oversee and assure my eventual salvation. Some of my father’s
people, too, had come up from the South, from Virginia and North
Carolina and Mississippi, and had settled around Farmington. Many
of them were excessively pious, although it is my recollection that
they did not carry their love of God and man into the conduct of their
temporal affairs; religion was not permitted to interfere with business.
Between them and my mother’s people there was a constant,
although not open, fight for my soul, and the souls of my sister and
brothers. The bout appears to have been a draw.

2
We were a musical family. My elder brother and I played the
harmonica, or French harp, as we called it then, and my sister
performed capably upon the organ, the guitar and the mandolin. She
was particularly adept upon the guitar, and enjoyed an enviable
reputation for the way she whanged out the fandango pieces and the
tune descriptive of the Battle of Sebastopol, which requires much
banging and thumping and difficult fingering. My father was a fiddler.
He did not know one note from another, but he could tuck his fiddle
under his chin, tap the floor with his foot and play with great spirit
such tunes as “Fisher’s Hornpipe,” “Billy in the Low Ground,” “Turkey
in the Straw” and “The Arkansas Traveler.” But his muse was dumb if
he could not pat his foot. I could also beat a snare drum passably,
and later I learned to play the violin, the cornet and the alto horn, so
that we had quite a family orchestra, and our house was frequently
filled with music. Anyhow we played these instruments.
But not on Sunday. Our Preacher assured us that music on Sunday,
except in church, was sinful and an affront to the Heavenly Father,
and on Saturday night, after a final orgy of melody, my mother
gathered up the guitars and mandolins, the fiddles, the drums and
the harmonicas and all of the other musical instruments, even the
jew’s-harp, and put them under lock and key until Monday morning.
We could not even play a comb on Sunday, although on rare
occasions, usually when the Preacher was there and gave
permission and absolution from sinful consequences, I was
permitted to bring out my big harmonica, from which I could produce
the sonorous tones of an organ, and play church hymns such as
“Rock of Ages” and “Nearer, My God, to Thee.” But I was forbidden
to play “Turkey in the Straw” or “The Mocking Bird” with variations.
The latter was my favorite tune, because by jiggling my hand over
the harmonica I could produce a very effective trill which I fondly
believed was as beautiful as the singing of a canary, but if I launched
into such a tune on Sunday I had debauched the Sabbath, and my
harmonica was taken from me. And frequently I myself was taken
into the woodshed and taught a proper respect for the Lord’s Day.
Under no circumstances could we play the fiddle in our house on
Sunday, because of all music, that which came from the fiddle was
the most sinful. It was the Devil’s instrument. No fiddling on Sunday
had been a cardinal rule of my father’s family since Colonial days in
Virginia, and later in Mississippi and in North Carolina my
grandmother had compelled her Negro slaves to put up their musical
instruments from Saturday night to Monday morning. Eventually I
took lessons from the music teacher in Farmington and learned to
call the fiddle a violin, and as I grew older I played when I pleased,
although not very successfully. But so long as the instrument
remained a fiddle it was played in our house on Sunday on only one
occasion. And then the performance was a neighborhood scandal,
and only the fact that the instrument had been played by a Preacher
saved us from getting into trouble with God and His representatives
in Farmington.
This tweaking of the heavenly nose occurred during a District
Conference, when the visiting preachers were parceled out among
the faithful of the local Methodist church. Two came to us, one a
young man filled with good works and a constant, fretful worry over
the low estate of the human race, and the other an old man who had
been a wicked sinner in his time and who had never been able to
resist an occasional temptation to have a good time. He was a
Virginian and an accomplished fiddler, but he could play nothing but
dance music, which the darkies had taught him. The first Sunday
they were at our house my father admitted that we had a fiddle, and
the old Preacher demanded that it be brought out for him to perform
upon. My father and mother were in terror all afternoon for fear that
the neighbors would hear the wailing of the fiddle, although they
prevailed upon the old man to use a mute and the music could
hardly be heard outside the room. We were particularly afraid that a
devout Sister, who lived next door to us and whose principal
occupation was going to church, might hear it; if she had it would
have been nothing short of a catastrophe, for the tale would have
been all over town before nightfall. So we closed the windows and
the doors, muted the fiddle and put the old Preacher in the parlor,
where he fiddled until he had sinned enough. But even then several
people passing along the street heard it, and I do not think that we
ever quite lived it down. We could convince no one that the fiddle
had been played by a Man of God. Everyone knew better; Men of
God did not do such things.

3
Every Wednesday night we attended prayer meeting, and on
Sundays we went to Sunday school and twice to church. And on
Sunday afternoon, and on week days, there were the sessions of the
various church organizations. We had grace before meat in our
home, and when the Preacher came to dinner he delivered long-
winded prayers on the universal theme of “gimme.” We did not have
that emotional orgy called family prayer, but I did not escape it; I
encountered it in many Farmington homes and in the houses of
almost all of my relatives.
It was particularly oppressive in the home of an oppressively devout
kinsman whom I called uncle. He was not actually my uncle; he was
related to my father by marriage, and I do not believe there was any
blood kinship, but I thought of him as uncle, and he had a certain
measure of authority over me, so that to a considerable extent I was
under his control and subject to his influence until I became
intelligent enough to have an occasional thought of my own.
My uncle was an extraordinarily pious man, an official of our church
and of our Sunday school, and a leader in every movement designed
to entice the sinner from his wicked ways and lead him to the true
religion of the Wesleyans. He was intent upon salvation for
everyone, and let no opportunity pass to serve the Lord. He frowned
upon laughter, and although he had a very charming family, there
was little joy in his home; a laugh seemed to make him
uncomfortable and start a train of dismal religious thought, and I
gathered the impression that all mirth was a direct and studied
affront to God.
Every night after dinner, or supper, as we called it then, his living
room was given over to family prayer. I frequently spent the night
with his youngest son, my chum for many years, and was compelled
to attend with the others and absorb my nightly dose of religion, and
listen to a solemn account of the fearful things that God would do to
us if we strayed from the path of righteousness. There was no
laughter, and there were no jokes; the whole atmosphere of the
house turned gray and gloomily oppressive when my uncle rose from
his seat, glanced sorrowfully at his family, and announced:
“We will now have prayers.”
He turned and with bowed head passed into the living room. We sat
at the supper table for a moment in silence, myself seeing goblins
and fearsome avenging creatures of God leering at me from every
shaded corner of the room, and my mind racing madly over the day’s
activities to discover what I had done that required an alibi. In a few
moments my aunt arose and went slowly into the other room, and
then one by one the others. We marched solemnly, with downcast
eyes; we might have been going to a funeral. Indeed, it seems to me
now that we must in truth have been going to a funeral; here was a
fine house built for the warmth of human happiness, turned into a
forbidding mausoleum by the mere mention of God.
In the living room Uncle awaited us, standing beside the small table
on which, always, there was nothing but the Family Bible. He waited
in silence until we had taken our places, and then he laid reverent
hands upon the Book and began fumbling with the pages, glancing
sharply over his spectacles to make sure that everyone was
undergoing some sort of emotional upheaval, and looking particularly
for some sign of revolt from his son and myself. I doubt if he ever
knew it, but when I attended family prayer in his house I did not think
of revolt. I was in an agony of fright; I felt as if something was
crushing me, and that something was my uncle’s God, an avenging
monster ready to devour me for my sins. God was in the house and I
was afraid.
The most uncomfortable chairs in the house were used for family
prayer, and we perched upon their edges, afraid to sink back and
relax, because we had been told many times that discomfort and
righteousness were well-nigh synonymous. God would have been
scandalized and indignant had we made ourselves comfortable to
listen to His Word. And then my uncle read from the Bible. He read
without joy; he held in his hand the Book which in his eyes was the
sole hope of humanity, the Book that contained the glad news that
for all mankind there was salvation, but he read it as if it were a
sentence of death, slowly and solemnly, dwelling with horrible clarity
upon those phrases that promised punishment. The Bible seemed to
have no effect upon him but to make him gloomy and miserable.

You might also like