This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes return value from main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "return value from main" Watch "return value from main" New topic
Author

return value from main

deepti krishna
Greenhorn

Joined: Jun 06, 2009
Posts: 3
Hello all
am a beginner in java

my doubts are as below

1.. where does the main return the value to?
2... can we capture the value returned by main? if yes how do we do it? can someone provide with an example?

Thanks in advance
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

deepti krishna wrote:1.. where does the main return the value to?

main method doesn't return any value, because its return type is void

deepti krishna wrote:2... can we capture the value returned by main? if yes how do we do it? can someone provide with an example?

I don't think we can capture the returned value(??) from main, If there is any way, then need to move this post to JiG


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Harsh Pensi
Ranch Hand

Joined: Aug 05, 2009
Posts: 67


The main method can be overloaded.


SCJP6 - 93% SCWCD5 - 97%
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

I'm afraid if that overloaded main is understood by JVM ;)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Murtuza Arzai wrote:The main method can be overloaded.

It can be overloaded, because it's just a normal method just like any other method. But you can't make the JVM start the execution of your program with an overloaded version of main() - it will always look for a main() method that is public, static, void, and takes a String[] as input.

As already said, the normal main method does not return any value. You can however end your program by calling System.exit(int). If you call your Java program from a Windows BAT file or Unix shell script, then you can get the value that you pass to System.exit in the BAT file or script.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Jesper Young wrote:You can however end your program by calling System.exit(int). If you call your Java program from a Windows BAT file or Unix shell script, then you can get the value that you pass to System.exit in the BAT file or script.

I didn't know that, thanks Jasper. System.exit(int) - an abrupt exit return
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: return value from main
 
Similar Threads
signed float & double
NaN
return types
Exceptions
JToolBar