Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can a main class return any value?

Status
Not open for further replies.

gobinda77

Programmer
Oct 27, 2002
3
IN
Can a main class return any value?
 
I don't think so, because of the very nature of how its defined:

public static void main(String[] args)

.... void indicates that main isn't returning anything.

I'm new to Java myself, so someone may want to confirm this.

However, I'll say no. If I find out more, I'll let you know.

HTH
Change Your Thinking, Change Your Life.
 
yeah, i think scripter is right, according to the Sun Educationl Services booklet (![bigsmile]!) the Java interpreter must find
Code:
public static void main(String[] args)
defined exactly or it refuses to run.

Alistair
 
public static void main(String[] args) is the precise syntax that the JVM looks for when executing a programme.

public static void String(String[] args) would return a String.

public static void int(String[] args) would return an int.

By definition, void returns nothing.
 
The main method of a Java class cannot return
a value.

However, I guess what you are looking for is
some way to let another application or a calling
script know how you program has terminated.

Let's put it this way: when you return form the
main method it means your application has finished
its job.

So what you can do is to use a static exit method
of the System class:



System.exit(<integer value>);

If you are are under Unix and your JVM was launched
from any Unix shell, you can get the value passed
to the exit method by using shell special variable $?.


In DOS/Windows you can use %ERRORLEVEL% variable
if you are using .cmd or .bat files to launch
your Java program.

Clarify what your goal is and may be we could
assist you more...




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top