Java Concepts 5 Pap/Onl Edition Cay Horstmanninstant download
Java Concepts 5 Pap/Onl Edition Cay Horstmanninstant download
or textbooks at https://ebookultra.com
_____ Follow the link below to get your download now _____
https://ebookultra.com/download/java-concepts-5-pap-onl-
edition-cay-horstmann/
https://ebookultra.com/download/java-concepts-5th-edition-cay-s-
horstmann/
https://ebookultra.com/download/big-java-compatible-with-
java-5-6-and-7-4th-edition-cay-s-horstmann/
https://ebookultra.com/download/brief-java-early-objects-9th-edition-
cay-horstmann/
https://ebookultra.com/download/python-for-everyone-2nd-edition-cay-
horstmann-rance-necaise/
Core Java Volume 1 Fundamentals 8th ed Edition Horstmann
https://ebookultra.com/download/core-java-volume-1-fundamentals-8th-
ed-edition-horstmann/
https://ebookultra.com/download/operating-systems-concepts-with-
java-6th-edition-silberschatz/
https://ebookultra.com/download/learning-java-3rd-edition-
covers-j2se-5-0-patrick-niemeyer/
https://ebookultra.com/download/java-ee-5-development-with-
netbeans-6-1st-edition-heffelfinger/
https://ebookultra.com/download/ivor-horton-s-beginning-
java-2-jdk-5-edition-ivor-horton/
Java Concepts 5 Pap/Onl Edition Cay Horstmann Digital
Instant Download
Author(s): Cay Horstmann
ISBN(s): 9780470112106, 0470112107
Edition: 5 Pap/Onl
File Details: PDF, 10.73 MB
Year: 2007
Language: english
Java Concepts, 5th Edition
Chapter 1 Introduction
CHAPTER GOALS
• To understand the activity of programming
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.
2
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.
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.
Chapter 1 Introduction Page 1 of 43
Java Concepts, 5th Edition
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.
Today's computer programs are so sophisticated that it is hard to believe that they are
all composed of extremely primitive operations.
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.
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.
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. What is required to play a music CD on a computer?
At the heart of the computer lies the central processing unit (CPU) (see Figure 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 principally 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).
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 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 3), provides less
Data and programs are stored in primary storage (memory) and secondary storage
(such as a hard disk).
Some computers are self-contained units, whereas others are interconnected through
networks. Home computers are usually intermittently connected to the Internet via a
dialup or broadband connection. The computers in your computer lab are probably
permanently connected to a local area network. Through the network cabling, the 4
computer can read programs from central storage locations or send data to other 5
computers. For the user of a networked computer, it may not even be obvious which
data reside on the computer itself and which are transmitted through the network.
Figure 2
Most computers have removable storage devices that can access data or programs on
media such as floppy disks, tapes, or compact discs (CDs).
Chapter 1 Introduction Page 5 of 43
Java Concepts, 5th Edition
Figure 3
A Hard Disk.
5
A Motherboard
To interact with a human user, a computer requires other peripheral devices. The
computer transmits information to the user through a display screen, loudspeakers, and
printers. The user can enter information and directions to the computer by using a
keyboard or a pointing device such as a mouse.
The CPU, the RAM, and the electronics controlling the hard disk and other devices are
interconnected through a set of electrical lines called a bus. Data travel along the bus
from the system memory and peripheral devices to the CPU and back. Figure 4 shows
a motherboard, which contains the CPU, the RAM, and connectors to peripheral
devices.
The CPU reads machine instructions from memory. The instructions direct it to
communicate with memory, secondary storage, and peripheral devices.
6
7
Figure 5
SELF CHECK
4. Where is a program stored when it is not currently running?
Work on the ENIAC was supported by the U.S. Navy, which was interested in
computations of ballistic tables that would give the trajectory of a projectile,
depending on the wind resistance, initial velocity, and atmospheric conditions. To 7
compute the trajectories, one must find the numerical solutions of certain 8
differential equations; hence the name “numerical integrator”. Before machines like
ENIAC were developed, humans did this kind of work, and until the 1950s the
word “computer” referred to these people. The ENIAC was later used for peaceful
purposes, such as the tabulation of U.S. census data.
The ENIAC
Generally, machine code depends on the CPU type. However, the instruction set of
the Java virtual machine (JVM) can be executed on many CPUs.
8
9
A typical sequence of machine instructions is
3. If the first value is greater than the second value, continue with the instruction
that is stored in memory location 240.
Actually, machine instructions are encoded as numbers so that they can be stored in
memory. On the Java virtual machine, this sequence of instruction is encoded as the
sequence of numbers
21 40
16 100
163 240
When the virtual machine fetches this sequence of numbers, it decodes them and
executes the associated sequence of commands.
How can you communicate the command sequence to the computer? The most direct
method is to place the actual numbers into the computer memory. This is, in fact, how
High-level languages allow you to describe tasks at a higher conceptual level than
machine code.
For example, in Java, the high-level programming language that you will use in this
book, you might give the following instruction:
if (intRate > 100)
System.out.println("Interest rate error");
This means, “If the interest rate is over 100, display an error message”. It is then the
job of the compiler program to look at the sequence of characters if (intRate >
100) and translate that into
21 40 16 100 163 240 . . .
Compilers are quite sophisticated programs. They translate logical statements, such as
the if statement, into sequences of computations, tests, and jumps. They assign
memory locations for variables—items of information identified by symbolic names—
like intRate. In this course, we will generally take the existence of a compiler for
granted. If you decide to become a professional computer scientist, you may well learn
more about compiler-writing techniques later in your studies.
7. Does a person who uses a computer for office work ever run a compiler?
Java was originally designed for programming consumer devices, but it was first
successfully used to write Internet applets.
Gosling recounts that in 1994 the team realized, “We could write a really cool
browser. It was one of the few things in the client/server mainstream that needed some
of the weird things we'd done: architecture neutral, real-time, reliable, secure”. Java
was introduced to an enthusiastic crowd at the SunWorld exhibition in 1995.
Since then, Java has grown at a phenomenal rate. Programmers have embraced the
language because it is simpler than its closest rival, C++. In addition, Java has a rich
library that makes it possible to write portable programs that can bypass proprietary
operating systems—a feature that was eagerly sought by those who wanted to be
independent of those proprietary systems and was bitterly fought by their vendors. A
“micro edition” and an “enterprise edition” of the Java library make Java programmers
at home on hardware ranging from smart cards and cell phones to the largest Internet
servers.
Java was designed to be safe and portable, benefiting both Internet users and
students.
Because Java was designed for the Internet, it has two attributes that make it very
suitable for beginners: safety and portability. If you visit a web page that contains Java
code (so-called applets—see Figure 6 for an example), the code automatically starts
running. It is important that you can trust that applets are inherently safe. If an applet
could do something evil, such as damaging data or reading personal information on
your computer, then you would be in real danger every time you browsed the Web—
an unscrupulous designer might put up a web page containing dangerous code that
would execute on your machine as soon as you visited the page. The Java language has
an assortment of security features that guarantees that no evil applets can run on your
computer. As an added benefit, these features also help you to learn the language
faster. The Java virtual machine can catch many kinds of beginners' mistakes and
report them accurately. (In contrast, many beginners' mistakes in the C++ language
merely produce programs that act in random and confusing ways.) The other benefit of
Java is portability. The same Java program will run, without change, on Windows,
UNIX, Linux, or the Macintosh. This too is a requirement for applets. When you visit 10
a web page, the web server that serves up the page contents has no idea what computer 11
you are using to browse the Web. It simply returns you the portable code that was
generated by the Java compiler. The virtual machine on your computer executes that
portable code. Again, there is a benefit for the student. You do not have to learn how
to write programs for different operating systems.
Figure 6
At this time, Java is firmly established as one of the most important languages for
general-purpose programming as well as for computer science instruction. However,
although Java is a good language for beginners, it is not perfect, for three reasons.
Because Java was not specifically designed for students, no thought was given to
making it really simple to write basic programs. A certain amount of technical
machinery is necessary in Java to write even the simplest programs. This is not a
problem for professional programmers, but it is a drawback for beginning students. As
you learn how to program in Java, there will be times when you will be asked to be
satisfied with a preliminary explanation and wait for complete details in a later chapter.
Java was revised and extended many times during its life—see Table 1. In this book,
we assume that you have Java version 5 or later.
Finally, you cannot hope to learn all of Java in one semester. The Java language itself 11
is relatively simple, but Java contains a vast set of library packages that are required to 12
write useful programs. There are packages for graphics, user interface design,
cryptography, networking, sound, database storage, and many other purposes. Even
expert Java programmers cannot hope to know the contents of all of the packages—
they just use those that they need for particular projects.
Java has a very large library. Focus on learning those parts of the library that you
need for your programming projects.
Using this book, you should expect to learn a good deal about the Java language and
about the most important packages. Keep in mind that the central goal of this book is
not to make you memorize Java minutiae, but to teach you how to think about
programming.
SELF CHECK
8. What are the two most important benefits of the Java language?
Language: English
ERSKINE CHILDERS
EDITOR OF VOL. V. OF “THE TIMES HISTORY OF THE WAR IN SOUTH AFRICA”
AUTHOR OF “THE RIDDLE OF THE SANDS”
WITH AN INTRODUCTION BY
LONDON
EDWARD ARNOLD
1910
CHAPTER PAGE
BY
FIELD-MARSHAL EARL ROBERTS, V.C., K.G.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com