没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
试读
1225页
其内容自然分为四个部分,分别为基于对象的基础、面向对象设计、数据结构与算法、高级主题。这四个部分分别介绍了Java的基本数据类型、类、继承、多态、数组、数组列表等概念,图形编程、基于对象编程和面向对象编程等内容,递归、排序和查找、链表和散列表等数据结构与算法,以及很多高级Java编程技术,包括多线程、网络、数据库、XML和Web应用程序。为帮助读者掌握要点、学习高效的编程技巧以及了解计算机科学的发展史,本书还提供了6个新增特性,分别为“常见错误”、“怎样做”、 “质量提示”、“增效提示”、“高级主题”和“纪事”。 本书面向大学低年级学生,适合作为第一门编程语言教材,也适合Java语言的初学者。
资源推荐
资源详情
资源评论
CHAPTER
1
Introduction
Chapter Goals
· To understand the activity of programming
· To learn about the architecture of computers
· To learn about machine code and high-level programming languages
· To become familiar with your computing environment and your compiler
· To compile and run your first Java program
· To recognize syntax and logic errors
The purpose of this chapter is to familiarize you with the concept of programming. It reviews the
architecture of a computer and discusses the difference between machine code and high-level
programming languages. Finally, you will see how to compile and run your first Java program, and how to
diagnose errors that may occur when a program is compiled or executed.
Copyright © 2008 John Wiley & Sons, Inc. All rights reserved.
1.1 What is Programming?
You have probably used a computer for work or fun. Many people use computers for everyday tasks such as balancing
a checkbook or writing a term paper. Computers are good for such tasks. They can handle repetitive chores, such as
totaling up numbers or placing words on a page, without getting bored or exhausted. Computers also make good
game machines because they can play sequences of sounds and pictures, involving the human user in the process.
The flexibility of a computer is quite an amazing phenomenon. The same machine can balance your checkbook, print
your term paper, and play a game. In contrast, other machines carry out a much narrower range of tasks—a car
drives and a toaster toasts.
A computer must be programmed to perform tasks. Different tasks require different programs.
To achieve this flexibility, the computer must be programmed to perform each task. A computer itself is a machine
that stores data (numbers, words, pictures), interacts with devices (the monitor screen, the sound system, the
printer), and executes programs. Programs are sequences of instructions and decisions that the computer carries out
to achieve a task. One program balances checkbooks; a different program, perhaps designed and constructed by a
different company, processes words; and a third program, probably from yet another company, plays a game.
A computer program executes a sequence of very basic operations in rapid succession.
Today's computer programs are so sophisticated that it is hard to believe that they are all composed of extremely
primitive operations.
A typical operation may be one of the following:
· Put a red dot onto this screen position.
·
Send the letter A to the printer.
· Get a number from this location in memory.
· Add up two numbers.
· If this value is negative, continue the program at that instruction.
A computer program tells a computer, in minute detail, the sequence of steps that are needed to complete a task. A
program contains a huge number of simple operations, and the computer executes them at great speed. The
computer has no intelligence—it simply executes instruction sequences that have been prepared in advance.
A computer program contains the instruction sequences for all tasks that it can execute.
To use a computer, no knowledge of programming is required. When you write a term paper with a word processor,
that software package has been programmed by the manufacturer and is ready for you to use. That is only to be
expected—you can drive a car without being a mechanic and toast bread without being an electrician.
A primary purpose of this book is to teach you how to design and implement computer programs. You will learn how
to formulate instructions for all tasks that your programs need to execute.
Keep in mind that programming a sophisticated computer game or word processor requires a team of many highly
skilled programmers, graphic artists, and other professionals. Your first programming efforts will be more mundane.
The concepts and skills you learn in this book form an important foundation, but you should not expect to immediately
produce professional software. A typical college program in computer science or software engineering takes four years
to complete; this book is intended as an introductory course in such a program.
Many students find that there is an immense thrill even in simple programming tasks. It is an amazing experience to
see the computer carry out a task precisely and quickly that would take you hours of drudgery.
Self Check
1.
Self Check 1.1 What is Required to Play a Music CD on a Computer?
What is required to play a music CD on a computer?
2.
Self Check 1.2 Why is a CD Player Less Flexible than a Computer?
Why is a CD player less flexible than a computer?
3.
Self Check 1.3 Can a Computer Program work Better than its Programmers Envisioned?
Can a computer program develop the initiative to execute tasks in a better way than its programmers
envisioned?
Copyright © 2008 John Wiley & Sons, Inc. All rights reserved.
1.2 The Anatomy of a Computer
To understand the programming process, you need to have a rudimentary understanding of the building blocks that
make up a computer. This section will describe a personal computer. Larger computers have faster, larger, or more
powerful components, but they have fundamentally the same design.
At the heart of the computer lies the central processing unit (CPU) (see Figure 1-1). It consists of a single chip
(integrated circuit) or a small number of chips. A computer chip is a component with a plastic or metal housing, metal
connectors, and inside wiring made princi-pally from silicon. For a CPU chip, the inside wiring is enormously
complicated. For example, the Pentium 4 chip (a popular CPU for personal computers at the time of this writing)
contains over 50 million structural elements called transistors—the elements that enable electrical signals to control
other electrical signals, making automatic computing possible. The CPU locates and executes the program
instructions; it carries out arithmetic operations such as addition, subtraction, multiplication, and division; and it
fetches data from storage and input/output devices and sends data back.
At the heart of the computer lies the central processing unit (CPU).
FIGURE 1-1
Central Processing Unit
The computer keeps data and programs in storage. There are two kinds of storage. Primary storage, also called
random-access memory (RAM) or simply memory, is fast but expensive; it is made from memory chips (see Figure 1-
2). Primary storage has two disadvantages. It is comparatively expensive, and it loses all its data when the power is
turned off. Secondary storage, usually a hard disk (see Figure 1-3), provides less expensive storage that persists
without electricity. A hard disk consists of rotating platters, which are coated with a magnetic material, and read/write
heads, which can detect and change the patterns of varying magnetic flux on the platters. This is essentially the same
recording and playback process that is used in audio or video tapes.
Data and programs are stored in primary storage (memory) and secondary storage (such as a hard
disk).
剩余1224页未读,继续阅读
资源评论
- wangyf19902014-02-18非常赞的资源。很适合像我这样的java初学者。
shenxuemei1984
- 粉丝: 2
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功