11.07.2015 Views

Introduction to Programming Using Java - Department of ...

Introduction to Programming Using Java - Department of ...

Introduction to Programming Using Java - Department of ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 1Overview: The Mental LandscapeWhen you begin a journey, it’s a good idea <strong>to</strong> have a mental map <strong>of</strong> the terrain you’llbe passing through. The same is true for an intellectual journey, such as learning <strong>to</strong> writecomputer programs. In this case, you’ll need <strong>to</strong> know the basics <strong>of</strong> what computers are andhow they work. You’ll want <strong>to</strong> have some idea <strong>of</strong> what a computer program is and how one iscreated. Since you will be writing programs in the <strong>Java</strong> programming language, you’ll want <strong>to</strong>know something about that language in particular and about the modern, networked computingenvironment for which <strong>Java</strong> is designed.As you read this chapter, don’t worry if you can’t understand everything in detail. (In fact,it would be impossible for you <strong>to</strong> learn all the details from the brief expositions in this chapter.)Concentrate on learning enough about the big ideas <strong>to</strong> orient yourself, in preparation for therest <strong>of</strong> the book. Most <strong>of</strong> what is covered in this chapter will be covered in much greater detaillater in the book.1.1 The Fetch and Execute Cycle: Machine LanguageA computer is a complex system consisting <strong>of</strong> many different components. But at theheart—or the brain, if you want—<strong>of</strong> the computer is a single component that does the actualcomputing. This is the Central Processing Unit, or CPU. In a modern desk<strong>to</strong>p computer,the CPU is a single “chip” on the order <strong>of</strong> one square inch in size. The job <strong>of</strong> the CPU is <strong>to</strong>execute programs.A program is simply a list <strong>of</strong> unambiguous instructions meant <strong>to</strong> be followed mechanicallyby a computer. A computer is built <strong>to</strong> carry out instructions that are written in a very simpletype <strong>of</strong> language called machine language. Each type <strong>of</strong> computer has its own machinelanguage, and the computer can directly execute a program only if the program is expressed inthat language. (It can execute programs written in other languages if they are first translatedin<strong>to</strong> machine language.)When the CPU executes a program, that program is s<strong>to</strong>red in the computer’s main memory(also called the RAM or random access memory). In addition <strong>to</strong> the program, memorycan also hold data that is being used or processed by the program. Main memory consists <strong>of</strong> asequence <strong>of</strong> locations. These locations are numbered, and the sequence number <strong>of</strong> a locationis called its address. An address provides a way <strong>of</strong> picking out one particular piece <strong>of</strong> informationfrom among the millions s<strong>to</strong>red in memory. When the CPU needs <strong>to</strong> access the programinstruction or data in a particular location, it sends the address <strong>of</strong> that information as a signal<strong>to</strong> the memory; the memory responds by sending back the data contained in the specified(online)1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!