All | 43 Folders | Accessibility | BoingBoing | Books | Computer Related | Family | Films | General | Hacking | Hobbies | Humor | Java | Links | Omni | OpenSolaris | Puzzles and Games

« Grokking the Gimp | Main | Doggie Update »
20050127 Thursday January 27, 2005

Java Pet Peeve

I'm guessing there's got to be a very good reason for this, but I can't see it. Perhaps somebody can enlighten me. I'm thinking of something here that can help novice Java users.

Hand's up all the people who, when they were first starting with Java, accidentally typed something like:

  % java SomeApp.class

when they really should have been trying to run:

  % java SomeApp

You got back an error message like:

Exception in thread "main" java.lang.NoClassDefFoundError: SomeApp/class

Now experienced Java users realise soon realise what's going on here and adjust accordingly. But what about helping novice Java users?

With just a little more effort the java program could check to see if there was a SomeApp.class file in the currently directory and then check if it was a valid class file and if so, it could return an error message like:

Exception in thread "main" java.lang.NoClassDefFoundError: SomeApp/class

Did you really mean "java SomeApp" ?

or something similar. I'd leave it to HCI people, or a flock of senior engineers or lawyers to properly define the wording.

What am I missing?

Update: After receiving some private email on this, I've filed CR #6222504 on this issue. If you are interested get yourself added to that bug's interest list.

[]

( Jan 27 2005, 07:50:24 AM PST ) [Listen] Permalink Comments [7]

Comments:

Or why not just silently drop any .class you specify. The word 'class' is a reserved word anyways, so there's no possibility you could even define a Java class named 'class'. Try to compile:
public class class {

}
You get:
% 
javac class.java
class.java:1: <identifier> expected
public class class {
             ^
class.java:1: <identifier> expected
public class class {
                   ^
class.java:4: '{' expected
^
3 errors

Posted by Watt on January 27, 2005 at 09:12 AM PST #

Good point.

Posted by Rich Burridge on January 27, 2005 at 09:37 AM PST #

I was always under the impression that the runtime did not do this because the classpath was *supposed to be* (but never really ended up being) an abstract concept. The idea seemed to be that the classpath could *conceivably* be set to, say, a list of URLs. So your .class file might not be in the classpath at all. Having said that, I agree that a little more hand-holding by javac is probably in order.

Posted by Laird Nelson on January 28, 2005 at 05:57 AM PST #

the one problem with your suggested solution is something bridge players often mention: <em>if you know the answer, don't ask the question</em>. why bother to ask what the user meant, if it can be derived with relative ease (assuming no conflicts across the classpath etc). [i have always felt that command-line interaction with java has always been rather clunky, quite a contrast to the general improvement in computation environments we now enjoy.]

Posted by ozan yigit on January 29, 2005 at 08:35 PM PST #

Hi ozan. The way I submitted the bug report (after Watt pointed out that "class" is a reserved word), was for the "java" command to just go ahead and execute "java SomeApp.class" as if the user had entered " java SomeApp", rather than try to output an "Did you really mean ..." message. That should hopefully improve its usability.

Posted by 67.114.129.160 on January 30, 2005 at 08:15 AM PST #

Yes... I will also wish that there is a new argument like -jardir which I put the directory of jars instead of writing a lot of shell script that just to extract the classpath from directory.

Posted by Carfield on February 01, 2005 at 02:04 AM PST #

Yes, this is one I've also noticed. But isn't the root of the problem that there is no usability testing for java ? Certainly most, if not all, the api's haven't been handed over to a (java) novice to see if they can understand and use them using the javadoc comments. There are thousands of useless doc comments, for instance where they don't even tell you the range of an int you're passing is origin 0 or 1. The canonical example is something like this: adjustGrommit(int i) - Adjusts the grommet

Posted by Fred on January 20, 2006 at 12:18 AM PST #

Post a Comment:

Comments are closed for this entry.