Java How to Program, 3/e

(Prentice Hall, July 1999)

[Dividing Line Image]

Table of Contents and A Tour of the Book
Contents    xxxi

  1. Introduction to Computers, the Internet and the Web
        1.1    Introduction   
        1.2    What is a Computer?   
        1.3    Computer Organization   
        1.4    Evolution of Operating Systems   
        1.5    Personal, Distributed Computing, and Client/Server Computing           
        1.6    Machine Languages, Assembly Languages, and High-level Languages           
        1.7    History of C++   
        1.8    History of Java   
        1.9    Java Class Libraries   
        1.10    Other High-level Languages   
        1.11    Structured Programming   
        1.12    The Internet and World Wide Web    
        1.13    Basics of a Typical Java Environment    
        1.14    General Notes About Java and this Book    
        1.15    A Tour of the Book   
    Summary • Terminology • Common Programming Error • Good Programming Practices • Performance Tips • Portability Tips • Software Engineering Observations • Testing and Debugging Tip • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  2. Introduction to Java Applications   
        2.1    Introduction   
        2.2    A Simple Program: Printing a Line of Text    
        2.3    Another Java Application: Adding Integers   
        2.4    Memory Concepts   
        2.5    Arithmetic   
        2.6    Decision Making: Equality and Relational Operators   
    Summary • Terminology • Common Programming Errors • Good Programming Practices • Software Engineering Observation • Testing and Debugging Tip • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  3. Introduction to Java Applets   
        3.1    Introduction   
        3.2    Thinking About Objects   
        3.3    Sample Applets from the Java 2 Software Development Kit   
        3.3.1    The TicTacToe Applet   
        3.3.2    The DrawTest Applet   
        3.3.3    The Java2D Applet   
        3.4    A Simple Java Applet: Drawing a String    
        3.5    Two More Simple Applets: Drawing Strings and Lines   
        3.6    Another Java Applet: Adding Floating-Point Numbers 
        3.7    Java Applet Internet and World Wide Web Resources    
    Summary • Terminology • Common Programming Errors • Good Programming Practices • Portability Tip • Software Engineering Observations • Testing and Debugging Tips • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  4. Control Structures: Part 1   
        4.1    Introduction   
        4.2    Algorithms   
        4.3    Pseudocode   
        4.4    Control Structures  
        4.5    The if Selection Structure   
        4.6    The if/else Selection Structure    
        4.7    The while Repetition Structure   
        4.8    Formulating Algorithms: Case Study 1 (Counter-Controlled Repetition)
        4.9    Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 2 (Sentinel-Controlled Repetition)            
        4.10    Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 3 (Nested Control Structures)   
        4.11    Assignment Operators   
        4.12    Increment and Decrement Operators    
        4.13    Primitive Data Types   
    Summary • Terminology • Common Programming Errors • Good Programming Practices • Performance Tips • Portability Tip • Software Engineering Observations • Testing and Debugging Tip • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  5. Control Structures: Part 2   
        5.1    Introduction   
        5.2    Essentials of Counter-Controlled Repetition    
        5.3    The for Repetition Structure   
        5.4    Examples Using the for Structure    
        5.5    The switch Multiple-Selection Structure    
        5.6    The do/while Repetition Structure    
        5.7    The break and continue Statements    
        5.8    The Labeled break and continue Statements    
        5.9    Logical Operators   
        5.10    Structured Programming Summary    
    Summary • Terminology • Common Programming Errors • Good Programming Practices • Performance Tips • Software Engineering Observations • Testing and Debugging Tip • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  6. Methods   
        6.1    Introduction   
        6.2    Program Modules in Java   
        6.3    Math Class Methods   
        6.4    Methods   
        6.5    Method Definitions   
        6.6    Java API Packages   
        6.7    Random Number Generation   
        6.8    Example: A Game of Chance   
        6.9    Duration of Identifiers   
        6.10    Scope Rules   
        6.11    Recursion   
        6.12    Example Using Recursion: The Fibonacci Series    
        6.13    Recursion vs. Iteration   
        6.14    Method Overloading   
        6.15    Methods of Class JApplet   
    Summary • Terminology • Common Programming Errors • Good Programming Practices • Performance Tips • Portability Tip • Software Engineering Observations • Testing and Debugging Tips • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  7. Arrays   
        7.1    Introduction   
        7.2    Arrays   
        7.3    Declaring and Allocating Arrays    
        7.4    Examples Using Arrays   
        7.5    References and Reference Parameters    
        7.6    Passing Arrays to Methods   
        7.7    Sorting Arrays   
        7.8    Searching Arrays: Linear Search and Binary Search    
        7.9    Multiple-Subscripted Arrays   
    Summary • Terminology • Common Programming Errors • Good Programming Practice • Performance Tips • Software Engineering Observations • Testing and Debugging Tips • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  8. Object-Based Programming   
        8.1    Introduction   
        8.2    Implementing a Time Abstract Data Type with a Class   
        8.3    Class Scope   
        8.4    Controlling Access to Members   
        8.5    Creating Packages   
        8.6    Initializing Class Objects: Constructors    
        8.7    Using Overloaded Constructors   
        8.8    Using Set and Get Methods   
        8.9    Software Reusability   
        8.10    Final Instance Variables   
        8.11    Composition: Objects as Instance Variables of Other Classes   
        8.12    Package Access   
        8.13    Using the this Reference   
        8.14    Finalizers   
        8.15    Static Class members   
        8.16    Data Abstraction and Information Hiding    
        8.16.1    Example: Queue Abstract Data Type    
    Summary • Terminology • Common Programming Errors • Good Programming Practices • Performance Tips • Software Engineering Observations • Testing and Debugging Tips • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  9. Object-Oriented Programming   
        9.1    Introduction   
        9.2    Superclasses and Subclasses   
        9.3    protected Members   
        9.4    Relationship between Superclass Objects and Subclass Objects   
        9.5    Constructors and Finalizers in Subclasses    
        9.6    Implicit Subclass-Object-to-Superclass-Object Conversion   
        9.7    Software Engineering with Inheritance    
        9.8    Composition vs. Inheritance   
        9.9    Case Study: Point, Circle, Cylinder    
        9.10    Introduction to Polymorphism   
        9.11    Type Fields and switch Statements    
        9.12    Dynamic Method Binding   
        9.13    final Methods and Classes 
        9.14    Abstract Superclasses and Concrete Classes    
        9.15    Polymorphism Examples   
        9.16    Case Study: A Payroll System Using Polymorphism    
        9.17    New Classes and Dynamic Binding    
        9.18    Case Study: Inheriting Interface and Implementation   
        9.19    Case Study: Creating and Using Interfaces    
        9.20    Inner Class Definitions   
        9.21    Notes on Inner Class Definitions    
        9.22    Type-Wrapper Classes for Primitive Types    
    Summary • Terminology • Common Programming Errors • Good Programming Practice • Performance Tips • Software Engineering Observations • Testing and Debugging Tips • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  10. Strings and Characters   
        10.1    Introduction   
        10.2    Fundamentals of Characters and Strings    
        10.3    String Constructors   
        10.4    String Methods length, charAt and getChars    
        10.5    Comparing Strings   
        10.6    String Method hashCode   
        10.7    Locating Characters and Substrings in Strings    
        10.8    Extracting Substrings from Strings    
        10.9    Concatenating Strings   
        10.10    Miscellaneous String Methods   
        10.11    Using String Method valueOf   
        10.12    String Method intern   
        10.13    StringBuffer Class   
        10.14    StringBuffer Constructors   
        10.15    StringBuffer Methods length, capacity. setLength and ensureCapacity            
        10.16    StringBuffer Methods charAt, setCharAt, getChars and reverse           
        10.17    StringBuffer append Methods   
        10.18    StringBuffer Insertion and Deletion Methods    
        10.19    Character Class Examples   
        10.20    Class StringTokenizer   
        10.21    A Card Shuffling and Dealing Simulation    
    Summary • Terminology • Common Programming Errors • Performance Tips • Software Engineering Observations • Self-Review Exercises • Answers to Self-Review Exercises • Exercises • Special Section: Advanced String Manipulation Exercises • Special Section: Challenging String Manipulation Projects

  11. Graphics and Java2D   
        11.1    Introduction   
        11.2    Graphics Contexts and Graphics Objects    
        11.3    Color Control   
        11.4    Font Control   
        11.5    Drawing lines, Rectangles and Ovals    
        11.6    Drawing Arcs   
        11.7    Drawing Polygons and Polylines    
        11.8    The Java2D API   
        11.9    Java2D Shapes   
    Summary • Terminology • Common Programming Errors • Portability Tips • Software Engineering Observations • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  12. Basic Graphical User Interface Components   
        12.1    Introduction   
        12.2    Swing Overview   
        12.3    JLabel   
        12.4    Event Handling Model   
        12.5    JTextField and JPasswordField   
        12.5.1    How Event Handling Works   
        12.6    JButton   
        12.7    JCheckBox and JRadioButton   
        12.8    JComboBox   
        12.9    JList   
        12.10    Multiple-Selection Lists   
        12.11    Mouse Event Handling   
        12.12    Adapter Classes   
        12.13    Keyboard Event Handling   
        12.14    Layout Managers   
        12.14.1    FlowLayout   
        12.14.2    BorderLayout   
        12.14.3    GridLayout   
        12.15    Panels   
    Summary • Terminology • Common Programming Errors • Good Programming Practices • Look-and-Feel Observations • Portability Tips • Software Engineering Observations • Testing and Debugging Tips • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  13. Advanced Graphical User Interfaces   
        13.1    Introduction   
        13.2    JTextArea   
        13.3    Creating a Customized Subclass of JPanel    
        13.4    Creating a Self-Contained Subclass of JPanel    
        13.5    JSlider   
        13.6    Windows   
        13.7    Designing Programs that Execute as Applets or Applications   
        13.8    Using Menus with Frames   
        13.9    Using JPopupMenus   
        13.10    Pluggable Look-and-Feel   
        13.11    Using JDesktopPane and JInternalFrame    
        13.12    Layout Managers   
        13.13    BoxLayout Layout Manager   
        13.14    CardLayout Layout Manager   
        13.15    GridBagLayout Layout Manager   
        13.16    GridBagConstraints Constants RELATIVE and REMAINDER   
    Summary • Terminology • Common Programming Errors • Look-and-Feel Observations • Performance Tip • Portability Tips • Software Engineering Observations • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  14. Exception Handling   
        14.1    Introduction   
        14.2    When Exception Handling Should Be Used    
        14.3    Other Error Handling Techniques    
        14.4    The Basics of Java Exception Handling    
        14.5    An Exception Handling Example: Divide by Zero    
        14.6    Try Blocks   
        14.7    Throwing an Exception   
        14.8    Catching an Exception   
        14.9    Rethrowing an Exception   
        14.10    Throws Clause   
        14.11    Constructors, Finalizers and Exception Handling    
        14.12    Exceptions and Inheritance   
        14.13    finally Block   
        14.14    Using printStackTrace and getMessage    
    Summary • Terminology • Common Programming Errors • Good Programming Practices • Performance Tips • Software Engineering Observations • Testing and Debugging Tips • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  15. Multithreading   
        15.1    Introduction   
        15.2    Class Thread: An Overview of the Thread Methods    
        15.3    Thread States: Life Cycle of a Thread    
        15.4    Thread Priorities and Thread Scheduling    
        15.5    Thread Synchronization   
        15.6    Producer/Consumer Relationship without Thread Synchronization   
        15.7    Producer/Consumer Relationship with Thread Synchronization   
        15.8    Producer/Consumer Relationship: The Circular Buffer   
        15.9    Daemon Threads   
        15.10    Runnable Interface   
        15.11    Thread Groups   
    Summary • Terminology • Common Programming Errors • Performance Tips • Portability Tips • Software Engineering Observation • Testing and Debugging Tips • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  16. Multimedia: Images, Animation, Audio and Video   
        16.1    Introduction   
        16.2    Downloading the Java Media Framework    
        16.3    Loading, Displaying and Scaling Images    
        16.4    Loading and Playing Audio Clips    
        16.5    The Java Media Player   
        16.6    Animating a Series of Images   
        16.7    Animation Issues   
        16.8    Customizing Applets via the HTML param Tag    
        16.9    Image Maps   
        16.10    Java Plug-In   
        16.11    Internet and World Wide Web Resources    
    Summary • Terminology • Good Programming Practice • Look-and-Feel Observations • Performance Tips • Portability Tips • Software Engineering Observation • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  17. Files and Streams   
        17.1    Introduction   
        17.2    Data Hierarchy   
        17.3    Files and Streams   
        17.4    Creating a Sequential-Access File    
        17.5    Reading Data from a Sequential-Access File    
        17.6    Updating Sequential-Access Files    
        17.7    Random-Access Files   
        17.8    Creating a Random-Access File   
        17.9    Writing Data Randomly to a Random-Access File    
        17.10    Reading Data Sequentially from a Random-Access File   
        17.11    Example: A Transaction-Processing Program    
        17.12    Class File   
    Summary • Terminology • Common Programming Errors • Good Programming Practices • Performance Tips • Software Engineering Observation • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  18. Java Database Connectivity (JDBC)   
        18.1    Introduction   
        18.2    Database Systems   
        18.2.1    Advantages of Database Systems    
        18.2.2    Data Independence   
        18.2.3    Database Languages   
        18.2.4    Distributed Database   
        18.3    Relational Database Model   
        18.4    Relational Database Overview: The Books.mdb Database   
        18.5    Structured Query Language   
        18.5.1    Basic SELECT Query   
        18.5.2    WHERE Clause   
        18.5.3    ORDER BY Clause   
        18.5.4    Using INNER JOIN to Merge Data from Multiple Tables   
        18.5.5    TitleAuthor Query from Books.mdb    
        18.6    A First Example   
        18.6.1    Registering Books.mdb as an ODBC Data Source    
        18.6.2    Querying the Books.mdb Database    
        18.7    Reading, Inserting and Updating a Microsoft Access database   
        18.8    Transaction Processing   
    Summary • Terminology • Common Programming Errors • Good Programming     Practice • Performance Tip • Portability Tips • Software Engineering Observations • Self-Review Exercises • Answers to Self-Review Exercises • Exercises • Bibliography

  19. Servlets   
        19.1    Introduction   
        19.2    Overview of Servlet Technology    
        19.2.1    The Servlet API   
        19.2.2    HttpServlet Class   
        19.2.3    HttpServletRequest Interface    
        19.2.4    HttpServletResponse Interface    
        19.3    Downloading the Java Servlet Development Kit    
        19.4    Handling HTTP GET Requests   
        19.5    Handling HTTP POST Requests   
        19.6    Session Tracking   
        19.6.1    Cookies   
        19.6.2    Session Tracking with HttpSession    
        19.7    Multitier Applications: Using JDBC from a Servlet   
        19.8    Electronic Commerce   
        19.9    Servlet Internet and World Wide Web Resources    
    Summary • Terminology • Software Engineering Observations • Testing and Debugging Tips • Self-Review Exercises • Answers to Self-Review Exercises •
    Exercises

  20. Remote Method Invocation (RMI)  
        20.1    Introduction  
        20.2    Case Study: Creating a Distributed System with RMI   
        20.3    Defining the Remote Interface   
        20.4    Implementing the Remote Interface    
        20.5    Define the Client   
        20.6    Compile and Execute the Server and the Client    
    Summary • Terminology • Common Programming Errors • Software Engineering     Observations • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  21. Networking   
        21.1    Introduction   
        21.2    Manipulating URLs   
        21.3    Reading a File on a Web Server    
        21.4    Establishing a Simple Server (Using Stream Sockets)   
        21.5    Establishing a Simple Client (Using Stream Sockets)   
        21.6    Client/Server Interaction with Stream Socket Connections   
        21.7    Connectionless Client/Server Interaction with Datagrams   
        21.8    Client/Server Tic-Tac-Toe Using a Multithreaded Server   
        21.9    Security and the Network   
    Summary • Terminology • Common Programming Errors • Performance Tips • Portability Tip • Software Engineering Observations • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  22. Data Structures   
        22.1    Introduction   
        22.2    Self-Referential Classes   
        22.3    Dynamic Memory Allocation   
        22.4    Linked Lists   
        22.5    Stacks   
        22.6    Queues   
        22.7    Trees   
    Summary • Terminology • Common Programming Errors • Good Programming Practice • Performance Tips • Self-Review Exercises • Answers

  23. Java Utilities Package and Bit Manipulation   
        23.1    Introduction   
        23.2    Vector Class and Enumeration Interface    
        23.3    Stack Class   
        23.4    Dictionary Class   
        23.5    Hashtable Class   
        23.6    Properties Class   
        23.7    Random Class   
        23.8    Bit Manipulation and the Bitwise Operators    
        23.9    BitSet Class   
    Summary • Terminology • Common Programming Errors • Performance Tips • Testing and Debugging Tips • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  24. Collections   
        24.1    Introduction   
        24.2    Overview   
        24.3    Class Arrays   
        24.4    Interface Collection and Class Collections    
        24.5    Lists   
        24.6    Algorithms   
        24.6.1    Algorithm sort   
        24.6.2    Algorithm shuffle   
        24.6.3    Algorithms reverse, fill, copy, max and min    
        24.6.4    Algorithm binarySearch   
        24.7    Sets   
        24.8    Maps   
        24.9     Synchronization Wrappers    
        24.10    Unmodifiable Wrappers   
        24.11    Abstract Implementations   
    Summary • Terminology • Common Programming Errors • Performance Tips • Software Engineering Observations • Self-Review Exercises • Answers to Self-Review Exercises

  25. JavaBeans   
        25.1    Introduction   
        25.2    BeanBox Overview   
        25.3    Preparing a Class to Be a JavaBean    
        25.4    Creating a JavaBean: Java Archive Files and the jar Utility   
        25.5    Adding Beans to the BeanBox   
        25.6    Connecting Beans with Events in the BeanBox    
        25.7    Adding Properties to a JavaBean    
        25.8    Creating a JavaBean with a Bound Property    
        25.9    Specifying the BeanInfo Class for a JavaBean    
        25.10    JavaBeans World Wide Web Resources    
    Summary • Terminology • Common Programming Errors • Good Programming Practice • Software Engineering Observations • Testing and Debugging Tip • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  1. Demos   
        A.1    Introduction   
        A.2    The Sites   

  2. Java Resources   
        B.1    Introduction   
        B.2    Resources   
        B.3    Products   
        B.4    FAQs   
        B.5    Tutorials   
        B.6    Magazines   
        B.7    Java Applets   
        B.8    Multimedia   
        B.9    Servlets   
        B.10    JavaBeans   
        B.11    Java CORBA   
        B.12    Newsgroups   

  3. Operator Precedence Chart   

  4. ASCII Character Set   

  5. Number Systems   
        E.1    Introduction   
        E.2    Abbreviating Binary Numbers as Octal Numbers and Hexadecimal Numbers           
        E.3    Converting from Octal Numbers and Hexadecimal Numbers to Binary Numbers            
        E.4    Converting from Binary, Octal, or Hexadecimal to Decimal   
        E.5    Converting from Decimal to Binary, Octal, or Hexadecimal   
        E.6    Negative Binary Numbers: Two’s Complement Notation   
    Summary • Terminology • Self-Review Exercises • Answers to Self-Review Exercises • Exercises

  6. Object-Oriented Elevator Simulator   
        F.1    Introduction   
        F.2    Problem Statement   
        F.3    Elevator Laboratory Assignment 1    
        F.4    Elevator Laboratory Assignment 2    
        F.5    Elevator Laboratory Assignment 3    
        F.6    Elevator Laboratory Assignment 4    
        F.7    Elevator Laboratory Assignment 5    
        F.8    Elevator Laboratory Assignment 6    
        F.9    Elevator Laboratory Assignment 7    
        F.10    Elevator Laboratory Assignment 8    
        F.11    Elevator Laboratory Assignment 9    
        F.12    Elevator Laboratory Assignment 10    
        F.13    Elevator Laboratory Assignment 11    
        F.14    Elevator Laboratory Assignment 12    
        F.15    Design Review Questions   
        F.16    Recommended Modifications   

  7. Creating HTML Documentation with javadoc   
        G.1    Introduction   
        G.2    Documentation Comments   
        G.3    Documenting Java Source Code   
        G.4    javadoc   
        G.5    Files Produced by javadoc   

  8. Enterprise JavaBeans (EJB) Web Resources   
        H.1    Introduction   
        H.2    Tutorials        
        H.3    Demos   
        H.4    Resources   
        H.5    Developers  
        H.6    Specifications   
        H.7    Frequently Asked Questions (FAQs)    
        H.8    Magazines   

  9. Jini Web Resources   
        I.1    Introduction   
        I.2    Tutorials   
        I.3    Resources   
        I.4    Demos   
        I.5    Specifications   
        I.6    FAQs   
        I.7    Magazines   

 

Excerpt from Chapter 1

1.15 A Tour of the Book

You are about to study one of today's most exciting and rapidly developing computer programming languages. Mastering Java will help you develop powerful business and personal computer applications software. In this section we take a tour of the many capabilities of Java you will study in Java How to Program: Third Edition.

Chapter 1: Introduction to Computers, the Internet and the World Wide Web

In Chapter 1, we present some historical information about computers and computer programming, and introductory information about Java, the Internet and World Wide Web. We overview the several tools provided with Sun's Java 2 Software Development Kit (J2SDK). We also present an overview of the remaining chapters in the book.

Chapter 2: Introduction to Java Applications

In Chapter 2, we present our first Java programs. The book uses a technique we call the live-code approach. Every concept is presented in the context of a complete working Java program which is immediately followed by the screen output produced when that program is executed on a computer. With Java you can write two kinds of programs: namely, applets, designed to be transported over the Internet and executed in World Wide Web browsers like Netscape Communicator, Microsoft's Internet Explorer and Sun's HotJava, and stand-alone applications, which are stored on your own computer and are designed to execute independent of a World Wide Web browser. This chapter concentrates on several basic applications. By the end of this chapter you will be writing Java applications that can display information on the screen for the user and input information from the user at the keyboard.

Chapter 3: Introduction to Java Applets

In Chapter 3, we present applets, which are designed to be transported over the Internet and executed in World Wide Web browsers. This chapter introduces applets by mimicking several examples from Chapter 2 so you can compare and contrast the two approaches. Because of the flexibility of working with applets as you learn Java, we use many applets in the early chapters. However, the book focuses on Java application development once the fundamental concepts are presented. In Chapters 2 and 3 (and throughout the book), we introduce various graphical user interface (GUI) components. These and other GUI components are discussed in detail in Chapters 12 and 13.

Chapter 4: Control Structures: Part 1

In Chapter 4, we focus on the program development process. The chapter discusses how to take a problem statement (i.e., a requirements document) and from it develop a working Java program. The chapter introduces some fundamental data types and some simple control structures used for decision making.

Chapter 5: Control Structures: Part 2

Chapter 5 discusses much of the material Java has in common with C, especially the sequence, selection and repetition control structures. The chapter uses flowcharts to show the flow of control through each of the control structures. The chapter concludes with a structured programming summary that enumerates each of the control structures. The techniques discussed in Chapters 4 and 5 constitute a large part of what has been traditionally taught in the universities under the topic of structured programming. With Java we seek to do object-oriented programming. We will discover that the insides of objects can make abundant use of control structures.

Chapter 6: Methods

In Chapter 6, we take a deeper look inside objects. Objects contain data that we will generally refer to as instance variables, and executable units called methods (often called functions in non-object-oriented, procedural programming languages like C). We explore methods in depth and include a discussion of recursive methods, i.e., methods that (strangely) call themselves. We enhance our graphical user interface (GUI) discussions to illustrate how to create buttons and text fields and attach them to applets. We also begin our discussions of event-driven programming--causing a program to perform a task in response to user interactions with GUI components. The GUI techniques introduced here are used in applications starting in Chapter 9.

Chapter 7: Arrays

Chapter 7 explores the processing of data in lists and tables of values called arrays. Arrays in Java are processed as objects, further evidence of Java's commitment to almost 100% object orientation.

Chapter 8: Object-Based Programming

Chapter 8 focuses on the essence and terminology of objects. What is an object? What is a class of objects? What does the inside of an object look like? How are objects created? How are they destroyed? How do objects communicate with one another? Why are classes such a natural mechanism for packaging software as reusable componentry? We begin defining applications that execute in their own windows that have a variety of GUI components attached to them.

Chapter 9: Object-Oriented Programming

Chapter 9 discusses the relationships among classes of objects and programming with related classes. How can we exploit commonality between classes of objects to minimize the amount of work it takes to build large software systems? What does it mean to "program in the general" rather than "programming in the specific"? How does programming in the general make it easy to modify software systems and add new features with minimal effort? How can we program for a whole category of objects rather than programming individually for each type of object? This chapter introduces applications that execute in their own window (JFrame). Such an application can have its own graphical user interface (as designed by the programmer). In this context, the chapter demonstrates inner classes and continues our discussion of event handling.

Chapter 10: Strings and Characters

Chapter 10 deals with the processing of words, sentences, characters and groups of characters. The key difference between Java and C here is that Java strings are objects, thus making string manipulation more convenient than in C, but more important, safer than in C, where string manipulation, like array manipulation, is based on dangerous pointers.

Chapter 11: Graphics and Java2D

Chapter 11 begins to introduce the multimedia "sizzle" of Java. Traditional C and C++ programming are pretty much confined to character mode input/output. Some versions of C++ are supported by platform-dependent class libraries that can do graphics, but using one of these libraries makes your applications nonportable. The beauty of Java's graphics capabilities is that they are platform independent and hence, portable.

Chapter 12: Basic Graphical User Interface Components
Chapter 13: Advanced Graphical User Interface Components

Chapter 12 introduces the creation of applets and applications with user-friendly graphical user interfaces (GUIs). Chapter 13 continues the discussion started in Chapter 12. Once again, the key to Java's treatment of these subjects is platform independence. A GUI-based applet or application developed once will run on all Java platforms. This text focuses on Swing GUI components. These platform-independent GUI components are written completely in Java. This provides the Swing GUI components with unparalleled flexibility--the GUI components can be customized to look like the user interface components of the computer platform on which the program executes, or they can use the standard Java look-and-feel that provides an identical user interface across all computer platforms.

Chapter 14: Exception Handling

Chapter 14 is one of the most important chapters in the book from the standpoint of building so-called mission-critical or business-critical applications. Things do go wrong, and in fact at today's computer speeds--commonly hundreds of millions of operations per second--if something can go wrong it probably will, and rather quickly at that. Programmers are often a bit naive about using prebuilt components. They ask, "How do I ask a component to do something for me?" They also ask "What value(s) does that component return to me to indicate it has performed the job I asked it to do?" But programmers also need to be concerned with, "What happens when the component I call upon to do a job for me experiences difficulty? How will that component signal to me that it had a problem?" In Java, when a component (i.e., a class object) encounters difficulty, it can "throw" an exception. The environment of that component is programmed to "catch" that exception and deal with it. Java's exception-handling capabilities are especially geared to an object-oriented world in which programmers construct software systems largely from reusable components built by other programmers. To use a Java component, you need to know not only how that component behaves when "things go well," but what exceptions that component throws when "things go poorly."

Chapter 15: Multithreading

Chapter 15 deals with how to program applets and applications that can perform multiple activities in parallel. Although our bodies are quite good at this (breathing, eating, blood circulation, vision, hearing, etc. can all occur in parallel), our conscious minds have trouble with this. Computers used to be built with a single rather expensive processor. Today, processors are becoming so inexpensive that it is possible to build computers with many processors that work in parallel--such computers are called multiprocessors. The trend is clearly toward computers that can perform many tasks in parallel. Most of today's programming languages, including C and C++, do not include features for expressing parallel operations. These languages are often referred to as sequential programming languages or single-thread-of-control languages. Java includes capabilities to enable multithreaded applications (i.e., applications that can specify that multiple activities are to occur in parallel). This makes Java better prepared to deal with the more sophisticated multimedia, network-based multiprocessor-based applications that programmers will be introducing in the new millennium. As we will see, multithreading is even effective on single-processor systems.

Chapter 16: Multimedia: Images, Animation, Audio and Video

Chapter 16 deals with Java's capabilities for images, animation, audio and video, and introduces the Java Media Player. It is remarkable that students in first programming courses will be writing applications with all these capabilities. The possibilities are intriguing and endless. Imagine having access (over the Internet and through CD-ROM technology) to vast libraries of graphics images, audios and videos and being able to weave your own together with those in the libraries to form applications. Already more than half the new computers sold come multimedia equipped with CD readers and sound cards.

Chapter 17: Files and Streams
Chapter 18: Java Database Connectivity (JDBC)

The next two chapters introduce data processing in Java. Chapter 17 deals with input/output that is accomplished through streams of data directed from and to files. This is one of the most important chapters for programmers who will be developing commercial applications. How does a program pass data to a secondary storage device like a disk? How does a program retrieve data already stored on disk? What are sequential files? What are random access files? What is buffering and how does it help programs that do significant amounts of input/output perform better?

Chapter 18 discusses how Java can be used to access relational databases. Businesses today are driven by data and Java provides a variety of classes for manipulating database data. In this chapter we focus primarily on Java's ability to use JDBC (Java Database Connectivity) to connect to a Microsoft ODBC (Open Database Connectivity) data source through the JDBC-to-ODBC bridge. The examples in the chapter use a sample Microsoft Access database, Books.mdb, that contains information about several of our textbooks. For accessing the database, we provide an overview of Structured Query Language (SQL).

Chapter 19: Servlets
Chapter 20: Remote Method Invocation (RMI)
Chapter 21: Networking

The next three chapters explain how to write programs that can communicate over computer networks. What is a client? What is a server? How do clients ask servers to perform their services? How do servers give results back to clients? What is a URL (uniform resource locator)? How can a program load World Wide Web pages? How can Java be used to develop collaborative applications? Our discussion of networking over these chapters focuses on both sides of a client-server relationship. The client requests that an action be performed and the server performs the action and responds to the client. This request-response model of communication is the foundation for the highest-level networking in Java--servlets.

Chapter 19 discusses networking with the commonly used request-response networking model in which World Wide Web browsers communicate with World Wide Web servers as users browse the Internet. When a user selects a Web site to browse through a Web browser (the client application), a request is sent to the appropriate Web server (the server application) which normally responds to the client by sending the appropriate HTML Web page to be displayed by the client's browser. In this networking model, the communication between the client and the server is handled automatically. The chapter begins our discussions of multi-tier distributed applications in which parts of the applications operate on separate computers distributed over a network. This chapter makes use of the streams technology of Chapter 17 and the database technology of Chapter 18 as we begin to build real-world applications in Java.

Chapter 20 takes a lower-level approach to writing programs that can communicate over computer networks and continues our discussion of multi-tier applications. RMI enables Java programs to communicate with each other via method calls that are automatically sent across the network. RMI is a more complex view of networking than servlets in that RMI requires more work on the part of the programmer to set up the initial interactions between applications. Once the mechanism is in place, the communication over the network is transparent to the application. Once again, this chapter makes use of the streams technology discussed in Chapter 17.

Chapter 21 introduces the lowest-level Java networking--streams-based sockets and datagram packets. We illustrate how to create simple clients and servers that deal with lower-level networking details. Here, too, Java still performs most of the complex networking tasks for you. Once again we rely on the streams technology of Chapter 17. The examples in this chapter illustrate an applet interacting with the browser in which it executes, creating a mini Web browser, communicating between two Java programs using streams-based sockets, communicating between two Java programs using packets of data and how to write a multithreaded server that can interact with more than one client at a time.

Chapter 22: Data Structures

Chapter 22 deals with arranging data elements into aggregations such as linked lists, stacks, queues and trees. Each data structure has important properties that are useful in a wide variety of applications. We discuss the details of building each of these data structures. This is a valuable experience in crafting useful classes, a crucial skill for Java programmers. Much of the value of this chapter is in general principles that are useful in implementing a wide variety of classes. Although it is useful to know how these classes work, Java programmers will quickly discover that most of the data structures they need are already available in class libraries such as Java's own java.util that we discuss in Chapters 23 and 24. Chapter 22 reinforces much of the class crafting technology discussed in Chapters 8 and 9 on object-based programming and object-oriented programming.

Chapter 23: Java Utilities Package and Bit Manipulation

Chapter 23 walks through several classes of the java.util package. This chapter reinforces the notion of reuse. Classes are included in class libraries because the classes are generally useful, correct, performance tuned, portability certified and/or for a variety of other reasons. Someone has invested considerable work in preparing these classes, so why not use them? Our belief is that the world's class libraries will grow exponentially over the next many years. If this is the case, then your skill and value as a programmer will depend on your familiarity with what classes already exist and how to reuse them cleverly to develop high-quality software rapidly. This chapter discusses many classes. Two of the most useful are Vector (a dynamic array that can grow and shrink as necessary) and Stack (a dynamic data structure that allows insertions and deletions from only one end--the top--thus ensuring last-in-first-out behavior). The beauty of studying these two classes is that they are related through inheritance as discussed in Chapter 9, so the java.util package itself implements some classes in terms of others, taking advantage of reuse.

Chapter 24: Collections

Chapter 24 discusses many of the new classes of the java.util package that provide pre-defined implementations of many of the data structures discussed in Chapter 22. This chapter, too, reinforces the notion of reuse. These classes are modeled after a similar class library in C++--the Standard Template Library. Collections provide Java programmers with a standard set of data structures for storing and retrieving data, and a standard set of algorithms (i.e., procedures) that allow programmers to manipulate the data (such as searching for particular data items and arranging data in order).

Chapter 25: JavaBeans

Chapter 25 discusses wrapping the Java classes you define as reusable software components. JavaBeans can be graphically manipulated and customized in Java program development environments. The chapter introduces the JavaBeans Development Kit (BDK) and the BeanBox that can be used to test your beans. The BeanBox illustrates the key concepts of manipulating a bean in a typical graphical development environment. The chapter discusses design issues surrounding bean development. In addition, we illustrate how to wrap an application as a Java Archive (JAR) file so you can execute the application by double-clicking the name of the file in your system's file manager (a typical way to execute an application on many platforms).


Send mail to deitel@deitel.com with questions or comments about this web site.
Copyright © 1997-1999 Deitel & Associates, Inc.
09/03/00 09:41:43 -0400