Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

AhmadLang / Java, How To Program, 2004

.pdf
Скачиваний:
588
Добавлен:
31.05.2015
Размер:
51.82 Mб
Скачать

Java 2 Platform Standard Edition (J2SE) Java 2 Platform Enterprise Edition (J2EE) Java 2 Platform Micro Edition (J2ME)

J2SE Development Kit (JDK) java interpreter

Java Virtual Machine (JVM) javac compiler

JIT (just-in-time) compiler

KIS (keep it simple)

LAN (local area network) legacy systems

live-code approach load phase machine language memory unit method

Microsoft Internet Explorer Web browser modeling

multiprocessor multiprogramming multithreading

.NET

nonfatal runtime error object

object-oriented design (OOD) object-oriented programming (OOP) operating system

output device output unit

Pascal

personal computing platform

portability primary memory

problem statement procedural programming programmer-defined type pseudocode requirements document reusable componentry runtime error

secondary storage unit software

software reuse structured programming Sun Microsystems throughput

timesharing translation translator program

Unified Modeling Language (UML) verify phase

Visual Basic .NET

Visual C++ .NET

World Wide Web

[Page 32]

Self-Review Exercises

1.1 Fill in the blanks in each of the following statements:

a.The company that popularized personal computing was __________.

b.The computer that made personal computing legitimate in business and industry was the __________.

c.Computers process data under the control of sets of instructions called

__________.

d.The six key logical units of the computer are the __________, __________,

__________, __________, and __________.

e.The three classes of languages discussed in the chapter are __________,and

__________.

f.The programs that translate high-level language programs into machine language are called __________.

g.The __________ allows computer users to locate and view multimedia-based documents on almost any subject over the Internet.

h.__________ allows a Java program to perform multiple activities in parallel.

1.2 Fill in the blanks in each of the following sentences about the Java environment:

a.The __________ command from the J2SE Development Kit executes a Java application.

b.The __________ command from the J2SE Development Kit compiles a Java program.

c.A Java program file must end with the __________ file extension.

d.When a Java program is compiled, the file produced by the compiler ends with the __________ file extension.

e.The file produced by the Java compiler contains __________ that are executed by the Java Virtual Machine.

1.3 Fill in the blanks in each of the following statements (based on Section 1.16):

a.Objects have the property of __________although objects may know how to communicate with one another across well-defined interfaces, they normally are not allowed to know how other objects are implemented.

b.Java programmers concentrate on creating __________, which contain fields and the set of methods that manipulate those fields and provide services to clients.

c.Classes can have relationships with other classes. These relationships are called __________.

d.The process of analyzing and designing a system from an object-oriented point of view is called __________.

e.OOD also takes advantage of __________ relationships, where new classes of objects are derived by absorbing characteristics of existing classes then

adding unique characteristics of their own.

f.__________ is a graphical language that allows people who design software systems to use an industry standard notation to represent them.

g.The size, shape, color and weight of an object are considered__________of the object.

[Page 32 (continued)]

Answers to Self-Review Exercises

1.1 a) Apple. b) IBM Personal Computer. c) programs. d) input unit, output unit, memory unit, arithmetic and logic unit, central processing unit, secondary storage unit. e) machine languages, assembly languages, high-level languages. f) compilers. g) World Wide Web. h) Multithreading.

1.2 a) java. b) javac. c) .java. d) .class. e) bytecodes.

1.3 a) information hiding. b) classes. c) associations. d) object-oriented analysis and design (OOAD). e) inheritance. f) The Unified Modeling Language (UML). g) attributes.

[Page 33]

Exercises

1.4Categorize each of the following items as either hardware or software:

a.CPU

b.Java compiler

c.JVM

d.input unit

e.editor

1.5Fill in the blanks in each of the following statements:

a.The logical unit of the computer that receives information from outside the computer for use by the computer is the __________.

b.The process of instructing the computer to solve a problems is called

__________.

c.__________ is a type of computer language that uses English-like abbreviations for machine-language instructions.

d.__________ is a logical unit of the computer that sends information which has already been processed by the computer to various devices so that it may be used outside the computer.

e.__________ and __________ are logical units of the computer that retain information.

f.__________ is a logical unit of the computer that performs calculations.

g.__________ is a logical unit of the computer that makes logical decisions.

h.__________ languages are most convenient to the programmer for writing programs quickly and easily.

i.The only language that a computer can directly understand is that computer's

__________.

j. __________ is a logical unit of the computer that coordinates the activities of all the other logical units.

1.6What is the difference between fatal errors and nonfatal errors? Why might you prefer to experience a fatal error rather than a nonfatal error?

1.7Fill in the blanks in each of the following statements:

a.__________ is now used to develop large-scale enterprise applications, to enhance the functionality of Web servers, to provide applications for consumer devices and for many other purposes.

b.__________ was designed specifically for the .NET platform to enable programmers to migrate easily to .NET.

c.__________ initially became widely known as the development language of the UNIX operating system.

d.__________ was developed at Dartmouth College in the mid-1960s as a means of writing simple programs.

e.__________ was developed by IBM Corporation in the mid-1950s to be used for scientific and engineering applications that require complex mathematical computations.

f.__________ is used for commercial applications that require precise and efficient manipulation of large amounts of data.

g.__________ was developed by Bjarne Stroustrup in the early 1980s at Bell Laboratories (now part of Lucent).

1.8Fill in the blanks in each of the following statements (based on Section 1.13):

a.Java programs normally go through five phases__________, __________,

__________, __________and __________.

b.A(n) __________ provides many tools that support the software development process, such as editors for writing and editing programs, debuggers for locating logic errors in programs and many other features.

[Page 34]

c.The command java invokes the __________, which executes Java programs.

d.A(n) __________ is a software application that simulates a computer, but hides the underlying operating system and hardware from the programs that interact with the VM.

e.A(n) __________ program can run on multiple platforms.

f.The __________ takes the .class files containing the program's bytecodes and transfers them to primary memory.

g.The __________ examines bytecodes to ensure that they are valid.

1.9Explain the two compilation phases of Java programs.

[Page 35]

Chapter 2. Introduction to Java Applications

What's in a name? that which we call a rose By any other name would smell as sweet.

William Shakespeare

When faced with a decision, I always ask, "What would be the most fun?"

Peggy Walker

"Take some more tea," the March Hare said to Alice, very earnestly. "I've had nothing yet, "Alice replied in an offended tone: "so I can't take more." "You mean you can't take less," said the Hatter: "it's very easy to take more than nothing."

Lewis Carroll

OBJECTIVES

In this chapter you will learn:

To write simple Java applications.

To use input and output statements.

Java's primitive types.

Basic memory concepts.

To use arithmetic operators.

The precedence of arithmetic operators.

To write decision-making statements.

To use relational and equality operators.

[Page 36]

Outline

2.1 Introduction

2.2 First Program in Java: Printing a Line of Text

2.3 Modifying Our First Java Program

2.4 Displaying Text with printf

2.5 Another Java Application: Adding Integers

2.6 Memory Concepts

2.7 Arithmetic

2.8 Decision Making: Equality and Relational Operators

2.9 (Optional) Software Engineering Case Study: Examining the Requirements Document

2.10 Wrap-Up

Summary

Terminology

Self-Review Exercises

Answers to Self-Review Exercises

Exercises

[Page 36 (continued)]

2.1. Introduction

We now introduce Java application programming which facilitates a disciplined approach to program design. Most of the Java programs you will study in this book process information and display results. We present six examples that demonstrate how your programs can display messages and how they can obtain information from the user for processing. We begin with several examples that simply display messages on the screen. We then demonstrate a program that obtains two numbers from a user, calculates their sum and displays the result. You will learn how to perform various arithmetic calculations and save their results for later use. Many programs contain logic that requires the program to make decisions. The last example in this chapter demonstrates decision-making fundamentals by showing you how to compare numbers then display messages based on the comparison results. For example, the program displays a message indicating that two numbers are equal only if they have the same value. We analyze each example one line at a time to help you ease your way into Java programming. To help you apply the skills you learn here, we provide many fun and challenging problems in the chapter's exercises.