Java Software Solutions Global Edition John Lewis All Chapter Instant Download
Java Software Solutions Global Edition John Lewis All Chapter Instant Download
com
https://ebookgate.com/product/java-software-
solutions-global-edition-john-lewis/
https://ebookgate.com/product/java-software-structures-designing-
and-using-data-structures-3rd-edition-john-lewis/
https://ebookgate.com/product/java-foundations-introduction-to-
program-design-and-data-structures-2nd-edition-john-lewis/
https://ebookgate.com/product/java-security-solutions-1st-
edition-helton/
https://ebookgate.com/product/software-solutions-for-rapid-
prototyping-1st-edition-ian-gibson/
Software Testing and Continuous Quality Improvement 2nd
ed Edition William E. Lewis
https://ebookgate.com/product/software-testing-and-continuous-
quality-improvement-2nd-ed-edition-william-e-lewis/
https://ebookgate.com/product/on-grand-strategy-1st-edition-john-
lewis-gaddis/
https://ebookgate.com/product/writing-compilers-and-interpreters-
software-engineering-approach-using-java-3-udg-edition-mak/
https://ebookgate.com/product/raspberry-pi-cookbook-software-and-
hardware-problems-and-solutions-2nd-edition-monk/
https://ebookgate.com/product/software-engineering-
measurement-1st-edition-john-c-munson-ph-d/
gLobaL
ediTion
SOFTWARE SOLUTIONS
JOHN LEWIS
Virginia Tech
•
WILLIAM LOFTUS
Accenture
•
Global Edition contributions by
Mohit Tahiliani
NITK Surathkal
Boston Columbus Indianapolis New York San Francisco Upper Saddle River
Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto
Delhi Mexico City São Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo
Editorial Director: Marcia Horton Manufacturing Buyer: Lisa McDowell
Editor-in-Chief: Michael Hirsch Art Director: Linda Knowles
Editorial Assistant: Stephanie Sellinger Cover Designer: Shree Mohanambal
Vice President, Marketing: Patrice Jones Inbakumar/Lumina
Marketing Manager: Yezan Alayan Datamatics, Inc.
Marketing Coordinator: Kathryn Ferranti Image Permission Coordinator: Rita Wenning
Vice President, Production: Vince O’Brien Cover Photograph: Eugene Sergeev/Shutterstock
Managing Editor: Jeff Holcomb Media Editor: Daniel Sandin
Production Project Manager: Marilyn Lloyd Media Project Manager: Wanda Rockwell
Head, Learning Asset Full-Service Project Management: Harleen Chopra, Cenveo®
Acquisition, Global Edition: Laura Dent Publisher Services
Acquisitions Editor, Global Edition: Karthik Subramaniun Composition: Cenveo Publisher Services
Project Editor, Global Edition: Anuprova Dey Printer/Binder: Courier Kendallville
Chowdhuri. Cover Printer: Courier Kendallville
Senior Operations Supervisor: Alan Fischer Text Font: Sabon LT Std
Microsoft® and Windows® 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.
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library
Typeset in 8 Sabon LT Std by Cenveo Publishing Services
Printed and bound by Courier Kendallville
The publisher’s policy is to use paper manufactured from sustainable forests.
10 9 8 7 6 5 4 3 2 1—DOC—14 13 12 11 10
on term JVM rather than the less helpful term interpreter. The figure related to
the translation process was also updated. The text file I/O discussion was also
updated, along with its example.
chapter Breakdown
Chapter 1 (Introduction) introduces computer systems in general, including basic
architecture and hardware, networking, programming, and language translation.
Java is introduced in this chapter, and the basics of general program development,
prEfacE 7
Chapter 11 (Exceptions) explores the class hierarchy from the Java standard
library used to define exceptions, as well as the ability to define our own excep-
tion objects. We also discuss the use of exceptions when dealing with input and
output and examine an example that writes a text file.
Chapter 12 (Recursion) covers the concept, implementation, and proper use of
recursion. Several examples from various domains are used to demonstrate how
recursive techniques make certain types of processing elegant.
Chapter 13 (Collections) introduces the idea of a collection and its underlying
data structure. Abstraction is revisited in this context and the classic data struc-
tures are explored. Generic types are introduced as well. This chapter serves as an
introduction to a CS2 course.
Supplements
Student Online resources
These student resources can be accessed at the book’s Companion Website,
www.pearsonglobaleditions.com/lewis:
■ Source Code for all the programs in the text
■ Links to Java development environments
■ VideoNotes: short step-by-step videos demonstrating how to solve prob-
lems from design through coding. VideoNotes allow for self-paced
instruction with easy navigation including the ability to select, play, re-
wind, fast-forward, and stop within each VideoNote exercise. Margin icons
in your textbook let you know when a VideoNote video is available for a
particular concept or homework problem.
Instructor resources
The following supplements are available to qualified instructors only. Visit the
Pearson Education Instructor Resource Center www.pearsonglobaleditions.com/
lewis for information on how to access them:
■ Presentation Slides—in PowerPoint.
■ Solutions—includes solutions to exercises and programming projects.
■ Test Bank with powerful test generator software—includes a wealth of free
response, multiple-choice, and true/false type questions.
■ Lab Manual—lab exercises are designed to accompany the topic
progression in the text.
prEfacE 9
features
Key concepts. Throughout the text, the Key Concept boxes highlight funda-
mental ideas and important guidelines. These concepts are summarized at the
end of each chapter.
Listings. All programming examples are presented in clearly labeled listings, fol-
lowed by the program output, a sample run, or screen shot display as appropri-
ate. The code is colored to visually distinguish comments and reserved words.
Syntax Diagrams. At appropriate points in the text, syntactic elements of the
Java language are discussed in special highlighted sections with diagrams that
clearly identify the valid forms for a statement or construct. Syntax diagrams for
the entire Java language are presented in Appendix L.
Graphics Track. All processing that involves graphics and graphical user inter-
faces is discussed in one or two sections at the end of each chapter that we col-
lectively refer to as the Graphics Track. This material can be skipped without loss
of continuity, or focused on specifically as desired. The material in any Graphics
Track section relates to the main topics of the chapter in which it is found.
Graphics Track sections are indicated by a brown border on the edge of the page.
Summary of Key concepts. The Key Concepts presented throughout a chap-
ter are summarized at the end of the chapter.
Self-review Questions and answers. These short-answer questions review
the fundamental ideas and terms established in the preceding section. They are
designed to allow students to assess their own basic grasp of the material. The
answers to these questions can be found at the end of the book in Appendix N.
Exercises. These intermediate problems require computations, the analysis or
writing of code fragments, and a thorough grasp of the chapter content. While the
exercises may deal with code, they generally do not require any online activity.
programming projects. These problems require the design and implementation
of Java programs. They vary widely in level of difficulty.
VideoNotes. Presented by the author, VideoNotes explain topics visually through
informal videos in an easy-to-follow format, giving students the extra help they need
to grasp important concepts. Look for this VideoNote icon to see which in-chapter
topics and end-of-chapter Programming Projects are available as VideoNotes.
Software failures. These between-chapter vignettes discuss real-world flaws in
software design, encouraging students to adopt sound design practices from the
beginning.
acknowledgments
I am most grateful to the faculty and students from around the world who have
provided their feedback on previous editions of this book. I am pleased to see
10 prEfacE
the depth of the faculty’s concern for their students and the students’ thirst for
knowledge. Your comments and questions are always welcome.
I am particularly thankful for the assistance, insight, and attention to detail
of Robert Burton from Brigham Young University. For years, Robert has con-
sistently provided valuable feedback that helps shape and evolve this textbook.
Brian Fraser of Simon Fraser University also has recently provided some excel-
lent feedback that helped clarify some issues in this edition. Such interaction with
computing educators is incredibly valuable.
I also want to thank Dan Joyce from Villanova University, who developed the
Self-Review questions, ensuring that each relevant topic had enough review mate-
rial, as well as developing the answers to each.
I continue to be amazed at the talent and effort demonstrated by the team at
Pearson. Matt Goldstein, our editor, has amazing insight and commitment. His
assistant, Kelsey Loanes, is a source of consistent and helpful support. Marketing
Manager Yez Alayan makes sure that instructors understand the pedagogical advan-
tages of the text. The cover was designed by the skilled talents of Joyce Wells. Scott
Disanno, Marilyn Lloyd, and Kayla Smith-Tarbox led the production effort. The
Addison-Wesley folks were supported by a phenomenal team at Cenveo Publisher
Services including Jerilyn Bockorick for the interior design and Harleen Chopra
for project management. We thank all of these people for ensuring that this book
meets the highest quality standards.
Special thanks go to the following people who provided valuable advice to us
about this book via their participation in focus groups, interviews, and reviews.
They, as well as many other instructors and friends, have provided valuable feed-
back. They include:
preface 5
chapter 1 Introduction 27
1.3 Networks 46
Network Connections 46
Local-Area Networks and
Wide-Area Networks 48
The Internet 49
The World Wide Web 50
Uniform Resource Locators 51
13
14 cONTENTS
Software failure:
Denver Airport Baggage
Handling System 231
Software failure:
Therac-25 293
Software failure:
2003 Northeast Blackout 403
Software failure:
LA Air Traffic Control 467
Index 815
cONTENTS 23
VideoNote
Overview of program elements. 55
comparison of Java IDEs. 67
Examples of various error types. 69
Developing a solution for pp 1.2. 80
Example using strings and escape sequences. 89
review of primitive data and expressions. 102
Example using the Scanner class. 117
Example using drawn shapes. 127
Developing a solution of pp 2.10. 135
creating objects. 141
Example using the random and Math classes. 155
Example using frames and panels. 176
Developing a solution of pp 3.6. 184
Dissecting the Die class. 190
Discussion of the account class. 204
Example using an extended Jpanel. 208
Overview of GUI development. 217
Developing a solution of pp 4.2. 228
Examples using conditionals. 247
Examples using while loops. 259
Examples using check boxes and radio buttons. 281
Developing a solution of pp 5.4. 290
Examples using for loops. 306
Developing a solution of pp 6.2 322
Exploring the static modifier. 331
Examples of method overloading. 370
Discussion of layout managers. 382
Developing a solution of pp 7.1. 400
24 cONTENTS
27
28 Chapter 1 Introduction
K e Y C O n C e pt
The hardware components of a computer are essentially useless
A computer system consists of
without instructions to tell them what to do. A program is a series of
hardware and software that work in instructions that the hardware executes one after another. Software
concert to help us solve problems. consists of programs and the data those programs use. Software is
the intangible counterpart to the physical hardware components.
Together they form a tool that we can use to help solve problems.
The key hardware components in a computer system are
■ central processing unit (CPU)
■ input/output (I/O) devices
■ main memory
■ secondary memory devices
Each of these hardware components is described in detail in the next section. For
now, let’s simply examine their basic roles. The central processing unit (CPU) is
the device that executes the individual commands of a program. Input/output
(I/O) devices, such as the keyboard, mouse, and monitor, allow a human being to
interact with the computer.
Programs and data are held in storage devices called memory, which fall into
two categories: main memory and secondary memory. Main memory is the storage
device that holds the software while it is being processed by the CPU. Secondary
memory devices store software in a relatively permanent manner. The most impor-
tant secondary memory device of a typical computer system is the hard disk that
resides inside the main computer box. A USB flash drive is also an important sec-
ondary memory device. A typical USB flash drive cannot store nearly as much infor-
mation as a hard disk. USB flash drives have the advantage of portability; they can
be removed temporarily or moved from computer to computer as needed. Another
portable secondary memory device is the compact disc (CD).
1 . 1 Computer Processing 29
Figure 1.1 shows how information moves among the basic hardware compo-
nents of a computer. Suppose you have an executable program you wish to run.
The program is stored on some secondary memory device, such as a hard disk.
When you instruct the computer to execute your program, a copy of the program
is brought in from secondary memory and stored in main memory. The CPU reads
the individual program instructions from main memory. The CPU
then executes the instructions one at a time until the program ends. KeY COnCept
The data that the instructions use, such as two numbers that will The CPU reads the program
be added together, also are stored in main memory. They are either instructions from main memory,
executing them one at a time until
brought in from secondary memory or read from an input device the program ends.
such as the keyboard. During execution, the program may display
information to an output device such as a monitor.
The process of executing a program is fundamental to the operation of a com-
puter. All computer systems basically work in the same way.
software Categories
Software can be classified into many categories using various criteria. At this point
we will simply differentiate between system programs and application programs.
The operating system is the core software of a computer. It performs two
important functions. First, it provides a user interface that allows the user to inter-
act with the machine. Second, the operating system manages computer resources
such as the CPU and main memory. It determines when programs are allowed to
run, where they are loaded into memory, and how hardware devices communi-
cate. It is the operating system’s job to make the computer easy to
use and to ensure that it runs efficiently. KeY COnCept
Several popular operating systems are in use today. The Windows The operating system provides
a user interface and manages
operating system was developed for personal computers by Microsoft, computer resources.
which has captured the lion’s share of the operating systems market.
30 Chapter 1 Introduction
Various versions of the Unix operating system are also quite popular, especially
in larger computer systems. A version of Unix called Linux was developed as an
open source project, which means that many people contributed to its develop-
ment and its code is freely available. Because of that, Linux has become a par-
ticular favorite among some users. Mac OS X is an operating system used for
computing systems developed by Apple Computers.
Operating systems are often specialized for mobile devices such as smart phones
and tablets. The iOS operating system from Apple is used on the iPhone, iPad, and
iPod Touch. It is similar in functionality and appearance to the desktop Mac OS,
but tailored for the smaller devices. Likewise, Windows Phone is the version of the
Windows operating system from Microsoft used in their phones. Android is a Linux-
based mobile operating system developed by Google and used on many phones.
An application (often shortened in conversation to “app”) is a generic term for
just about any software other than the operating system. Word processors, missile
control systems, database managers, Web browsers, and games all can be consid-
ered application programs. Each application program has its own user interface
that allows the user to interact with that particular program.
The user interface for most modern operating systems and applications is a
graphical user interface (GUI, pronounced “gooey”), which, as the name implies,
makes use of graphical screen elements. Among many others, these elements include
■ windows, which are used to separate the screen into distinct work areas
■ icons, which are small images that represent computer resources, such as a file
■ menus, checkboxes, and radio buttons, which provide the user with select-
able options
■ sliders, which allow the user to select from a range of values
■ buttons, which can be “pushed” with a mouse click to indicate a user selection
The mouse is the primary input device used with GUIs; thus, GUIs are some-
times called point-and-click interfaces. The screen shot in Figure 1.2 shows an
example of a GUI.
K e Y C O n C e pt
The interface to an application or operating system is an impor-
As far as the user is concerned, the
tant part of the software because it is the only part of the program
interface is the program. with which the user interacts directly. To the user, the interface is
the program. Throughout this book we discuss the design and imple-
mentation of graphical user interfaces.
The focus of this book is the development of high-quality application pro-
grams. We explore how to design and write software that will perform calcula-
tions, make decisions, and present results textually or graphically. We use the
Java programming language throughout the text to demonstrate various comput-
ing concepts.
1 . 1 Computer Processing 31
Digital Computers
Two fundamental techniques are used to store and manage information: analog
and digital. Analog information is continuous, in direct proportion to the source
of the information. For example, an alcohol thermometer is an analog device for
measuring temperature. The alcohol rises in a tube in direct proportion to the
temperature outside the tube. Another example of analog information is an elec-
tronic signal used to represent the vibrations of a sound wave. The signal’s voltage
varies in direct proportion to the original sound wave. A stereo amplifier sends
this kind of electronic signal to its speakers, which vibrate to reproduce the sound.
We use the term analog because the signal is directly analogous to the information
it represents. Figure 1.3 graphically depicts a sound wave captured
by a microphone and represented as an electronic signal. KeY COnCept
Digital technology breaks information into discrete pieces and Digital computers store information
by breaking it into pieces and repre-
represents those pieces as numbers. The music on a compact disc is senting each piece as a number.
stored digitally, as a series of numbers. Each number represents the
32 Chapter 1 Introduction
voltage level of one specific instance of the recording. Many of these measure-
ments are taken in a short period of time, perhaps 44,000 measurements every
second. The number of measurements per second is called the sampling rate. If
samples are taken often enough, the discrete voltage measurements can be used
to generate a continuous analog signal that is “close enough” to the original. In
most cases, the goal is to create a reproduction of the original signal that is good
enough to satisfy the human senses.
Figure 1.4 shows the sampling of an analog signal. When analog information
is converted to a digital format by breaking it into pieces, we say it has been
Analog signal
Sampling process
Sampled values 12 11 39 40 7 14 47
H i , H e a t h e r.
digitized. Because the changes that occur in a signal between samples are lost, the
sampling rate must be sufficiently fast.
Sampling is only one way to digitize information. For example, a sentence of
text is stored on a computer as a series of numbers, where each number represents
a single character in the sentence. Every letter, digit, and punctuation symbol has
been assigned a number. Even the space character is assigned a number. Consider
the following sentence:
Hi, Heather.
The characters of the sentence are represented as a series of 12 numbers, as shown
in Figure 1.5. When a character is repeated, such as the uppercase 'H', the same
representation number is used. Note that the uppercase version of a letter is stored as
a different number from the lowercase version, such as the 'H' and 'h' in the word
Heather. They are considered separate and distinct characters.
Modern electronic computers are digital. Every kind of information, including
text, images, numbers, audio, video, and even program instructions, is broken into
pieces. Each piece is represented as a number. The information is stored by storing
those numbers.
binary numbers
A digital computer stores information as numbers, but those numbers are not stored
as decimal values. All information in a computer is stored and managed as binary
values. Unlike the decimal system, which has 10 digits (0 through 9), the binary
number system has only two digits (0 and 1). A single binary digit is called a bit.
All number systems work according to the same rules. The base value of a
number system dictates how many digits we have to work with and indicates the
place value of each digit in a number. The decimal number system
KeY COnCept
is base 10, whereas the binary number system is base 2. Appendix B
Binary is used to store and move
contains a detailed discussion of number systems. information in a computer because
Modern computers use binary numbers because the devices that the devices that store and manipu-
late binary data are inexpensive and
store and move information are less expensive and more reliable reliable.
if they have to represent only one of two possible values. Other
34 Chapter 1 Introduction
than this characteristic, there is nothing special about the binary number system.
Computers have been created that use other number systems to store and move
information, but they aren’t as convenient.
Some computer memory devices, such as hard drives, are magnetic in nature.
Magnetic material can be polarized easily to one extreme or the other, but intermedi-
ate levels are difficult to distinguish. Therefore, magnetic devices can be used to rep-
resent binary values quite effectively—a magnetized area represents a binary 1 and a
demagnetized area represents a binary 0. Other computer memory devices are made
up of tiny electrical circuits. These devices are easier to create and are less likely to fail
if they have to switch between only two states. We’re better off reproducing millions
of these simple devices than creating fewer, more complicated ones.
Binary values and digital electronic signals go hand in hand. They improve our
ability to transmit information reliably along a wire. As we’ve seen, an analog signal
has continuously varying voltage with infinitely many states, but a digital signal is
discrete, which means the voltage changes dramatically between one extreme (such
as +5 volts) and the other (such as –5 volts). At any point, the voltage of a digital
signal is considered to be either “high,” which represents a binary 1, or “low,”
which represents a binary 0. Figure 1.6 compares these two types of signals.
As a signal moves down a wire, it gets weaker and degrades due to environ-
mental conditions. That is, the voltage levels of the original signal change slightly.
The trouble with an analog signal is that as it fluctuates, it loses its original infor-
mation. Since the information is directly analogous to the signal, any change in
the signal changes the information. The changes in an analog signal cannot be
recovered because the degraded signal is just as valid as the original. A digital
signal degrades just as an analog signal does, but because the digital signal is
originally at one of two extremes, it can be reinforced before any information is
lost. The voltage may change slightly from its original value, but it still can be
interpreted correctly as either high or low.
The number of bits we use in any given situation determines the number of
unique items we can represent. A single bit has two possible values, 0 and 1, and
a. 2 bits
b. 4 bits
c. 5 bits
d. 7 bits
SR 1.6 Suppose you want to represent each of the 50 states of the United
States using a unique permutation of bits. How many bits would be
needed to store each state representation? Why?
Computer architecture
The architecture of a house defines its structure. Similarly, we use the term com-
puter architecture to describe how the hardware components of a computer are put
together. Figure 1.9 illustrates the basic architecture of a generic computer system.
Information travels between components across a group of wires called a bus.
The CPU and the main memory make up the core of a computer.
K e Y C O n C e pt
The core of a computer is made up
As we mentioned earlier, main memory stores programs and data
of main memory, which stores pro- that are in active use, and the CPU methodically executes program
grams and data, and the CPU, which instructions one at a time.
executes program instructions one
at a time.
Suppose we have a program that computes the average of a list of
numbers. The program and the numbers must reside in main memory
while the program runs. The CPU reads one program instruction from
main memory and executes it. If an instruction needs data, such as a number in the
list, to perform its task, the CPU reads that information as well. This process repeats
until the program ends. The average, when computed, is stored in main memory to
await further processing or long-term storage in secondary memory.
Almost all devices in a computer system other than the CPU and main memory
are called peripherals; they operate at the periphery, or outer edges, of the system
(although they may be in the same box). Users don’t interact directly with the
CPU or main memory. Although they form the essence of the machine, the CPU
and main memory would not be useful without peripheral devices.
Controllers are devices that coordinate the activities of specific peripherals. Every
device has its own particular way of formatting and communicating data, and part
of the controller’s role is to handle these idiosyncrasies and isolate them from the
rest of the computer hardware. Furthermore, the controller often handles much of
the actual transmission of information, allowing the CPU to focus on other activities.
Input/output (I/O) devices and secondary memory devices are considered periph-
erals. Another category of peripherals consist of data transfer devices, which allow
information to be sent and received between computers. The computer specified in
Figure 1.8 includes a network card, also called a wireless network interface controller
(WNIC), which connects to a radio-based computer network.
In some ways, secondary memory devices and data transfer devices can be
thought of as I/O devices because they represent a source of information (input)
and a place to send information (output). For our discussion, however, we define
I/O devices as those devices that allow the user to interact with the computer.
input/Output Devices
Let’s examine some I/O devices in more detail. The most common input devices
are the keyboard and the mouse or trackpad. Others include
■ bar code readers, such as the ones used at a retail store checkout
■ microphones, used by voice recognition systems that interpret voice commands
■ virtual reality devices, such as handheld devices that interpret the move-
ment of the user’s hand
■ scanners, which convert text, photographs, and graphics into machine-
readable form
1 . 2 Hardware Components 39
■ cameras, which capture still pictures and video, and can also be used to
process special input such as QR codes
Monitors and printers are the most common output devices. Others include
■ plotters, which move pens across large sheets of paper (or vice versa)
■ speakers, for audio output
■ goggles, for virtual reality display
Some devices can provide both input and output capabilities. A touch screen
system can detect the user touching the screen at a particular place. Software can
then use the screen to display text and graphics in response to the user’s touch.
Touch screens have become commonplace for handheld devices.
The desktop computer described in Figure 1.8 includes a monitor with a
17-inch diagonal display area. It makes use of liquid crystal display (LCD)
technology, unlike the older cathode ray tube (CRT) monitors that required
substantial voltage and generally were not portable. A picture is represented in a
computer by breaking it up into separate picture elements, or pixels. The monitor
might display a grid of 1280 by 1024 pixels. Representing and managing graphi-
cal data is discussed in more detail in Chapter 2.
4802
Data values are stored in
Addresses 4803 memory locations.
4804
4805
4806 Large values are stored
4807 in consecutive memory
locations.
4808
4809
4810
4811
4812
The cache is used by the central processing unit (CPU) to reduce the average
access time to instructions and data. The cache is a small, fast memory that stores
the contents of the most frequently used main memory locations. Contemporary
CPUs include an instruction cache to speed up the fetching of executable instruc-
tions and a data cache to speed up the fetching and storing of data.
The most common secondary storage devices are hard disks and USB flash
drives. A typical USB flash drive stores between 1 GB and 256 GB of information.
The storage capacities of hard drives vary, but on personal computers, capacities
typically range between 120 GB and 500 GB, such as in the system described in
Figure 1.8. Some hard disks can store 2 TB of data.
A USB flash drive consists of a small printed circuit board carrying the circuit
elements and a USB connector, insulated electrically and protected inside a plastic,
metal, or rubberized case, which can be carried in a pocket or on a key chain, for
example.
A disk is a magnetic medium on which bits are represented as magnetized parti-
cles. A read/write head passes over the spinning disk, reading or writing information
as appropriate. A hard disk drive might actually contain several disks in a vertical
column with several read/write heads, such as the one shown in Figure 1.12.
To get an intuitive feel for how much information these devices can store,
consider that all the information in this book, including pictures and formatting,
requires about 7 MB of storage.
Magnetic tapes also have been used as secondary storage but are considerably
slower than hard disk and USB flash drives because of the way information is
accessed. A hard disk is a direct access device since the read/write head can move, in
general, directly to the information needed. A USB flash drive is also a direct access
Read/write
head
Disks
Figure 1.12 A hard disk drive with multiple disks and read/write heads
42 Chapter 1 Introduction
device, but nothing moves mechanically. The terms direct access and random access
are often used interchangeably. However, information on a tape can be accessed
only after first getting past the intervening data. A tape must be rewound or fast-for-
warded to get to the appropriate position. A tape is therefore considered a sequential
access device. For these reasons, tapes largely have fallen out of use as a computing
storage device, just as audio cassettes have been supplanted by compact discs.
Two other terms are used to describe memory devices: random access
memory (RAM) and read-only memory (ROM). It’s important to understand
these terms because they are used often and their names can be misleading. The
terms RAM and main memory are basically interchangeable, describing the
memory where active programs and data are stored. ROM can refer to chips
on the computer motherboard or to portable storage such as a compact disc.
ROM chips typically store software called BIOS (basic input/output system)
that provide the preliminary instructions needed when the computer is turned
on initially. After information is stored on ROM, generally it is not altered (as
the term read-only implies) during typical computer use. Both RAM and ROM
are direct (or random) access devices.
A CD-ROM is a portable secondary memory device. CD stands
K e Y C O n C e pt
The surface of a CD has both
for compact disc. It is called ROM because information is stored
smooth areas and small pits. A pit permanently when the CD is created and cannot be changed. Like
represents a binary 1 and a smooth its musical CD counterpart, a CD-ROM stores information in binary
area represents a binary 0. format. When the CD is initially created, a microscopic pit is pressed
into the disc to represent a binary 1, and the disc is left smooth to
represent a binary 0. The bits are read by shining a low-intensity laser beam onto
the spinning disc. The laser beam reflects strongly from a smooth area on the
disc but weakly from a pitted area. A sensor receiving the reflection determines
whether each bit is a 1 or a 0 accordingly. A typical CD-ROM’s storage capacity
ranges between 650 and 900 MB.
Variations on basic CD technology emerged quickly. Most personal computers
are equipped with a CD-Recordable (CD-R) drive. A CD-R can be used to cre-
ate a CD for music or for general computer storage. Once created, you can use a
CD-R disc in a standard CD player, but you can’t change the information on a
CD-R disc once it has been “burned.” Music CDs that you buy are pressed from
a mold, whereas CD-Rs are burned with a laser.
A CD-Rewritable (CD-RW) disc can be erased and reused. It can be reused because
the pits and flat surfaces of a normal CD are simulated on a CD-RW
K e Y C O n C e pt by coating the surface of the disc with a material that, when heated
A rewritable CD simulates the pits to one temperature becomes amorphous (and therefore nonreflective)
and smooth areas of a regular CD and when heated to a different temperature becomes crystalline (and
by using a coating that can be made
amorphous or crystalline as needed.
therefore reflective). The CD-RW media doesn’t work in all players, but
CD-RW drives can create both CD-R and CD-RW discs.
1 . 2 Hardware Components 43
CDs were initially a popular format for music; they later evolved to be used
as a general computer storage device. Similarly, the DVD format was originally
created for video and is now making headway as a general format for computer
data. DVD once stood for digital video disc or digital versatile disc, but now the
acronym generally stands on its own. A DVD has a tighter format (more bits per
square inch) than a CD and can therefore store much more information. DVD-
ROMs eventually may replace CD-ROMs completely because there is a compat-
ible migration path, meaning that a DVD drive can read a CD-ROM. Similar to
CD-R and CD-RW, there are DVD-R and DVD-RW discs. The drive listed in
Figure 1.8 allows the user to read and write CD-RW discs and read DVD-ROMs,
including the ability to play music CDs and watch DVD videos.
The speed of a CD or DVD is expressed in multiples of x, which represents
a data transfer speed of 153,600 bytes of data per second for a CD; nine times
that speed, or about 1.5 megabytes of data per second, for a DVD; and three
times the speed of a DVD, or 4.5 megabytes of data per second, for a Blu-ray
disc. The drive described in Figure 1.8 has a maximum data access speed of
16x, or about 72 MB of data per second. A dual-layer Blu-ray disc has a stor-
age capacity of 50 GB.
The capacity of storage devices changes continually as technology improves.
A general rule in the computer industry suggests that storage capacity approxi-
mately doubles every 18 months. However, this progress eventually will slow
down as capacities approach absolute physical limits.
CPU
Arithmetic/logic
unit
Bus
Main
Control unit
memory
Registers
contains a set of general-purpose registers that are used for temporary storage
of values as needed.
The concept of storing both program instructions and data together in main
memory is the underlying principle of the von Neumann architecture of computer
design, named after John von Neumann, a Hungarian-American mathematician
who first advanced this programming concept in 1945. These computers continu-
ally follow the fetch-decode-execute cycle depicted in Figure 1.14. An instruction
is fetched from main memory at the address stored in the program counter and is
put into the instruction register. The program counter is incremented
K e Y C O n C e pt at this point to prepare for the next cycle. Then the instruction is
The fetch-decode-execute cycle
decoded electronically to determine which operation to carry out.
forms the foundation of computer
processing. Finally, the control unit activates the correct circuitry to carry out
the instruction, which may load a data value into a register or add
two values together, for example.
The CPU is constructed on a chip called a microprocessor, a device that is part
of the main circuit board of the computer. This board also contains ROM chips
a. 3 KB
b. 2 MB
c. 4 GB
a. 8 bytes
b. 2 KB
c. 4 MB
a. Almost all devices in a computer system, other than the CPU and
the main memory, are categorized as this.
46 Chapter 1 Introduction
1.3 networks
A single computer can accomplish a great deal, but connecting several computers
together into networks can dramatically increase productivity and facilitate the
sharing of information. A network consists of two or more computers connected
together so they can exchange information. Using networks has become the nor-
mal mode of commercial computer operation. New technologies are
K e Y C O n C e pt emerging every day to capitalize on the connected environments of
A network consists of two or more
modern computer systems.
computers connected together so
that they can exchange information. Figure 1.15 shows a simple computer network. One of the devices
on the network is a printer, which allows any computer connected
to the network to print a document on that printer. One of the computers on
the network is designated as a file server, which is dedicated to storing programs
and data that are needed by many network users. A file server usually has a large
amount of secondary memory. When a network has a file server, each individual
computer doesn’t need its own copy of a program.
network Connections
If two computers are directly connected, they can communicate in basically the
same way that information moves across wires inside a single machine. When
File server
Shared printer
connecting two geographically close computers, this solution works well and is
called a point-to-point connection. However, consider the task of connecting many
computers together across large distances. If point-to-point connections are used,
every computer is directly connected by a wire to every other computer in the
network. A separate wire for each connection is not a workable solution because
every time a new computer is added to the network, a new communication line will
have to be installed for each computer already in the network. Furthermore, a single
computer can handle only a small number of direct connections.
Figure 1.16 shows multiple point-to-point connections. Consider the number of
communication lines that would be needed if two or three additional computers were
added to the network. These days, local networks, such as those within a single build-
ing, often use wireless connections, minimizing the need for running wires.
Compare the diagrams in Figure 1.15 and Figure 1.16. All of the computers
shown in Figure 1.15 share a single communication line. Each computer on the
network has its own network address, which uniquely identifies it. These addresses
are similar in concept to the addresses in main memory except that they identify
individual computers on a network instead of individual memory locations inside
a single computer. A message is sent across the line from one computer to another
by specifying the network address of the computer for which it is intended.
Sharing a communication line is cost effective and makes adding
new computers to the network relatively easy. However, a shared line KeY COnCept
Sharing a communication line creates
introduces delays. The computers on the network cannot use the com- delays, but it is cost effective and
munication line at the same time. They have to take turns sending infor- simplifies adding new computers to
mation, which means they have to wait when the line is busy. the network.
the others would be waiting a long time before they could use it. By taking turns,
each person can put one box on at a time, and they all can get their work done.
It’s not as fast as having a conveyor belt of your own, but it’s not as slow as hav-
ing to wait until everyone else is finished.
One computer
LAN
in a LAN
Long-distance
connection
the internet
Throughout the 1970s, an agency in the Department of Defense known as the
Advanced Research Projects Agency (ARPA) funded several projects to explore
network technology. One result of these efforts was the ARPANET, a WAN that
eventually became known as the Internet. The Internet is a network of networks.
The term Internet comes from the WAN concept of internetworking—connecting
many smaller networks together.
From the late 1980s through the present day, the Internet has KeY COnCept
grown incredibly. In 1983, there were fewer than 600 computers The Internet is a wide-area network
connected to the Internet. At the present time, the Internet serves (WAN) that spans the globe.
billions of users worldwide. As more and more computers con-
nect to the Internet, the task of keeping up with the larger number of users
and heavier traffic has been difficult. New technologies have replaced the
ARPANET several times since the initial development, each time providing more
capacity and faster processing.
A protocol is a set of rules that governs how two things communicate. The
software that controls the movement of messages across the Internet must con-
form to a set of protocols called TCP/IP (pronounced by spelling out the let-
ters, T-C-P-I-P). TCP stands for Transmission Control Protocol, and IP stands
for Internet Protocol. The IP software defines how information is formatted
and transferred from the source to the destination. The TCP software handles
problems such as pieces of information arriving out of their original order or
information getting lost, which can happen if too much information converges
at one location at the same time.
Every computer connected to the Internet has an IP address that uniquely iden-
tifies it among all other computers on the Internet. An example of an IP address
is 204.192.116.2. Fortunately, the users of the Internet rarely have
to deal with IP addresses. The Internet allows each computer to be KeY COnCept
given a name. Like IP addresses, the names must be unique. The Every computer connected to the
Internet has an IP address that
Internet name of a computer is often referred to as its Internet
uniquely identifies it.
address. An example of Internet address is hector.vt.edu.
The first part of an Internet address is the local name of a specific computer. The
rest of the address is the domain name, which indicates the organization to which
the computer belongs. For example, vt.edu is the domain name for the network
of computers at Virginia Tech, and hector is the name of a particular computer on
Another random document with
no related content on Scribd:
would restore loyalty, De Witt hove his topsails to the mast, and
formed line.
By four in the afternoon the English line was also formed and well
up, the only order issued from the Resolution being “to attack, but
hold their fire until close in with the enemy.” Then the whole of the
English van bore down upon the Dutch, who kept up an intermittent
and harmless fire as it approached. Just then the Dutch line tacked,
and the two fleets came into almost instant collision. They were so
close together that an unusual number of shots told, and the crash
of the first broadside was terrific; the roar of artillery continuing
incessantly for more than an hour.
After that the action became less furious, and there were pauses
in the storm of battle. The Dutch ships fell off to a greater distance,
and, as a breeze arose the clouds of powder smoke partially cleared
away. But, although the Dutch fell back, they fell back fighting, and
with their faces to the enemy; and, with their usual obstinate valor
they continued the battle until night fell upon the scene of slaughter.
The Dutch had lost most men, while the English had suffered most
severely in masts and rigging. It was thought by experienced
commanders, in both fleets, that De Witt would have been
completely defeated and broken had he not drawn off at nightfall.
Ruyter had, as usual, commanded his important division with
consummate skill and bravery. He lost a large proportion of the crew
of his own ship, and his masts and rigging were almost destroyed,
and the hull seriously shattered. De Witt himself, by his courage and
conduct during the battle, atoned in part for his rashness in fighting
such an enemy in the then condition of his fleet. But, in spite of their
efforts, the Dutch had the worst of it. Two of their ships foundered
in the first shock of battle; and two others were boarded and taken,
one of them being the Rear Admiral’s flag-ship. As has been seen,
the loss of life in the Dutch fleet was great, and this, in addition to
the general disaffection, caused about twenty of De Witt’s captains
to take advantage of the darkness, withdraw their ships from the
main fleet, and make for Zealand, where they carried the first news
of disaster.
As many of the Dutch fleet remained in sight, and kept their lights
burning during the night, Blake naturally assumed that they would
fight again at daylight. Every one, therefore, on board the English
fleet was engaged in repairing damages, in securing prisoners,
caring for the wounded and burying the dead.
At daylight the whole fleet bore down for the Dutch position, and,
from the attitude of the latter, it seemed likely that the bloody work
of the previous day would begin again.
De Witt wished to fight; but a change of counsel took place before
the fleets got within cannon shot of each other. Evertz and De
Ruyter’s opinion prevailed, and it was decided to collect the
scattered ships, to gain one of their own ports, repair, refit, and re-
man the ships, and await the orders of the States General.
Blake, in his disabled state, could not prevent them from carrying
out this decision; and was obliged to content himself with petty raids
upon the Dutch coasts, such as Tromp had inflicted upon the English
in the preceding year.
The news of this action was received in London and throughout
England with great exultation. It was the first great naval action
fought by the English since the days of Elizabeth. England had come
off victorious against the best seamen and most experienced
admirals of the world. Tromp, Evertz, and Ruyter had been regarded
as invincible sea commanders; yet now a land officer, with but three
years’ experience of the sea, with soldiers and landsmen, had
successfully withstood the attacks of veteran sailors who had swept
the great navies of Spain from the face of the ocean.
Blake took his place at once among the highest of living Admirals.
1652-3.
And now we shall see how sturdy Van Tromp came to the fore
again.
De Witt’s return with his discomfited fleet was the signal for great
disorders in Holland. The enemies of the Orange party did not
hesitate to accuse him of rashness, cowardice and treason. The
sailors of the fleet, who had been almost mutinous before the battle,
really became so after it.
Even on board his own flag-ship De Witt was not entirely free from
danger. He had, before sailing, executed some seamen for mutiny,
and excited much silent rage thereby; but when he came back
unsuccessful, the popular passions were aroused, and he was
mobbed as soon as he landed, in Flushing; his proud heart being
almost broken by the insult from a people he had served so long and
well, he fell sick, and relinquished his command. Ruyter shared some
of his unpopularity, but was persuaded to continue in his command.
Having so often triumphed at sea, the Dutch could not understand
that their reverses were not the result of gross misconduct in their
sea generals; and they now remembered that, if Tromp’s success in
the early part of the war had not been very great, he had not, at
least, suffered defeat, and they felt that the elements, and not man,
had destroyed the powerful fleet which he had lost.
His reputation became once more the first in Holland, while
personal feeling and his past training peculiarly fitted him to meet
the English.
The States General were ready to reverse their decision when they
found him necessary, and this was confirmed when they found that
the King of Denmark, alarmed by the sudden growth of England’s
maritime power, was making interest with leading Dutch statesmen,
not only for a vigorous renewal of hostilities, but also for the
restoration of Tromp to his offices and honors.
The most eminent of his rivals in naval ability and in political
influence were, upon his restoration, appointed to serve under him
as Vice and Rear Admirals. These were De Witt, Ruyter, Evertz and
Floritz. De Witt, completely mortified and disgusted, excused himself
on the plea of ill health; and Ruyter joined the fleet as second in
command.
The Danish King now refused to allow the English ships, which
had been sent to the Baltic for the naval stores so necessary to the
fleet, to return through the Sound or the Belts, and thus proved a
new enemy for the Commonwealth to deal with.
As the term for which Blake had been appointed sole General and
Admiral of the fleet had expired, he requested the appointment of
two colleagues, as he considered the coast command of England
equally important with that of the cruising fleet.
Colonel Deane and General Monk were accordingly so
commissioned, both these officers being in the land service, and at
that time actively employed in Scotland.
Winter had now set in, and Blake distributed the fleet, some for
convoy duty, and some for repairs. The Dutch were hard at work in
their dock-yards, and Blake, with a reduced force, cruised from port
to port of the Channel, not expecting the enemy to appear at sea
before the return of fine weather. In this he had greatly mistaken the
energy and influence of Tromp, who, in an incredibly short time,
fitted out and manned a vast fleet; and while the English squadrons
were dispersed in various directions, suddenly appeared off the
Goodwins with more than one hundred sail of the line, frigates and
fire-ships. His plan was bold and well conceived. Coming suddenly
into the Downs with this large force, he intended to close up the
Thames, cut off reinforcements preparing there, and then to fall
upon Blake’s division, and either capture it or drive it westward out
of the Channel; then, with the coast at his mercy, he could dictate
terms to the Commonwealth. At that time a winter cruise or
campaign was hardly thought possible; but Tromp relied upon a
swift and daring blow to finish the war in a few days.
Blake was then in the Triumph, and the first intimation he had of
Tromp’s being at sea was from his own look-out ships. On the 9th of
December the two fleets were in presence of each other, between
Calais and Dover; and the English Admiral then learned that Tromp
was in command, and accordingly prepared himself for serious work.
A council of war was held on board the Triumph. Blake declared
his intention to fight, even without his detached squadrons, rather
than leave the coast exposed to the incursions of the great and
uncrippled Dutch fleet.
All that December day the two Admirals worked for the weather
gage. The succeeding night was long, cold and stormy, and the ships
were unable to keep well together. At daylight of the 10th the
manœuvres for the weather gage were renewed, the two flag-ships,
the Brederode and the Triumph, both drawing toward the Nase, and
by three in the afternoon the fleets were quite near each other, off
that headland of Essex.
Tromp being most anxious to engage, made a sudden effort to get
alongside the English Admiral. The latter’s ship, however, by a skillful
evolution, passed under the Brederode’s bows to the weather gage.
In passing the two ships exchanged broadsides, and the battle
opened. Blake’s ship was closely followed by the Garland, and
missing the Triumph, Tromp ran afoul of this second ship, and
carried away her bowsprit and head. The Garland and the Brederode
then engaged, the English ship, though much lighter, fighting bravely
until joined by the Bonaventure, 30, when the two together rather
overmatched the Brederode. Tromp, by every possible appeal,
encouraged his men; but his position was becoming very precarious,
when Evertz, seeing him in such straits, attacked the Bonaventure,
placing that small ship between the two Dutch flag-ships. The four
ships were all grappled together, and it was more than an hour
before the weight of metal obliged the two English ships to yield.
After they had suffered great loss the Dutch boarded and captured
them. Of the other English ships the Triumph, the Vanguard and the
Victory bore the brunt of the action. In spite of being surrounded by
enemies, and suffering severely in men, hull, masts and rigging, they
all came out of the desperate encounter uncaptured. Night came
early at that season, and the fleets were about separating, when
Blake heard of the capture of the Garland and Bonaventure, and he
at once attempted their recapture. This brought on a more
destructive conflict than the previous one. Blake was surrounded by
the Dutch ships, and the Triumph was three times boarded, and the
assailants as often repulsed. She was reduced to a wreck, and with
difficulty kept afloat, and had it not been for the Sapphire and the
Vanguard, which stood by him with extraordinary courage and
devotion, the English Admiral must have succumbed. Thick fog and
darkness at last interposed and enabled Blake to draw off his ships
toward Dover Roads.
The next morning there was a dense fog, and the Dutch were not
to be seen. His disabled vessels required a shelter, and the English
Admiral, therefore, resolved to run into the Thames, and there repair
damages, ascertain the enemy’s intentions, and wait the recall and
concentration of his scattered squadrons.
In the action off the Nase the Dutch had had much the best of it,
but had lost many men, and one of their ships had blown up, every
soul on board of her perishing. Tromp’s and Ruyter’s ships were both
unfitted for further service, and many others were crippled; but they
were the victors, and once more masters of the Channel.
Blake offered to resign, but the Council would not hear of this, and
only seemed intent upon weeding out of the fleet those captains
who had not shown sufficient zeal and courage. Several were broken
after proper inquiry, among others, Blake’s own brother, who was
reported as guilty of neglect of duty.
More vessels were concentrated and placed under Blake’s orders,
and the effective force of the navy raised to 30,000 men.
While reforms, renovations and recruitments were being carried
on under Blake’s own eye, Tromp sailed up and down the Channel
with a broom at his masthead, typical of his having swept the
Narrow Seas; and the States General proclaimed a state of blockade
of the British Islands.
Caricatures and ballads were circulated in the Dutch cities, all
bearing upon the late naval event. The fear that Tromp would seize
the Channel islands, and the certainty that he had effectually cut off
commerce, hastened the preparations of the English for a second
winter campaign; and, on the 8th of February, 1653, Blake, still in
the Triumph, sailed, at the head of some sixty men-of-war and
frigates, having Monk and Deane with 1200 soldiers from the army
on board. Penn, the father of the Quaker proprietor of Pennsylvania,
was the vice admiral, and Lawson the rear admiral.
In the Straits of Dover he was joined by the Portsmouth squadron,
of twenty sail; and with this addition to his strength, Blake resolved
to seek the Dutch fleet, and once more give battle.
Tromp had gone to the southward, to meet a large fleet of Dutch
traders which had collected near Rochelle, with the intention of
convoying them home. Here intelligence reached him that the
English were about to quit the Thames with a large fleet, and he
hoped to be able to return in time to block it up in the river mouth,
and to keep the Portsmouth squadron from effecting a junction with
the main body. But Blake had stolen a march upon the Dutch
Admiral, and when the latter came up with Cape la Hogue, he was
surprised to find a force equal to his own prepared to dispute the
passage of the seas so lately swept by his broom. He, however,
accepted battle eagerly, for he was confident of victory.