my dog learned polymorphism*
The moose likes Beginning Java and the fly likes returning int from the main.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "returning int from the main...." Watch "returning int from the main...." New topic
Author

returning int from the main....

abhishek kunal
Ranch Hand

Joined: Jul 27, 2009
Posts: 42
cant we return int from main function of a class...so the main method's signature w'd look like public static int main(String args[]), i ahve done it, but it shows a problem, NoSuchMethodError . isn't there any way to overcome this limitation???
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

Well, what do you expect the application to do with the int that is returned?

If you are expecting it to return as the exit code, as in a C application, then you can accomplish the same thing with using the system exit() method. The parameter passed to the exit method is the exit code.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Praveen Sangolli
Greenhorn

Joined: May 22, 2008
Posts: 28
JVM is the one that calls the main method and what will the JVM do with the int that you return. No you cannot change the method signature for public static void main(String args[])
abhishek kunal
Ranch Hand

Joined: Jul 27, 2009
Posts: 42
hmmm, so main method doesn't provide this, we have to achieve this by System.exit(), while it was possible by both ways in c++......anyways tx!!
abhishek kunal
Ranch Hand

Joined: Jul 27, 2009
Posts: 42
gud!! tx !!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14116
    
  16

abhishek kunal wrote:... while it was possible by both ways in c++......

Yes, but Java is not C++, there's no reason why it should be the same in Java as it is in C++.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
abhishek kunal wrote:gud!! tx !!
Please don't write gud, tx, or similar.
abhishek kunal
Ranch Hand

Joined: Jul 27, 2009
Posts: 42
ohh i am very sorry, it was polite and humble from my side...please don't take it other way...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
Apologies accepted. I knew what you meant, but other people who didn't grow up speaking English might not.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: returning int from the main....