
Taming Java for the Classroom∗ James I. Hsia Elspeth Simpson Daniel Smith Robert Cartwright [email protected] [email protected] [email protected] [email protected] Rice University 6100 S. Main St. Houston TX 77005 ABSTRACT teach Java to first-year computing students without hav- Java is the canonical language for teaching introductory pro- ing those students overwhelmed by its complexity [emphasis gramming, but its complex syntax and abundance of con- added]” [1]. Java’s complex syntax and plethora of language structs are difficult for beginners to learn. This paper shows features are a serious obstacle to learning OOP and interfere how object-oriented programming in Java can be made more with an early focus on OO concepts. Even the traditional accessible to beginners through the use of “language levels”, first program, “Hello World”, seems daunting to a beginner. a hierarchy of progressively richer subsets of Java. This hi- To run “Hello World” from the command line, the student erarchy is implemented as an extension of the DrJava ped- must write a main method whose declaration looks like this: agogic programming environment. public static void main(String[] args) Categories and Subject Descriptors In this one declaration, the student is confronted with visi- bility modifiers, static methods, return types, and arrays— D.2.6 [Software Engineering]: Programming Environments none of which are central to OOP. The instructor faces a choice between taking the time to explain what these com- Keywords plex, unrelated pieces of the language mean or telling the DrJava, language levels, object-oriented programming students to blindly cut and paste the code. Neither of these choices is very attractive. 1. INTRODUCTION To make Java more accessible to beginners, educators Programming technology is in the midst of a paradigm have developed pedagogic programming environments such shift. Object-oriented programming (OOP) in safe, object- as BlueJ [8] and DrJava [2] that support simpler, more intu- oriented (OO) languages like Java and C# is gradually sup- itive programming interfaces. BlueJ provides a graphically planting object-based programming in C++ for mainstream based workbench where students can create objects and ap- applications. Many colleges have recently revised their in- ply methods to them, while DrJava provides users with troductory programming sequence (CS1/CS2) to use Java an Interactions Pane that transforms Java from a batch- instead of Pascal or C++. High school courses in AP Com- oriented language to an interactive one with a read-eval- puter Science made the transition from C++ to Java last year. print-loop. Both of these interfaces completely eliminate In the wake of this paradigm shift, computing educators the need to define a main method. face a dilemma about what concepts to teach in introduc- While these pedagogic environments are a major step for- tory courses using Java. Should they continue to teach the ward over conventional Java environments, they do not fully object-based perspective that has dominated programming shield students from the complexities of Java syntax or nec- curricula for the past decade? Or should they embrace a essarily encourage OO design. Nearly all Java texts, in- truly OO approach to program design for which there is cluding those that presume the support of a pedagogic en- little precedent? There is a growing consensus that OOP vironment like BlueJ or DrJava, cover the major syntactic concepts should be taught in Java as early as possible [9]. elements of procedural programming—namely assignment, Despite the growing consensus in favor of an “objects- conditionals, and looping constructs—plus Java language first” curriculum, the implementation of this pedagogy has features like static, final and visibility modifiers, before proven to be a challenge. The ACM Education Board re- discussing the essence of OOP: polymorphism (dynamic dis- cently formed a Java Task Force “to develop a stable col- patch). The detour through the mechanics of procedural lection of pedagogical resources that will make it easier to programming is time-consuming and distracting, making it difficult to teach an OO perspective on program design. ∗ This research has been partially supported by the Texas Advanced What is needed is a hierarchy of Java language levels— Technology Program and the National Science Foundation. progressively richer subsets of the Java language that facili- Permission to make digital or hard copies of all or part of this work for tate a focus on OO design rather than the mechanics of the personal or classroom use is granted without fee provided that copies are Java language. The idea of partitioning a language into a not made or distributed for profit or commercial advantage and that copies hierarchy of language levels dates back to at least the 1970’s bear this notice and the full citation on the first page. To copy otherwise, to when Richard Holt et al developed the SP/k framework for republish, to post on servers or to redistribute to lists, requires prior specific teaching structured programming in PL/I [7] at the Univer- permission and/or a fee. SIGCSE'05, February 23–27, 2005, St. Louis, Missouri, USA. sity of Toronto. More recently, the DrScheme environment Copyright 2005 ACM 1-58113-997-7/11/0002 ...$5.00. developed by Matthias Felleisen and his students at Rice University pioneered the idea of partitioning a language into a semantic hierarchy of language levels. In DrScheme, the language level hierarchy supports a corresponding hierarchy of computational models, each with a richer data model and more complex semantics than its predecessor. As a result, the progression of language levels in DrScheme directly cor- responds to a progression of programming abstractions suit- able for teaching. The pedagogy underlying this progres- sion is explained in the textbook How to Design Programs (HTDP)[4]. Although HTDP focuses on “mostly” functional program- ming in Scheme, the underlying pedagogy is largely lan- guage independent. In fact, the same programming concepts and principles can be articulated in the context of OOP in Java. In HTDP, program design is data-directed, primarily using inductively-defined algebraic types like lists and trees.1 Given the inductive definition for a data domain, there is a corresponding, mechanically generated template for writing a function to process that form of data. In addition, the program development process is test-driven; test cases are written for each program function before it is coded. In an OO context, the design concepts in HTDP corre- spond to progressively more sophisticated uses of polymor- phism that have been codified as design patterns in the well- known “Gang of Four” tome [5] on the subject. It is remark- Figure 1: DrJava at Elementary Level able that two largely disjoint programming cultures have • distilled essentially the same principles of program design. compiling and unit testing open document(s); • The programming methodology from HTDP looks equally enabling a source level debugger integrated with the familiar when it is translated to an OO context: it is simply Interactions Pane; Extreme Programming (XP) [10] in-the-small: test-driven • running javadoc on all of the source files to generate development using JUnit. HTML output; In this paper, we describe a language levels framework • changing the configuration options for DrJava; and that we have developed for the DrJava programming envi- • selecting a language level. ronment. This framework supports our translation of the The most common commands are bound to buttons on a programming pedagogy from HTDP into an OO context. tool bar just below the title bar. With this framework, OO programming in Java is easily ac- Although DrJava is targeted primarily at supporting be- cessible to beginners, as demonstrated by the simplicity of ginning and intermediate programming courses taught in the OO program written at the Elementary level in Figure Java, it is also particularly well-suited to small production 1. programming projects that use test-driven development. In fact, for the past two years, DrJava has been developed us- 2. AN OVERVIEW OF DRJAVA ing DrJava. The combination of a general read-eval-print- loop (the Interactions pane) with tightly integrated support DrJava [2] is a free, open-source, lightweight IDE devel- for unit testing and source level debugging provides an un- oped at Rice University by undergraduate and graduate stu- usually responsive and productive environment for software dents under the direction of Prof. Robert Cartwright. The development. To our knowledge, DrJava is the only IDE, user interface is designed to be simple and highly interactive. commercial or open-source, that supports a full read-eval- There are only three panes: a Navigator Pane lists all open print loop capable of evaluating arbitrary program text in documents, a Definitions Pane displays the selected docu- the context of a debugger breakpoint environment. ment (typically a file defining a Java class), and an Inter- The most recent release of DrJava fully supports Java 1.5 actions Pane allows the user to evaluate arbitrary Java pro- including generic types and the “Tiger” (JSR-201) language gram text. The Definitions Pane supports the “intelligent” extensions (autoboxing and auto-unboxing, foreach, enum editing of Java program text through syntax highlighting, types, and varargs). It also includes a lightweight project brace matching, and uniform indenting to help beginners ad- facility capable of building projects like DrJava itself. CVS just to Java syntax. The Interactions Pane encourages stu- (the most widely used open source version control package) dents to experiment with both their code and Java libraries support has not yet been integrated in DrJava, but will soon by accepting an arbitrary series of program statements and be forthcoming. The primary features offered by profes- expressions and evaluating them cumulatively “on-the-fly”. sional IDE’s (like Eclipse and JBuilder) that are missing The value of each top-level expression is printed using the in DrJava are code completion and refactoring transforma- toString() representation of that value.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages5 Page
-
File Size-