You are on page 1of 73

CHAPTER 1 Introduction to Computer Systems

The word computer refers to a system composed of many components. A computer system has both hardware and software components. This chapter discusses these components. Chapter Topics:

Computer Systems. Hardware and Software. Hardware components of a computer system. Software components of a computer system. Networks. World-Wide Web.

QUESTION 1:

What did you think about the movie Monsters, Inc.?

A good answer might be:


A great movie!

Hardware and Software


In thinking about Monsters, Inc., you are thinking about something conceptual. It is intangible. You can't grab it and throw it against a wall, or break it in half, or weight it on a scale. It does not have a physical existence. You might record Monsters, Inc. on a VCR tape. The tape is physical, but the movie is conceptual. When you speak of the movie, you usually mean the conceptual movie, not a particular tape that has a record of it. Sometimes the phrase "intellectual material" is used for movies, TV programs, novels, music, and computer programs. Sometimes the word "software" is used for the same purpose, although usually "software" refers to computer programs and data. The TV set you used to watch Monsters, Inc. is tangible. It has a physical existence. You can weigh it on a scale, you can throw it against a wall, you can break it in half, you can pound it to pieces with a hammer (and your grades will improve if you do). TV sets are useful because they combine the tangible (the TV set itself) and the intangible (TV programs). Computer systems are useful in the same way--they

combine tangible components called hardware and conceptual components called software.

QUESTION 2:

Imagine that you have a copy of Mark Twain's "Tom Sawyer". You tear it to pieces and push the shreds through your garbage disposal. Have you destroyed "Tom Sawyer"?

A good answer might be:


No. You have destroyed the physical book, but not the intangible "book". It is saddening how many governments don't understand this.

Components of a Computer System


Software is stored on hardware such as hard disks or tape. Monsters, Inc. can be recorded on a VCR tape. But the computer program (and the TV episode) is intangible. It is not the physical storage medium. The hardware components of a computer system are the electronic and mechanical parts. The software components of a computer system are the intangible parts: the data and the computer programs. The major hardware components of a computer system are:

Processor Main memory Secondary memory Input devices Output devices

You probably have a computer in front of you. The processor, main memory, and secondary memory devices are inside the systems unit. This is the metal box that is sometimes called "the computer." The monitor (the TV-like screen) is an output device.

QUESTION 3:

Is a mouse and input device or an output device?

A good answer might be:

A mouse is an input device.

Hardware Components
The terms "input" and "output" say if data flow into or out of the systems unit. The picture shows the major hardware components of a computer system. The arrows show the direction of data flow.

The bus is a group of wires on the main circuit board of the computer. It is a pathway for data flowing between components. Most devices are connected to the bus through a controller which coordinates the activities of the device and the bus. The processor is an electronic device about a one inch square, covered in plastic. Inside the square is an even smaller square of silicon containing millions of tiny electrical parts. A processor may contain 100 million transistors. The processor is the "brain" of the computer system. It does the fundamental computing within the system, and directly or indirectly controls all the other components. The processor is sometimes called the Central Processing Unit or CPU. A particular computer will have a particular type of processor, such as a Pentium or a SPARC chip. (processors are often called "chips.") Click Here to see the computer system these notes were prepared on. (It probably looks much like what you are yourself using.) You might notice that it is 5 years old. It works fine for running Java programs.

Typical Computer System

QUESTION 4:

Say that a computer has just added 13 to 27. Where did this activity take place?

A good answer might be:


In the processor.

Memory
The processor is the brain of the computer. All fundamental computing takes place in the processor. Other components contribute to the computation (by doing such things as moving data in and out of the processor), but the processor is where the fundamental action takes place.

Unlike a human brain, which combines memory with processing power, a computer processor has very little memory. It must rely on other components to hold data and programs and to save results. The memory in a computer system is of two fundamental types:

Main memory: o very closely connected to the processor. o the contents are quickly and easily changed. o holds the programs and data that the processor is actively working with. o interacts with the processor millions of times per second. Secondary memory: o connected to main memory through the bus and a controller. o the contents are easily changed, but this is very slow compared to main memory. o used for long-term storage of programs and data. o The processor only occasionally interacts with secondary memory.

Main memory is where programs and data are kept when the processor is actively using them. When programs and data become active, they are copied from secondary memory into main memory where the processor can interact with them. A copy remains in secondary memory. Main memory is intimately connected to the processor, so moving instructions from the program and data into and out of the processor is very fast. Main memory is sometimes called RAM. RAM stands for Random Access Memory. "Random" means that the memory cells can be accessed in any order. When people say that a computer has "128 megabytes of RAM" they are talking about how big its main memory is. One megabyte of memory is enough to hold approximately one million characters of a word processing document. (There will be more about bytes and megabytes later on in these notes.) Nothing permanent is kept in main memory. Sometimes data are placed in main memory for just a few seconds; only as long as they are needed.

QUESTION 5:

Imagine that you are using a word processor program to write a letter.

Where (in the computer system) is the program you are running? Where are the characters you have typed?

A good answer might be:

Where (in the computer system) is the program you are running? o In main memory. (A permanent copy will also be in secondary memory--the hard disk).

Where are the characters you have typed? o In main memory. (When you "save" your document, they will be copied to a file on the hard disk.)

Secondary Memory
Secondary memory is where programs and data are kept on a long-term basis. Common secondary storage devices are the hard disk and floppy disks. The hard disk has enormous storage capacity compared to main memory. The hard disk is usually contained in the systems unit of a computer. The hard disk is used for long-term storage of programs and data. Data and programs on the hard disk are organized into files--named sections of the disk.

A hard disk might have a storage capacity of 40 gigabytes. This is about 300 times the amount of storage in main memory (assuming 128 megabytes of main memory.) However, a hard disk is very slow compared to main memory. The reason for having two types of storage is this contrast:
Primary memory 1. Fast 2. Expensive 3. Low capacity 4. Connects directly to the processor Secondary memory 1. Slow 2. Cheap 3. Large capacity 4. Not connected directly to the processor

Floppy disks are mostly used for transferring software between computer systems and for casual backup of software. They have low capacity, and are very, very slow compared to other storage devices.

QUESTION 6:

You have just purchased a copy of the computer game Tomb Raider (you were waiting for the price to fall below $20). You follow the directions on the package and install the game on your computer. Tomb Raider consists of

A program (that controls the action of the game.) Data (the images and other information.)

After you have installed the game, where does each of these things exist in the computer system? After you have installed the game, where do its parts exist?

A good answer might be:


A program (that controls the action of the game.) o On the hard disk Data (the images and other information.) o On the hard disk

(When you play the game, its various parts are copied into and out of main memory.)

Input and Output Devices


Input and output devices allow the computer system to interact with the outside world by moving data into and out of the system. An input device is used to bring data into the system. Some input devices are:

Keyboard Mouse Microphone Bar code reader Graphics tablet

An output device is used to send data out of the system. Some output devices are:

Monitor Printer Speaker

Input/output devices are usually called I/O devices. They are directly connected to an electronic module inside the systems unit called a device controller. For example, the speakers of a multimedia computer system are directly connected to a device controller called an audio card (such as a Soundblaster), which in turn is connected to the rest of the system. Sometimes secondary memory devices like the hard disk are called I/O devices (because they move data in and out of main memory.) What counts as an I/O device depends on context. To a user, an I/O device is something outside of the system box. To a programmer, everything outside of the processor and main memory looks like an I/O devices. To an engineer working on the design of a processor, everything outside of the processor is an I/O device.

QUESTION 7:

Most modern automobiles are controlled by a computer. Do you think that the computer in your car has:

Input devices?

Output devices? Main storage? Secondary storage?

A good answer might be:


Most modern automobiles are controlled by a computer. Do you think that the computer in your car has: Input devices? Yes--various sensors throughout the car deliver data to the computer. Output devices? Yes--various actuators have their actions controlled by data. Main storage? Yes--probably not very much. Secondary storage? No.

Software
A computer that is dedicated to running a program that controls another device is an embedded system. An embedded system is usually embedded inside the device it controls. Usually they run just one program that is permanently kept in a special kind of main memory called ROM (for Read Only Memory). More processor chips are sold per year for embedded systems than for all other purposes. Software is the programs and data that a computer uses. Software is kept on some hardware device such as a hard disk or floppy disk, but it itself is intangible. Say that you have a floppy disk with a program saved on it. Now say that you erase the program from the disk. The atoms and molecules of the disk are the same ones as before, but now the program is "gone." The intangible software has been removed without removing anything tangible. Software consists of both programs and data. Programs are lists of instructions for the processor. Data can be any information that a program needs: character data, numerical data, image data, audio data, and countless other types. The distinction between programs and data is not as clear-cut as you might think, however. Fundamental Idea: Both programs and data are saved in computer memory in the same way. The electronics of computer memory (both main memory and secondary memory) make no distinction between programs and data. The insight that both programs and data can be saved using the same electronic methods is one of the most important ideas in computer science. Computer systems can use their memory for whatever needs arise.

QUESTION 8:

Which of the following can be saved on a floppy disk?

A game program. Accounting data (numbers.) Audio data. Graphics data. Digital photographs. Video data.

A good answer might be:


Everything on the list can be stored on a floppy disk (or in any other kind of computer memory, for that matter.)

Types of Programs
There are two categories of programs. Application programs (usually called just "applications") are programs that people use to get their work done. Computers exist because people want to run these programs. Systems programs keep all the hardware and software running together smoothly. The difference between "application program" and "system program" is fuzzy. Often it is more a matter of marketing than of logic.
Application Programs

Systems Programs

Word processors Game programs Spreadshee ts Data base systems Graphics programs

Operating system. Networking system. Database system. Programming language software. Web site server.

Data backup.

Web browsers

The most important systems program is the operating system. The operating system is always present when the computer is running. It coordinates the operation of all the hardware and software components of the computer system. The operating system is responsible for starting application programs running and finding the resources that they need. When an application program is running, the operating system manages the details of the hardware for it. For example, when you type characters on the keyboard, the operating system determines which application program they are intended for and does the work of getting them there. Modern operating systems usually come with a user interface that enables users to easily interact with application programs (and with the operating system itself) by using windows, buttons, menus, icons, the mouse, and the keyboard. Examples of

operating systems are Unix, Windows 98, Windows NT, Linux, Solaris, and System 7.

QUESTION 9:

(Thought question:) Imagine that you have just turned on your computer and have not yet started any application. Are any programs running?

A good answer might be:


Yes--the operating system is running. Mostly it is managing the user interface, waiting for some input to tell it what to do.

Operating Systems
The operating system is a complex collection of many programs concerned with keeping the hardware and software components of a computer system coordinated and functioning. It is like a shop keeper who keeps a shop in order by attending to customers, handling supplier deliveries, stocking the shelves, doing the bookkeeping, and so on. The operating system is software; the same hardware can be used with many different operating systems (although only one at a time.) Sometimes the operating system on a computer becomes corrupted (perhaps because of a computer virus) and must be tediously re-installed. Until it is up and running again, other programs will not be available.

QUESTION 10:

What component of a computer system holds the operating system when the computer is not running?

A good answer might be:


The hard disk. The hard disk is used for long-term storage of all software, including the operating system.

Starting a Program
When a computer is started up, the hardware will automatically load the operating system and start it running. This process is called booting. The reason for this odd term is that the operating system is itself involved in getting itself running---a process that is like someone "pulling themselves up by their bootstraps." Once the operating system is running, it is used to start up any other program.

Here is a (simplified) list of what happens when the user (you) starts up an application. Assume that the operating system (OS) is already running. 1. The user asks to run an application. o This could be done by clicking on an icon, making a menu choice, or other means. 2. The OS determines the name of the application. 3. The OS finds the section of the hard disk where the application program and its data are stored. 4. The OS finds an unused section of main memory that is large enough for the application. 5. The OS makes a copy of the application and its data in that section of main memory. o The software on the hard disk is unchanged; a copy of it has been made in main memory 6. The OS sets up resources for the application. 7. Finally, the OS starts the application running. As the application runs, the OS is there in the background managing resources, doing input and output for the application, and keeping everything else running.

QUESTION 11:

When an application is closed (stops running), do you think that it is copied from main memory back to the hard disk?

A good answer might be:


No. The hard disk already has a copy, and that copy will be used the next time the application is run.

Networks
A computer network consists of two or more computers connected so that they can exchange data and programs. When a computer is a member of a network, the programs it runs and the data it uses can be on the hard disk of some other computer on the network. In business and industrial settings, most computers are on a network. The operating system that runs on a networked computer must manage its share of the network (along with managing all its other responsibilities.) The operating system is able to find programs and data that are stored on other network computers, and copy them into its own main memory. In a local-area network only a few dozen computers are connected together, usually all located within the same building. Each computer has a network address that the other computers use to access it. Usually the computers share a printer. There may be an especially powerful computer called a server whose hard

disk holds all the application programs and data that the other computers are expected to need. Each computer in a network has a network interface card in its systems unit. This is an input/output device that sends and receives data over cables. The network interface cards of computers on a network are connected together with cables.

QUESTION 12:

(Thought question:) Say that the server computer of a local area network has the only copy of WordPerfect (a word processor application.) Now ten users of other computers on the network each ask to run WordPerfect. Can this be done?

A good answer might be:


Yes. All each user computer needs is a copy of WordPerfect in its main memory. The required copies can easily be made from the single long-term copy on the server.

Wide-Area Networks
Large organizations need to connect many more computers than can be handled with a local area network. A wide-area network can connect thousands of computers together over great distances. The long distance connections are made by using fiber optic lines, telephone lines, microwave communications, and satellite communications. Each computer in the network has a network address (as with local-area networks) to uniquely identify it. Wide-area networks use a variety of special hardware to manage the flow of data. When two computers share data, this hardware makes it appear that the two computers are connected together directly. In reality, there may be dozens of network devices between the two computers. All these devices use the same method for dealing with data. Without a common method of dealing with data, a large network would become a hopeless muddle. An agreement about how to represent and transmit data over a network is called a protocol. Usually large networks use a protocol called TCP/IP (for transmission control protocol/internet protocol.) The Internet consists of many wide-area networks that have been connected together to form one huge worldwide network. Even on this huge network, each computer must have a unique network address, much like each telephone in the world has a unique telephone number (if you include the country code and area code.)

QUESTION 13:

Can programs, as well as data, be exchanged over the Internet?

A good answer might be:


Yes.

World Wide Web


Remember that important idea (discussed several pages back): Fundamental Idea: Both programs and data are saved in computer memory in the same way. The electronics of computer memory (both main memory and secondary memory) make no distinction between programs and data. Communications equipment makes no distinction between programs and data, either. It is all information as far as it is concerned, and all information is transmitted the same way. The Internet is like a worldwide package delivery service. It is concerned with moving packages from one address to another, without concern about what is in the packages. The Internet provides the hardware and the information transmission protocols for the World-Wide Web. Data intended for the Web is transmitted over the Internet just like any data. What makes Web data special is that it is intended for Web browsers (such as the one you are probably looking at.) A browser is a program that can read Web pages and display them in a nicely formatted way. A Web page is a package of data that contains information on how it is to be displayed on a monitor. This information is given using a language called Hypertext Markup Language (HTML). If you want to see an example of what this looks like, left-click on View in your browser, then left-click on Page Source. After you are done viewing, click on the close button in the upper right corner (the button marked with X).

QUESTION 14:

Would the World-Wide Web and the Internet have been possible without the United States' space program of the 1960s?

A good answer might be:


Probably not. City-sized networks would still be possible, but a worldwide network would be nearly impossible without satellites.

Hyperlinks

One Web page is connected to another with a hyperlink. If you have been reading these notes over the Web, you have been linking between Web pages by using hyperlinks. A web browser (such as Netscape Navigator) usually displays a hyperlink in a distinguishing color (usually blue.) When you click on it, the browser asks the operating system of the computer to get a particular Web page from another computer connected to the Internet. The Web page to get is specified with a uniform resource locator URL. A URL specifies both the computer (among all the Internet computers in the world) and the exact Web page on that computer. To see some examples of URLs, keep watching the box in your browser labeled "Location:"

QUESTION 15:

When you click on the following hyperlink, will the URL in the "Location:" box change?

A good answer might be:


Yes. The new Web page is specified with its unique URL.

End of the Chapter


We have ended this general overview of computer systems. At this point, you should have an idea of what computer systems are all about. But you will likely be uncertain about quite a few things. The following chapters will clarify some topics, and others will remain mystifying until later courses. For now, you may wish to review the following. Click on a blue subject that interests you to go to where it was discussed.

Hardware and software. Major hardware components of a computer system Types of memory Characteristics of a hard disk. I/O devices Two categories of programs The operating system. How programs start running. Computer networks

The next chapter will discuss analog and binary signals and why binary signals are important in computer systems.

CHAPTER 2 Analog and Binary Signals


Everyone knows that computers are "digital" and that they use "binary" numbers. You probably have some idea of what these terms mean. But we need to be clear about their precise meaning and to be clear about why computers are digital. Chapter Topics:

Binary signals. Analog signals. Advantages of Binary. Bits. Noisy signals.

Study these topics carefully if you want to know what is really going on with computers.

QUESTION 1:

Why is a digital wristwatch called "digital?"

A good answer might be:


Because it shows time using definite digits, rather than positions of hands that have to be measured. (It would be less correct to say "because it has a computer inside.")

Binary
Binary means "two states." The two states are sometimes called "1" and "0", or called "true" and "false", or called "on" and "off", (or other names.) The essential characteristic is that a single binary device can be in just one of two possible states. A bit is a single "on/off" value. A good example is a toggle switch, such as a light switch. You can turn it "on" or "off" but not (in normal operation) anything else. A light switch holds one bit of information. A light dimmer is not a binary device: it has many positions between "off" and "fully on". If you want a light dimmer in to be set to 25%, you must carefully adjust it.

QUESTION 2:

Which of the following is a binary device:


The ignition switch of an automobile. The hour hand of a clock. A button on a hand calculator. The volume control on a stereo.

A good answer might be:


The ignition switch of an automobile. No The hour hand of a clock. No A button on a hand calculator. Yes The volume control on a stereo. No

Why Computers use Binary

The ignition switch of an automobile is discreteit has definite statesbut there are usually more than two states (off, running, start, acc...) A button on a hand calculator is a binary device. It is either on or off. Ordinarily it is "off." When you push it, it is "on." It springs back to "off" when you release it, which is different from a toggle switch, but it still is a binary device. There are many advantages to binary. Here are four (somewhat overlapping) important reasons for using binary: 1. Simple; easy to build. 2. Unambiguous signals (hence noise immunity). 3. Flawless copies can be made. 4. Anything that can be represented with some sort of pattern can be represented with patterns of bits. These characteristics of binary were realized by Claude Shannon, a mathematician at Bell Telephone Laboratories. His 1948 paper A Mathematical Theory of Communication is the foundation of information theory and much of computer science.

QUESTION 3:

Which is easier to build:


An on/off switch. A light dimmer.

A good answer might be:

An on/off switch.

Advantages of Binary 1: Simple; easy to build


An on/off switch is simple and easy to build. An on/off switch moves two pieces of metal together or moves them apart. A light dimmer must gradually and smoothly change the current that reaches the light. It has more components that an on/off switch and must be carefully assembled. An accurate dimmer (where 25% means exactly 25%) is even harder to build.

The same is true for the tiny devices inside of a silicon chip. On/off switches are relatively easy to fabricate. Easy to build means that the devices are cheap, small, and reliable, and millions of them can be put in a small area.

QUESTION 4:
Which of the following methods for producing books is simple and easy?

Each book is individually made by scratching marks onto tablets of wet

clay. Each book is individually made by copying the characters onto paper with pen and ink. Many copies of the book are made by carving flat wooden blocks with the text then printing the text on paper. Many copies of the book are made by setting movable type and printing the text on paper.

A good answer might be:

Setting type.

Advantages of Binary 2: Unambiguous Signals


Carving a block of wood into a book page requires high technical and artistic skill. The task is complex and labor intensive. A small mistake might ruin the whole block. The Renaissance woodcarvers were as skilled as woodcarvers ever have been. Setting type is comparatively easy. Little artistic or technical skill is needed. Individual pieces of type are just dropped into place. The method is robust and reliable; mistakes can be corrected. The type can be reused many times. It is a paradox that advances in technology often lead to simple methods. Woodcarving is complex; setting type is easy. The computer revolution (ca. 1950 ) is often compared to the Gutenberg revolution (ca. 1450). Review the advantages of binary: 1. Simple; easy to build. 2. Unambiguous signals (hence noise immunity). 3. Flawless copies can be made. 4. Anything that can be represented with patterns can be represented with patterns of bits.

QUESTION 5:

Which is easier to do: (a) determine exactly how bright a light is, or (b) decide if it is on or off?

A good answer might be:


On or Off.

Old North Bit


Unambigous Signals: Consider Paul Revere, waiting for news of the attack of the British troops. He is expecting to see a signal lantern in the tower of Old North Church telling him how the British are attacking: 1.32456 if by land, 1.71922 if by sea. The signal shines out! ...and Paul Revere's famous ride is delayed for several hours as he tries to figure out just how bright that signal is. Lack of ambiguity is a tremendous advantage. The signal that Paul Revere was actually waiting for that night in 1775 was: One (lantern) if by land, and two (lanterns) if by sea. ...an easily interpreted signal. All Paul Revere had to do was count. Such signals are called discrete because they have a fixed number of definite states. Sometimes the word digital is used to mean the same thing.

QUESTION 6:

Why can a Chinese abacus be regarded as a "digital computer."

A good answer might be:


The computation is done by moving beads into definite positions. A bead is either placed where it counts as part of a number, or it is placed where it does not count. This "all or nothing" operation means that an abacus is a discrete device.

An Analog Signal
An analog signal may continuously change in value. Its values can be anything within a range of values, and its exact value at any time is important. The graph

below represents an audio signal. The exact value at each time is part of the information it contains. For example, the value at time "T2" must be measured exactly.

Now say that you are observing the voltage of a wire. It has been agreed that any voltage below a threshold will be counted as an "off" signal, and that any value above the threshold will be counted as an "on" signal.

QUESTION 7:

At time "T2", is the signal "on" or "off"?

A good answer might be:


ON. The analog signal (continuously changing voltage signal) moves up and down, but at time "T2" it is clear that it is above the threshold. Exact measurement is not needed.

Binary Signal
Analog signals continuously change in value. By using a threshold, analog signals can represent binary data ("on/off" data). It is easy and fast (for electronics, as well as for humans) to determine if a voltage is above or below a threshold. The figure shows a signal that transmits "off" then "on". (The signal is examined at times T1 and T2.)

QUESTION 8:

Is is clear that the signal is "off" at time T1 and "on" at time T2?

A good answer might be:


Yes.

Imperfect Transmission
The "ons" and "offs" of previous signal are clear. But what if the signal is sent down a long wire and someone nearby turns on a vacuum cleaner? The graph shows the signal at the other end of the wire. Even though the signal is noisy (at the analog level), the binary values are transmitted perfectly. You (and the electronics) can still tell that at time T1 the signal represents "off" and that at time T2 the signal represents "on" The receiving end just needs to get the binary values.

Since only the "on" "off" information matters, the analog noise is irrelevant, and the original signal is received perfectly (so far as the binary information goes.)

QUESTION 9:

If the signal were regarded as an analog signal, and exact values were important, would some information present in the first signal (before the noise) have been lost?

A good answer might be:


Yesif the signals represented a singer's voice, the noisy signal would sound, er.. well... noisy. After just one copy, information has been lost.

Advantages of Binary 3: Flawless copies can be made.


Review the advantages of binary: 1. Simple; easy to build. 2. Unambiguous signals (hence noise immunity). 3. Flawless copies can be made. 4. Anything that can be represented with some sort of pattern can be represented with patterns of bits.

Flawless copies can be made: The receiving end of the signal is only interested in the binary values. All it has to do it check if the signal is above or below the threshold. This can be done perfectly (as long as the noise is not too great.) For example, here is the noisy signal with the "on"/"off" values recovered from it:

The original signal has been recovered flawlessly. This process can occur as many times as needed with a perfect copy made each time. This is essential in a computer system, where bit patterns (patterns of one and zero, or on and off) are copied back and forth between the processor and memory millions of times a second. The copies have to be perfect.

QUESTION 10:

Something might be wrong here. Is the signal is "on" or "off" at the time "x"? This is not easy to tell. What is worse, a different amount of noise changes the answer. What can be done about this problem? (Hint: must the value of the signal be known at all times?)

A good answer might be:


The system is built so that the signal is tested only at particular times, and that changes in the signal occur between these times.

Clocks
Digital systems are built so that the "on" "off" (binary) value is only tested at certain times, giving the wire (or transistor, or...) a chance to change its state between

these times. This is why computer systems have a "clock" to keep all these times synchronized. So faster clocks mean wires can be tested more times per second, and the whole system runs faster. Processor chips (and the computers that contain them) are often described in terms of their clock speed. Clock speed is measured in Hertz, where one Hertz is one clock tick per second. The symbol MHz means mega Hertz, a million clock ticks per second. A 700 MHz Pentium processor checks binary values 700 million times in each second. In between these times values are allowed to change and settle down. The faster a processor chip is, the more times per second values can be tested, and the more decisions per second can be made.

QUESTION 11:

Which is faster, a 400 MHz Pentium processor or a 800 MHz Pentium processor?

A good answer might be:


The 800 MHz processor, since it checks values 800 million times per second (twice as many as the 400 MHz processor). (However, if the processors are different types there are other factors besides clock speed that determine how much each processor can do in a second.)

Advantages of Binary Representation 4: Representing Anything


Recall that last advantage of binary: Anything that can be represented with patterns can be represented with patterns of bits.

Since data of all kinds is stored in computer memory (main and secondary) using the same electronic methods, this means that endless perfect copies can be made of any type of data or program. This idea is that any system of symbols can be translated into bit patterns. An example is how English characters are represented as eight-bit patterns. The agreeement about what patterns represent what characters is called ASCII. The hardware and the software of a computer system (usually) follow this agreement when the data is "text". (You will learn more about this later). Other types of data (non-character data) are represented using other methods.

QUESTION 12:

Can charaters from alphabets other than English be represented?

A good answer might be:


Of course. Any type of symbol at all can be assigned a binary pattern to represent it.

More on Representing Anything in Binary


Japanese and Chinese characters, also, have been translated into bit patterns, and computers can manipulate those symbols just as easily as ASCII. Unicode is an agreement created by an international committee on how to represent characters using 16 bits. Here are 16 bits 111110011111110 and here is the character it represents in Unicode: Say that the international committee decides to represent a new Chinese character. How can they do this? Easy: they find a bit pattern not yet used to represent any symbol and assign the new character to that pattern. The correspondence between human language symbols and bit patterns is arbitrary. All you have to do is be sure that you are using enough bits so that all the symbols of the language have a unique bit pattern to represent them.

QUESTION 13:

Can printed music be represented using binary?

A good answer might be:


Sure any symbols can. There are "music processor" programs for printed music that work like word processor programs for printed text.

Symbols and Patterns


Recall that last advantage of binary: Anything that can be represented with patterns can be represented with patterns of bits.

What about representing things other than the written characters of a language? This is a deep topic, and entire books have been written on it. Here is a very

sloppy discussion: Pick some subject. Use English sentences to describe it. Represent those sentences in ASCII (characters encoded as byte patterns.) Now the subject is represented in binary. If something can be represented in English, then it can be represented in binary. Notice that this says nothing about "meaning" or "understanding." Printed books don't understand their own contents. A digital version of the book (say on CD ROM) doesn't understand the book, either. It mearly holds the information, waiting for a human mind to do the understanding. However the book has been represented as bit patterns. Nobody said that binary representations are easy to use. Some representation methods are very useful for computers (for instance, using binary patterns to represent numbers), others are nearly usless. Much of the work that computer scientists do is figuring out how to represent things using binary in ways that are useful. For example, much work has been done in the last ten years in figuring out how best to represent image and audio data. Important Point: All that computer memory (and other parts) holds is bit patterns. What those bit patterns represent depends on how they are used.

QUESTION 14:

Sometimes people say, "All that a computer can handle is numbers. It doesn't understand anything else." Do you think that this is correct?

A good answer might be:


No. Any type of symbolic data can be represented using binary, not just numbers. At the electronic level, everything is a bit pattern (which some people call a "number"), so the statement is sort-of correct.

End of this chapter.


You may wish to review the following terms. Click on the hypertext phrase to go the page where the term was discussed.

What "binary" means. What a "bit" is. The advantages of using binary in a computer. What "analog" means. How thresholds are used. The master clock of a computer. Memory contents as bit patterns.

Back to the main menu. You have reached the end of the chapter.

CHAPTER 3Computer Memory


Recall from chapter one that the major hardware components of a computer system are:

Processor Main memory Secondary memory devices Input/output devices

This chapter looks at main and secondary memory. Chapter Topics:


Bits and Bytes. Kilobytes, megabytes, gigabytes. Main memory and addresses. Secondary memory. Files.

QUESTION 1:

(Educated Guess: ) If you bought a new computer, about how much main memory would you expect it to have: 128 bytes, 64 kilobytes, 4 megabytes, or 64 megabytes? (Hint: Encarta (a multimedia encyclopedia) needs a minimum of 16 megabytes.)

A good answer might be:


A new PC should have at least 64 megabytes, and more if possible. (A few years ago the answer would have been 16 megabytes.)

Characteristics of Main Memory


Main memory is as vital as the processor chip to a computer system. Fast computer systems have both a fast processor and a large, fast memory. Here is a list of some characteristics of computer memory. Some characteristics are true for both kinds of memory; others are true for just one.

Characteristic

True for Main Memory

True for Secondary Memory

Very closely connected to the processor. Holds programs and data that the processor is actively working with. Used for long term storage. The processor interacts with it millions of times per second. The contents is easily changed. Relatively low capacity. Relatively huge capacity. Fast access. Slow access. Connected to main memory. Holds programs and data. Usually its contents are organized into files.

QUESTION 2:

What do you remember about computer memory? In the table, decide what is true for main memory and for secondary memory. (Click on a button to see if you are correct.)

A good answer might be:


Click!

Bit
In both main and secondary memory, information is stored as patterns of bits. Recall from chapter two what a bit is: A bit is a single on/off value. Only these two values are possible. The two values may go by different names, such as true/false, or 1/0. There are many ways in which a bit can be implemented. For example a bit could be implemented as:

A mechanical electrical switch (like a light switch.) Voltage on a wire. A single transistor (used in main memory). A tiny part of the surface of a magnetic disk. A tiny part of the surface of a magnetic tape. A hole punched in a card. A tiny part of the light-reflecting surface of a CD. Part of a radio signal. Many, many more ways

So the particular implementation of bits is different in main memory and secondary memory, but logically, both types of memory store bits.

QUESTION 3:

(Thought question:) Does the information change when a bit is copied from one form of storage to another? For example, does the information change when a bit implemented as a voltage level on a wire is copied to a tiny part of a disk?

A good answer might be:


No. The different ways of storing a bit do not change the information that is being stored.

Copied Information
Information stored in binary form does not change when it is copied from one medium (storage method) to another. And an unlimited number of such copies can be made (remember the advantages of binary.) This is a very powerful combination. You may be so accustomed to this that it seems commonplace. But when you (say) download an image from the Internet, the data has been copied many dozens of times, using a variety of storage and transmission methods. It is likely, for example, that the data starts out on magnetic disk and is then copied to main storage of the web site's computer (involving a voltage signal in between.) From main storage it is copied (again with a voltage signal in between) to a network interface card, which temporarily holds it in many transistors. From there it is sent as a electrical signal down a cable. Along the route to your computer, there may be dozens of computers that transform data from an electical signal, into main memory transistor form, then back to an electrical signal on another cable. Your data may even be transformed into a radio signal, sent to a satellite (with its own computers), and sent back to earth as another radio signal. Eventually the data ends up as data in your video card (transistors), which transforms it into a TV signal for your monitor. The point of all of this is that the actual information (in this example the picture) does not change from one media to the next.

QUESTION 4:

Analog data (continuously changing signals) such as on LP records or audio tape also can be copied from medium to medium. Does the information of analog data change when it is copied to a different media?

A good answer might be:


Usually we don't want it to (and for audio data use "high fidelity" electronics to minimize the change.) But always some information is lost.

Byte
Name byte kilobyte megabyte gigabyte terabyte Number of Bytes 1 1024 1,048,576 1,073,741,824 1,099,511,627,776 power of 2 20 210 220 230 240

One bit of information is so little that usually computer memory is organized into groups of eight bits. Each eight bit group is called a byte. When more than eight bits are required for some data, a whole number of bytes are used. One byte is about enough memory to hold a single character. Often very much more than eight bits are required for data, and thousands, millions, or even billions of bytes are needed. These amounts have names, as seen in the table. If you expect computers to be your career, it would be a good idea to become very familiar with this table. (Except that the only number you should remember from the middle column is that a kilobyte is 1024 bytes.) Often a kilobyte is called a "K" and a megabyte is called a "Meg."

QUESTION 5:

Some Hollywood actors have been named after units of memory, for example, Giga Young. Can you think of any others?

A good answer might be:

Mega Ryan and Tera Garr come to mind. There must be others.

Bytes, not Bits


The previous table listed the number of bytes, not bits. So one K of memory is 1024 bytes, or 1024*8 == 8,192 bits. Usually one is not particuarly interested in the exact number of bits. It will be very useful in your future career to be sure you know how to multiply powers of two. 2M * 2N = 2(M+N)

In the above, * means multiplication. For example: 26 * 210 = 216

QUESTION 6:

Locations in a digital image are specified by a row number and a column number (both of these are integers). Say that a particular digital image is 1024 rows by 1024 columns, and that each location holds one byte. How many megabytes are in that image? Locations in a digital image are specified by a row number and a column number (both of them integers). A particular digital image is 1024 rows by 1024 columns, and each location holds one byte. How many megabytes are in that image?

A good answer might be:


1024 * 1024 = 210 * 210 = 2(10+10) = 220 = one megabyte

Picture of Main Memory


Main memory consists of a very long list of bytes. In most modern computers, each byte has an address that is used to locate it. The picture shows a small part of main memory:

Each box in this picture represents a single byte. Each byte has an address. In this picture the addresses are the integers to the left of the boxes: 0, 1, 2, 3, 4, ... and so on. The addresses for most computer memory start at 0 and go up in sequence until each byte has an address. Each byte contains a pattern of eight bits. When the computer's power is on, every byte contains some pattern or other, even those bytes not being used for anything. (Remember the nature of binary: when a binary device is working it is either "on" or "off", never inbetween.) The address of a byte is not part of its contents. When the processor needs to access the byte at a particular address, the electronics of the computer "knows how" to find that byte in memory.

QUESTION 7:

Decide which of the following are true:


Each byte of main memory has a unique address. If main memory is 4 megabytes large, there will be 4 * 220 addresses.

A good answer might be:


Each byte of main memory has a unique address. Yes If main memory is 4 megabytes large, there will be 4 * 220 addresses.

Yes

Contents of Main Memory


Main memory (as all computer memory) stores bit patterns. That is, each memory location consists of eight bits, and each bit is either "0" or "1". For example, the picture shows the first few bytes of memory.

The only thing that can be stored at one memory location is eight bits, each with a value of "0" or "1". The bits at a memory location are called the contents of that location. Sometimes people will say that each memory location holds an eight bit binary number. This is OK, as long as you remember that the "number" might be used to represent a character, or anything else. Remember that what a particular pattern represents depends on its context (ie., how a program is using it.) You cannot look at an arbitrary bit pattern (such as those in the picture) and say what it represents.

QUESTION 8:

In the picture, what is the contents of:


Memory location 0? Memory location 4?

A good answer might be:


In the picture, what is the contents of:

Memory location 0? 0100 1111 Memory location 4? 0000 0000

(It is customary to show bit patterns with a space every 4 bits. The space is not actually part of the pattern.)

Reading and Writing Memory


The processor can do two fundamental things with in main memory: 1. It can write to a byte at a given memory location. o The previous bit pattern in that location will be destroyed. o The new bit pattern is now saved for future use.

2. It can read a byte from a given location. o The processor gets the bit pattern stored at that location. o The contents of that location are NOT changed. For example, if the processor needs to get the byte stored at location 5, it can read it. It gets the byte "0110 1110" as the data it needs (but location 5 in memory does not change.) Most processors can write (and read) more than a single byte at a time. This speeds things up. But the two operations above are fundamental. You may have heard talk about the new 64-bit processors and 128bit processors. A 64-bit processor can read and write 64/8 = 8 bytes at a time.

QUESTION 9:

Say that later on the processor needs to save the byte "1111 1111" and picks location 7 for this. How will main memory be changed?

A good answer might be:


The answer is in the picture below.

Programs and Memory


The processor has written a byte of data at location 7. The old contents of that location are lost. Main memory now looks like the picture. When a program is running, it has a section of memory for the data it is using. Locations in that section can be changed as many times as the program needs. For example, if a program is adding up a list of numbers, the sum will be kept in main memory (probably using several bytes.) As new numbers are added to the sum, it will change and main memory will have to be changed, too. Other sections of main memory might not change at all while a program is running. For example, the instructions that make up a program do not (usually) change as a program is running. The instructions of a running program are located in main memory, so those locations will not change.

When you write a program in Java (or most other languages) you do not need to keep track of memory locations and their contents. Part of the purpose of a programming language is to do these things automatically.

QUESTION 10:

(Review Question:) Where are programs and data kept for long-term storage?

A good answer might be:


In secondary storage (usually the computer system's hard disk.)

Hard Disks
The hard disk of a computer system records bytes on a magnetic surface much like the surface of audio tape. The recording (writing) and reading of the data is done with a read/write head similar to that used with audio tape. The picture shows one disk and one read/write head at the end of a movable arm. The arm moves in and out along a radius of the disk. Since the disk is rotating it will record data in a circular track on the disk. Later on, to read the data, it must be moved to the right position, then it must wait until the rotating disk brings the data into position. Just as with audio tape, data can be read without changing it. When new data it recorded, it replaces any data that was previously recorded at that location. Unlike audio tape, the read/write head does not actually touch the disk but skims just a little bit above it. Usually the component called the "hard disk" of a computer system contains many individual disks and read/write heads like the above. The disks are coated with magnetic material on both sides (so each disk gets two read/write heads) and the disks are all attached to one spindel. All the disks and heads are sealed into a dust-free metal can. Since the operation of a hard disk involves mechanical motion (which is much slower than electronic processes), reading and writing data is much slower than with main memory.

QUESTION 11:

(Thought Question:) Why does not the read/write head of a hard disk touch its surface?

A good answer might be:


Since the disk is constantly rotating when the computer is on it would soon wear out if the read/write head were in contact with it.

Files
Hard disks (and other secondary memory devices) are used for long-term storage of large blocks of information, such as programs and data sets. Usually disk memory is organized into files. A file is a collection of information that has been given a name and is stored in secondary memory. The information can be a program or can be data. The form of the information in a file is the same as with any digital information---it consists of bits, usually grouped into eight bit bytes. Files are frequently quite large; their size is measured in kilobytes or megabytes. If you have never worked with files on a computer before you should study the documentation that came with your operating system, or look at a book such as Windows NT for Dummies (or whatever is appropriate for your computer.) One of the jobs of a computer's operating system is to keep track of file names and where they are on its hard disk. For example, in DOS the user can ask to run the program DOOM like this:
C:\> DOOM.EXE

The "C:\>" is a prompt; the user typed in "DOOM.EXE". The operating system now has to find the file called DOOM.EXE somewhere on its hard disk. The program will be copied into main storage and will start running. As the program runs it asks for information stored as additional files on the hard disk, which the operating system has to find and copy into main memory.

QUESTION 12:

Where does a program typically put its results for long-term storage?

A good answer might be:


Usually in a file in secondary storage. If the file does not already exist, the program will ask the operating system to create it.

Files and the Operating System


Usually all collections of data outside of main storage are organized into files. The job of keeping all this information straight is the job of the operating system. If the computer system is part of a network, keeping straight all the files on all the computers can be quite a task, and is the collective job of all the operating systems involved. Application programs (including programs that you might write) do not directly read, write, create, or delete files. Since the operating system has to keep track of everything, all other programs ask it to do file manipulation tasks. For example, say that a program has just calculated a set of numbers and needs to save them. The following might be how it does this: 1. Program: asks the operating system to create a file with a name RESULTS.DAT 2. Operating System: gets the request; finds an unused section of the disk and creates an empty file. The program is told when this has been completed. 3. Program: asks the operating system to save the numbers in the file. 4. Operating System: gets the numbers from the program's main memory, writes them to the file. The program is told when this has been completed. 5. Program: continues on with whatever it is doing. So when an application program is running, it is constantly asking the operating system to perform file manipulation tasks (and other tasks) and waiting for them to be completed. If a program asks the operating system to do something that will damage the file system, the operating system will refuse to do it. Modern programs are written so that they have alternatives when a requests is refused. Older programs were not written this way, and do not run well on modern computers.

QUESTION 13:

In modern computer systems, only the operating system can directly do anything with disk files. How does this: 1. 2. 3. affect the security of the system? affect computer games? affect the ease in creating programs?

(You might not be certain about your answers, but please think about the questions.)

A good answer might be:

In modern computer systems, only the operating system can directly do anything with disk files. How does this: 1. affect the security of the system? o The security is increased because programs that try to do dangerous or stupid things to files can't. They have to ask the operating system, which will only do safe and sensible things. affect computer games? o Older computer games did their file manipulation themselves without asking the operating system (old DOS was stupid and slow and many application programs ignored it.) Those games won't run on modern computers. affect the ease in creating programs? o Program creation is easier because the work of dealing with files is done by the operating system.

2.

3.

Types of Files
As far as the hard disk is concerned, all files are the same. At the electronic level, there is no difference between a file containing a program and a file containing data. All files are named collections of bytes. Of course, what the files are used for is different. The operating system can take a program file, copy it into main memory, and start it running. The operating system can take a data file, and supply its information to a running program when it asks. Often then last part of a file's name (the extension) shows what the file is expected to be used for. For example, in "mydata.txt" the ".txt" means that the file is expected to be used as a collection of text, that is, characters. With "Netscape.exe" the ".exe" means that the file is an "executable," that is, a program that is ready to run. With "program1.java" the ".java" means that the file is a source program in the language java (there will be more about source programs later on in these notes.) To the hard disk, each of these files is the same sort of thing: a collection of bytes.

QUESTION 14:

What happens when a file is used in a way other than its intended use? For example, what happens if you try to use a word processor on an ".EXE" file?

A good answer might be:


Something will likely go wrong. The information contained in the file is not appropriate for a word processor.

End of the Chapter

You have reached the end of the chapter. If you have trouble with your own memory, and need to review a topic, click on it in the list below to go to where it was discussed. To get back here, click on the "back arrow" button of your browser.

Types of computer memory and their characteristics. Bit. Byte, kilobyte, megabyte, gigabyte, terabyte. Multiplication rule for exponents. Picture of main memory. Contents of main memory, Two things that the processor can do with main memory. Picture of a hard disk. Files. Operating system and file i/o.

Back to the main menu. You have reached the end of the chapter.

CHAPTER 4 The Processor


From previous chapters you know that the major hardware components of a computer system are:

Processor Main memory Secondary memory devices Input/output devices

This chapter first examines the "brain" of the computer system -- the processor. Chapter Topics:

Machine operations and machine language. Example of machine language. Different types of processor chips. High level programming languages. Language translators (compilers.) Language interpreters.

QUESTION 1:

What component of a computer system is directly responsible for running a program?

A good answer might be:


The processor.

Electronic Operations of a Processor


When a program is running on a computer the processor is constantly performing very many, very tiny electronic operations. For example, one such operation reads one byte of data from main memory into the processor. Another operation tests if one of the bits in the byte is a "1" bit. Most processors are able to perform several hundred types of small operations like these. Click Here to see a picture of a Pentium processor.

A Pentium Processor

This is the Pentium 90 processor from my 1995 Dell Dimension computer. The actual silicon chip is sealed inside the golden colored metal rectangle. The picture shows the bottom of the Pentium. The many gold fingers are usually pushed into a socket on the main circuit board of the computer.

Those are the only things that a processor can do. It has a small set of tiny electronic operations that it can to perform, and that is all. These little electronic operations are performed one at a time. But millions of them are performed per second. Millions of small operations can add up to a large and useful action. Everything that a processor does are built out of these tiny operations! Luckily, you don't need to know these details to write programs in Java. The purpose of a "highlevel language" like Java is to organize the tiny electronic operations into large, useful units represented by program statements.

QUESTION 2:

(Thought question:) When you click on a hyperlink (such as the next button) your Web browser (a computer program) finds and displays a new page. About how many detailed electronic operations does the processor perform in doing this?

1 10 100 100,000

A good answer might be:


I would guess about 100,000 operations. Certainly not as few as 100 or less. All these small opertions add up to a useful big operation: displaying a new Web page.

Machine Instructions
Users and programmers of computers usually don't think about the millions of tiny electronic operations that go on each second. The situation is (very roughly) similar to when you are driving your car. You think about the "big operations" it can perform, such as "accelerate", "turn left", "brake", and so on. You don't think about the valves in your engine opening and closing 24,000 times per minute. Each tiny electronic operations that a processor can perform is called a machine operation. A processor (a "machine") performs these one at a time, but millions of them in a second. A machine instruction consists of several bytes in memory that tells the processor to perform one machine operation. The processor looks at machine instructions in main memory one after another, and performs one machine operation for each machine instruction. The collection of machine instructions in main memory is called a machine language program or (more commonly) an executable program. Don't panic if the above seems incomprehensible. It takes some getting used to. (And to really understand it all takes several courses.)

QUESTION 3:

When they are running, are machine langage programs in main memory along with data?

A good answer might be:


Yes. Programs and data are both in main memory when they are active.

Example of Machine Language


Let us say that an electric toothbrush has a processor and main memory. The processor can rotate the bristles left and right, and can check the on/off switch. The machine instructions are one byte long, and correspond to the following machine operations:

Machine Operation

Machine Instruction 0000 0000 0000 0001 0000 0010 0000 0100 0000 1000 Stop Rotate bristles left Rotate bristles right Go back to start of program Skip next instruction if switch is off

Here is the main memory for the toothbrush system:


Address 0 1 2 3 Machine Instruction

The toothbrush is wired so that when the switch is turned on, the instructions are performed one at a time, in order, starting at address zero. The program can be restarted at address zero with the instruction 0000 0100. The toothbrush is supposed to rotate the bristles left and right while the switch is on, and stop when the switch is off.

QUESTION 4:

Fill in main memory starting at address 0 with the machine instructions to control the toothbrush. (Please take the time to do this. If you do, you will be able to tell people that the first program you ever wrote was for an electric toothbrush. You do not want to pass up this opportunity).

A good answer might be:


The embedded control program for the dental appliance is given below.

Machine Language Program


There are at least two sensible programs for the toothbrush. Here is one of them:
Address 0 1 2 3 4 Machine Instruction 0000 0001 0000 0010 0000 1000 0000 0100 0000 0000

To help you read the program, here is the list of machine operations:
Machine Instruction 0000 0000 0000 0001 0000 0010 0000 0100 Stop Rotate bristles left Rotate bristles right Go back to start of program Machine Operation

0000 1000

Skip next instruction if switch is off

This is, of course, a stupid example. Electric toothbrushes are not controlled by computer processors. And, the machine instructions of actual processors are much more detailed. But the essential ideas of the example are these: A machine language program is a sequence of machine language instructions in main memory. A machine instruction consists of one or more bytes (in the example, only one.) The processor runs a program one machine instruction at a time. All the little machine operations add up to something useful.

If toothbrush user leaves the switch "on" for a while, the program repeats its operations many times. This is how most programs in real computers run--many little operations add up to a useful function, which is then repeated many times.

QUESTION 5:

Will the electric toothbruch stop immediately when the switch is turned off? (Follow through the program to see if this happens.)

A good answer might be:


No. The program may run for several instructions before the switch is tested.

Executing Instructions
The word "execute" is often used to mean "perform the machine operation that an instruction asks for." So you can say that "executing the instruction 0000 0000 stops the toothbrush," or "millions of instructions execute per second." "Execute" is also used for an entire program or part of a program: "to execute the program, turn the switch to on." Most machine language programs are made up of instructions that are executed again and again. In the toothbrush program there was an instruction that caused the processor to start the program again from the beginning. In a real computer, millions of instructions execute per second, so something like this is necessary if the 32 megabytes of a typical computer are to hold a program that runs for more than a few seconds. A group of machine instructions that can be repeatedly executed is called a loop. A typical processor is made up of several million transistors, all on one small wafer of silicon called an integrated circuit (also called a chip.) The toothbrush processor could probably be built with just a few hundered transistors. Integrated

circuits are used for other electronic parts of a computer: for example main memory is implemented with memory chips.

QUESTION 6:

Do Apple computers and IBM compatible computers use the same processor chips?

A good answer might be:


No.

Different Processors
There are many types of processors used in computer systems. You probably know something about the most popular ones such as Intel Corporation's processors (486, Pentium, Pentium II), and the processors used in Apple computers. A computer system is designed around its processor. The other electronics are designed for a particular type of processor. The fundamental difference between (say) an Apple Power Macintosh and a Dell Corporation computer is the processor each is designed around. Different processors have different machine operations. A machine program for a Dell computer (with a Pentium processor) would make no sense to an Apple computer. This is why you ordinarily have to be careful to purchase the correct version of an application for your home computer. If you buy the game Myst, you need to get the version for whatever processor your home computer uses. But there is a version of Myst for both Pentium-based computers and for Apples. How can this be, if the processors perform different machine operations? The answer is that even though the processors are different, the machine operations available on each can be used to build the same things. Both processor types have enough power in their little machine operations so that anything one processor can do with a machine program, the other processor can do with a different machine program. The architecture of a processor is the choices that have been made for its machine operations, how they have been oraganized and implemented, and how it interacts with main memory and other components. Architecture is concerned with the general plan and functions of a processor; it is not much concerned with electronic details. A course in computer architecture is required in most computer science departments.

QUESTION 7:

(Thought question:) Say that you are looking at two different processor chips. The first processor has twice as many types of machine operations as the second chip. Is the first processor necessarily the best one?

A good answer might be:


Nothe smaller chip might have a well chosen set of operations that work together better and faster than the poorly chosen operations of the other processor.

High Level Programming Languages


It is very rare for programmers to write programs in machine language like we did for the electric toothbruch. The executable files (the directly runnable machine language programs) for most applications contain hundereds of thousands of (if not millions) of machine language instructions. It would be very hard to create something like that. As an experiment, look through your hard disk with the file listing utility (the explorer on Microsoft systems.) Look at the size of the something.EXE files. (Remember that there are usually several bytes per machine instruction.) Most programs are created using a high level programming language such as Java, C, C++, or BASIC. With a high level language, a programmer creates a program using powerful, "big" operations which will later be converted into many little machine operations. For example, here is a line from a program in the language "C":
int sum = 0;

The machine operations that correspond to this line will set up a small part of main memory to hold a number, store the number zero there, and arrange things so other parts of the program can use it. It might take a hundred machine operations to do all this. Obviously, it is easier for a human programer to ask for all these operations using "C".

QUESTION 8:

Say that a corporation pays programmers $50 an hour. Will the corporation want programmers to program in machine language or in a high level language?

A good answer might be:


A high level language. Programmers can create programs in much less time (costing much less money) by using a high level language.

Source Programs

Programers create programs by writing commands in a high level language. A high level language program consists of lines of text that have been created with a text editor and are kept in a file on the hard disk. For example, here is a complete program in "C" (Java will be discussed later):
#include <stdio.h> main() { int sum = 0; sum = 2 + 2; printf( "%d\n", sum ); }

This program could be saved on the hard disk in a file called addup.c. Like all files, it consists of a sequence of bytes. Since it is a text file, these bytes contain character data. You can edit the file with a text editor and print the file on a printer. It does not contain machine instructions. If the bytes are copied into main memory, they cannot run as a program without some extra work being done. A source program (or source file) is a text file that contains instructions written in a high level language. It can not be executed (made to run) by a processor without some intermediate steps. Usually a source program is translated into a machine language program An application program called a translater takes a source file as input and produces an executable program (machine language program) as output. For example, the "C" program addup.c could be translated into an executable program. The executable program might be called addup.exe and can be saved on the hard disk. Now the executable version of the program can be copied into main memory and executed. The word compile means the same thing as translate. So one can say that a source program is compiled into an executable program.

QUESTION 9:

Say that a source program has been translated into an executable. The executable has been run a few times, and the programer decides to make a change to the program. Where is the change made? To the source program or to the executable program?

A good answer might be:


To the source program, where the change is easy to make. The changed source program is then translated into a new executable program.

Program Translation

Here is a picture that shows what usually happens with programs written in "C" (Java is different; it will be discussed in the next chapter.)

Here is a review of what goes on: 1. The source file is created using a text editor. o It contains instructions in a high level language. o It contains bytes that hold characters. 2. The source file is kept on the hard disk. 3. The source file can not be run by the processor. 4. A translator (compiler) program can translate the source file into an executable file. o The source file remains unchanged; a new executable file is created. o A translator is used for programs written in a specific high level language (like "C") and a specific processor type (like "Pentium"), and only runs under a specific operating system (like "Windows".) 5. The executable file is also kept on hard disk. 6. To run the program, the operating system is told to copy the executable file into main memory and to start it running. The above is what goes on with most languages: Ada, Pascal, C, C++, FORTRAN and others. Java adds a few more steps, which will be discussed in the next chapter.

QUESTION 10:

A source program has been written in the "C" language. The file has been copied onto the hard disk of a Pentium-based computer and onto the hard disk of an Apple Macintosh. What must now be done so that the program can execute on both computers?

A good answer might be:


Each copy of the source program must be translated into an executable that is correct for each machine:

On the Pentium: A "C" translator for Pentium processors is used. On the Macintosh: A "C" translator for Macintosh processors is used.

Portability
Ideally, only one program needs to be written in the high level language. That source file can then be translated into several executable files, each containing the correct machine instructions for its intended processor. This is how versions of "Myst" for Pentium computers and Apple computers were made: one source file was created, and it was translated into two different executable files. The idea of using one source file for executables that run on different processors is part of software portability. You would like to write a program just once (in a high level language) and then be able to run it on any computer system by translating it into that systems machine language. Usually, unfortunately, things do not work out that nicely. There are enough little problems so that it takes a substantial amount of human effort to get a program running on a new system. One of the big advantages of Java is that it is automatically portable between computer systems that have Java support. No human effort is involved at all.

QUESTION 11:

Say that a corporation pays programmers $50 an hour to write application programs that will run on both Apple and Intel computers. Will the corporation want programmers to program in Java or in some other high level language?

A good answer might be:


Java. All the time (and expense) of getting the program to run on other computers is avoided. (Actually, the issue is not quite so clear-cut as this.)

Interpreter
Programs written in a high level language are never directly executed by the processor. You have already seen one way to execute such a program: use a translator to create a machine language program that can be executed directly. Another way to is to use an interpreter for the language.

An interpreter is a program that acts like a processor that can directly execute a high level language. This is a fairly complicated thought. The figure might help:

In this figure, the source program "program.bas" has been written in BASIC (a programming language) by a programmer with a text editor. It is being interpreted by the BASIC interpreter, which is running on the processor. The BASIC interpreter will read each command in the source program and do what it says. You have probably done this many, many times without realizing it. It is exactly accurate (although an unusual use of the words) to say that the computer game DOOM (or any other game) is an interpreter for the commands that the user enters using the mouse and keyboard. The commands for the game DOOM are not the usual type of commands used in a general purpose programing language, but none the less, they are commands. The set of commands and the rules for how to use them correctly form a programming language for the DOOM interpreter. When DOOM is running in "demo mode" (a sample game played without user input) it is in fact running a program written in the DOOM language. This program is not being directly processed by the Pentium chip in your computer. The DOOM game is interpretting it command by command.

QUESTION 12:

An interpreter runs directly on the processor. What type of instructions must an interpreter consist of?

A good answer might be:


An executable interpreter consists of machine instructions, like all programs that can execute directly on the processor.

Virtual Machine
When an interpreter is running a BASIC source program, both the interpreter and the source program are in main memory. The interpreter consists of machine instructions that the hardware can execute directly. The BASIC source program consists of commands in the language BASIC that the interpreter knows. From the perspective of the BASIC program, it looks like the commands in BASIC are being directly executed by some sort of machine. Here is the figure, modified to show this:

This is really the same as the previous figure, but now a box has been drawn around the actual (hardware) processor and the interpreter that it is executing. The combination "looks like" a machine that can directly act upon BASIC source programs. The word virtual is used in situations where software has been used to make something look like the real thing. In this case it looks like we have a machine that can directly execute BASIC, so we can say that we have a BASIC virtual machine.

QUESTION 13:

Do you think that it would also be possible to use a translator to translate a BASIC source program into an executable file (containing machine instructions)?

A good answer might be:


Yes. Most high level languages have a translator and have an interpreter.

Speed
The situation with computer languages is somewhat like that with human languages: Translator: takes a complete document in one language and creates a complete document in another language, which can then be used at any time. Interpreter: acts as an intermediate between a speaker of one language and a speaker of another language to make it look like both speakers are talking directly to each other.

Using a human interpreter as an intermediate is slower than conversing directly in a particular language. The same is true with computer language interpreters. The interpreter has to do quite a bit of work to deal with the language it is interpreting. The extra work makes it look like the virtual processor is much slower than the real one.

QUESTION 14:

Is it always important for a program to run as fast as possible? (Hint: take some time to answer this question.)

A good answer might be:


No. Programs should get their work done in a timely fashion, but often moderately slow is fast enough. For example, the Web browser you are using mostly does nothing as it waits for your commands. It would be only a slight improvement to make it run much faster.

End of the Chapter!


You may wish to review the following. Click on a subject that interests you to go to where it was discussed.

Machine operations and machine instructions. Executing a program. Differences in types of processor chips. High level programing language. Source program. Program translation. Program interpretation. Portability.

The next chapter will discuss how the language Java fits into the concepts this chapter has discussed.

Back to the main menu. You have reached the end of the chapter.

CHAPTER 5 Introduction to Java


The previous chapters have discussed computer hardware, computer software, bits and bytes, machine language, language translation, language interpretation, and virtual machines. This chapter assumes that you know all that and are ready to look at Java. Chapter Topics:

Hello World program. Java Bytecodes. Java compiler and Java virtual machine. Using Notepad to create a source program. Running a Java program.

These notes are written for JavaTM 2 SDK Standard Edition version 1.3 or higher. The current release is version 1.4.2 (as of June, 2003). Earlier versions will usually work for these notes and may be easier to obtain (perhaps on a CD that came with a book.)

QUESTION 1:

Is it necessary to spend lots of money to get Java?

A good answer might be:


Only at Starbucks.

Installing Java
If you already have some version of Java installed on your computer it will almost certainly be sufficient for these notes. You don't need the latest version. To run the current version of Java you need a computer that is running:

Windows 98 or higher, Windows NT or higher, most versions of Unix (including Linux), or a recent Apple.

If you have Windows 95 you will need to install an older version of Java. Java 1.3 will work. These Notes were prepared using Windows NT 4.0 with Java 1.3, but the screen shots are typical of all Windows operating systems. If you are running some other operating system there will be small differences in how you create and run programs, but absolutely no difference in the Java language itself.

The JavaTM 2 Software Development Kit (SDK) is a collection of software available at no charge from Sun Microsystems, Inc. At the time of writing (July 16, 2003) the download is available at java.sun.com. Detailed instructions on how to download it and install it are available at that site. If you have not yet installed Java, get the most recent version. The SDK for Windows comes in a file named j2sdk1_4_2-windows-i586.exe (or a similar name.) This is a 44 megabyte file, which may take hours to download over a modem. Once you have this file install it by clicking on it. This starts an installer program. Then mostly all you do is keep clicking the buttons that accept the default options. If the installation worked you should now have a new subdirectory on your C: drive named j2sdk1.4.2 (or similar).

(The directory jdk1.3.1 in this picture is left over from a previous installation.)

QUESTION 2:

Would you like to test the installation?

A good answer might be:

Of course.

Java Documentation
(If you don't know about DOS windows, skip this section.) A simple test is to open a command line window (a DOS window) and CD to C:\j2sdk1.4.2\bin. Type "javac" after the prompt.
C:\j2sdk1.4.2\bin>javac

The java compiler should run, briefly. It will write out about 15 lines of instructions on how to use it. (Details on how to use it come later in this chapter.) While you are at java.sun.com (or later if you don't have time) get the Java documentation. This comes in a file j2sdk-1_4_2-doc.zip. You will have to "un-zip" it after you download it. On most computers un-zipping a file can be started by clicking on the file name. You will end up with a set of web pages (stored on your computer) that describe the features of Java.

QUESTION 3:

When you create a program, do you keep it in the same directory as the compiler?

A good answer might be:


Not usually.

PATH variable
Usually you create a subdirectory to hold the various program files for a new project. You would like to run the compiler while working in that directory. The Windows operating system uses an environment variable called PATH that is a list of all the subdirectories in which it is to look to find programs. In a DOS window, type "path" after the prompt:
C:\j2sdk1.4.2\bin>path PATH=C:\WINNT\system32;C:\WINNT;.;C:\j2sdk1.4.2\bin

Exactly what you see depends on your OS and what you have done with it. If you don't see C:\j2sdk1.4.2\bin (or similar) in your PATH you will have to edit your PATH variable. How you do this depends on your operating system. Look for detailed instructions on the Sun Web site.

If you can't figure out how to set the PATH variable, then you can put all your programs in C:\j2sdk1.4.2\bin and compile and run them there. This is crude, but it works.

QUESTION 4:

Are you using Borland's JBuilder, Symantec's Cafe, or similar program?

A good answer might be:


If so, you can still use these notes.

Commercial Java Software


If you have installed a commercial version of the Java software (such as JBuilder or Symantec Cafe) you will have a better environment than the one assumed here; read your software's documentation on how to use it. As part of your commercial software, you will probably automatically have the Java tools discussed in this chapter, so you can do exactly what is described in this chapter.

QUESTION 5:

Can the processor of a computer system directly execute source programs written in Java?

A good answer might be:


No. (If you got this question wrong, or don't even know what it asks, you need to study Chapter Four.)

Sample Java Program


Here is an example Java program. It is about as small a program as is possible. Some of its details will be explained later.
class Hello { public static void main ( String[] args ) { System.out.println("Hello World!"); } }

This program will be created as a text file using a text editor such as the "NotePad" editor (details on how to do this will come later.) The important thing for now is to understand that it is a file that is saved on the hard disk. The file should be named Hello.java. This file is called a source program. Since the file contains characters (stored as bytes) it can not be directly executed (run) by the computer system. As a text file, you can print it, display it on the monitor, or alter it with a text editor.

QUESTION 6:

(Review of Chapter 4:) What are the two ways that a source program can be run on a computer system?

A good answer might be:


1. Translation (into machine instructions, which are then executed by the processor.) 2. Interpretation (by an interpreter program.)

Bytecodes
Java combines these ideas in a way that will take some explaining. To get the sample program running, it first is translated into bytecodes. A Java bytecode is a machine instruction for a Java processor. The architecture of this processor has been very carefully described by the designers of Java and is available to anyone. To run a Java program on the Java processor, the souce program (the text file) must be translated into bytecodes. Here is a picture of the sample Java program Hello.java being translated into bytecodes. The file of bytecodes (machine language for the Java processor) is called Hello.class.

In this picture, the source program Hello.java is examined by a program called javac running on your computer. The javac program is a compiler (a translator) that translates the source program into a bytecode file called Hello.class.

Important Idea: The bytecode file will contain exactly the same bytecodes no matter what computer system is used. The Java compiler on a Macintosh will produce the exact same bytecodes as the Java compiler on an Intel system.

QUESTION 7:

If you had a hardware Java processor could it run the bytecodes as a program?

A good answer might be:


Yes.

Java Virtual Machine


Usually, however, people do not have hardware Java processors (although such computers have been built.) They have ordinary PCs and Apples. Now for the clever part: the Java processor can be implemented as software! It is implemented as a program that reads the bytecodes and performs the operations they specify. (This type of program is called an interpreter.) The Java bytecode interpreter is an executable program that runs on whatever computer system you have. Here is a picture showing this:

The "Java interpreter" in the picture is an executable program that is running on the computer system. Each type of computer system has its own Java interpreter that

can run on that system. The "Actual Processor" is the actual, hardware, processor chip of that computer system. (Another) Important Idea: The Java interpreter running on any computer system "looks like" a hardware Java processor chip. It is a Java Virtual Machine. Any computer system can execute Java bytecode programs if it has a Java interpreter. The Java interpreter has to be specifically written for the specific processor type of the computer system, but once that is done, the computer system can become a Java virtual machine. That is, it looks like a computer with a hardware Java processor chip and can run Java bytecodes. When a Java program is translated into bytecodes, the bytecodes are exactly the same no matter what computer system is used. This means the bytecodes on a Sun computer can be sent to an Intel based computer and they will run without a problem.

QUESTION 8:

Can bytecodes be sent from computer to computer over the Internet?

A good answer might be:


Yes. This is part of the reason for the popularity of Java.

Applets
An applet is a Java bytecode program that runs on a Web browser. Most up-todate Web browsers include a Java interpreter. A Web page on a host computer on the Internet can contain instructions that send Java bytecodes to a client computer (like yours) that has asked to view the page. The Web browser on the client runs the Java applet with its built-in interpreter. Applets are used for user interaction, graphics, and animation. Applets will be discussed in later chapters of these notes. For now, let us concentrate on Java programs that get input from the keyboard and write output to the DOS window of the monitor. These are called Java application programs.

QUESTION 9:

Is the Java used to write applets different from that used to write applications?

A good answer might be:


No. The fundamental language is the same.

Creating a Java Source Program


We will use the "Notepad" editor that comes with Microsoft Windows operating systems. I am using Notepad here because everyone has it and can use it to get started. After you see how things work using Notepad, you should find a better text editor to use. The goal is to create a text file called Hello.java containing the characters below:
class Hello { public static void main ( String[] args ) { System.out.println("Hello World!"); } }

On an Intel-based computer running Windows, first start up the DOS command prompt. One way to do this is to click on the "Start" button in the lower right of your screen. You should now see a menu of choices similar to below. Look for the "MS DOS" Icon:

The more recent the Windows system, the harder it is to find the command prompt. If you don't see it at first, click on "Programs" and look futher. When you find it, click on the "MS DOS" icon to start a command interpreter window.

QUESTION 10:

Will you see exactly the same things on your computer system?

A good answer might be:


No. You will probably have different choices, depending on what you have installed. (The happy little spider is a free HTML editor available at www.arachnoid.com).

Command Interpreter Window


After you click on the "MS DOS" icon you will have a command interpreter window that allows you to type in commands as if you were running an old-time DOS computer. You should see something like the following:

The prompt starts out as:


C:\WINNT\System32>

This prompt means that the files you create will automatically go onto the hard disk in the subdirectory C:\WINNT\System32. (A subdirectory is a section of the disk that has a name. A subdirectory can hold many files.) You should not create files in this subdirectory. You will probably get a prompt that starts out in some other subdirectory. It doesn't matter where you start out because you can always move to where you want to be using the CD command. For now, let us create a Java program in the C:\Temp directory. To get to this directory type the command:

cd \Temp

Type the command in after the DOS prompt (as above). The prompt changes to show the current default directory.

QUESTION 11:

Can a user (such as you) create a subdirectory?

A good answer might be:


Yes. If you know how, create one (perhaps "C:\JavaPrograms") and use the CD command to move to it.

Starting Notepad
The text editor we will use is called "Notepad." It comes with Microsoft operating systems. Click on the "Start" button in the lower left, then on "Programs" then on "Accessories", and then on "Notepad". As you might expect, different versions of Windows put Notepad in different places. You may have to hunt.

After clicking on the icon, Notepad starts. Another way is to start it from the DOS prompt:
C:\TEMP> notepad C:\TEMP>

QUESTION 12:

Is all this getting to be too much?

A good answer might be:


Yes --- Find a book on basic computer use like Windows for Dummies. The "for Dummies" books are cheap, and very well written. Any public library should have them and other suitable books. You will only need to look at one or two chapters. No --- Good.

Notepad
Once Notepad is running, just type in the program. Here is Notepad with the sample program:

To enter characters, just type them. You can move around the text using the mouse or arrow keys. To delete mistakes, use the "backspace" key or the "delete" key. To start a new line, just hit "Enter". In typing in the program, you DO have to get upper and lower case letters, and all punctuation exactly correct. You do not have to get the spaces exactly correct.

Now you need to save the file to the hard disk. One of the selections in the menu bar at the top of the Notepad window is used to do this.

QUESTION 13:

Which of the menu selections (in the menu bar at the top of the Notepad window) do you suppose is used to save the file?

A good answer might be:


The "File" menu.

Saving the Source File


Move the mouse pointer to "File" and click on it. You will get a sub-menu. Now click on "Save As". As the picture shows, you may not start out n the C:\Temp directory. If not, you will have to use the various controls at the top of the "Save As" dialog to get to the directory you want.

When you see it, click on the "Temp" directory to say that it is where you wish to save your program. The "Temp" directory is intended for temporary files and will usually be full of many different files.

QUESTION 14:

If you save the file in a different directory than the one being used for the DOS window, will there be a problem?

A good answer might be:


Only a slight problem. You can CD to the correct directory and save the file there, also.

Naming the File


When you get to the "Temp" directory: 1. 2. Type the file name into the box. The file name should be Hello.java o For some versions of Notepad you should put quote marks around the file name like this: "Hello.java" even though the quote marks will not be part of the file name. 3. Select "Save as all files" by clicking on the little down arrow it the box below the file name box. 4. Click on "Save" Your system is likely to be slightly different. Experiment with different choices until you are able to create a text file that contains the sample Java program.

Fussy, bothersome, irksome, irritating details. Yes, I know... Some people actually like this stuff. But if you can drive a car you can do this. It might take some practice.

QUESTION 15:

So, finally your Java program source file is saved. What must you do to run it?

A good answer might be:

Compile it into Java bytecodes, then run the bytecode with the Java interpreter.

Running the Program


To do all that, find the DOS command window you started up a while back. It should still be positioned in the C:\Temp directory. To check that you put the source file ("Hello.java") in this directory, enter the command dir *.java. You should see the source file, as below.
C:\TEMP>dir *.java Volume in drive C has no label. Volume Serial Number is 7C68-1E55 Directory of C:\TEMP 08/23/98 01:07a 1 File(s) 115 Hello.java 115 bytes 2,448,368,640 bytes free

To compile the source file (thereby producing a file of bytecodes) enter the command javac Hello.java.
C:\TEMP>javac Hello.java compiling: Hello.java

If you see the following...


C:\TEMP>javac Hello.java The name specified is not recognized as an internal or external command, operable program or batch file.

... then the PATH environment variable has not been set correctly. Either go back and figure out how to do that, or use the directory C:\j2sdk1.4.2\bin instead of C:\TEMP. Finally, to run the program, enter the command java Hello.
C:\TEMP>java Hello Hello World! C:\TEMP>

QUESTION 16:

After all of this, what did the Java program actually do?

A good answer might be:


The example Java program wrote the words "Hello World!" in the command interpreter window.

Result of Running the Example Java Program


Your program may not have run correctly. It is possible that you did not type in exactly the characters that were required. The spaces don't particularly matter. But check especially the characters like "[" and "{" and "(". You have to use the correct ones. Fuss around for a while to get the program to work. If you just can't get it to work, give up and move on. Probably there is some trival detail that you have overlooked and will see clearly later on. This happens all the time in programming. If everything worked out perfectly, then go back and do something wrong. This will help you understand what happened later on when you do something wrong, but didn't intend to.

QUESTION 17:

Had enough, for now?

A good answer might be:


Yes.

End of the Chapter!


Hopefully this chapter explained just exactly what you needed to know to run Java programs, and everything worked out perfectly, and you can now create Java source programs, and compile them into bytecodes, and execute them using the Java interpreter. Well.... one can hope. If something was less than perfect, find a friend that knows more about these things and is happy to help. Or, start again and go through everything once again. Or, move on and come back to this chapter later. You may wish to review the following. Click on a subject that interests you to go to where it was discussed.

Example Java program. Java bytecodes. Java virtual machine. Applets. Starting the command prompt. Starting Notepad. Saving the source code to a file. Running the program.

The next chapter discusses how the example program worked.

Back to the main menu.

CHAPTER 6 Small Java Programs


The previous chapter discussed the mechanics of creating and running a Java program. This chapter is an overview of Java using the example program from that chapter. Chapter Topics:

Small example programs. Names for source files and class files. Syntax errors. Bugs. The Edit, Compile, and Run cycle Matching braces. Neat indenting.

QUESTION 1:

(Review:) What role in Java programming does each of the following files play?

Source code file. Bytecode file.

You might also like