This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is "long" valid for main() ??" Watch "Is "long" valid for main() ??" New topic
Author

Is "long" valid for main() ??

sonir shah
Ranch Hand

Joined: Nov 01, 2001
Posts: 435

I tried running the program, though it compiled fine, it threw an error at Runtime.
But my question is that why did the compiler allow the program to compile successfully.
Is "long" valid in main??
Sonir
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
the main method is just an other method. It's perfectly valid to declare the main method as you did but the problem arises when you try to run the application because the interpreter is lokking for a method called main and declared as follows:
public static void main(String args[])
replace long with void and it should run fine


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
That is a valid method declaration. As far as the compiler is concerned, it is no different than writing
public static long aMethod(String[] stringArray)

However, if you want the virtual machine to "run" an application, must pass it a class that has a main method with this *exact* signature:
public static void main(String[] args)
Otherwise, it won't run. But as you can see, it compiles just fine.

Rob


Rob
SCJP 1.4
 
Don't get me started about those stupid light bulbs.
 
subject: Is "long" valid for main() ??
 
Similar Threads
Java Letter/Number counter
Overriding
Regrding Access Specifier used of main method
Passing primitive values to methods and method overloading
main(String args[])?