Java Software Solutions: Foundations of Program Design – 2nd Edition / An Introduction to Object-Oriented Programming with Java – 2nd Edition / Java Elements: Principles of Programming in Java
Rogers, Michael P
THREE JAVA-BASED TEXTBOOKS FOR AN INTRODUCTORY PROGRAMMING COURSE
Java Software Solutions: Foundations of Program Design – 2″d Edition
by John Lewis and William Loftus
Addison-Wesley, Reading, MA, 2000, 780 pp.
An Introduction to Object-Oriented Programming with Java – 2nd Edition
by C. Thomas Wu
McGraw-Hill, New York, NY, 2001, 863 pp.
Java Elements: Principles of Programming in Java
by Duane A. Bailey and Duane W. Bailey
McGraw-Hill, New York, NY, 2000, 333 pp.
A cursory glance through the catalogs of the major textbook publishers, or a stroll through the computer section of your local bookstore, underlines the obvious: that the development of Java, a modestly sized language accompanied by a staggeringly large and powerful set of classes, over 2,000 at last count, has triggered a tsunami of textbooks.
Since choosing a textbook is a highly personal decision, and since there are such a large number of good-to-excellent works on the market, I will discuss three texts written for beginning programmers that take different approaches. At least one of these may be appropriate for your needs.
JAVA SOFTWARE SOLUTIONS, by John Lewis and William Loftus, consists of 12 chapters: Computer Systems, Objects and Primitive Data, Program Statements, Writing Classes, Enhancing Classes, Arrays and Vectors, Inheritance, Exceptions and I/O Streams, Graphical User Interfaces, Software Engineering, Recursion, and Data Structures. The book contains 13 appendices which cover aspects of the language, HTML, and describe the main classes (in 150 pages). Supplementary material is also available on Lewis’ website.
The book commences with a relatively thorough overview of computer systems – discussing critical background material, such as the difference between hardware and software, computer architecture, the internet and the world wide web, and finally, the essentials of programming. The sections in the chapters are nicely compartmentalized so that, if your students are already cognizant of the basics, they can leap into section 1.4, on Programming, without loss of continuity.
There are two schools of thought regarding object-oriented programming (OOP). Advocates of the objects-first model suggest instructors seize the nettle and provide an early, comprehensive discussion of the topic. Proponents of the imperative-first model recommend postponing an in-depth conversation until the “basics” are understood. While Lewis and Loftus are devoted OOP-fists, they take this latter route. Students are exposed to objects early on – indeed it is virtually impossible to do anything in Java without them – but the objects are simply used rather than becoming the focus of study. After a brief discussion of objects, students are introduced to Strings and Random objects. Students will use them before fully comprehending the underlying principles – which is fine. However, instructors might opt to either supplement the text at this point, or take a brief segue into section 4.1, “Objects Revisited”.
Lewis and Loftus introduce applets at the end of Chapter 2, in such a way that the topic could easily be omitted if desired. The careful reader will observe that although the authors use Java 2, and they use applets, they do not use the two together: in the chapter on Swing, they deal exclusively with applications. This is thoroughly understandable. As of this writing, the use of Java 2 in web browsers requires the Java plug-in, and a different, more complicated HTML tag. This should be a transient phenomenon, and in a textbook whose emphasis is CS I material, its mention would needlessly muddy the waters. Fortunately, the website that accompanies the text indicates how to use the Java plug-in.
Chapters 3 and 4 offer a generally thorough and fine explanation of the basics of the Java language, but it seems that constructors don’t quite get the respect that they deserve. While the subject of constructors is discussed in several places, the section entitled “Constructors” is itself quite short. Also, the discussion of constructor overloading appears in a section on “Method Overloading”, which may serve to mislead students who don’t always grasp the difference between methods and constructors. Still, these remain minor quibbles in a generally well-written chapter.
In Chapter 5, Lewis and Loftus explore a miscellany of important OOP topics – the details of reference variables, static vs. non-static methods and variables, and a brief mention of nested and inner classes. Detailed discussion of these latter two syntactically awkward and advanced topics is wisely relegated to their web site. Interfaces receive full coverage. After a suitably simple first example, the authors introduce MouseListeners, MouseMotionListeners, and ActionListeners – providing opportunities for some very exciting and motivating assignments.
Java, and even more so the Java Class Library (JCL), is constantly evolving and expanding. This presents numerous difficulties for instructors. The quintessential example is GUI (graphical user interface), and the difficulty may be summarized as “To Swing, or not to Swing?” The GUI that shipped with Java 1, part of the Abstract Windowing Toolkit (AWT) package, has numerous problems, and it is clear that the future of the Java GUI rests with Swing. Yet the AWT GUI does have the advantage of simplicity and, as mentioned earlier, is the only guaranteed package for applets running in web browsers. So, it is to their credit that Lewis and Loftus, while not completely abandoning AWT, present both AWT and Swing, in separate chapters to reduce confusion.
Keeping up with the JCL is a major challenge. Sun’s website provides the definitive documentation, but Lewis and Loftus provide a convenient local alternative: over 150 pages of an appendix devoted to this Sisyphean task. They cover only a fraction of the classes, for obvious reasons, but still enough to please students.
One of my major criticisms of the first edition of this text was the dearth of exercises. This has been triumphantly dealt with in the second edition. A number of stylistic changes, the introduction of “Key Concepts” sections, and syntax diagrams also improve the text.
AN INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING WITH JAVA, by Thomas Wu, consists of 17 chapters (in true Java fashion, numbered 0 through 16): Introduction to Computers and Programming Languages, Introduction to Object-Oriented Programming and Software Development, Java Programming Basics, Numerical Data, Defining Instantiable Classes, Processing Input with Applets, Selection Statements, Repetition Statements, Characters and Strings, Arrays, Sorting and Searching, File Input and Output, Reusable Classes and Packages, GUI Objects and Event-Driven Programming, Inheritance and Polymorphism, Class Roster Maintenance Program, and Recursive Algorithms.
Initial chapters in many textbooks often seem problematic due to marketing considerations (“you must talk about thus and such, otherwise no one will buy it”) rather than a desire on the part of the authors. Someone could benefit the entire industry by writing a definitive short monograph on the whole smorgasbord of topics that often receive preemptory treatment in a CS I text – history of computers, computer architecture, languages, compilers, etc. – put it on the web, and let the authors get to the topics that they want to talk about sooner.
After the optional introductory chapter, Wu plunges deep into OOP territory, covering, at a conceptual level, classes and objects, messages and methods, class and instance variables, and inheritance. And, if there could possibly be any remaining doubt as to Wu’s commitment to the OOP-first camp, inspecting the text’s first program will lay that doubt to rest. The “Hello, world!” application, that for reasons of historical inertia is usually a student’s first introduction to Java, has been justifiably criticized because it is completely non-OOP: maino is a static method, System.out is a static variable, and nothing gets instantiated! Wu has a better idea: a three-line program that instantiates a SketchPad object – a subclass of Frame that can be “doodled on”. The program is as brief as it is enticing, and subliminally emphasizes the importance of reusability, the joys of abstraction, and the power of Java.
The textbook is visually impressive, abounding with illustrations that are an essential part of the exposition, rather than just window dressing. The numerous object diagrams are particularly notable. Reminiscent of Edward R. Tufte, they simply but effectively convey a great deal of information, making it easier for students to comprehend objects and classes. A public method, for example, is drawn straddling the class border; a private method is drawn entirely within the class boundary; overloaded methods/constructors are drawn as nested rectangles; etc.
Chapter 2 introduces the basics of Java programming as well as the author’s own package, javabook, which is used throughout the book. This versatile package provides frames for drawing, dialog boxes for input and output (including File IIO), and a Clock class for managing time. The author robustly and preemptively defends the inclusion of the package against “purists” who would argue that students should use the JCL classes exclusively. The defense must be provided, however, because much of the book relies on this package, and these purists need to be reminded that the purpose of a CS I text is not to produce Java developers. Anyone who has tried to teach I/O in Java to CS I students must surely be sympathetic to the author’s case.
In chapters 3 – 5, students are introduced to standard topics: arithmetic, creation and instantiation of their own classes, and applets. By this time, thanks to the author’s early introduction of OOP, students should be thoroughly comfortable instantiating objects, invoking methods, and so on. An inspection of the sample programs and the exercises makes that clear. However, that inspection also reveals something else: all of the programs are strictly sequential. Wu delays discussion of two fundamental topics, decision and repetition structures, until Chapters 6 and 7, respectively.
One might think that strictly sequential programs would lack excitement, but in fact, thanks to javabook and the emphasis on OOP, the programs are quite sophisticated and will surely keep students engaged even if the flow is largely linear. Still, instructors using this book may be tempted to insert at least some of this material into earlier chapters, and that could certainly be easily done.
Applets are introduced quite early, and are the sole concern of Chapter 5. The author introduces GUI, and has chosen to use java.awt rather than Swing. However, he does direct readers to his website, where he provides an in-depth discussion of Swing, among other topics. (Incidentally, these topics are distributed in pdf files, with the same distinctive format as the text, and they make excellent supplements.) In the discussion of GUI, Wu has wisely chosen to eschew layout managers, eliminating 20 pages from the text and much student unease.
As students become more advanced, the author reveals the magic behind javabook. Chapter 11 describes how to do File I/O from “first principles”, and includes a section on the sublime ObjectInputStream and ObjectOutputStream classes. The chapter on “GUI Objects” shows students how to use java.awt components and process events, again without reference to the javabook package. By this stage students can read through the source code of javabook and appreciate it for its elegance, but no longer need to rely on it.
It is a universal lament that CS programs are graduating students who have little or no experience with large software projects. To partially address this, Wu describes, in the penultimate chapter, a substantive, 10-class “Class Roster Maintenance” program. He carefully guides students through the development life cycle, and for those who diligently follow along through this 80-plus-page chapter, the effort will be worthwhile.
JAVA ELEMENTS: PRINCIPLES OF PROGRAMMING IN JAVA, by Duane A. Bailey and Duane W. Bailey, consists of 12 chapters (again numbered starting at 0) and several appendices: Welcome, Values, Variables and Expressions, The Element Package, Conditions and Loops, Methods, Strings, Recursion, Arrays and Vectors, Classes, Recursive Structures, Threads, and Machines.
The first thing one notices about this book is its comparative, and deceptive, thinness. Bailey and Bailey manage to cover all the critical CS I topics in this diminutive volume through a combination of taut writing, the use of packages to hide details, and the refusal to consider classes that, while undoubtedly powerful, are ancillary to the matter at hand.
The Baileys do teach OOP, introducing objects early on in the proceedings and touching on all the requisite topics. Yet their passion appears to be for Computer Science, and Mathematics. That is made abundantly clear in Chapter 0, where they introduce a series of programs and then ask questions: “What happens if you change this?” and “Try this, will it work?” They explicitly encourage students to experiment, and reassure them that breaking a program is perfectly acceptable. By the second program, in what may well be the first lecture, students are working with While Loops; experience suggests most will have no problem whatsoever grasping the concept.
Chapter 0 also introduces students to the Baileys’ light-hearted writing style. Each chapter is presaged with an amusing but relevant quote, and an occasional bad pun.
The authors spend no time at all on the history of computer science or computer architecture. Instead, in Chapter 1 on values, variables, and expressions, they offer, with a mathematician’s precision, a description of all the primitive types (including the boolean logical and relational operators), the fundamentals of arithmetic (including all of the assignment operators and typecasting), as well as objects (Strings and Randoms). A lot of material is contained in the chapter’s 25 pages, and yet it does not feel condensed. The examples in the chapter underscore the authors’ mathematical bent. They include a discussion of the quadratic formula, a comparison of Pythagorean tuning versus equal temperament, and some simple trigonometry to properly locate the hour hand at 2 o’clock. An example to time how long it takes to execute a statement gives the instructor an excuse to wax eloquent on factors that affect performance while giving the students additional opportunity to experiment.
Chapter 2 introduces the element package, consisting of two classes – a ConsoleWindow for I/O and a DrawingWindow for Graphics. The design of these classes is clever. They hide the details, yet employ methods with similar names to the standard ones. For instance, a ConsoleWindow called con would require con.out.println() for output; a DrawingWindow called dw would require dw.draw(), where the argument would be a Drawable object (the same strategy adopted by Sun with the Graphics2D class, except that the interface is a Shape rather than Drawable).
The problems at the end of each chapter, and to a lesser extent the exercises that are scattered throughout, can be quite challenging, especially for the non-mathematically inclined: a relatively high proportion of these questions are mathematical in nature. Those teaching primarily CS and/or Mathematics majors will find the problems delightful; but instructors with a more diverse group may need to pick and choose problems, add a few from their own repertoire, or better still, be willing to spend time explaining the underlying mathematics. This book has been field tested by its authors at liberal arts institutions (at the time of its writing, they were at Williams and Amherst Colleges), in courses open to all-comers.
In Chapter 4, on methods, the authors do an excellent job carefully explaining how methods work and how to write them. They offer a useful distinction between functions (methods that return values), procedures (methods that return nothing) and predicates (methods that return boolean values). And the examples, including ones on Bezier curves and shading rectangles with a gradient of grays, are intriguing.
It might seem that the next logical step, after discussing methods, would be an in-depth discussion of classes. However, while the Baileys discuss the concept, they proffer only one example and then continue with static methods, in a single main class, in all their examples up to Chapter 8. Clearly, in the debate between imperative-first and objects-first models, the authors lean toward imperative-first. (They do suggest an alternative path through the text, studying the classes chapter immediately after Chapter 4; but all the intervening examples, with their static methods, tend to subtly belie the importance of objects.)
Neither GUI nor event handling is explicitly covered in the text. Instead, the authors hide the details within the DrawingWindow class. Instructors may wish to supplement the text at this point, or defer the topic until CS II. Indeed, considering that one could easily spend a semester and triple the size of the book studying the JCL; that the GUI classes are still to a certain extent in flux; and that Sun’s online tutorial is absolutely top-notch, the authors may be doing everyone a favor by omitting the topics. The authors do mention a (highly) select subset of the JCL, those classes of immediate relevance: Color, Math, Random, String, System, Thread, and Vector.
The last two chapters of the book are somewhat atypical for a CS I text: a discussion of Threads, and machines (the Java Virtual Machine, the Turing Machine, and P-RAM). Between the discourse and the stimulating examples including a threaded Mandlebrot Viewer – the Baileys continue to the very end to remind their readers of why Computer Science is such an exciting, appealing, and challenging adventure.
And “to the very end” includes the appendix where the authors offer a series of contest problems that will, at the least, test the mettle of the very best students.
Reviewed by Michael P. Rogers
Millikin University
Copyright Mathematics and Computer Education Fall 2001
Provided by ProQuest Information and Learning Company. All rights Reserved