Rethinking the Java Curriculum: Goodbye, HelloWorld!
by Daniel H. Steinberg08/21/2002
This is the first in a series of articles that looks at how programming in Java is taught to new programmers. In part, this series proposes to introduce object-oriented programming using the programming-centric practices of Extreme Programming (XP). This is not an argument of whether XP is the right methodology for you to use when developing your applications; instead, we'll rethink what new programmers should learn in an introductory course in Java. Please join the discussion at the end of each article and feel free to suggest future topics in the forum or by emailing me at DSteinberg@core.com.
When the Java programming language was new, introductory books, courses, and online tutorials stressed that the C-like syntax would make it easy for experienced programmers to move to Java. Sure, there were books that focused on the advantages of object-oriented programming and promised that inheritance would save the world. But, after a brief history that included some references to Oak, set-top boxes, and the Web, most introductions were ports of existing books on C and C++.
We didn't have to throw out our copies of
Kernighan and Ritchie, we could just learn this extra "object stuff." Somehow, Java was supposed to be better. We were told that Java didn't have any pointers, and yet many of us, within hours of
downloading the JDK, immediately threw a NullPointerException.
As we learned more and more about programming in Java, we found that C
was not the right way to approach Java. That doesn't mean the early books were
wrong; that's what we needed to hear at the time. Those resources feel dated now
because many of the newcomers to Java are newcomers to programming. We don't
need to explain to them how to get to Java from C -- we get to rethink the best
way to approach programming, if Java is the first language.
This is a particularly interesting time to rethink our approach. Starting in September 2003, the High School Advanced Placement exam in Computer Science will be available in Java. Introductory courses at colleges are being taught in Java, and educators have put a lot of effort into rethinking the curriculum. One project led by Lynn Andrea Stein has resulted in the Rethinking CS101 Project and its upcoming Web site. Stein has moved from the AI lab at MIT to the newly-created Olin College.
A Non-OO Intro to OO
If you were allowed to begin a course on object-oriented programming using Java, where would you begin? An obvious choice is:
public class HelloWorld {
public static void main( String [] args) {
System.out.println("Hello, world.");
}
}
As Jason Hunter notes in his
Java Servlet Programming book (O'Reilly, 2nd edition 2002), HelloWorld
has been used as a first program since the B language (the predecessor to the
C language). Introductions to everything from Java to JSPs and Servlets to Ruby to JDBC start with some sort of HelloWorld example program. It's a short, simple-to-write program with an
immediately observable result. A novice user can be led through the
editing tools to enter and save the half a dozen lines of source code. The
beginner can then be told how to compile and run the program. Even a newbie
knows that the tasks have been successfully completed when the words "Hello
World" appear in the console window.
|
Related Reading
|
On the other hand, there are many reasons to view HelloWorld as the worst
possible way to begin a course in object-oriented programming. At its core, an
object-oriented program should consist of highly-cohesive objects sending
and receiving messages to other objects. Maybe when a user clicks on a JButton
that is part of the application's GUI, all of the objects interested in knowing
when this particular JButton is clicked will be notified. These objects then
do what needs to be done -- perhaps by sending
messages to other objects.
Now look back at HelloWorld. No objects are created. The HelloWorld class
doesn't even contain any method, other than main() -- that's a rant I'll save
for the next section. HelloWorld is a class without any reason to exist,
and yet this is where we begin our discussion of object-oriented
programming. If you were highly charitable, you might give HelloWorld OO points
because the println() method of the out class in
the System package is being invoked. Blech.
The Big Bang
So an OO program is all about objects interacting with each other by
sending messages back and forth. A pedagogical dilemma is that all of this interacting
has to start somewhere, but this isn't where the explanation of object-oriented programming should begin.
In other words, you need to have a main() method to start a program, but you don't want to
start the course by explaining all of the components of main().
Similarly, in a Physics course, we begin by explaining how physical objects interact
with each other. We don't begin by explaining the Big Bang and the creation of the universe.
It's much easier to demonstrate and explain Newton's laws of motion. In
a Java program, the "big bang" that creates the first object is the main()
method:
public static void main( String [] args );
You could start the class by explaining what each keyword means. This means you'll have to begin the class by explaining:
Accessors: Before students even understand the difference between objects and classes, before they have even seen a program with more than one object or class, you have to explain levels of access. The
HelloWorldclass isn't even in a package, and yet you'll be forced to discuss packaging and hierarchies in order to distinguish amongpublic,protected,private, and that access level that doesn't even have a name.Class methods: The use of the
statickeyword depends on students having an understanding of which methods and attributes should belong to a class and which should belong to an object. As mentioned before, at this point, students don't see the difference between classes and objects. (If you are an experienced Java developer, you may not remember how difficult it is to grasp this distinction.) Note that theHelloWorldclass has a single method. Whether or notmain()isstaticis not based so much on the conceptual differences between a class and an object as it is on whether themain()method needs to be called before an object of typeHelloWorldis created.Return type: Imagine it is your task to explain the return type of a method. You may choose something like
int add(int i, int j)to illustrate that theadd()method will return the sum ofiandjas anint. You would not choose a method that doesn't return anything as your first example. You wouldn't introducevoidas your first return type any more than you would try to explain multiplication starting with examples of numbers multiplied by zero.Command line arguments: The parameters of the
main()method are command-line arguments. Often the example that followsHelloWorldis a refinement that allows the user to type injava HelloWorld myNameand get the feedbackHello myName. Do you really want to cover these right away? For this and the other items in this list, the question isn't whether these are important topics, but rather whether they are the topics that would best be presented first in a course designed to teach students object-oriented programming in Java.Arrays of Strings: The
argsvariable is aStringarray. I don't want to beat this example to death, but you don't want to have to introduce arrays in order to adequately explain the signature of this method. You also don't want to have to explain that if you want to read in anint, then you read it in as aStringand convert it to anintby using anotherstaticmethod in a wrapper class.
Sigh. The main() method might be the right place to start the
execution of a Java program, but it's not the right place to start your
explanation of a Java program.
The Challenge
So what do you think? Are you ready to give up on HelloWorld as a first
program, or do you see benefits that you would like to argue in favor of? What
about main()? You need main() or your program
won't run. How do you approach it? Do you tell your students to "just type it in
verbatim, you learn what all of the terms mean later"? Do you explain each of
the terms and then continue the semester with the three people that haven't dropped
your class?
How would you begin a Java-based introduction to object-oriented programming?
Daniel H. Steinberg is a podcaster, author, editor, trainer, and developer at Dim Sum Thinking. He co-authored the book Zero Configuration Networking: The Definitive Guide.
Return to ONJava.com.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 50 of 50.
-
Bootstrap class
2002-10-22 09:36:39 anonymous2 [Reply | View]
This occurred to me several weeks ago after looking at BlueJ again. What I figured out to do is write (as an instructor) a bootstrap class that will bootstrap any class by calling the default constructor. But again, this is not completely correct, because it just basically renames main() to MyClass().
I think BlueJ's approach is pretty solid.
-
Re: Common teaching errors
2002-10-17 22:01:45 anonymous2 [Reply | View]
Heh, you must have experience with Deitel's "Java: How to Program" text book, which is the text for my second semester of java programming.
My first semester, (into to OOP), was a joke. The instructor was not familiar with online classes and basically ignored the class until the very end. Then seemed to get irritated that so many were doing so poorly. We did not even get to arrays.
This semester is different. I am taking both C and intermediate java programming online. DON'T DO THIS AT HOME!! It was a mistake to do both at the same time. It's been very difficult and frustrating to deal with such opposite approaches at the same time.
I am breezing through C, but am struggling with java. I have to agree with some of the criticism against what you suggest. It would be two months before your students could reasonably be expected to start writing code, if you insist on doing a full-scale OOP from the start.
OOP is an abstract and complicated subject. Java is an enormous and complex language. It's very frustrating to have to go through the whole superclass, subclass, interfaces, methods business in java, when I could just hammer out some C functions in an hour or two.
For most of the initial school projects, the OOP approach seems like a bunch of needless nonsense and overkill. Personlly, I'm getting an awful lot of frustration out of the class, without seeing much benefit from OOP. So far, C is much more approachable and enjoyable.
I'm not real happy with the text book, as it seems to ratchet the complexity up pretty fast (faster than I can deal with anyway). There are way too many "and a miracle happens here" issues with java. However, the miracles only happen a certain way, in certain situations.
For example, we just wrote a program that accepts String input from a user and turns it into pig latin. Man, this would be way easier in Perl.
I chose to learn java. From what I had heard, OOP made programming easier and more effective. Well, so far I don't really see it. Just seems like a huge amount of added complexity, with little payoff.
About the only real benefit of OOP is polymorphism (inheritance is NOT all it's cracked up to be). I'm still not sure if the cost in complexity and general obfuscation is worth it.
Maybe I'll feel better after living with the language a couple years.
-
Design as important as implementation
2002-10-08 01:30:59 anonymous2 [Reply | View]
I've just completed a basic programming degree at a British University. The approach taken there was to take a fairly procedural approach to programming in Java (which probably was a bit of a cop out). Alongside this we learnt OO design, concepts and UML. Having learnt the basics of loops and selection we were then in a position to move on to more OO implementation concepts, and already had an idea about things like inheritance and interfaces from the design part of the course. The follow up lectures didn't cover enough detail, but the theory certainly makes sense.
-
What is your goal???
2002-09-19 13:43:46 anonymous2 [Reply | View]
Until you tell me what the prerequisites for this course are it is pointless to make a comment. There is a world of difference between teaching Java to students have never had a programming course and those who have. There is motivation for either kind of course, in particular I like the idea of first programming course that introduces OO concepts from the start, but their designs would be substantially different.
-
Here's my article
2002-09-16 08:40:15 anonymous2 [Reply | View]
I wrote a similar piece sometime back http://www.developersatlarge.com/java/helloworld.html
-
Common teaching errors
2002-09-05 06:58:54 uncledave [Reply | View]
There are several traps that even experienced teachers fall into, many of which can be avoided with common sense, deliberation, and stepping back from the subject they love so much. Here is some advice to avoid the traps:
* You recovered from earlier programming experiences that were "wrong" (e.g., I started in FORTRAN); so can your students. You do not have to be "right" from the very beginning.
* Problem solving is done in terms of certain tools; it cannot be taught in the abstract. You need to know something about a programming language before you can begin to solve problems in programs.
* OOP and all other "right" techniques are expressed in a language or they are not intelligible. In addition, they are motivated by need, not by altruism and "rightness". Until your students get into predicaments, or until they can be shown a useful simplification (etc.), they will not understand the "right" way.
* Hello World is an introduction to programming, not to OOP. You can teach all the basic language constructs using code placed only in the main method. There are many, many language and programming details that can be introduced this way. At some point, the main gets big enough that you have genuine motivation for introducing concepts for information hiding, parameterization, partitioning, and ultimately OOP.
* Students must (and do) take a lot on faith when they begin programming; so do you, even now. There is nothing damaging about it.
* The "grad student syndrome" in which the instructor wants to do a direct brain dump to his students is frightening to students, and wrong; it can be avoided.
After the main method gets too unweildy, and you start using other methods, consider changing to applets using the AWT to heighten interest and a sense of reality.
By the way, while we are all correcting our behavior with respect to teaching and writing about programming, here are some other pointers for getting out of the rut:
* Put discussions of machine structure at the end of the course, where it can have some meaning.
* Don't pretend to show the stepwise (or other rational) development of common algorithms unless you know for a fact that they were actually developed that way; most were not.
* Quit using the word "notion" all the time; try "idea", "concept", and others.
* Don't provide quotes from "Alice in Wonderland" or Douglas Adams' books.
* Skip the "Towers of Hanoi" and other cliche examples. Use something real, even if trivial.
-
Speaking as a student
2002-09-04 22:43:15 darkglory [Reply | View]
This is just my two cents for what it's worth. As a 19 year old college student in the computer science major, I have been at the receiving end of these teaching methods for some time now. Having recieved a rudimentary education in C++ in high school, when I entered college and began programming in Java, I was slightly more prepared than some of the other students, but still had a lot to learn (as you all know).
Anyway, I opted to take an extra computer course my first semester as a freshman as a sort of "Intro" to programming. The course used a program called "Alice" available at http://www.alice.org
This sort of 3-D animation programming environment (that was the best way I could think to describe it at 1:40 AM on 4 hours of sleep) provided a very good stepping stone to programming in general.
Animations are accomplished by using a drag-and-drop type programming interface which was valuable to myself and many less-experienced students. It also gave a general introduction to the idea of methods to contain often repeated actions.
While this is not necessarily Java-specific, I feel it was a valuable learning experience, and I would be interested to see if other classes may benefit from the same exposure.
-Evan Shea
-
HelloWorld crashes
2002-09-03 15:28:08 bjsyd70 [Reply | View]
HelloWorld will frequently not run.
I recently looked at Java CORBA examples.
It is a HelloWorld.
The Java Tutorial example crashed (JDK1.3).
The JavaWorld example did work (JDK1.4).
Sometimes its the fact that Java is not installed.
Sometimes its classpath.
Sometimes its arguement changes for idlj.
HelloWorld is not for teaching,
its for crashing.
Brendan
-
how about using JSP
2002-08-31 17:51:59 michael_jug [Reply | View]
Merigold proposed using JSP.
I have had the same idea and am currently trying to figure out how to do it best.
the problem with teaching java to complete beginners and to procedural programmers is:
-they have to learn a new syntax (most don't come from c/c++)
-they have to learn what objects are
-they have to learn, at least some, of the Java classes
and all of that at the same time.
With JSP one can start off with just explaining the syntax at first (primitives, loops etc).
Next would be using some of the classes of the api.
Own classes would be last.
One has to face it, it is hard to grasp the principles of oop, probably it is impossible to fully understand it in a couple of days (mastering oop definitively takes years).
And if you are confronted with a completly new syntax at the same time, it makes it even harder.
So if your students have at least some practise with the syntax ( a day), it is easier to concentrate on oop.
Of course using JSP for larger production sites is problematic, but sciptlets are just the most simple way to write some java code. And with simple examples used for teaching there won't be any maintenance problems.
Well it may be a little problematic teaching people something and later telling them "don't use it this way for your real work"???
Another major benefit of JSP is that you get an easy user interface for your example programms (simple html forms).
Using swing or awt is much to difficult for beginners and console applications, well you can't excite anyone with them nowadays. Plus one has to use a lot of classes to read some input from the console (can't do it without exception handling!).
What I am struggling with is, how to best introduce objects. Let them write a bean for session data?
Should one include JSP specific stuff (actions, taglibs ...). If yes to what extend?
Any ideas?
-
Two Mindsets
2002-08-30 14:15:57 geraldaschwartz [Reply | View]
I think the problem is more fundamental. Just browsing some of the comments already posted, I feel that the respondents are of two mindsets.
1. Those that feel one should quickly demonstrate that Java is easy to learn by having them type in a simple program
2. Those that feel an introduction to the abstract world of objects is necessary before any programming is done
Actually, there are some who would like both, as well.
Let's face facts. HelloWorld is a lousey way to introduce C and C++, let alone Java. It's time that object oriented languages were taught with the idea that the student better have the ability to deal readily with abstractions and if they don't they shouldn't be being taught Java.
We already have a host of so called programmers out there who have been taught how to hack solutions to problems using code, rather than how to abstract solutions for themselves.
The productivity of real problem solvers to rote problem solvers is 10 to 1, so why promote more of the latter? Java is an elegant language, and deserves more.
Gerald Schwartz,
Retired Programmer
-
First use a template
2002-08-30 04:44:29 mikkale [Reply | View]
Having just finished teaching an introductory course on java, i get the impression that for teaching java as a first programming language, you first have to simplify a great deal in order to prevent students with little or no programming experience from being totally confused with different concepts that are not essential for the problem you are trying to solve, e.g. main being a static method and the consequences of that (compilation errors when referencing non-static members) required a quite big amount of time.
So now I use two different Class-templates for introduction:
1.
class MyClass {
public static void main(String[] args) {
MyClass m = new MyClass();
m.runApplication();
}
void runApplication() {
// insert your code here
}
}
2. if I need command line arguments, I use:
class MyClass {
public static void main(String[] args) {
MyClass m = new MyClass();
m.runApplication(args);
}
void runApplication(String[] commandLineArgs) {
// insert your code here
}
}
With these templates I only have to explain what runApplication does and thus don't have to explain access modifiers, static methods etc.
In future I'm thinking of using BlueJ because of its visualization of objects. I think that with BlueJ students should be able to get an understanding of OOP quicker. Especially I like the live introspection features of BlueJ. (But I think I first have to patch the Moe Editor because tab handling when using backspace is awful: Caret should snap back to previous tab if you delete whitespace at start of your line).
-
Is Java the right langage to teach OO ?
2002-08-30 00:47:01 dweeves [Reply | View]
Hello,
OOP is all about concepts and not about languages !
The problem with Java is that its Class Library (API) is itself a very sophisticated OO architecture , already using/implementing a lot of advanced OO concepts (like patterns) and system techniques (like threading , delayed calls in Swing)
I began OO programming in 89 with Borland Pascal for Objects. And i found the OO approach very well explained in the manuals .
Using the classical 'figure' example to explain virtuality and inheritance.
I saw a lot of "young" java programmers falling into the trap of using the class library without knowing the concepts they were manipulating just because Java had already implemented these concepts and made them easy to "call".
But calling already made objects is exactly what's done in Visual Basic which is all but an object oriented language (not speaking of VB.Net which is no more VB)
"Hello world" has simply no architecture. It is not an example to take for OO teaching !
The main interest in OOP is creating objects suiting an application architecture. For creating these objects, you can use other objects of course.
You can't teach Java before teaching OOP . But you can use Java as an OOP teaching language by using only the java.lang package and taking the approach of "problem solving".
I explain : ask the students how they would do something and tell them the benefits of doing it in an object way. By taking this approach, you could focus on each OOP concept , by refining the solution provided incrementally.
-
Is Java the right langage to teach OO ?
2005-06-02 03:08:43 MSCstudent [Reply | View]
On my MSC course we were introduced to Java as the first and most important module on a conversion course. Most of the group had very limited computing backgrounds, and many of the students fell behind.
However, for the few of us who were able to engage with the concepts immediately and navigate the API, we soon excelled and have since become competent programmers in multiple OO languages.
In September 2004 I had never programmed before, and less than 9 months later I am nearing the end of my MSC course with an amazing breadth of knowledge and understanding.
Therefore, for me Java was the best language to learn. However, the course has caused some students to struggle, but the focus should be on trying to find out what new students find difficult with the concepts so these issues can be addressed.
-
Hello, World! is not a "Java" program...
2002-08-29 09:37:54 rwehrli [Reply | View]
While I do not necessarily think that the advantages of the mechanical requirements of Java transcend the traditional benefit of a "Hello, World!," it, as written, is !Java.
How about...
// HelloJava.java
package edu.myschool.FirstPrograms;
/**
* A First Java Class Definition
* (additional, necessary code comments
* removed to constrain message size)
*/
public class HelloJava
{
public static void main( String args[] )
{
System.out.println( new HelloJava().toString() );
}
public String toString()
{
return new String( "Hello, World!" );
}
}
...as a potential counterpart? :)
I think that the most important thing to teach when first learning OO is the concepts of using objects to accomplish the promise of reusability offered through mechanisms available from the chosen programming language. The mechanics of the language, while significant and often daunting (especially C++) are secondary elements that provide a "look" into what OO has to offer from the perspective of features offered by a particular language.
I find that traditional "procedural/structured" programmers often never acquire the "mindset" necessary to "think OO." While they do often learn the "packaging" fundamentals of producing objects, they often horrendously violate "rules" of abstraction, inheritance and encapsultation...and rarely, if ever, use polymorphism at all or effectively. The biggest "first" sin seems to be one of inheritance. I've seen many, many cases of "Bird is a Rock" because a Bird must use a Rock object for a particular functional role. The mechanics of the language allow you to declare your hierarchy as you choose, even if a Bird is most definitely not a kind of Rock. Too many programmers are content with accepting the outcome of the compilation process and execution for desired effect as an indication of successfulness in architectural design choices. It makes me scream...
For the sake of tradition and the lesson of mechanical "influence" that a language brings to the table, I'd not vary from an appropriate Hello, World! in a "first program." If students are unable or unwilling to come back the following session, hey, maybe programming and/or OOP are not their bags, baby?! ...or perhaps the presentation interface offered by the instructor leaves them wallowing in a sea of stupor rather than invigorating them to investigate their potential for a future in Java? Of course, a good salesperson should be able to sell more than 3 people in a classroom of 25-ish on the coolness of using Java where its benefits might be realized when applied to some business or academic challenge. The easiest thing in the world to do is blame the message content and not the messenger... You might expect that a messenger in Nebuchadnezzar II's era, after having ran across a decent bit of desert at an Egyptian front back to the Babylonian command and control center, would have had some way of presenting an otherwise disappointing message?
However, in contrast to my previous mention of learning OO concepts, if this is a first-ever programming course for students, I tend to prefer to first explore the importance of data and its type(s) as they are "seen" from the programming language, before ever launching an IDE. And, on that note, is the student learning to use an IDE or the language/concepts of OO? I strongly prefer the CLI and vi(m) as a core development "environment."
But, by the second session, your 3 will be only one remaining geek in a penguin shirt :) Far better to save the one who can be saved, IMHO! :D
Take Care.
Rob!
-
The first program needs to show it all
2002-08-28 21:13:43 porterskog [Reply | View]
"Hello World" is just the sound check, and has no pedagogical value.
We need to look at enriched environments in which to teach programming. The sparse environments bore the students. Enriched environments in which the students modify interesting programs to learn the various structures and techniques is much more interesting to students. I believe someone has already mentioned Robocode.
If you are using an IDE with a good step though debugger, I would avoid "cout" all together.
The following is a one file example that is a starting point for teaching that allows modification to learn all the control structures and allows introduction of objects, inheritance, and polymorphism.
A multi file example can place the arrayOfObjects in another file and "extern" them into the program, to show that you may not have control over the objects that are used in your porgram.
#include <iostream>
using std::cout;
using std::endl;
class CBaseClass
{
public:
virtual void whatAmI()
{
cout << "I am CBaseClass. If the Sub classes "
<< "defines a function with this signiture/n"
<< "You should never see this!" << endl;
}
void nonpolymorphic()
{
cout << "I am CBaseClass. You should always see this!" << endl;
}
// For our example this prevents an object of type
// CBaseClass from being instantiaed
private:
virtual void purevirtual() = 0;
};
class CSubClass1 : public CBaseClass
{
public:
virtual void whatAmI()
{
cout << "I am CSubClass1!" << endl;
}
void nonpolymorphic()
{
cout << "This is the nonpolymorphic all from "
<< "CSubClass1" << endl;
}
private:
virtual void purevirtual()
{
// It is now defined. Are you happy?
}
};
class CSubClass2 : public CBaseClass
{
public:
virtual void whatAmI()
{
cout << "I am CSubClass2!" << endl;
}
void nonpolymorphic()
{
cout << "This is the nonpolymorphic all from "
<< "CSubClass2" << endl;
}
private:
virtual void purevirtual()
{
// It is now defined. Are you happy?
}
};
int main(int argc, char* argv)
{
int numberOfObjects = 2;
CBaseClass* arrayOfObjects[2];
arrayOfObjects[0] = new CSubClass1;
arrayOfObjects[1] = new CSubClass2;
for (int i = 0; i < numberOfObjects; ++i)
{
cout << "The value of the variable \"i\" is "
<< i << endl << endl
<< "The next statement is: arrayOf"
<< "Objects[i]->whatAmI()" << endl;
arrayOfObjects[i]->whatAmI();
cout << endl << "The next statement is: arrayOf"
<< "Objects[i]->nonpolymorphic()" << endl;
arrayOfObjects[i]->nonpolymorphic();
cout << endl << "End of this cycle through the loop" << endl << endl;
}
cout << "I am out of the loop" << endl;
return 0;
}
</code>
-
The first program needs to show it all
2002-08-28 21:21:17 porterskog [Reply | View]
I know that the code is C++, but break it out into a few files for the classes and get rid of the cout and pointers and your there. OOP is the same in both languages, just the libraries are different.
My fingers just took over and banged out the C++ stuff, sorry.
-
Print out the System Properties
2002-08-27 07:20:40 bayard [Reply | View]
I long ago dumped Hello World in favour of the following snippet:
package test;
import java.util.Properties;
public class ShowProperties {
static public void main(String[] args) {
Properties props = System.getProperties();
props.list(System.err);
}
}
It can start very small [without the import and without the package. Just declaring java.util.Properties direct] and can grow larger by switching to an instance of of ShowProperties, then waking over the Properties instead of using list(OutputStream) etc.
One of Hello World's great problems is that it doesn't scope. You do it on the command line. You do it in a GUI. On a webpage. But there's no easy continuation of the lesson, you just throw it away.
A Properties outputter gives you a nice timeline into many of the core Java concepts. -
Print out the System Properties
2002-08-28 16:50:48 amuys [Reply | View]
>One of Hello World's great problems is that it
>doesn't scope. You do it on the command line. You do
>it in a GUI. On a webpage. But there's no easy
>continuation of the lesson, you just throw it away.
When the language in question (as it is here) is Java I must agree. However when teaching other languages, I have progressed from HelloWorld thus:
1) console based hello-world.
2) GUI label.text = "" based hello-world.
3) button with command=quit based hello-world.
4) button with command->change label -> quit
5) Basic GUI adder (two text boxes, one button, and a label for the result)
6) String copier using two text area's (on-click copy text from one area to the other).
At this point you have enough basic GUI components to allow a switch to traditional lessons, introducing fuctional decomposition, data-structures, and basic algorithms. OTOH, you also have given the students the perception of signifigant progress. I have generally found the resulting morale boost leads to spontaneous experimentation and self-directed learning.
Still there is nothing magical about "HelloWorld", the properties example could be structured in a similar way.
With Java, the lack of a syntactially clean analogue for lisp/python closures, smalltalk blocks, or tcl eval(), C/C++'s function pointers, etc. There is a substantial barrier to introducing GUI programming that early.
Note that this is an issue with using Java as a *FIRST* language only. Once a student has learnt basic programming skills, the learning barrier is substantially reduced.
Andrae Muys
-
Perhaps the Problem is OOP and Java itself
2002-08-26 13:35:08 cdmiller [Reply | View]
Perhaps you need to approach programming in a different way.
Maybe what Hello World in Java is illustrating is that OOP and specialized OO syntax languages are not the best answer to many real world programming problems.
-
OOP might be less elementary than you wish it were
2002-08-28 10:01:12 franzn [Reply | View]
If you cannot find an obvious simple example to introduce OOP, I wouldn't consider this as a problem, but rather as an indicator that OOP might just be a bit less elementary than you wish it were.
I have always found that 'pure' programming philosophies, like 'pure functional', 'pure declarative', 'pure OO' anyway do not hold what they (superfluously) promise. Look into some textbook on LISP or PROLOG programming and you will find imperative sequential methods have to be applied in time to make things work.
OOP, to be sure, is very convincing if you eventually see it working. I'll never forget how at the end of my first C++ lesson I thought: So this feels like real programming at last.
I believe there are experiences which you just cannot have right at the beginning. So why not accept that there is a HelloWorld Level first?
-
In defense of Hello World.
2002-08-25 21:36:41 amuys [Reply | View]
I run a computer based holiday camp for High School students, during which we (attempt to) teach them basic programming over the course of one week. Over the years, we have used a number of languages, Java included. In all cases helloworld proved critical.
1) As mentioned previously, it provideds a critical system environment test. You simply cannot assume that just because the environment for N-1 lab machines is correct, environment N is as well.
2) It provides an opportunity to introduce the development environment. This *must* include concepts such as editing, compiling/interpreting, and executing files etc.
3) It provides immediate feedback, and a substantial morale boost at a critical stage of the learning process (ie. the start).
4) Contary to previous comments, focusing on code modification rather then creation is a serious mistake. The critical skill the student needs to learn as soon as possible is the mental process of functional decomposition. Helloworld demonstrates a minimal complete program; even the fuzziest cognative map of the execution entry-point is infinately preferable to the impression of 'black magic happens here'.
5) It provides a natural point of comparision should you decide to use a GUI Helloworld example next. We have found this very advantagous as it substantially reduces the perceievd gap between the program the student has just written, and the programs the student has previously used. This perceived gap can be very deoralizing to some students.
Compared to the disadvantage of using a non-OO first program we find these advantages compelling. I don't see us abandoning the classic helloworld application anytime soon.
-
How would I begin an Intro Java OOP Course
2002-08-24 13:02:31 dbaldwin [Reply | View]
I would and I do begin with the lesson that you will find at the following URL:
http://softwaredev.earthweb.com/java/article/0,,12082_935351,00.html
Prof. Richard Baldwin
-
how about using JSP
2002-08-23 14:25:37 merigold [Reply | View]
Just a wild idea...
You can completely eliminate the need for tricky "main" and "hello world" as well as even teaching them about compilers to begin with if you start off using JSP. Just install Tomcat and then have them save their files in .jsp files, tomcat will automatically compile and display in a web browser.
The code they write in their scriptlets can then call the objects they learn about in existing packages, as well as the objects they write themselves.
You can save main and System.out for much later when they're comfortable with objects.
This will work even if they know no html; the browser will display just text just fine. It also allows you to postpone all the details about package names, .class files, etc for the third or fourth class instead of the first one.
-
Confusing two different things
2002-08-23 07:48:58 davetron5000 [Reply | View]
As many have pointed out, HelloWorld.java and the like is for learning two things:
1. The development cycle for programming anything: write code, compile code, run code, repeat
2. To verify that your environment is set up.
I feel that schools do not spend enough time on "how to program" and too much on theoretical discussions about non-applicable things. Articles like this make me think that there is even more removal of "how to program" knowledge from the students.
I also feel that Java should not be the introductory language for students, because it robs them of the chance to learn about resource allocation and management (namely memory), which is very important in helping them PROGRAM COMPUTERS, which is what they are being trained to do for the most part.
Additionally, once you are in your methods of your well-architected objects and all that, you are writing a procedure. A method in the real world EVENTUALLY boils down to a procedure for acomplishing some task. That is where programming should start.
The first programming language I learned in school was Karel the Robot, because it taught me how to problem solve and write a robust procedure to accomplish something. From there you expand.
OO is a tool. Not all of it is good. XP is a tool. Not all of it is good. The ability to solve a problem and tell a computer EXACTLY what to do IS what programming is all about. This should be taught in school, and it should not be intermingled with the teaching of various techniques/theories/etc. -
Confusing two different things
2002-08-23 15:05:50 blrfl [Reply | View]
Well said. I have to agree.
The education system has stopped turning out developers who can construct a solution that is thoughtfully-designed, well-engineered, efficient, elegant, understandable and maintainable. Sadly, as time marches on, I see more and more code in the flavor-of-the-month language which does the job but makes use of few of the language's features and has all of the appeal of a stomach pump. Sure, it's OO because the environment dictates it, but what's inside is still procedural in nature, and a lot of what I see in those procedures is of pretty low quality.
Part of the problem is that our tool boxes have much more complex tools in them than when I started writing software (23 years ago). I've been fortunate in that I've been able to grow along with the industry and absorb new concepts gradually. Maybe in our zeal to turn out programmers who can get a job using the latest language, we're trying to cram in too many things too early on. Maybe because of the amount of material, it should take six years to get a CS degree instead of four.
The solution? Don't use Java as an introductory language. I don't think someone who's never written a program in his life is ready for it. Start with a nice, strict procedural language that's good for introducing the foundation concepts. And don't forget a little assembly, so students can understand what's going un underneath all of those calls to system.out.println(). I find that few do these days. (Wow! You mean the machine actually has to send out one character at a time? Whoa!)
-
'package' access level
2002-08-23 03:15:52 calvineet [Reply | View]
All access levels have names. They are 'private', 'protected', 'package' (the default), and 'public'.
-
how about jython then?
2002-08-23 01:51:49 davidccrane [Reply | View]
I'll throw my favourite language into the bag. Jython seems to ddress a few of the issues the author and other commentators have raised so far:
- python is a clean, simple language, designed to be easy to learn
- it can be run without any IDE, it's portable (this applies to both 'proper' Cpython and to jython)
- no main() method. If you wanbt to do something really simple like Hello World, you write it as a functional language: the python/jython listing for Hello World is simply:
print "Hello World"
- you can then graduate onto using OO techniques when required, starting with defining a class and then manipulating it via top-level functions, then on to getting several objects talking to each other
- it can be run interactively : great for learning, quickly testing things out, etc.
- if you teach jython, then you can familiarise your students with any parts of the java APIs that you like, and then move them on to native java coding gradually
- easy to install, I've set it up on various Linux and Windows without any problems.
Downside is that the syntax for python and java are not that similar, but there are other java scripting language implementations e.g. Netscape's Rhino, that offer similar benefits with a more C-like syntax. (I'm recommending jython specifically because its the one I know.)
Jython can be found at http://www.jython.org
Dave Crane
-
how about jython then?
2002-08-23 06:50:53 eallen [Reply | View]
Jython is great. Another big advantage of it is that Jython classes compile to ordinary Java class files, so you can subclass Java classes with Jython classes and conversely. Also, Jython has (a limited form of) lambda expressions and other very useful language features.
We considered using Jython for the read-eval-print-loop in DrJava, but ultimately we decided to use DynamicJava instead. The only reason we decided not to use Jython was because the differences in syntax would prevent students from lifting into their Java programs expressions and statements typed interactively. That's too bad, because in many ways, Jython syntax is cleaner. For instance, simple lambda expressions can be added to GUI elements as action listeners (it's very convenient).
-- Eric
-
Objective-C
2002-08-22 23:39:36 jasontm [Reply | View]
I'll probably get flamed for writing this in an article about Java, but...
I'm of the opinion that Obj-C is by far the clearest OO language i've seen yet. It's so simple and uncluttered.
It's very message centric, and for me at least, that made it easy to see in my mind the connections i was making.
For those of you who may not be familiar with Obj-C, it looks like this:
[Receiver Message:Argument]
I personally like the bracket style, which makes it easy to pick out nested messages.
[Receiver1 Message1:[Receiver2 Message2:Argument2]]
It seems almost instantly obvious what's going on.
Yeah, it's a superset of C, and C isn't as 'convenient' as Java can be (though, with Apple's runtime, and the way it handles object lifetimes with reference counting, it's pretty easy to make sure things are released properly).
But then again, if you want to teach someone the simplest possible language, teach them Basic (just for the record, i can't stand that language).
Complexity isn't bad, as long as the rules are presented in a simple and straightforward manor. Kinda like the game of Go. :)
Which, i suppose, is the point of this article. I whole-heartily agree, most intro to programming classes are horrible. My first was on C++. I'm not a big fan of the language, i wonder why? :)
JtM
-
Check out DrJava and for teaching Extreme Programming
2002-08-22 20:47:32 eallen [Reply | View]
Great article!
In order to address many of the very issues you describe, we've developed DrJava, an open-source (GPL'd) Java IDE at Rice University. DrJava has an integrated read-eval-print-loop, allowing students to instantly call methods, evaluate expressions, and otherwise interact with their code without having to write a single main method or println. You can download it at:
http://drjava.sourceforge.net
You'll find that the philosophy behind DrJava is very different from other intro tools, such as BlueJ. DrJava is heavily influenced by extreme programming: we try to keep students focused on the code, and the tests over the code, instead of on UML. In addition to the read-eval-print loop, DrJava includes seamless integration of JUnit, as well as a JPDA-based debugger.
BTW, DrJava is itself a great example of an extreme programming project. Approximately one-third of the DrJava code base consists of unit tests. For this reason, we also use the code as the basis for our upper-level software engineering course. This gives students the opportunity to work on a real body of XP software, and it helps us to further extend the available functionality. Since the code is open-source, the same thing could be done at other universities, and extensions could even be submitted for inclusion in future releases. Check it out; we think you'll like it!
Eric Allen
JavaPLT laboratory
Rice University
-
Instead of HelloWorld
2002-08-22 20:27:05 maggiel [Reply | View]
Even though it does in fact start with HelloWord.java (and the applet equivalant HewlloWorldApp.java, I think the very best Java tutorial on the planet is the one published by Sun called "The Java Tutorial", available online at http://java.sun.com/docs/books/tutorial/.
Perhaps the best new substitute for HelloWorld would be ClickMe, found in the topic "How Do These Concepts Translate Into Code", which occurs *after* an explanation of the fundamentals of object-orientation.
See:
http://java.sun.com/docs/books/tutorial/java/concepts/practical.html
-
Beginning to teach Java
2002-08-22 19:55:13 bearcatben [Reply | View]
Frankly, I would take a set of building blocks into the classroom -- just like little children use in kindegarten.
Set one on the table, and announce that it is an object. Let a few exaggerated OOooo's and Ahhh's pass, then take another block and set next to it. - Again, announce that it is an object.
Place the second next to the first, then drop a few more onto the table. Line them all up end to end, and say: "Here is one object."
Tap the end two together, and announce that what affects one affects all of them; and push one end of the row of blocks, moving them across the table a little ways
Take two sets of three blocks and make a small pyramid; move one pyramid, then the other across the table; then push one pyramid next to the other.
Do all of this without much commentary, just the visual demonstration.
Now, announce that each block is an object, and each pyramid is an object. Looking a little amused, say that every motion can be considered a "method"; and that the number of blocks in each pyramid (maybe add 3 blocks to one pyramid for distinction)are attributes.
How far the blocks are pushed, are parameters. Ergo, the teacher him/her-self is an object with parameters, attributes, and methods -- that can use the methods within the "exposed" objects within certain parameters. (You can't push too fast or the pyramids will disconnect or fall. You can't go past the edge of the table, or you lose the objects altogether.)
Then hold up a block, and ask if anyone knows what a "string" is, letting the obvious pun stand for a moment. (This can be a seque to the "Hello World" program.)
And continue on from there.
Does one pyramid "inherit" the parameters, methods and attributes of the individual blocks?
How do the position or size of the blocks affect the stability of the pyramids?
Can you see that each pyramid or block has an interface? (the sides of the blocks or pyramids)
Are there things you can do with one block that become more difficult when dealing with the blocks in a pyramid?
The analogy goes on and on, of course, and can be expanded by shaping forms -- even some low-grade sculpture of an animal or something -- out of a large number of blocks.
(Someone in the class may decide that art is a better career choice that IT if they make a good enough sculpture. -- Hopefully, that will not be the instructor.)
A box can be used to contain a few blocks, making a simpler interface and allowing better control over all the blocks in the box -- and the other blocks can be shown to 'address' exposed parameters of the box by setting it on them.
Anyway, you asked how I would begin teaching OOP. That's about it.
Paul
-
What HelloWorld is good for
2002-08-22 15:27:38 ljagged [Reply | View]
I think that you're missing a couple of the good points of HelloWorld.
1) It's small. It's about as small as you can get and still have some working code.
2) It provides feedback to the user. By actually printing something to the screen, the user -- a newbie by definition -- gets immediate feedback that s/he did something right.
3) It's friendly. It's hard not to feel good when you see the cheerful 'Hello World!' staring at you from the terminal window.
I agree with you that HelloWorld doesn't teach good OO practices, but I think the purpose of HelloWorld is to show the user that everything is set up correctly for some real programming to occur. It's more of a system check than a model of the RightThing. -
What HelloWorld is good for
2003-04-21 09:54:22 anonymous2 [Reply | View]
So why not write an OOP version of Hello World
such as
public class HelloWorld
{
public void displayMessage()
{
System.out.println("Hello World");
}
}
Now create a HelloWorld object in BlueJ and
invoke its displayMessage method.
-
I thought I said that in the article
2002-08-22 18:42:32 Daniel H. Steinberg [Reply | View]
Not to be argumentative -- but I said that HelloWorld "is a short, simple-to-write program with an immediately observable result." I believe those address (1) and (2).
As for point (3), I admit I'm at a loss. I don't find the words 'Hello World!' staring at me from a terminal window as being cheerful or friendly.
I also agree with your final point that HelloWorld is a system check and note in the article that this program is where the novice user first learns to use the editor, compiler, and first runs a Java application.
In other words, given all of the traditional benefits of the HelloWorld program, I am still suggesting that it is not the best way to start a course in object oriented programming.
-
I thought I said that in the article
2002-08-23 07:31:28 ljagged [Reply | View]
I agree with all your points, except for the last one. I think that starting a course with a system check is _exactly_ the way to start a computer course, OO or not. Particularly, if the student has little/no programming experience.
When you're doing a physics experiment, you want to reduce the variables to an absolute minimum. The best situation is to have one variable that you can control. Similarly, if you start the student out with an example of a good OO program and it doesn't work, they need to figure out why. is the JVM not on their PATH? Is the jar file not on their CLASSPATH? Are they treating an instance method as a static method? By starting with HelloWorld you're limiting the number of variables. If HelloWorld is working, then they probably have their PATH and CLASSPATH set up correctly. That's to say, their toolset is in working order and they can go forth with confidence.
Admittedly, I'm a little vague on your goal. When you say a "Java-based introduction to object-oriented programming" is the intention that the students are already familiar with programming and this is their first foray into OO? The impression I got from the top of the article where you mention CS101 and CS in high school for the AP is that these are first time programmers. If that's the case, I'd argue that they should start with a language like python, scheme, or logo.
Python: print "Hello World!"
Scheme: (print '"Hello World!")
even BASIC is just: 10 PRINT "HELLO WORLD!"
and, I agree, that's probably a waste of time. If I had to teach Java to beginners, I'd probably teach them Jython. They get the benefits of a REPL environment and the ability to learn Java's class libraries. Eventually, I'd wean them off of Jython and into writing actual java code. -
What if we change the context
2002-08-22 21:41:39 trajano [Reply | View]
When I was in university, I do not recall them really teaching us "hello world", our first assignment was to do with graphics already (this was a first year intro CS course).
Anyway, the way we had it was we had a few labs that we had to do to get us familiarized with the environment (how to compile, how to list directories, how to log in and log out). The "hello world" would be perfect for a lab task.
The intro course itself could start teaching OO concepts from the get go. We learned other concepts on my day, but I think this would be the best way to teach an intro to CS course.
Also on a side note, our labs were basically graded as "complete" and "incomplete", and do not count to your final mark because someone who knows programming will think its a waste of time anyway. But beginners would have an opportunity to understand how things work.
-
Look at BlueJ, and also other languages
2002-08-21 13:18:47 tpherndon [Reply | View]
This problem with Java has been thoroughly addressed by the good folks at www.bluej.org, who created the BlueJ IDE for Java specifically to enable them to teach proper OOP in Java at a CS101 level. They are a group of CS teachers and researchers from (IIRC) Monash University in Australia.
On the other hand, perhaps this kind of problem is a really good reason not to use Java as a CS101-level language. Maybe the difficulties involved in teaching proper programming using Java simply show that Java might be better used as a second or third language, rather than the first language to which a budding programmer is exposed. After all, MIT teaches programming using LISP, right? "Structure and Interpretation of Computer Programs". And Python is also being pushed as a great introductory language, as well.
Java's wide-spread popularity in the business world for server-side programming does not automatically make it the best choice for all purposes. I think we should remember this principle when contemplating CS curriculum, something that affects the future of, well, darn near every aspect of life (at the risk of sounding somewhat melodramatic ;). -
Disadvantages of teaching an IDE to intro
2002-08-22 21:51:08 trajano [Reply | View]
I have to admit that BlueJ is a very user friendly tool to learn about OO concepts. But as an intro to CS course, this may be hiding too much of how the systems work from the student.
I am all for making things easier for people, but I would rather have my students taking time to learn about the environment, perhaps using a simple text editor that is installed in the system and command line tools to compile their code.
The concepts they would learn would pass on to future years to come.
However, I think BlueJ would be useful to teach in the 102 class or a class that specifically teaches OO at a higher level.
-
Don't have them write the whole app
2002-08-21 12:33:20 cmoyer [Reply | View]
Well, a simple way to avoid the "main" issue and present them with something interesting to do is to provide them with a harness for objects they create.
Perhaps the instructors provides aquarium.class and fish.class. Then the students simply write myfish.java which inherits from fish and pass it to the aquarium. The fish can react to events OnFood(), OnTapOnTank(), etc...
-
couldn't agree more
2002-08-22 07:28:59 dscotson [Reply | View]
This is important both pedagogically and for real world experience. How often do you sit down and write entire apps from scratch? Surely extending, enhancing, incorporating and fixing(!) existing code are all essential skills to be learnt by any coder.
Robocode (robocode.alphaworks.ibm.com) where java classes compete battlebots-style has the right idea. Unfortunately the current implementation encourages many bad habits and introduces too many concepts tangential to basic programming skills.
Something simpler like Logo in Java would let students learn basic concepts while making pretty pictures - far more stimulating feedback than standard out provides.
Utilizing XP principles you can create self-marking activities with JUnit. The students must make each test pass in sequence giving immediate feedback and breaking tasks up into manageable chunks. -
couldn't agree more
2002-08-23 11:35:01 tomhunt [Reply | View]
Guy Haas put together a java curriculum for our middle school, Longfellow Arts & Technology Middle School in Berkeley, CA. He has a large part of Logo as a Turtle Graphics java class. See: http://www.bfoit.org/Intro_to_Programming/index.html -
Coincidence
2002-08-22 21:54:30 trajano [Reply | View]
Actually my intro class did use something like Logo for Pascal (that was my generation still). We didn't have to do anything like knowing how to code with XLib and such just pascal with a drawing head.
Though I have to admit it was the toughest assignment I ever had in university considering that it was my first assignment. Everything else was simpler in comparison after that.





In the article it said (and I quote): "...you might give HelloWorld OO points because the println() method of the out class in the System package is being invoked..."
If I remember right, this is the case with C#, where System.Console.Write is used: System is a package, Console is a class within it, and Write is a [static] method of this class (Sorry, but I'm not sure about the C# stuff).
Barak Ori