I noticed this a few days back.Drjava successfuly runs
a 'main' method with 'int' return type,while the standard
'java' command(java.exe with sun sdk 1.4.2,on Windows
XP SP1),shows an error when asked to run the same
program.
Error pointed by std 'java.exe':
**Exception in thread "main"
java.lang.NoSuchMethodError: main**
This is also the error generated when I ran the same
program in other IDEs like jEdit,Eclipse etc.
The code I ran was like this:
**
public class Test{
//following 'main' is not recognized by std. 'java' cmd
public static int main(String args[]){
System.out.printnl("Test");
return 0;//or '1' etc.
}
}
**
System :
**OS: Windows XP SP1(Ver. 5.1)
Drjava: 20040326-2216
Runtime:Java(TM) 2 Runtime Environment S.E
Runtime Ver.:1.4.2-b28
Vendor:Sun Microsystems Inc.
Java Ver: 1.4.2
JVM Name:Java HotSpot(TM) Client VM
JVM Ver.:1.4.2-b28
**
My Question:**Is it a problem with drjava or some
adjustment is needed here?**
Logged In: NO
**One Typing Error: I meant 'println' up there..**
Logged In: YES
user_id=697810
The reason this happens has to do with the way typing "java
ClassName" works. Unlike most IDEs, DrJava does not start
up a new Java Virtual Machine when asked to run the main
method of a class, because the Interactions Pane already has
a separate JVM associated with it. In fact, when you type
"java ClassName some args" DrJava translates this to the
static method invocation "ClassName.main(new String[]
{"some", "args"})" which is why it is running the method
with return type int.
DrJava people -- I'm interested in a discussion of this
issue. For my part, I don't care that this happens, but I
can see beginners being confused by it, especially people
coming from a C(++/#) background where main() can return
int. We should consider adding a check to the return type
of the main() method before calling it, though in my mind
this sounds like it would be difficult to do easily. Ideas,
suggestions are welcome.
Logged In: YES
user_id=557360
I think this should be fixed for the reasons you stated
Neal. It shouldn't be too tough to just check the static
main method's return type and make sure it is void before
invoking it. We'll take a look at this soon.
Logged In: NO
Thank you guys for your response!
I would like to add here that I am finding drjava immensly
helpful in my preparation for Sun Certification.Especially
for those numerous methods with all those classes,which I
can test and practice rather quickly with a tool like drjava.
It would be damn tedious to write a source file for each small
thing to learn.
drjava brings the fuctionality of an interactive interpreter to
java(almost),something like IDLE does to Python,or irb to
Ruby.
Thanks to drjava people for this very good tool!!
As for the 'main' method with 'int' return type,I got the
concept working behind drjava,as explained here by you
guys.But it would be so much nicer if this rather 'non-
standard-compliant' behaviour could be done away
with.Atleast for the sake of those newcomers who are not
conversant with how drjava invokes the 'main', or the JVM.
Else it might lead to confusion.
Thank you once again.
Abhi.