public class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
He/she saves it into a file called HelloWorld.java and says:
javac HelloWorld.java
java HelloWorld
[Why not HelloWorld.class like every other
unix command-line application? No-one knows.]
For what should be an incredibly simple program, the student needs to understand access modifiers, classes, class names, objects, static methods, the main method, method parameters, arguments to a program, Strings, arrays, arrays of Strings, the Java library, the System class, compilers, interpreters, and classpaths, plus assorted syntactical details such as how curly-braces work and when a semi-colon is required and when it breaks the whole program to include one. Only one fifth of the code even relates to performing the actual task that the program is designed to accomplish. That's an awful lot to learn just for HelloWorld. Just wait until they get to inheritance and polymorphism.
print "Hello World!";Here, there's only one thing to focus on. Indeed, there's only one line in the whole program. Students can learn what they need to learn, and not have to worry about any of the other features of the language. When they need them, they can learn them.
That’s why there’s Basic.
But then some people complain that it corrupts the minds of young programmers. Pft. :)
~Grauw
Yea, there is Basic, but an even better one would be Perl, as it more closely resembles C/C++ and is extremely learnable.
Posted by: Doug Wilson on November 25, 2005 4:01 PMOf course in Python, "Hello World" is much simpler:
print "Hello World"
Look, ma, no semi-colon!
Posted by: Screwtape on November 25, 2005 4:02 PMPython for the win. It's very easy to pick up, but supports complex OOP concepts - look at __metaclass__ if you don't believe me.
My college is planning on moving from Java to Python as a teaching language for CS 5 next year. I approve.
Posted by: andfarm on November 25, 2005 5:33 PMJava starts out confusing, then when it starts making sense they throw in all the UI stuff.
I agree, this is a horribly complex way to start a language... but coding AWT / Swing by hand is far worse.
Personally, I prefer PHP.
Posted by: BB on November 25, 2005 6:48 PMAt my Uni, we started learning Java through a tool called BlueJ, which is a "click and play" class designer. That simplifies the process of making a "Hello World" program to just a couple of steps.
I agree that Java is not an ideal solution for throwing a quick hack together, but the Uni course is not trying to teach that. Having seen some truly awful code written in a BASIC language as part of a commercial product, I see the point in teaching good OO design right off the bat.
Posted by: Robert Knight on November 26, 2005 3:16 PMWhat always annoyed me about learning programming via Java (and BlueJ) in high school was that there wasn’t any interactive mode like in Python.
If you just wanted to experiment with a particular line of code and see what it does, you had to create a whole new class (BlueJ would provide a template for it), write that line of code, and compile it. If it didn’t raise any compile-time errors, you then had to switch over to the main window and run the program. If you encountered any problems there and wanted to tweak your program, you had to compile and redo everything from there.
I often found myself opening up Firefox’s JavaScript Console to see if something would work, before trying it in Java. (Thank goodness I found a way to get Firefox installed on the lab computer, despite my school’s restrictions.) You shouldn’t have to do that when you’re learning your first programming language.
Posted by: Minh Nguyễn on November 26, 2005 3:39 PMOptimizing a language for "Hello World" is not necessarily a good idea. Many of those "extraneous concepts" may be unnecessary for "Hello World" but they'll be immediately useful for non-trivial programs.
Posted by: Robert O'Callahan on November 26, 2005 9:17 PMAn environment like Eclipse is also an option. There is no compilation step, your code is compiled whenever you save it. Running your program is as simple as clicking on a button. You can evaluate typed-in expressions or run statements in the debugger. You can even modify your program while it is running.
Posted by: Robert O'Callahan on November 26, 2005 9:19 PMNot Python, Jython!
It has all the benefits and libraries of Java, with the language construction of Python.
Posted by: Greg on November 27, 2005 8:05 PMIf you start somebody with
Print "Hello world!";
The normal barrage of questions tends to be why Print? Where does that come out? Why isn't it in a window. Why are there quotes around it? What does the ; mean?
You can take the time to answer these, they probably won't remember or understand all the answers.
Even if they do understand all that they still won't understand *how* the computer achieves this at a low-level so either way there is a little bit of "don't worry about that, it will come with time."
Which of course, is the same answer to the Java example.
[)amien
Posted by: Damien Guard on November 28, 2005 3:23 AMPython add some nice habits for the new programmers; specially the use of Indexing tabs.
Posted by: Fred.cpp on November 29, 2005 7:25 AMHere's the list of Java stupity that I have after only using the language for 3 months:
* ResultSet.getInt(blah) will return null even though the return value type is an int and thus
crash if assigned to the primitive type int.
* A ResultSet object is *automatically* closed when the Statement object that generated it
is closed, re-executed, or used to retrieve the next result from a sequence of multiple results.
However...(see next)...
* ...Database connections and statements are NOT (*automatically*) closed when they fall out of scope
(as they should be by scope definition of any object oriented language).
* Even though braces {} are optional on control syntax like if-else and while, they are not optional
on try,catch, or finally.
* The JSP get and set parameters insist on the arbitrary style of capitalizing the first letter
of the corresponding bean function name: I.e.
==> setMyfunc(), and even though the following work: setMYFUNC(),setMyFunc(); this ONE case won't
work: setmyfunc().
* Iterators can not be reset!
* jar files are not found if put in a classpath'd directory. Must be explicitly named.
* JSP errors show wrong line numbers (and I'm not talking about _servlet.java files either).
* getString("MYFIELDNAME") doesn't work on "SELECT MAX(MYFIELDNAME) FROM...". Have to use getString(1).
* Prior to j2sdk1.5: Integer mynum=5; won't work. Have to use Integer mynum = new Integer(5);
Also mynum++; mynum>n, etc won't work. Have to use mynum.intValue()
* Prior to j2sdk1.5 Integer, Double, etc are immutable! can't change value!.
* Java doesn't recognize that the ternary operator will always assign a result so that:
String season = (month>5 && month<10)?"summer":"not summer"; will give you a
"variable season might not have been initialized" error.
Rick, your list of stupidity isn't fool enough, so I suggest you to continue expand it. I also have another bunch of issues you might consider:
* prior 1.5: string.compareTo(not_a_string) throws ClassCastException exception
* since 1.5: string.compareTo(not_a_string) gives "cannot be applied to" error
* o instanceof Object ? null : o always returns null
* assert false fails
* .. continue working on ..
You know, you haven't seen anything yet if you haven't looked at the insanity they call J2EE. If you print out hardcopy for the specifications of all the parts (including related specs like JSTL, etc.), you will have killed an entire forest. It would stack to the top of your cathedral ceiling. And talk about an unintuitive, kludged up HACK! These specs were not the result of a careful design process, they GREW like a fungus. Gawd save us from J2EE.
Posted by: Kalyson on January 13, 2007 1:15 PMPS That being said, I'd still probably pick it over .net from microslop if those were my only two choices. Why are we always having to choose between the Devil and Beelzebub?
Posted by: Kalyson on January 13, 2007 1:19 PMHh. Just got to this from a search.
I agree with the original point. It's dumb to start from an advanced point and to work backwards.
Better to start with something procedural such as Pascal say. Teaches good habits. Plus - you can then simultaneously extend into both lower level and higher level concepts.
The procedural approach is fine for most problems (eg macros) and it relates better to the conceptual basis of computing. State machines, CPUS etc etc.
My other concern is - if you start with the OO paradigm, who is ever going to think of something different. It's like teaching Quantum Mech based on the Multi-World view. Why not start with a neutral approach.
Posted by: Richard Gowan on March 22, 2007 2:35 AMI searched for "java sucks" and found this page. I am happy a lot of people agree that java sucks. My first programming language was C++ which I learnt by reading this great book "Problem Solving with C++" by Walter Savitch. I strongly recommend that book to anyone starting to learn programming.
I love PHP but my current job needs me to work in Java. I have to put up with this hell for about 1/2 a year :(
PHP beats Java is every aspect. Java is just ridiculous compared to PHP.