This text is intended for a complete course in
programming and problem solving. The book covers the material of typical CS1 and CS2 courses at the undergraduate level. The book is
also AP-compliant for the A and AB
levels, covering all of the required subset of Javaä for both levels.
We present seven major aspects of computing, some in stand-alone lessons and others spread across several lessons:
1. Programming Basics. This deals with the basic ideas of problem solving with computers, including primitive data types, control structures, methods, and algorithm analysis.
2. Object-Oriented Programming. OOP is today's dominant programming paradigm. All the essentials of this subject are covered.
3. Data and Information Processing. Fundamental data structures are discussed. These include strings, arrays, files, lists, stacks, queues, trees, sets, and maps. The general concept of abstract data type is introduced, and the difference between abstraction and implementation is illustrated.
4. Software Development Life Cycle. Rather than isolate software development techniques in one or two lessons, the book deals with them throughout in the context of numerous Case Studies.
5. Graphical User Interfaces and Event-Driven Programming. Many books at this level restrict themselves to character-based terminal I/O. The reason is simple. Graphical user interfaces and event-driven programming are usually considered too complex for beginning students. In this book, we circumvent the complexity barrier and show how to develop programs with graphical user interfaces with the same ease as their terminal-based counterparts.
6. Graphics. Problem solving with simple graphics is explored. This includes drawing basic geometric shapes, representing data graphically, and implementing a rudimentary sketching program.
7. Web Basics. The programming of Web pages with HTML and applets is introduced.
Focus on Fundamental Computer Science Topics
There seem to be two types of introductory Java textbooks. The
first emphasizes basic problem solving and programming techniques, and the
second emphasizes language features. This book takes the former approach and
introduces Java features as they are needed to support programming concepts. In
this way, all the AP required syntax is covered without allowing the book to be
syntax driven. Some additional and more advanced Java features, not part of the
AP requirement, are covered in Lessons 19-22 and Appendix B.
Methods and Objects, Early or Late?
Occasionally, people argue about whether methods and objects should be introduced early or late in the first course. In Java, even the simplest program involves both, so the problem really becomes one of how to introduce these concepts in a clear and meaningful manner from the outset. Starting with the first program, we show how to instantiate and send messages to objects. The book's early lessons (2 through 4) focus on the use of objects, arithmetic expressions, control constructs, and algorithms in the context of short, simple programs. As programs become more complex, it becomes advantageous to decompose them into cooperating components. With this end in mind, Lesson 5 shows how to develop systems of cooperating classes and methods. Thus, we take a pragmatic rather than an ideological approach to the question of when to introduce methods and objects with complete confidence that students will master both by the end of the course.
Revisiting Control Structures, Classes, and Arrays
Years of teaching experience have demonstrated that beginning programming students have the most difficulty with control structures, classes, and arrays. We have sought in this text to soften the blow by introducing these ideas in two steps. First, a lesson gives an initial overview of a topic using the most basic features in simple but realistic applications. A follow-up lesson then revisits the topic to fill in and refine the details.
Two Approaches to Data Structures
There are two approaches usually taken to data structures, that of the client who uses them and that of the implementer who writes their code. Courses that emphasize the first approach tend to be application-oriented. Modern languages such as Java tend to support this approach well by providing a large set of classes for such data structures as lists and sets. However, some data structures, for example, queues and binary search trees, are not provided, so instructors must provide add-ons or require students to implement them. Over the past few years, the AP has taken this approach, providing the so-called "AP classes" when necessary.
Courses that emphasize data structure implementation tend to use it as a vehicle for discussing space/time complexity tradeoffs and as an entry point for examining broad concepts such as memory management and algorithm design. Unfortunately, students who are expected to implement a list interface with arrays, linked structures, and iterators are likely to get bogged down in hundreds of lines of code and never see an application.
This text straddles both of these approaches to data structures. We provide introductory lessons on the interfaces and applications of each data structure and then follow-up lessons on implementations. Moreover, each implementation is presented as a prototype or trimmed-down version that allows students to explore its essential features and the space/time tradeoffs without getting bogged down in details.
Input and Output Styles
The AP requires simple standard terminal output but no input. A realistic first course will need some form of input, if only from the keyboard. We provide easy to use open source toolkits for terminal I/O, GUI-based I/O, and simple graphics. From the perspective of the AP requirements, however, all this material on I/O is optional and should be fitted into the course only as time allows. It is the authors' experience that I/O adds interest without being overly burdensome; however, on some programming projects instructors may reasonably prefer to provide all or most of the interface-related code. In general, students and instructors are free to choose the I/O style that suits their needs and interests.
Lessons 2-6 use terminal I/O and demonstrate standard terminal-based interface techniques such as how to write query-based and menu-driven programs. After that, instructors have the choice of asking students to write terminal-based or GUI-based programs. Terminal input is based on the TerminalIO package, which is an extension of the standard stream classes. Later in the book, we show how to use these standard stream classes directly.
The early lessons also provide the option of using a TurtleGraphics package that allows students to draw images without worrying about Java's complex painting mechanisms. Again, later in the book, we take students through the significant details. The book uses turtle graphics because they provide an engaging context for illustrating the use of objects.
GUIs are usually considered beyond the scope of an introductory Java course. This book uses a package called BreezySwing that allows students to develop GUIs with the same ease as terminal-based interfaces. BreezySwing extends Java's Abstract Windowing Toolkit (AWT) and Swing in a manner that hides most of the underlying complexities from the beginning programmer. Using BreezySwing, students write event-driven programs with realistic graphical user interfaces, but without becoming entangled in numerous and difficult details.
People sometimes argue that students need to know how to develop GUIs the real way - that is, using AWT and Swing - and of course they are correct; however, the first course is probably not the right place to master this material. In the meantime, BreezySwing provides a useful introduction to GUI-based programming. It is easy to learn and use, and it provides a bridge to AWT and Swing. For those who are interested and highly motivated, Lesson 22 explains the details. After mastering Lesson 22, students are ready to abandon BreezySwing and undertake full-fledged Java GUI development with all its power and complexity.
All of the I/O packages are available on the CD accompanying this book and from the Web site http://www.wlu.edu/~lambertk/hsjava/. The Web site is the preferred source because it contains the latest release of BreezySwing together with online documentation and other related materials.
Case Studies, the Software Life Cycle, and Comments
The book contains numerous Case Studies. These are complete Java programs ranging from the simple to the substantial. To emphasize the importance and usefulness of the software development life cycle, Case Studies are presented in the framework of a user request followed by analysis, design, and implementation, with well-defined tasks performed at each stage. Some Case Studies are carried through several lessons or extended in end-of-lesson programming projects.
Programming consists of more than just writing code, so we encourage students to submit an analysis and design as part of major programming assignments. We also believe that code should be properly commented, and for purposes of illustration, we include comments in most of the listings in the book.
The book contains several different types of exercises. Most
sections end with
questions that reinforce the reading by asking basic questions about the
material in the section. Each lesson ends with a set of review exercises. All
lessons but the first one include programming projects of varying degrees of
difficulty. Finally, each lesson has a critical thinking exercise
that allows the student to reflect
on a major topic covered in the lesson.
Scattered throughout the book are short essays called Special Features. These present historical and social aspects of computing, including computer ethics and security.
Alternative Paths Through the Book
The AP A level material is covered in the first 11 lessons of the book. The AB-only material is covered in Lessons 12-18. Lessons 19-22 cover optional material not required by the AP. It is possible to cover some of this optional material early.
§ Those who want to do applets early can insert Lesson 21 between Lessons 3 and 4.
§ Those who want to do graphics early can jump ahead to Lesson 19 after finishing Lesson 7.
§ Files, in Lesson 20, can be presented after Lesson 7.
Again, Lesson 22 is intended only for those who want to explore GUI-based development in detail and shows how to make the transition from BreezySwing to AWT and Swing.
We have tried to produce a high quality text, but should you encounter any errors, please report them to email@example.com. A listing of errata, should they exist, and other information about the book will be posted on the Web site http://www.wlu.edu/~lambertk/hsjava/.
Kenneth A. Lambert