| 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: 2896
|
|
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: 2896
|
|
|
I'm afraid if that overloaded main is understood by JVM ;)
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
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: 2896
|
|
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
|
 |
 |
|
|
subject: return value from main
|
|
|