Preface
This book presents object-oriented programming with C++ and Java, which are today's two
dominant languages for such programming. The presentation format is mostly comparative, all the
way from the basic language constructs to application-level issues dealing with graphics
programming, network programming, and database programming. This book is intended for a reader
who is well-conversant with the important features of C: pointers, strings, arrays, and structures.
The author strongly believes in the notion that, in addition to the syntax, it is essential to also show
a programming language through its applications to fully establish its beauty and power. Teaching a
programming language divorced from its applications—not uncommon in many educational
programs—would be like teaching English through just its grammar.
This book grew out of an attempt to meet a specific academic need for a comprehensive
educational program in object-oriented programming. We wanted a program that would not be too
indoctrinating with regard to any one style (or any one language, since language often dictates
style) of object-oriented programming. While programming skill could have been taught by focusing
on a single language, education in its larger sense demanded that we provide a broader menu of
styles and concepts. The result was what the reader sees in this book: An integrated presentation
of C++ and Java. There is educational value in comparing and contrasting the two languages, from
basic language constructs to how the languages are used in application-level programming. Such
comparisons may even inspire an enterprising student to think of new and more powerful object-
oriented languages of the future. To further enhance the educational value of this comparative
approach, this book also includes treatment of simulated object-orientation in plain C, with
GNOME/GTK+ presented as a major example of this approach.
This book is based on the philosophy that learning by comparison is very efficient and can be a lot
of fun. Sometimes we find it easier to remember and learn things if we can anchor our memory and
comprehension in interesting differences and similarities between supposedly similar objects,
structures, and situations. Learning C++ and Java together can exploit this aspect of human
cognition. Students find it interesting to compare C++ and Java programming constructs for doing
the same thing.
Teaching and learning C++ and Java together have some unique advantages. First, because both
C++ and Java were born out of C, they have much in common at the level of basic language
structures. Teaching these structures together saves time. For example, once the concept of a
vector in C++ is made clear and some of the more useful functions associated with C++ vectors are
elucidated, the discussion of the Java ArrayList takes hardly any time. The Java discussion consists
mostly of pointing out the Java functions that do the same thing as the previously discussed C++
functions.
Then there is also the unique process of learning by coding up a program in C++ that does the
same thing as a given program in Java, or vice versa. My experience is that this approach enables
the students to tackle more difficult projects in both C++ and Java than would otherwise be the case
under the time constraints of a course.
Learning two large languages together does have its down side. One can get confused as to what
feature belongs to which language. Fortunately, this difficulty is minimized by the modern
programming practice of keeping one eye on the online documentation in one terminal window
while programming in another terminal window. Both Java and C++ have become so large that it
would be impossible for anyone to commit to memory all of the classes and all of the functions and
attributes defined for the classes. So even if one were not learning two languages simultaneously,
one would still need to refer to documentation while writing programs.
The book contains more material than can be accommodated in a typical one-semester course. In
my experience, the book works well for a sequence of two back-to-back courses, the first focusing
on the basic language constructs as presented in the first fifteen chapters, and the second focusing
评论2