Google
Web deitel.com
Deitel® Buzz Online
free e-mail newsletter
Register Now!


HTML Text
Lotus Notes users,
please select Text

Java How to Program, 3/e

Tour of the Book
 

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

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).