Java Software Solutions For Ap Computer Science 3rd Edition Loftus Download
Java Software Solutions For Ap Computer Science 3rd Edition Loftus Download
https://ebookbell.com/product/java-software-solutions-for-ap-
computer-science-3rd-edition-loftus-21354562
https://ebookbell.com/product/domaindriven-design-with-java-a-
practitioners-guide-create-simple-elegant-and-valuable-software-
solutions-for-complex-business-problems-chandrasekaran-55937292
https://ebookbell.com/product/java-software-solutions-foundations-of-
program-design-7th-edition-7th-edition-john-lewis-2371348
https://ebookbell.com/product/java-software-solutions-global-
edition-8th-edition-john-lewis-30066712
https://ebookbell.com/product/java-software-solutions-9th-edition-
john-lewis-william-loftus-33941204
Java Software Solutions 8th Edition 8th Edition Lewis John
https://ebookbell.com/product/java-software-solutions-8th-edition-8th-
edition-lewis-john-55557960
https://ebookbell.com/product/java-software-solutions-foundations-of-
program-design-4th-edition-john-lewis-1294350
Java Software And Embedded Systems 1st Edition Mattis Hayes Isaiah
Johansen
https://ebookbell.com/product/java-software-and-embedded-systems-1st-
edition-mattis-hayes-isaiah-johansen-51764284
https://ebookbell.com/product/java-software-structures-designing-and-
using-data-structures-4th-edition-international-edition-lewis-21976872
https://ebookbell.com/product/java-software-structures-designing-and-
using-data-structures-3rd-edition-john-lewis-2614256
J ava 3rd Edition
S O F T WA R E S O L U T I O N S
™
*AP and Advanced Placement Program are registered trademarks of The College Board,
which was not involved in the production of, and does not endorse, this product.
This page intentionally left blank
J ava 3rd Edition
S O F T WA R E S O L U T I O N S
™
Addison-Wesley
Boston Columbus Indianapolis New York San Francisco Upper Saddle River
Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto
Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo
*AP and Advanced Placement Program are registered trademarks of The College Board,
which was not involved in the production of, and does not endorse, this product.
Editor in Chief: Michael Hirsch
Editorial Assistant: Stephanie Sellinger
Marketing Coordinator: Kathryn Ferranti
Managing Editor: Jeffrey Holcomb
Production Project Manager: Heather McNally
Senior Manufacturing Buyer: Carol Melville
Art Director: Linda Knowles
Cover Designer: Joyce Cosentino Wells
Text Designer: Jerilyn Bockorick, Nesbitt Graphics, Inc.
Cover Art: Michael Shivers / Alamy
Full-Service Project Management: Rose Kernan, Nesbitt Graphics, Inc.
Composition and Art: Nesbitt Graphics, Inc.
Credits and acknowledgments borrowed from other sources and reproduced, with permission, in this textbook appear on appropriate
page within text. Many of the designations by manufacturers and seller to distinguish their products are claimed as trademarks. Where
those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed in initial
caps or all caps.
Microsoft® and Windows® are registered trademarks of the Microsoft Corporation in the U.S.A. and other countries. Screen shots and
icons reprinted with permission from the Microsoft Corporation. This book is not sponsored or endorsed by or affiliated with the
Microsoft Corporation.
The programs and applications presented in this book have been included for their instructional value. They have been tested with care,
but are not guaranteed for any particular purpose. The publisher does not offer any warranties or representations, nor does it accept
any liabilities with respect to the programs or applications.
Copyright © 2011, 2007, 2004 Pearson Education, Inc., publishing as Addison-Wesley, 501 Boylston Street, Suite 900, Boston,
Massachusetts 02116. All rights reserved. Manufactured in the United States of America. This publication is protected by Copyright,
and permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmis-
sion in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission(s) to use material
from this work, please submit a written request to Pearson Education, Inc., Permissions Department, 501 Boylston Street, Suite 900,
Boston, Massachusetts 02116.
1 2 3 4 5 6 7 8 9 10--CRK--14 13 12 11 10
*AP and Advanced Placement Program are registered trademarks of The College Board,
which was not involved in the production of, and does not endorse, this product.
To Sharon, Justin, Kayla, Nathan, and Samantha Lewis
—J.L.
—W.L.
—C.C.
This page intentionally left blank
Preface
Welcome to Java™ Software Solutions for AP* Computer Science. This
Advanced Placement* book matches both the AP* Computer Science topic
outline and Java subset set forth by the College Board.
Chapter Breakdown
Chapter 1 (Computer Systems) 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 pro-
gram development are discussed. This chapter contains broad introductory
material that can be covered while AP* students become familiar with their
development environment.
Chapter 2 (Objects and Primitive Data) establishes the concept of objects
and how they can be used. Many predefined classes from the Java standard
library are explored and used. Enumerated types, primitive types, operators,
and expressions are also explored.
Chapter 3 (Program Statements) covers most of the fundamental state-
ments including conditionals, loops, and iterators. Some additional operators
are introduced at this point as well. Establishing key statements at this point
allows the classes of the next chapter to be fully functional and realistic.
Chapter 4 (Writing Classes) explores issues related to writing classes and
methods. Topics include instance data, visibility, scope, method parameters,
and return types. Method overloading is covered as well. Some of the more
involved topics are deferred to or revisited in Chapter 5. The key to Chapter
4 is the many fully implemented, realistic classes that are presented as exam-
ples of class design.
Chapter 5 (Enhancing Classes) covers additional issues related to class
design and revisits topics that need further exploration. Object references are
revisited and carefully explored, and their impact on parameter passing is
discussed. Exceptions, interfaces, and their effect on design are also covered.
Finally, guidelines on designing classes, as well as testing, are given.
Chapter 6 (Arrays) contains extensive coverage of arrays and array pro-
cessing. Topics include multidimensional arrays, searching, and sorting.
The ArrayList class is explored as well, and generic types are introduced
here.
x PR EFA C E
Supplements
AP* students are welcome to visit www.pearsonhighered.com/cssupport
(author: Lewis/Loftus/Cocking) for the following resources:
■ Source Code to all program examples in the text.
■ Case Study section for most chapters linking the concepts covered in
that chapter with the official AP* case study.
The following supplements are available online for qualified AP* teachers
only, at www.pearsonhighered.com/irc. Teachers may obtain a code to access
the supplements below from their Pearson sales representative. If you need
help finding this material, contact your Pearson sales representative. You can
find your rep in the “Find your sales rep” section atwww.pearsonschool.com.
■ Lesson Plans with Pacing Guide.
■ Solutions to all end-of-chapter exercises and programming projects.
■ PowerPoint slides.
■ Test Bank with powerful test generator software, includes a wealth of
free response, multiple choice, and true/false questions.
■ Source Code to all program examples in the text.
V. STANDARD ALGORITHMS
Standard algorithms serve as examples of good solutions to standard problems. Many are inter-
twined with standard data structures. These algorithms provide examples for analysis of program effi-
ciency.
A. Operations on data structures previously listed
1. Traversals Sections 6.0, 6.1, 6.7
2. Insertions Sections 6.0, 6.1, 6.7
3. Deletions Sections 6.0, 6.1, 6.7
B. Searching
1. Sequential Section 6.2
2. Binary Section 6.2
C. Sorting
1. Selection Section 6.3
2. Insertion Section 6.3
3. Mergesort Section 8.3
An awareness of the ethical and social implications of computing systems is necessary for the study
of computer science. These topics need not be covered in detail but should be considered through-
out the course.
A. System reliability Appendix F
B. Privacy Appendix F
C. Legal issues and intellectual property Appendix F
D. Social and ethical ramifications of computer use Appendix F
Acknowledgments
We are most grateful to the AP* teachers and AP* students from around the
world who have provided their feedback on the previous edition of this book.
We are pleased to see the depth of the faculty’s concern for their AP* students
and the AP* students’ thirst for knowledge. Your comments and questions
are always welcome.
Michael Hirsch and Stephanie Sellinger, our editors at Addison-Wesley,
went above and beyond the call of duty to ensure that the book met the high-
est quality standards. Their support and enthusiasm are greatly appreciated.
We are also grateful to Andrea Sheehan and Courtney Marsh with Pearson
School for making sure that AP* teachers understand the pedagogical advan-
tages of this text. The devotion that the Addison-Wesley and Pearson folks
show to their books is evident in the high-quality results.
xiv PR EFA C E
The production team for this edition is a group of gifted and hard-working
people—miracle workers all. Thanks go to Heather McNally, Joyce
Cosentino Wells (for the wonderful cover), and Rose Kernan and the rest of
the Nesbitt Graphics group. The quality of the book is due largely to their
personal attention, and it is greatly appreciated.
Special thanks also go to the reviewers of this text over the last few edi-
tions, as well as the many other instructors and friends who have provided
valuable feedback.
They include Neil Ascione—Wayne Valley High School, NJ; Brian Ellis—
Manheim Township School District, PA; Kathy Gilbert—Cary-Grove High
School, IL; Gregory King—Dublin Coffman High School, OH; Richard
Lamb—Cranbrook High School, MI; Deepa Muralidhar—Northview High
School, GA; Kim Murphy—Weber High School, UT; G. Lynne Ryan—North
Crowley High School, TXJenka Guevara, American School Foundation,
Mexico City; Leigh Ann Sudol, Fox Lane High School/New York University,
NY; Kathleen Weaver, Hillcrest High School, Dallas, TX; John E. Hanna,
Teaneck High School, NJ; Brian G. Scarbeau, Lake Highland Preparatory
School, FL; Frances Caruso Wolanczyk, Fieldston School, NY; Mark
Hanington, Punahou School, Honolulu, HI; Rose M. Hoffman, Catholic
Memorial High School, Waukesha, WI; Kathleen Larson, Kingston High
School, Kingston, NY; Bob Beck, Villanova University; Paul Gormley,
Villanova University; Cathy Helwig, Villanova University; Dan Joyce,
Villanova University; Najib Nadi, Villanova University; Beth Taddei,
Villanova University; Barbara Zimmerman, Villanova University; John
Simms, Marquette University; Marian Manyo, Marquette University.
Most importantly, we thank our families for their support during the busy
process of writing, not to mention the other times.
Feature Walkthrough
Key Concepts. Throughout the
2.1 Computer Processing 63
text, the Key Concept boxes high-
disk. When you instruct the computer to execute your program, a
light fundamental ideas and
KEY C ON C EPT
copy of the program is brought in from secondary memory and
stored in main memory. The CPU reads the individual program
The CPU reads the program important guidelines. These con-
instructions from main memory,
instructions from main memory. The CPU then executes the instruc-
tions one at a time until the program ends. The data that the instruc-
executing them one at a time
until the program ends. cepts are summarized at the end
tions use, such as two numbers that will be added together, are also
stored in main memory.
of each chapter.
The process of executing a program is fundamental to the operation of a
computer. All computer systems basically work in the same way.
O U T P U T
xv
xvi F EAT U R E WALKTHRO UG H
Graphics
cal user interfaces is discussed in K EY C ON C EPT
Graphics play a crucial role in computer systems. Throughout
this book we explore various aspects of graphics and discuss
one or two sections at the end of Graphical data is represented by
dividing it into many small pieces how they are accomplished. In fact, the last one or two sec-
called pixels. tions of each chapter are devoted to graphics topics. We refer
each chapter that we collectively to this as the Graphics Track through the book. These sections
can be skipped without losing continuity through the rest of the text, incor-
refer to as the Graphics Track. This porated into the regular flow of the chapters, or explored as a group.
A picture, like all other information stored on a computer, must be digi-
material can be skipped without tized by breaking the information into pieces and representing those pieces as
numbers. In the case of pictures, we break the picture into pixels (picture ele-
loss of continuity, or focused on ments). A pixel is a tiny region that represents a very small piece of the pic-
ture. The complete picture is stored by storing the color of each individual
specifically as desired. The mate- pixel.
rial in any Graphics Track section A digitized picture can be reproduced when needed by reassembling its
pixels. The more pixels used to represent a picture, the more realistic it looks
relates to the main topics of the when it is reproduced. The number of pixels used to represent a picture is
called the picture resolution. The number of pixels that can be displayed by
chapter in which it is found. a monitor is called the monitor resolution. A black and white picture can be
stored by representing each pixel using a single bit. If the bit is 0, that pixel
Graphics Track sections are indi- is white; if the bit is 1, it is black. Figure 2.8 shows a black and white picture
that has been stored digitally and an enlargement of a portion of that picture,
cated by a light blue border on which shows the individual pixels.
Graphics play a crucial role in computer systems. Throughout this book
the edge of the page. we explore various aspects of graphics and discuss how they are accom-
plished. In fact, the last one or two sections of each chapter are devoted to
graphics topics. We refer to this as the Graphics Track through the book.
F EAT U RE WALK T H RO U G H xvii
Preface vii
xix
xx CONTENTS
1.5 Graphics 38
Coordinate Systems 38
Representing Color 40
Index 621
J ava 3rd Edition
S O F T WA R E S O L U T I O N S
™
*AP and Advanced Placement Program are registered trademarks of The College Board,
which was not involved in the production of, and does not endorse, this product.
This page intentionally left blank
Computer
Systems
This book is about writing well-designed software. C HA PTE R
1
O B J E C TI V E S
To understand software, we must first understand its ■ Describe the relationship
between hardware and software.
role in a computer system. Hardware and software
■ Define various types of software
work together in a computer system to accomplish com- and how they are used.
■ Identify basic computer
plex tasks. Furthermore, computer networks have
hardware and explain what
changed how computers are used, and they now play a it does.
■ Explain how the hardware
key role in even basic software development. This chap-
components execute programs
ter explores a broad range of computing issues, laying and manage data.
■ Describe how computers are
the foundation for the study of software development. connected together into
networks to share information.
■ Explain the importance of the
Internet and the World Wide Web.
■ Introduce the Java programming
language.
■ Describe the steps involved in
program compilation and
execution.
■ Introduce graphics and their
representations.
1
2 C HAPT ER 1 Computer Systems
1.0 Introduction
We begin our exploration of computer systems with an overview of computer
processing, defining some basic terminology and showing how the key pieces
of a computer system work together.
Figure 1.1 shows how information moves among the basic hard-
KEY CON CEPT
ware parts of a computer. Suppose you have a program you wish to
To execute a program, the computer
run. The program is stored on some secondary memory device, such first copies the program from second-
as a hard disk. When you tell the computer to execute your program, ary memory to main memory. The CPU
then reads the program instructions
a copy of the program is brought in from secondary memory and from main memory, executing them
stored in main memory. The CPU reads the program instructions one at a time until the program ends.
from main memory. The CPU then executes the instructions one at a
time until the program ends. The data that the instructions use, such
as two numbers that will be added together, also are stored in main memory.
They are either brought in from secondary memory or read from an input
device 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 basic to the operation of a com-
puter. All computer systems work in about the same way.
Software Categories
There are many types of software. At this point we will simply look at sys-
tem programs and application programs.
The operating system is the main software of a computer. It does
KEY CON CEPT
two things. First, it provides a user interface that allows the user to
The operating system provides a user
interact with the machine: to click on an icon, for example, or delete interface and manages computer
a file. Second, the operating system manages computer resources such resources.
as the CPU and main memory. It decides when programs can 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
keep it running well.
Several popular operating systems are in use today. The Windows 7 operat-
ing system was developed for personal computers by Microsoft which has cap-
tured an operating system market share of almost 90%. Versions of the Unix
Hard disk
Keyboard
Main
CPU
memory
operating system are also quite popular, such as Linux. Mac OS X is an oper-
ating system used on Apple computers.
An application is just about any software other than the operating system.
Word processors, missile control systems, database managers, Web browsers,
and games are all 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 uses graphical
screen elements. Among 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
■ checkboxes, and radio buttons, which give the user selectable options
■ sliders, which let the user select from a range of values
■ buttons, which can be “pushed” with a mouse click
The mouse is the primary input device used with GUIs, so GUIs are some-
times called point-and-click interfaces. The screen shot in Figure 1.2 shows
an example of a GUI.
The interface to an application or operating system is an important part of
the software because it is the only part of the program the user directly inter-
acts with. To the user, the interface is the program.
Digital Computers
Two techniques are used to store and manage information: analog and digi-
tal. Analog information is continuous. For example, an alcohol thermometer
is an analog device for measuring temperature. The alcohol rises in a tube at
the same time the temperature outside the tube rises. Another example of
analog information is the speed at which a car is going. As you press and
release the gas and brake pedals, the car’s speed varies. Figure 1.3 graphically
depicts a car’s speed as it varies over time.
Digital technology breaks information into pieces and shows those pieces
as numbers. The music on a compact disc is stored digitally, as a series of num-
bers. Each number represents the voltage level of one specific instance of the
recording. Many of these measurements 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
separate voltage measurements can be used to create an analog signal that is
“close enough” to the original. In most cases, the reproduction is good
enough to satisfy the human ear.
Figure 1.4 shows the sampling of an analog signal. When analog
KEY CON CEPT
information is converted to a digital format by breaking it into pieces,
Digital computers store information
we say it has been digitized. Because the changes that occur in a sig- by breaking it into pieces and repre-
nal between samples are lost, the sampling rate must be fast enough senting each piece as a number.
to make up the difference.
Sampling is only one way to digitize information. For example, a sentence
can be stored on a computer as a series of numbers, where each number
represents a single character in the sentence. Every letter, digit, and punctuation
60 mph
0 mph
time
Analog signal
Sampling process
Sampled values 12 11 39 40 7 14 47
mark has been given a number. Even the space character gets a number.
Consider the following sentence:
Hi, Heather.
Binary Numbers
A digital computer stores information as numbers, but those numbers are
not stored as decimal numbers. All information in a computer is stored and
managed as binary numbers. Unlike the decimal system, which has 10 digits
H i , H e a t h e r.
(0 through 9), the binary number system has only two digits (0 and 1). A sin-
gle binary digit is called a bit.
All number systems work according to the same rules. The base value of a
number system tells us how many digits we have to work with and what is
the place value of each digit in a number. The decimal number system is base
10, whereas the binary number system is base 2.
Modern computers use binary numbers because the devices that
KEY CON CEPT
store and move information are less expensive and more reliable if Binary values are used to store and
they have to represent only one of two possible values. Other than move all information in a computer
this, there is nothing special about the binary number system. Some because the devices that use binary
information are inexpensive and
computers use other number systems to store and move information, reliable.
but they aren’t as convenient.
Some computer memory devices, such as hard drives, are magnetic. Magnetic
material can be polarized easily to one extreme or the other, but in-between lev-
els are hard to tell apart. So magnetic devices can be used to represent binary
values very well—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 making 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 send 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. That is, the voltage levels of
the original signal change slightly. The trouble with an analog signal is that as it
changes, it loses its original information. Since the information is directly anal-
ogous to the signal, any change in the signal changes the information. The
changes in an analog signal cannot be recovered because the new, 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 how many
items we can represent. A single bit has two possible values, 0 and 1, so it can
represent two items or situations. If we want to represent the state of a light-
bulb (off or on), one bit will suffice, because we can interpret 0 as the light-
bulb being off and 1 as the lightbulb being on. If we want to represent more
than two things, we need more than one bit.
Two bits, taken together, can represent four items because there are exactly
four ways we can arrange two bits: 00, 01, 10, and 11. Suppose we want to
represent the gear that a car is in (park, drive, reverse, or neutral). We would
need only two bits, and could set up a mapping between the bits and the gears.
For instance, we could say that 00 represents park, 01 represents drive, 10 rep-
resents reverse, and 11 represents neutral. (Remember that ‘10’ is not
‘ten’ but ‘one-zero’ and ‘11’ is not ‘eleven’ but ‘one-one.’) In this case,
K E Y C ON C E PT it wouldn’t matter if we switched that mapping around, though in
There are exactly 2N ways of arrang-
ing N bits. Therefore N bits can repre-
some cases the relationships between the bit permutations and what
sent up to 2N unique items. they represent is important.
Three bits can represent eight unique items, because there are eight
arrangements of three bits. Similarly, four bits can represent 16 items, five
bits can represent 32 items, and so on. Figure 1.7 shows the relationship
FIG URE 1 .7 The number of bits used determines the number of items
that can be represented
1.1 Hardware Components 9
between the number of bits used and the number of items they can represent.
In general, N bits can represent 2N unique items. For every bit added, the
number of items that can be represented doubles.
We’ve seen how a sentence of text is stored on a computer as numeric values.
Those numeric values are stored as binary numbers. Suppose we had character
strings in a language with 256 characters and symbols. We would need to use
eight bits to store each character because there are 256 unique ways of arrang-
ing eight bits (28 equals 256). Each arrangement of bits is a specific character.
Ultimately, representing information on a computer boils down to the
number of items and how those items are mapped to binary values.
Computer Architecture
The architecture of a house describes its structure. Similarly, we use the term
computer architecture to describe how the hardware components of a com-
puter are put together. Figure 1.9 shows the basic architecture of a 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. As we
mentioned earlier, main memory stores programs and data that are being
used, and the CPU executes program instructions one at a time.
Central Main
processing memory
unit
Bus
Disk Video
Controller Controller
controller controller
Input/Output Devices
Let’s look at some I/O devices in more detail. The most common input devices
are the keyboard and the mouse. Others include:
■ bar code readers, such as the ones used at a retail store checkout
■ joysticks, often used for games and advanced graphical applications
■ microphones, used by voice recognition systems that interpret voice
commands
■ virtual reality devices, such as handheld devices that interpret the
movement of the user’s hand
■ scanners, which convert text, photographs, and graphics into machine-
readable form
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 handle both input and output. 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 computer described in Figure 1.8 includes a monitor with a 17-inch
diagonal display area. A picture is created by breaking it up into small pieces
called pixels, a term that stands for “picture elements.” The monitor can
display a grid of 1280 by 1024 pixels. The last section of this chapter explores
the representation of graphics in more detail.
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
F I G U RE 1 . 1 0 Memory locations
in a single byte, such as a large number, then multiple, consecutive bytes are
used to store the data.
The storage capacity of a device such as main memory is the total
K E Y C O N C E PT number of bytes it can hold. Devices can store thousands or millions
Data written to a memory location
of bytes, so you should become familiar with larger units of measure.
overwrites and destroys any informa-
tion that was stored at that location. Because computer memory is based on the binary number system, all
Data read from a memory location units of storage are powers of two. A kilobyte (KB) is 1,024, or 210,
leaves the value in memory alone.
bytes. Some larger units of storage are a megabyte (MB), a gigabyte
(GB), a terabyte (TB), and a petabyte (PB), as listed in Figure 1.11.
It’s usually easier to think about these numbers if we round them off. For
example, most computer users think of a kilobyte as approximately one thou-
sand bytes, a megabyte as approximately one million bytes, and so forth.
Many personal computers have 4 gigabytes of main memory, or RAM,
such as the system described in Figure 1.8. (We discuss RAM in more detail
later in the chapter.) A large main memory allows large programs, or several
programs, to run because they don’t have to get information from secondary
memory as often.
petabyte PB 1,099,511,627,776
Read/write
head
Disks
Magnetic tapes also have been used as secondary storage but are 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 a
direct access device, but nothing moves mechanically. The terms direct access
and random access are often confused. However, information on a tape can
be accessed only after first getting past the intervening data. A tape must be
rewound or fast-forwarded to get to the right place, the same way you have
to fast-forward through a cassette tape to get to the song you want to hear.
A tape is therefore considered a sequential access device. Tapes have been
used to store information when it is no longer used very often, or to provide
a backup copy of the information on a disk.
Two other terms are used to describe memory devices: random access mem-
ory (RAM) and read-only memory (ROM). It’s important to understand these
terms because they are used often, and their names can be misleading. RAM
and main memory are basically the same thing. The term RAM seems to mean
something it shouldn’t. Both RAM and ROM are direct (or random) access
devices. RAM should probably be called read-write memory, since data can be
both written to it and read from it. Information stored on ROM, on the other
hand, cannot be changed (as the term “read-only” implies). ROM chips are
often embedded into the main circuit board of a computer and used to pro-
vide the instructions needed when the computer is initially turned on.
A CD-ROM is a portable secondary memory device. CD stands for
K E Y C O N C E PT compact disc. It is called ROM because information is stored perma-
The surface of a CD has both smooth
areas and small pits. A pit represents a
nently when the CD is created and cannot be changed. Like a musi-
binary 1 and a smooth area represents cal CD, a CD-ROM stores information in binary format. When the
a binary 0. CD is 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 determines whether each bit is a 1 or a 0. A typical
CD-ROM can store between 650 and 900 MB.
There are many kinds of CD technology today. Most personal computers
are equipped with a CD-Recordable (CD-R) drive. A CD-R can be used to
create 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 informa-
tion 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 made on a CD-RW by
coating the surface of the disc with a material that, when heated to one tem-
perature becomes nonreflective and when heated to a different temperature
becomes reflective. The CD-RW media doesn’t work in all players, but CD-
Rewritable drives can create both CD-R and CD-RW discs.
1.1 Hardware Components 15
CPU
Arithmetic/logic
unit
Bus
Main
Control unit
memory
Registers
In most CPUs, some registers have special purposes. For example, the
instruction register holds the current instruction being executed. The program
counter holds the address of the next instruction to be executed. In addition
to these and other special-purpose registers, the CPU also contains a set of
general-purpose registers.
The idea of storing both program instructions and data together in main mem-
ory is called 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 continually follow the fetch-
decode-execute cycle depicted in Figure 1.14. An instruction is fetched from main
memory and put into the instruction register. The program counter increases to
get ready for the next cycle. Then the instruction is decoded electronically
KE Y C O N C E PT to determine which operation to carry out. Finally, the control unit turns
The von Neumann architecture and the on the correct circuitry to carry out the instruction, which may load a
fetch-decode-execute cycle form the
foundation of computer processing.
data value into a register or add two values together, for example.
The CPU is on a chip called a microprocessor, a part of the main
circuit board of the computer. This board also contains ROM chips and com-
munication sockets to which device controllers, such as the controller that
manages the video display, can be connected.
Another part of the main circuit board is the system clock. The clock sends
out an electronic pulse at regular intervals, so that everything going on in the
CPU happens on the same schedule. The rate at which the pulses occur is called
the clock speed, and it varies depending on the processor. The computer
KE Y C O N C E PT described in Figure 1.8 includes an Intel Core I7 processor that runs at
The speed of the system clock a clock speed of 3.07 gigahertz (GHz), or about 3.1 billion pulses per
indicates how fast the CPU executes
instructions.
second. The speed of the system clock tells you about how fast the CPU
executes instructions. Like storage capacities, the speed of processors is
constantly increasing with advances in technology.
1.2 Networks
A single computer can do a lot, but connecting several computers together into
networks can dramatically increase how much they can do and make it easier to
share information. A network is two or more computers connected together so
1.2 Networks 17
File server
Shared printer
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 two computers are close to each other, this is called a point-to-point
connection. If point-to-point connections are used, every computer is directly
connected by a wire to every other computer in the network. But if
the computers are far apart, having a separate wire for each connec- KEY CON CEPT
tion won’t work because every time a new computer is added to the A network is two or more computers
connected together so they can
network, a new wire will have to be installed for each computer exchange information.
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 num-
ber of wires that would be needed if two or three additional computers were
added to the network.
Look at the diagrams in Figure 1.15 and Figure 1.16. All of the computers
in Figure 1.15 share a single communication line. Each computer on the net-
work has its own network address. These addresses are like 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
from one computer to another needs the network address of the computer
receiving the message.
Sharing a communication line is less expensive and makes adding
K E Y C O N C E PT new computers to the network easier. However, a shared line also
Sharing a communication line creates
delays, but it is cost effective and
means delays. The computers on the network cannot use the commu-
simplifies adding new computers to nication line at the same time. They have to take turns, which means
the network. they have to wait when the line is busy.
One way to improve network delays is to divide large messages
into small pieces, called packets, and then send the individual packets across
the network mixed up with pieces of other messages sent by other users. The
packets are collected at the destination and reassembled into the original mes-
sage. This is like a group of people using a conveyor belt to move a set of
boxes from one place to another. If only one person were allowed to use the
conveyor belt at a time, and that person had a lot of boxes to move, every-
one else would have to wait 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 having to wait until everyone else is finished.
One computer
LAN
in a LAN
Long-distance
connection
now possible. In fact, the use of networks is now so common that some com-
puters can’t work on their own.
The Internet
Throughout the 1970s, an agency in the Department of Defense, known
KEY CON CEPT
as the Advanced Research Projects Agency (ARPA) funded several proj-
The Internet is a wide-area network
ects to explore network technology. One result of these efforts was the (WAN) that spans the globe.
ARPANET, a WAN that eventually became known as the Internet. The
Internet is a network of networks. The term “Internet” comes from
the word internetworking—connecting many smaller networks together.
From the mid 1980s through today, the Internet has grown incredibly. In 1983,
there were fewer than 600 computers connected to the Internet. At the present
time, the Internet serves billions of users worldwide. As more and more comput-
ers connect to the Internet, keeping up with the larger number of users and heav-
ier traffic has been difficult. New technologies have replaced the ARPANET
several times over, each time providing more capacity and faster processing.
A protocol is a set of rules about how two things communicate.
The software that controls the movement of messages across the KEY CON CEPT
TCP/IP is the set of software
Internet must follow a set of protocols called TCP/IP (pronounced by
protocols, or rules, that govern
spelling out the letters, T-C-P-I-P). TCP stands for Transmission the movement of messages across
Control Protocol, and IP stands for Internet Protocol. The IP soft- the Internet.
ware defines how information is formatted and transferred. The TCP
software handles problems such as pieces of information arriving out of order
or information getting lost, which can happen if too much information arrives
at one location at the same time.
20 C HAPT ER 1 Computer Systems
During this visit to Porirua, the attention of the official party had
been directed to the presence of the New Zealand Company's boat,
which had been brought by the natives from the Wairau, after the
massacre, and hauled up on the shore of Taupo Bay amongst some
twelve or fifteen canoes; and this fact was made a subject of
discussion next day when the frigate reached Kapiti.
Landing at Waikanae, where the interview was to take place, Sir
Everard Home says—
"We were received by the Rev. Mr. Hadfield, a missionary, a gentleman of high
character and great intelligence, who, living in the pa amongst the natives,
knows every movement, for none could take place without his knowledge. He
at once declared all the reports (of an intended attack upon Wellington) to be
without foundation. Having walked to his house, which is within the pa, we
proceeded to his school-yard, and the chiefs, Te Rauparaha, and Rere, chief of
the tribe inhabiting the pa of Waikanae, came, accompanied by about fifty
men. I then stated to the chief all that was reported of him, and asked him
what he had to say to contradict it. He replied that, far from wishing to
continue the quarrel with the Europeans, which had been commenced by
them, and not by him, his whole time was occupied in travelling up and down
the coast, endeavouring to allay the irritation of the natives and to prevent
any ill consequences arising from the provoking language and threats with
which they were continually annoyed by the Europeans travelling backwards
and forwards. That, for himself, he believed them to be lies invented by the
white men, having been assured by the Police Magistrate that no steps would
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
ebookbell.com