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

AhmadLang / Java, How To Program, 2004

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

a.test object-oriented systems

b.design object-oriented systems

c.implement object-oriented systems

d.Both a and b

Answers to Section 1.16 Self-Review Exercises

1.1 [Note: Answers may vary.] a) A television's attributes include the size of the screen, the number of colors it can display, its current channel and its current volume. A television turns on and off, changes channels, displays video and plays sounds. b) A coffee maker's attributes include the maximum volume of water it can hold, the time required to brew a pot of coffee and the temperature of the heating plate under the coffee pot. A coffee maker turns on and off, brews coffee and heats coffee. c) A turtle's attributes include its age, the size of its shell and its weight. A turtle walks, retreats into its shell, emerges from its shell and eats vegetation.

1.2 c.

1.3 b.

[Page 26]

1.17. Wrap-Up

This chapter introduced basic hardware and software concepts, and basic object technology concepts, including classes, objects, attributes, behaviors, encapsulation, inheritance and polymorphism. We discussed the different types of programming languages and which programming languages are most widely used. You learned the steps for creating and executing a Java application using Sun's JDK 5.0. The chapter explored the history of the Internet and the World Wide Web and Java's role in developing distributed client/ server applications for the Internet and the Web. You also learned about the history and purpose of the UMLthe industry-standard graphical language for modeling software systems. Finally, you "test drove" a sample Java application similar to the types of applications you will learn to program in this book.

In the next chapter, you will create your first Java applications. You will see several examples that demonstrate how programs display messages and obtain information from the user for processing. We closely analyze and explain each example to help ease your way into Java programming.

[Page 26 (continued)]

1.18. Web Resources

This section provides many Web resources that will be useful to you as you learn Java. The sites include Java resources, Java development tools for students and professionals, and our own Web sites where you can find downloads and resources associated with this book. We also provide a link where you can subscribe to our free Deitel Buzz Online e-mail newsletter.

Deitel & Associates Web Sites

www.deitel.com/books/jHTP6/index.html

The Deitel & Associates home page for Java How to Program, Sixth Edition. Here you will find links to the book's examples (also included on the CD that accompanies the book) and other resources, such as our free Dive Into™ guides that help you get started with several Java integrated development environments (IDEs).

www.deitel.com

Please check the Deitel & Associates home page for updates, corrections and additional resources for all Deitel publications.

www.deitel.com/newsletter/subscribe.html

Please visit this site to subscribe to the free Deitel Buzz Online e-mail newsletter to follow the Deitel & Associates publishing program.

www.prenhall.com/deitel

Prentice Hall's home page for Deitel publications. Here you will find detailed product information, sample chapters and Companion Web Sites containing bookand chapter-specific resources for students and instructors.

Sun Microsystems Web Sites

java.sun.com

Sun's home page for Java technology. Here you will find downloads, reference guides for developers, community forums, online tutorials and many other valuable Java resources.

java.sun.com/j2se

The home page for the Java 2 Platform, Standard Edition.

[Page 27]

java.sun.com/j2se/5.0/download.jsp

The download page for the Java 2 Platform, Standard Edition version 5.0 and its documentation. This development kit includes everything you need to compile and execute your Java applications. Please note that as Sun updates Java, the number 5.0 in the preceding URL will change. You can always go to java.sun.com/j2se to locate the most recent version of Java.

java.sun.com/j2se/5.0/install.html

Instructions for installing the JDK version 5.0 on Solaris, Windows and Linux platforms. Please check this site if you are having difficulty installing Java on your computer. Also please note that as Java is updated, 5.0 in the preceding URL will change. You can always go to java.sun.com/j2se to locate the most recent version of Java.

java.sun.com/learning/new2java/index.html

The "New to Java Center" on the Sun Microsystems Web site features online training resources to help you get started with Java programming.

java.sun.com/j2se/5.0/docs/api/index.html

This site provides the Java 2 Platform, Standard Edition version 5.0 API documentation. Refer to this site to learn about the Java class library's predefined classes and interfaces.

java.sun.com/reference/docs/index.html

Sun's documentation site for all Java technologies. Here you will find technical information on all Java technologies, including API (application programming interface) specifications for Java and related Sun technologies.

java.sun.com/products/hotspot

Visit the product information page for Sun's HotSpot virtual machine and compiler, a standard component of the Java 2 Runtime Environment and the JDK, for the latest information on high-speed Java program translation.

developers.sun.com

Sun's home page for Java developers provides downloads, APIs, code samples, articles with technical advice and other resources on the best Java development practices.

Editors and Integrated Development Environments

www.download.com

A site that contains freeware and shareware application downloads. In particular, several editors are available at this site that can be used to edit Java source code.

www.eclipse.org

The home page for the Eclipse development environment, which can be used to develop code in any programming language. You can download the environment and several Java plug-ins to use this environment to develop your Java programs.

www.netbeans.org

The home page for the NetBeans IDE, one of the most widely used, freely distributed Java development tools.

borland.com/products/downloads/download_jbuilder.html

Borland provides a free Foundation Edition version of its popular Java IDE JBuilder. The site also provides 30-day trial versions of the Enterprise and Developer editions.

www.blueJ.org

The home page for the BlueJ environmenta tool designed to help teach object-oriented Java to new programmers. BlueJ is available as a free download.

www.jgrasp.org

The home page for jGRASP provides downloads, documentation and tutorials for this tool that displays visual representations of Java programs to aid comprehension.

[Page 28]

www.jedit.org

The home page for jEdita text editor for programmers that is written in Java.

wwws.sun.com/software/sundev/jde/

The home page for Sun Java Studiothe Sun Microsystems enhanced version of NetBeans.

www.jcreator.com

The home page for JCreatora popular Java IDE. JCreator Lite Edition is available as a free download. A 30-day trial version of JCreator Pro Edition is also available.

Additional Java Resource Sites

www.javalobby.org

Provides up-to-date Java news, forums where developers can exchange tips and advice, and a comprehensive Java knowledge base organizing articles and downloads from across the Web.

www.jguru.com

Provides forums, downloads, articles, online courses and a large collection of Java FAQs (Frequently Asked Questions).

www.javaworld.com

Provides resources for Java developers, such as articles, indices of popular Java books, tips and FAQs.

www.ftponline.com/javapro

The home page for the JavaPro magazine features monthly articles, programming tips, book reviews and more.

sys-con.com/java/

The home page for the Java Developer's Journal from Sys-Con Media, provides articles, e-books and other Java resources.

[Page 28 (continued)]

Summary

The various devices that comprise a computer system (e.g., the keyboard, screen, disks, memory and processing units) are referred to as hardware.

The computer programs that run on a computer are referred to as software.

Java is one of today's most popular software development languages. Java is a fully objectoriented language with strong support for proper software-engineering techniques.

A computer is a device capable of performing computations and making logical decisions at speeds millions, even billions, of times faster than humans can.

Computers process data under the control of sets of instructions called computer programs. Computer programs guide the computer through actions specified by computer programmers.

The input unit is the "receiving" section of the computer. It obtains information from input devices and places it at the disposal of other units for processing.

The output unit is the "shipping" section of the computer. It takes information processed by the computer and places it on output devices to make it available for use outside the computer.

The memory unit is the rapid-access, relatively low-capacity "warehouse" section of the

computer. It retains information that has been entered through the input unit, making it immediately available for processing when needed, and retains information that has already been processed until that information can be placed on output devices by the output unit.

The arithmetic and logic unit (ALU) is the "manufacturing" section of the computer. It is responsible for performing calculations and making decisions.

The central processing unit (CPU) is the "administrative" section of the computer. It coordinates and supervises the operation of the other sections.

[Page 29]

The secondary storage unit is the long-term, high-capacity "warehousing" section of the

computer. Programs or data not being used by the other units are normally placed on secondary storage devices (e.g., disks) until they are needed, possibly hours, days, months or even years later.

Software systems called operating systems were developed to help make it more convenient to use computers.

Multiprogramming involves the sharing of a computer's resources among the jobs competing for its attention, so that the jobs appear to run simultaneously.

With distributed computing, an organization's computing is distributed over networks to the sites where the work of the organization is performed.

Java has become the language of choice for developing Internet-based applications.

Any computer can directly understand only its own machine language. Machine languages

generally consist of strings of numbers (ultimately reduced to 1s and 0s) that instruct computers to perform their most elementary operations one at a time.

English-like abbreviations form the basis of assembly languages. Translator programs called assemblers convert assembly-language programs to machine language.

Compilers translate high-level language programs into machine-language programs. High-level languages (like Java) contain English words and conventional mathematical notations.

Interpreter programs directly execute high-level language programs, eliminating the need to compile them into machine language.

Java is used to create Web pages with dynamic and interactive content, develop large-scale

enterprise applications, enhance the functionality of Web servers, provide applications for consumer devices and more.

Java programs consist of pieces called classes. Classes include pieces called methods that perform tasks and return information when they complete their tasks.

C++ is an extension of C developed by Bjarne Stroustrup in the early 1980s at Bell Laboratories.

C++ provides a number of features that "spruce up" the C language, but more important, it provides capabilities for object-oriented programming.

FORTRAN (FORmula TRANslator) was developed by IBM Corporation in the mid-1950s for scientific and engineering applications that require complex mathematical computations.

COBOL (COmmon Business Oriented Language) was developed in the late 1950s by a group of

computer manufacturers and government and industrial computer users. COBOL is used primarily for commercial applications that require precise and efficient data manipulation.

Ada was developed under the sponsorship of the United States Department of Defense (DOD)

during the 1970s and early 1980s. One important capability of Ada is multitaskingthis allows programmers to specify that many activities are to occur in parallel. The Ada language was named after Lady Ada Lovelace, daughter of the poet Lord Byron. Lady Lovelace is credited with writing the world's first computer program in the early 1800s.

The BASIC (Beginner's All-Purpose Symbolic Instruction Code) programming language was

developed in the mid-1960s at Dartmouth College as a language for writing simple programs. BASIC's primary purpose was to familiarize novices with programming techniques.

Microsoft's Visual Basic was introduced in the early 1990s to simplify the process of developing Microsoft Windows applications.

Microsoft has a corporate-wide strategy for integrating the Internet and the Web into computer

applications. This strategy is implemented in Microsoft's .NET platform, which provides developers with the capabilities they need to create and run computer applications that can execute on computers distributed across the Internet.

[Page 30]

The .NET platform's three primary programming languages are Visual Basic .NET (based on the

original BASIC), Visual C++ .NET (based on C++) and C# (a new language based on C++ and Java that was developed expressly for the .NET platform).

Developers using .NET can write software components in the language they are most familiar

with and then form applications by combining those components with components written in any

.NET language.

Java, through a technique called multithreading, enables programmers to write programs with parallel activities.

Java programs normally go through five phasesedit, compile, load, verify and execute.

Java source code file names end with the .java extension.

The Java compiler (javac) TRanslates a Java program into bytecodesinstructions understood by

the Java Virtual Machine (JVM), which executes Java programs. If a program compiles correctly, the compiler produces a file with the .class extension. This is the file containing the bytecodes that are executed by the JVM.

A Java program must be placed in memory before it can execute. This is done by the class

loader, which takes the .class file (or files) containing the bytecodes and transfers it to memory. The .class file can be loaded from a disk on your system or over a network.

Object orientation is a natural way of thinking about the world and of writing computer programs.

The Unified Modeling Language (UML) is a graphical language that allows people who build systems to represent their object-oriented designs in a common notation.

Object-oriented design (OOD) models software components in terms of real-world objects. It

takes advantage of class relationships, where objects of a certain class have the same characteristics. It also takes advantage of inheritance relationships, where newly created classes of objects are derived by absorbing characteristics of existing classes and adding unique characteristics of their own. OOD encapsulates data (attributes) and functions (behavior) into objectsthe data and functions of an object are intimately tied together.

Objects have the property of information hidingobjects normally are not allowed to know how other objects are implemented.

Object-oriented programming (OOP) allows programmers to implement object-oriented designs as working systems.

In Java, the unit of programming is the class from which objects are eventually instantiated.

Java programmers concentrate on creating their own classes and reusing existing classes. Each class contains data and functions that manipulate that data. Function components are called methods.

An instance of a class is called an object.

Classes can have relationships with other classes. These relationships are called associations.

With object technology, programmers can build much of the software they will need by combining standardized, interchangeable parts called classes.

The process of analyzing and designing a system from an object-oriented point of view is called object-oriented analysis and design (OOAD).

[Page 30 (continued)]

Terminology

Ada

ALU (arithmetic and logic unit)

ANSI C

arithmetic and logic unit (ALU) assembler

assembly language attribute

BASIC behavior bytecode

[Page 31]

bytecode verifier C

C#

C++

central processing unit (CPU) class

.class file class libraries class loader

client/server computing COBOL

compile phase compiler compile-time error

computer computer program

computer programmer

CPU (central processing unit) disk

distributed computing dynamic content

edit phase editor encapsulation execute phase

execution-time error fatal runtime error file server

FORTRAN hardware high-level language HotSpot™ compiler

HTML (Hypertext Markup Language)

IDE (Integrated Development Environment) information hiding

inheritance input device input unit

input/output (I/O) Internet interpreter

Java

Java API (Java Application Programming Interface)

.java file-name extension