1. INTRODUCTION
Although weâd like to say that the language used in CS1 doesnât matter, it does impact what concepts are emphasized and the student outcomes from the course. The basic language concepts to cover in CS1 include [Koffman1987]:
2. Statements and blocks of statements
3. Modularization (and consequently argument passing and return types)
4. Control structures
5. Mechanisms for collecting data of the same type (arrays)
6. Mechanism for collecting data of different types (records/classes).
7. Input/Output to both users and storage media.
Recently many schools have either changed to Java in CS1 or are considering making this change. The reasons have been discussed elsewhere [paper by author1997]. Issues raised include the claim that Java is a more tightly-constrained language than is C++ or C (for example, no pointers or reference parameters, strong typing, the misuse of = for == is not allowed). Also, Java is a more effective vehicle for teaching the object-oriented paradigm than is Ada-95 or C++. Unlike Scheme or Pascal, Java is a popular programming language in industry because of its widespread use on the world wide web. Of course Java is not without its own problems [Stroustrup1998]. Some concerns are the fact that the language is still under development and is growing, and some key elements such as the event model may change from one version to the next.
Nevertheless, there is currently a bandwagon effect occurring with regard to Java. However a number of questions relating to its use in CS1 have not been addressed:
2. When to "do" objects: early, late, or constantly.
3. What about language particulars: Applets vs. Applications, the AWT, threads
2. THE THREE APPROACHES
2.1 Language Features First
We claim that the language features first approach is doomed to failure with all but the most-prepared students. In order to cover applets and GUIs properly students must have mastery of inheritance, events and threads. Also, you must cover an overwhelming amount of specialized detail for the individual AWT classes. The course can get so involved in objects that it ignores the basic essentials of programming such as control structures.
2.2 Language Features Last
On the other hand, if you ignore the AWT and GUIs throughout most of the course, the course will follow the traditional ordering of concepts, but will not necessarily teach them well. The programs students write may promote an object avoidance, or worse, an anti-object viewpoint. This approach in Java also requires students to code statements that they don't fully understand such as "public static void". In our experience, students often try to leap ahead and attempt to create complex interactivity with primitive tools. They become frustrated and bored with writing programs that are restricted to simple text-based interactivity. Also, they are not introduced to web-based concepts and, therefore, completely miss a major reason for the excitement of Java.
2.3 Language Features Gently
Our "language features gently" approach attempts to create a balance between these two approaches It gives beginning students a grounding in the basics of object-oriented programming from the start, but ignores the complications of the AWT and more theoretical concepts of object-oriented programming until later. We have developed a package called simpleIO that enables students to easily incorporate GUIs in their applications, so they aren't restricted by limitations of text-based (System.in, System.out) applications. Also, we introduce applets and graphics at a relatively early point, so they do get an introduction to web-based concepts and benefit from the added motivation of being able to write rudimentary graphics programs.
3. THE LANGUAGE FEATURES GENTLY COURSE
Table 1 shows the ordering of topics for our course [book by authors1999]. The discussion of objects and object-oriented programming is spread throughout the course, beginning as early as the second unit where classes and objects (as specific instances of a class) are first introduced. We also discuss classes and object-oriented programming in units 3, 4, and 8. Our simpleIO package contains a class SimpleGUI (for simple GUI-like I/O) that is introduced in unit 2. Other features of this package are shown in units 5 and 7. We introduce applets in unit 4 and cover applets and GUIs in more detail in units 9 and 10.
3.1 Application and support classes
A hard concept for beginners is the "static main" method of a Java application where processing begins. We address by using a simple two class model for applications. Each program uses two classes, a support class and an application class. The application class consists of the single method, main, with the general form:
2. Ask the support class to get data from the user..
3. Ask the support class to display the results.
public class GenApp {
s.readData(); // step 2
s.showResults(); // step 3
Figure 1. A Generic Application Class
The support class contains private data fields needed to store the input data. It also contains a method that reads the data (e.g., method readData), a method that calculates and returns a simple result, and a method that displays the results. Initial sample applications involve converting units of measurement, calculating the value in dollars and cents of a coin collection, and translating from English to simple pig Latin.
Each support class extends class SimpleGUI so that it can use SimpleGUI methods. Figure 2 shows a sample support class. Method getInt (from class SimpleGUI) pops up a data entry window. The data entry window displays the method argument (String "Enter an integer:") as a label and gives a text field in which the user can type in the actual data value. All of the SimpleGUI "get" methods do error checking and recovery automatically for the programmer.
import simpleIO.*;
public class Support extends SimpleGUI {
·}
Figure 2. A Sample Support Class
Instantiating a subclass of SimpleGUI causes a "user interaction history" window (UIH) with a scrollable text area to appear on the screen. After a call to a data entry method such as getInt, getDouble, or getString, the prompt string and data value are listed in the UIH for the object that received the data entry message. Similarly, each call to method displayResult appends a display line the objectâs UIH. This provides a record of the interaction between the object and the user.
Although one could argue that such simple applications could be written as a single class with a single static main method, we believe our approach is superior as it helps to promote the idea of object interaction, even at the basic level. Also, it leads naturally to the idea that the support class could be used in another application.
3.2 Inheritance and Other OOP Concepts
The definition of a support class as a subclass of SimpleGUI provides a gentle introduction to inheritance. Right from the beginning, students see the benefits derived from subclassing. The syntax of Java makes it easy to introduce this concept so early. We revisit inheritance in unit 4 where we use it to extend support classes that we have built. In this context, we discuss visibility of data fields and introduce protected visibility. We also describe how to write several different kinds of methods: accessors, modifiers, and constructors, but in later units we do not belabor it. We use examples that require math functions which leads naturally to system-defined class Math, giving us an opportunity to explain class methods and data fields in a relevant context.
Our emphasis in unit 4 is on re-use, not pure object-oriented design. In unit 8 we cover more advanced aspects of object-oriented programming including abstract classes, multiple inheritance, and user interfaces. We also provide more details on concepts such as encapsulation, visibility, and polymorphism.
3.3 Coverage of Applets and the AWT
We introduce applets in unit 4. By this time students have written several linear programs and are ready for a little fun. We provide a simple HTML file that students can easily modify. Next, we introduce methods from class Graphics (part of the AWT) for drawing shapes such as filled and unfilled rectangles, ovals arcs and lines. Students are introduced to method over-riding. They extend the applet class and over-ride its paint method, displaying simple drawings in the browser window. In unit 6, the learn to draw more interesting patterns using loops and recursion.
We wait until units 9 and 10 to provide more detailed descriptions of the AWT and applets. Unit 9 provides more details on the AWT, the Java event model, and applet/browser interaction. We continue our discussion of HTML in unit 9 and show how an applet can retrieve values from an HTML file using method getParameter. Unit 10 provides more detail on GUI design. We also describe threads in unit 9 that leads to primitive threaded animation.
6. EXPERIENCE WITH OUR APPROACH
The language features gently approach has been used during the past two years at one of our institutions. Over-all students enjoy programming in Java, especially writing GUI-based code. In a single semester students have created graphics drawings of their own design, written advice giving expert systems (using selection statements), generated calendars given a start day for January 1, and have written interactive games such as concentration, score four, and scrabble as final projects.
Our students are reaching the same level of mastery of the essential concept of CS 1 listed above in section 1 as in those we taught in years previous to switching to Java. The one failing of our course is that we de-emphasize file handling. However, in Java this concept is rapidly being replaced by serialized objects. We have not included this in our CS 1 course because it is still an unstable feature of Java implementations.
The "features gently" students are demonstrating through lab assignments and exams that they understand the rudiments of object design, including simple inheritance. The best of them master events and autonomous threads. Most embrace the AWT component and take great pleasure in creating event generators such as buttons and lists, even if their understanding is not complete. However, in general, our students are having fun programming and appreciate a systematic modular design approach.
7. Summary
This paper describes a language features gently course for CS1 in Java. The course introduces language features of object-oriented programming as needed rather than overwhelming the student in the beginning with unnecessary detail. The studentâs capabilities in object-oriented programming grow gradually as the course progresses. The course uses an author-supplied package to simplify input/output, including classes for GUI-like interaction, adding GUIs to graphics, displaying arrays, and performing file input and output.
References
[Decker194] R. Decker and S. Hirshfield, "The Top 10 Reasons Why Object-Oriented Programming Canât be Taught in CS1", Proceedings of the Twenty-Fifth SIGCSE Technical Symposium on Computer Science Education, pp. 51-55, 1994.
[Koffman1987] E. Koffman, P. Miller, and C. Wardle, "Recommended Curriculum for CS1", Communications of the ACM, Vol. 27, No. 10, pp. 998-1001, October, 1984.
[Pattis93] R. Pattis, "The Procedures Early Approach in CS1: A Heresy", Proceedings of the Twenty-Fourth SIGCSE Technical Symposium on Computer Science Education, pp. 122-126, 1993.
[Stroustrup1998] Stroustrup, B. and Hamilton, S., "The Real Stroustrup Interview: Standards, C++, and Java", Computer, pp. 110-114, June, 1998.
[book by authors1999] Deleted for blind review
[paper by author1997] _________, "Language Considerations in a Goal-Centered Approach to CS 1
and 2: Java, C, or What?", Journal of Computing in Small Colleges, Vol. 12, No. 5, p12 ö 20, 1997.
| Unit | Content Emphasis | Objects and Concurrency | Interactivity & Graphics | Program Type |
| 1 | Introduction to computers, networks, programming languages | Overview of the object concept | History of Interactivity models | |
| 2 | Introduction to the software development method, classifying data, overview of Java applications, defining classes and methods | Defining classes, methods and data | SimpleGUI to get and show integers, reals and strings to the user | Applications |
| 3 | Method bodies, including statements (assignment, return, sequences), expressions | Message passing between an application and a support class | SimpleGUI to get and show integers, reals and strings to the user | Applications |
| 4 | Introduction to code reuse. Reinforce data transfer through method arguments and return values. The Graphics object as an example of passing argument values. | inheritance (extending classes such as applet), method types (accessors, modifiers, constructors), overriding (e.g., paint), class methods (class Math ) | SimpleGUI for interactivity without graphics. Introduction to applets and the Graphics object that can paint. | Applications and applets. |
| 5 | Selection statements (if and switch) and Boolean expressions. | Introduce exception handling. | SimpleGUI methods for Boolean and menus | Applications |
| 6 | Repetition and tail recursion. | No new OO concepts | SimpleGUI methods for mixing graphics and interactivity | Applications and applets |
| 7 | Arrays and vectors, simple searching and sorting. Introduction to time complexity. | No new OO concepts | SimpleGUI displayRow for arrays, I/O through SimpleReader and SimpleWritier | Applications |
| 8 | Formal introduction to OOD including concepts of abstraction, encapsulation, polymorphism and inheritance | Visibility, Class methods and data fields, Method overloading and over-riding, Abstract classes and Interfaces to support inheritance | No new concepts | Applications |
| 9 | Web programming, client/server model, threaded animation, browser/applet interaction | Formal overview of Applets and their relationship to HTML, Introduction to threads. | Introduction to AWT Component and Container class, introduction to events | Applets |
| 10 | GUI components and containers, turn-taking with the event model | The object model of the AWT as a vehicle to re-enforce OOD principles. | More details on the component and container class, layoutmanagers, low level events | Applets and Applications |