#310 Order of classes in source code

open
nobody
Other (46)
5
2006-09-21
2006-09-21
perva
No

Hello!
I have only used DrJava one day to compare DrJava with
other IDEs. Until now I have used the old IDE Kawa (not
updated anymore), but I am now looking for a new to use.

I have found out with DrJava that if I write a source
code (java file) with more than one class, I have to
put the one which contain the main method first.
Otherwise I get a runtime error: “No 'main' method in ...”

I am used to that the order of the classes is of no
consequence. It does not help if I give the Java file
the same name as the class which contain the main method.

Why does DrJava behave like this? If there is no
reason, would you please change DrJava?

perva

Discussion

  • Dan Smith
    Dan Smith
    2006-09-21

    Logged In: YES
    user_id=1060117

    Could you submit an example file that demonstrates this? Ideally, this should be
    a file that will compile and run fine in other IDEs but not in DrJava.

     
  • Logged In: YES
    user_id=430590

    DrJava is designed first and foremost for teaching
    programming. In this context, root program classes are not
    necessarily "public" so the filename is not necessarily the
    name of the root class in a file. When you ask DrJava to
    run the main method in a document, which class should DrJava
    use? Since the filename does not reveal this information,
    DrJava uses the first class in the file.

    We do all DrJava development in Drjava. We NEVER user "Run
    Document's Main Method" except to test this feature; it i an
    archaic command line interface. We either run JUnit tests
    or execute code directly from the interactions pane.

    We could conceivably add a configuration option that would
    tell DrJava to always use the file name as the main method,
    but I am reluctant to add more complexity to the Java
    profile. Perhaps we could simply have DrJava try using the
    filename as a classname if there is no main method in the
    first class in a file.