Could your students explain how main() was called? Could they create their own functions and invoke them based on what they had learned? And how forgiving would Java be of minor errors, say, creating class a class named HelloWorld inside a file named Hello.java? Why does the filename even matter, if the class's name is defined right inside the file, or vice versa? And if the class is in a block inside the file, why can't they just create another block like the first one and have two classes in the same file? Why do they type 'javac HelloWorld.java', but not 'java HelloWorld.class'? How can java find the HelloWorld class if you're not pointing it to the class file? Why is 'javac' so damn picky about the file name matching the class name when you don't point 'java' to any files at all?
Seriously, there's a ton of voodoo in there. Things break in surprising ways, and it's hard to synthesize new knowledge based on prior experience.
Take Python, on the other hand. You can address things in a much more controlled order, with each step yielding practical information, starting with
print("Hello, world")
which tells the students how to call a function, and pass it an argument. Every other time they call a function or pass it an argument will look like this. Then you can show them how to make their own function: def hello():
print("Hello, world")
But nothing gets printed? Hey! You've just explained defining a function, and based on the previous example, they can probably suggest how to invoke hello(). At this point, they can easily make and call new functions of their own. Then you can go on to introduce the basics of OOP: class Greeter():
def __init__(self, name):
self.name = name
def say_hello(self):
print("Hello, " + self.name)
Sure, the "self" is a little magical there, but hey, you're comparing this to Java. Plus, you've got an interactive console that you can jump into and poke at the darn thing. Hey, what do I get when I say g = Greeter("Saundby")? Oh a "Greeter object". That makes sense. What can I do with it? Well, we made a say_hello, so what's g.say_hello? Oh, a "method Greeter.say_hello of <Greeter object>." And hey, it's the same Greeter object as g!What if the students want to make a new class? They just put it in the same file, like you would expect. What if they want to rename the class? They just do it.
And you run it with "python filename.py" which appears to work exactly like how every other command that operates on files. There's no explicit compilation step to forget or trip over.
Yes, you can teach kids to read and understand a Java program, but what do you gain by handicapping yourself and foregoing the pedagogical tools, like an interactive console, available elsewhere? Similarly, what do they gain by being deprived of such a wonderful and frictionless means of exploring and experimenting with the language?