About the Book 

[ Home ]General Information ] Student Resources ] [ Site Map ]

   
  A quick tour of the third edition can be found at the McGraw-Hill website. I repeat here a portion of the Preface to the third edtiion.
   
 

We have made a number of improvements in this third edition of the book, but the main objectives remain the same. This book is intended as an introductory text on object-oriented programming, suitable for use in a one-semester CS1 course, and assumes no prior programming experience from the students. We only assume basic computer skills and some background in algebra and trignometry to solve certain chapter exercises. Those who already have experience in traditional non-object-oriented programming languages such as C, BASIC, and others also can use this book as an introduction to object-oriented programming, graphical user interface, and event-driven programming. The two main objectives of this book are to teach

  • Object-oriented programming.
  • The foundations of real-world programming.

Object-orientation has become an important paradigm in all fields of computer science, and it is important to teach object-oriented programming from the first programming course. Teaching object-oriented programming is more than teaching the syntax and semantics of an object-oriented programming language. Mastering object-oriented programming means becoming conversant with the object-oriented concepts and being able to apply them effectively and systematically in developing programs. The book teaches object-oriented programming, and students will learn how to develop object-oriented programs.

The second objective of this book is to prepare students for real-world programming. Knowing object-oriented concepts is not enough. Students must be able to apply that knowledge to develop real-world programs. Sample programs in many introductory textbooks are too simplistic, and they do not teach students techniques to develop large object-oriented programs. In this book, we teach students how to use classes from the class libraries from Chapter 2 and how to define their own classes from Chapter 4. We emphasize foremost the teaching of effective object-oriented design and necessary foundations for building large-scale programs. We will discuss further on this point in the Features section of this preface.

New Features in the Third Edition

We would like to take this opportunity to thank the adopters of the earlier editions. Numerous suggestions we received from the adopters and their students helped us tremendously in improving the texbook. For this edition, we focused on improving the strengths of the earlier editions, updating and adding the materials by incorporating capabilities of Java 2 SDK 1.4 class libraries, and removing the materials that have less relevance and significance today. Before we get into the features of the book, first we will highlight briefly the changes we made in the third edition:

1. Full-color pages. We started with one color in the first edition. We introduced the second color in the second edition to enhance the illustrations and the overall presentation of the materials. We took one step further and decided to use full-color pages in this edition. The result is dramatic. Different sections are clearly identified, syntax coloring is used in code listings, illustrations are more lucid, and the overall flow of the pages are very attractive and appealing. Pedagogy has been greatly enhanced by the use of full-color pages.

2. No reliance on the javabook classes. In the earlier versions of Java systems, we did not have an easy way to perform input and output. To work around this shortcoming, many authors provided their own classes which the students can use to perform input and output. To that end, we provided a GUI (graphical user interface) based collection of classes organized into a package named javabook . The situation has improved with the introduction of new Swing classes, most notably the JOptionPane class. In this edition, we will be using the standard classes exclusively for input and output. The javabook package is still available, however, for those who wish to use them. We will discuss more on this in the Features section of this preface.

3. Short sample programs. Many reviewers and adopters requested more short sample programs that illustrate the concepts in a succint manner. We now have numerous short sample programs throughout the chapters. At the end of many sections, we provide one or two short sample programs to illustrate the main concept taught in that section. A complete list of all sample classes (programs) is given in Appendix B.

4. Java 2 SDK 1.4 materials. Many new features are added to the newest Java SDK version 1.4. Not only our sample programs are compatible with SDK 1.4, we actively teach newly added features of version 1.4 such as pattern matching capabilities and assertion features.

5. No applets. We do not teach applets in this textbook anymore. After students cover Chapter 7 and a portion of Chapter 14, they can easily master applets on their own. A short handout on applets is available from our website.

6. Swing classes for GUI. For teaching GUI and event-driven programming, we use Swing classes exclusively. There will be no discussion on AWT-based GUI components.

7. UML notations. UML diagrams are used to document the relationships of the classes in the sample programs. Other diagrams (such as state-of-memory diagrams) will also use UML notations for consistency. Notice that although UML notations are used in these diagrams, these illustrative diagrams are not strictly speaking UML diagrams.

Features

There are many pedagogical features that make this book attractive. We will describe the defining features of this book.

 

Java

We chose Java for this book. Unlike C++, Java is a pure object-oriented language, and it is an ideal language to teach object-oriented programming because Java is logical and much easier to program when compared to other object-oriented programming languages. Java's simplicity and clean design make it one of the most easy-to-program object-oriented languages today. Java does not include language features that are too complex and could be a roadblock for beginners in learning object-oriented concepts. Although we use Java, we must emphasize that this book is not about Java programming. It is about object-oriented programming, and as such, we do not cover every aspect of Java. We do, however, cover enough language features of Java to make students competent Java programmers.

Standard Classes for Input and Output

In this edition, we decided to use the standard classes exclusively for both GUI and console input and output. We still make the author-defined javabook classes available for use, but there will be no discussion on their use in the textbook We use two javabook classes in Chapter 13 as an illustration of using classes from a programmer-defined package. Other classes can easily substitute for these two javabook classes. Also, some exercises may still suggest the use of certain javabook classes, but its use is not mandatory in solving them. In the first two editions, we provided javabook classes for pedagogical and practical reasons. For the pedagogical reasons, we provided the javabook package because

  1. It minimizes the impact of programming language syntax and semantics.
  2. It allows students to write useful programs from very early on, which helps to sustain the students' initial interest and motivation to learn.
  3. It serves as a model when students start designing their own classes.
  4. It can customized to suit individual instructor's needs.

For the practical reason, we provided the package because the earlier versions of Java did not support an easy way for the beginners to implement the input and output routines. We still feel the use of author-defined classes such as javabook is effective, but many instructors have strong negative reaction to any author-defined classes. Promoting the use of the javabook package was never our objective. Rather, our objective was always, and still is, to teach object-oriented programming. The javabook package was simply a means for us to teach object-oriented programming effectively. If there's a suitable replacement, we would replace it.

With the advent of Swing classes, specifically the JOptionPane class, the practical reason for using the javabook classes is eliminated for the most part. Moreover, we can achieve most of the pedagogical reasons for providing the javabook classes by using appropriate standard classes such as String , Date , and others instead. We, therefore, decided to drop the javabook classes in this edition.

Full-Immersion Approach

We wrote a series of articles in 1993 on how to teach object-oriented programming in the Journal of Object-Oriented Programming (Vol. 6, No. 1; Vol. 6, No. 4; and Vol. 6 No. 5). The core pedagogic concept we described in the series is that one must become an object user before becoming an object designer. In other words, before being able to design one's own classes effectively, one first must learn how to use predefined classes. We adopt a full-immersion approach in which students learn how to use objects from the first program. It is very important to ensure that the core concepts of object-oriented programming are emphasized from the beginning.

 

Illustrations

We believe a picture is worth a thousand words. Difficult concepts can be explained nicely with lucid illustrations. Diagrams are an important tool for designing and documenting programs, and no programmers will develop real-world software applications without using some form of diagramming tools. We use UML diagrams for the sample programs, and UML notations are used consistently in all types of illustrations.

This book includes numerous illustrations that are used as a pedagogic tool to explain core concepts such as inheritance, memory allocation for primitive data types and objects, parameter passing, and others.

Incremental Development

We teach object-oriented software engineering principles in this book. Instead of dedicating a separate chapter for the topic, we interleave program development principles and techniques with other topics. Every chapter from Chapter 2 to Chapter 14 includes a sample development to illustrate the topics covered in the chapter, and we develop the program using the same design methodology consistently.

This book teaches a software design methodology that is conducive to object-oriented programming. All sample developments in this book use a technique we characterize as incremental development. The incremental development technique is based on the modern iterative approach (some call it a spiral approach), which is a preferred methodology of object-oriented programmers.

Beginning programmers tend to mix the high-level design and low-level coding details, and their thought process gets all tangled up. Presenting the final program is not enough. If we want to teach students how to develop programs, we must show the development process. An apprentice will not become a master builder just by looking at finished products, whether they are furniture or houses. Software construction is no different.

The problem with other textbooks is that the authors often dedicate a single chapter to discuss and preach effective software development methodologies, but they never actually show how to put these methodologies into practice. They only show and explain the finished products. But without putting what they preach into practice by showing the development process, students will not learn how to develop programs. And it is not enough to show the development process once. We must show the development process repeatedly. In this book, we develop every sample development program incrementally to show students how to develop programs in a logical and methodical manner.

Design Guidelines, Helpful Reminders, and Quick Checks

Throughout the book, we include design guidelines and helpful reminders. Almost every section of the chapters is concluded with a number of Quick Check questions to make sure that students have mastered the basic points of the section.

Graphical User Interface and Event-Driven Programming

Since modern real-world programs are GUI-based and event-driven, we cannot skirt around them if we want to teach the foundation of real-world programming. Although we teach console input and output and use them in many sample programs, the large sample programs in this book are GUI-based. We introduce Swing-based GUI components in Chapter 7 and present advanced GUI topics in Chapter 14. We feel strongly that GUI and event-driven programming must be taught in CS1, but for those instructors who wish to keep the discussion on user interface to a minimum can omit the entire Chapter 14.

Assertions and Pattern Matching

Two of the new features added to Java 2 SDK 1.4 are pattern matching and assertions. Pattern matching is a very powerful and flexible tool in manipulatiing strrings, and we teach pattern matching with many examples in Chapter 9. Assertion is one of the software engineering techniques to ensure the program reliablity, and finally, the assertion feature is added to Java. In Chapter 8, we explain two key language features--exception handling and assertion--which we can use to improve program reliability.

Book Organization

There are 16 chapters in this book, numbered from 0 to 15. There are more than enough topics for one semester. Basically the chapters should be covered in linear sequence, but nonlinear sequence is possible. We show the dependency relationships among the chapters at the end of this section.

Here is a short description for each chapter:

  • Chapter 0 is an optional chapter. We provide background information on computers and programming languages. This chapter can be skipped or assigned as an outside reading if you wish to start with object-oriented programming concepts.
  • Chapter 1 provides a conceptual foundation of object-oriented programming. We describe the key components of object-oriented programming and illustrate each concept with a diagrammatic notation using UML.
  • Chapter 2 covers the basics of Java programming and the process of editing, compiling, and running a program. From the first sample program presented in this chapter, we emphasize object-orientation. We will introduce the standard classes String , JOptionPane , Date , and SimpleDateFormat so we can reinforce the notion of object declaration, creation, and usage. Moreover, by using these standard classes, students can immediately start writing practical programs.
  • Chapter 3 introduces variables, constants, and expressions for manipulating numerical data. We explain the standard Math class from java.lang and introduce more standard classes ( GregorianCalendar and DecimalFormat ) to continually reinforce the notion of object-orientation. We describe and illustrate console input and output ( System.in and System.out ) so the students can see the use of non-GUI I/O. The optional section explains how the numerical values are represented in memory space.
  • Chapter 4 teaches how to define and use your own classes. The key topics covered in this chapter are constructors, visibility modifiers ( public and private ), local variables, parameter passing, and value-returning methods. We explain and illustrate parameter passing and value-returning methods using both primitive data types ( int , double , etc.) and reference data types (objects). Through these explanations and illustrations, we clearly distinguish the primitive and reference data types. By the end of this chapter, students will have a solid understanding of object-orientation.
  • Chapter 5 explains the selection statements if and switch . We cover boolean expressions and nested- if statements. We explain how objects are compared by using equivalence ( == ) and equality (the equals and compareTo methods). Illustrative and meaningful examples are provided to make the distinction between the equivalence and equality clear. Drawing 2-D graphics is introduced, and a screensaver sample development program is developed.
  • Chapter 6 explains the repetition statements while , do-while , and for . Pitfalls in writing repetition statements are explained. The use of comfirmation dialog with the showConfirmDialog method of JOptionPane is shown. The optional last section of the chapter introduces recursion as another technique for repetition.
  • Chapter 7 covers basic GUI components and event-driven programming. Only the Swing-based GUI components are covered in this chatper. This chapter provides a first glimpse of using inheritance. We limit the discussion to defining a subclass of a standard class ( JFrame ) as a nice foundation for a fuller coverage of inheritance in Chapter 13. GUI components introduced in this chapter are JButton , JLabel , ImageIcon , JTextField , JTextArea , and menu-related classes . Our main focus for this chapter is event-driven programming, so we keep the discussion on GUI components at the basic level. For instance, we defer the discussion on layout managers and mouse events until Chapter 14. For those who wish to cover more GUI topics can teach a portion of Chapter 14 before continuing to Chapter 8.
  • Chapter 8 teaches exception handling and assertions. The focus of this chapter is the construction of reliable programs. We provide a detailed coverage of exception handling in this chapter. In the previous edition, we presented exception handling as a part of discussing file input and output. In this edition, we treat it as a separate topic. We introduce an assertion, a newly added Java 2 SDK 1.4 feature, and show how it can be used to improve the reliability of finished products by catching logical errors early in the development.
  • Chapter 9 covers nonnumerical data types: characters and strings. Both the String and StringBuffer classes are explained in the chapter. An important application of string processing is pattern matching. We describe pattern maching and regular expression in this chapter. We introduce the Pattern and Matcher classes, newly added to Java 2 SDK 1.4 and show how they are used in pattern matching.
  • Chapter 10 teaches arrays. We cover arrays of primitive data types and of objects. An array is a reference data type in Java, and we show how arrays are passed to methods. We describe how to process two-dimensional arrays and explain that a two-dimensional array is really an array of arrays in Java. Lists and maps are introduced as a more general and flexible way to maintain a collection of data. The use of ArrayList and HashMap classes from the java.util package is shown in the sample programs. Also, we show how the WordList helper class used in Chapter 9 sample development program is implemented with another map class called TreeMap .
  • Chapter 11 presents searching and sorting algorithms. Both N 2 and N log2 N sorting algorithms are covered. The mathematical analysis of searching and sorting algorithms can be omitted depending on the students' background.
  • Chapter 12 explains the file I/O. Standard classes such as File and JFileChooser are explained. We cover all types of file I/O, from a low-level byte I/O to a high-level object I/O. We show how the file I/O techniques are used to implement the helper classes-- Dorm and FileManager-- in Chapter 8 and 9 sample development programs.
  • Chapter 13 discusses inheritance and polymorphism and how to use them effectively in program design. The effect of inheritance for member accessibility and constructors is explained. We also explain the purpose of abstract classes and abstract methods.
  • Chapter 14 covers advanced GUI. We describe the effective use of nested panels and layout managers. Handling of mouse events is described and illustrated in the sample programs. A capstone sample development program that uses a modified Model-View-Controller design pattern is constructed in this chapter.
  • Chapter 15 covers recursion. Because we want to show the examples where the use of recursion really shines, we did not include any recursive algorithm (other than those used for explanation purposes) that really should be written nonrecursively.