• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

return value from main

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The main method can be overloaded.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid if that overloaded main is understood by JVM ;)
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sagar Rohankar wrote:

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


if we mention it as an int return type then is the main() method return the value???
 
lowercase baba
Posts: 13081
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sireesha vadlamani wrote:if we mention it as an int return type then is the main() method return the value???


If you declare a method called "main" that returns an int, that specific method will not be run when you start your program.

That does not prevent you from calling it explicitly in your program, but the value will be returned to whatever called it, not to the OS.
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sireesha vadlamani wrote:
if we mention it as an int return type then is the main() method return the value???



Bumping an old topic, when you don't seem to be getting an answer from your other topic is not going to help you here -- especially since the answer is "it doesn't work that way". See Fred's response -- to both topics.

Henry
 
Trust God, but always tether your camel... to this tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic