2

I'm C programmer. I'd like the function main return a value but apparently main is alway void. Is it true in Java?

1
  • 2
    to it's maker. But with java being platform atheist... Commented Apr 10, 2011 at 21:57

6 Answers 6

17

Main always returns void in Java. If you want your program to return an error value use System.exit()

Sign up to request clarification or add additional context in comments.

Comments

4

Yes, in Java main is always public static void main(String[] args). Why would you want it to return a value anyways? It would just be returning to the enclosing java.exe process and not to the OS, which isn't very useful.

To exit and return a code to the OS, use System.exit(int code).

Comments

3

Use java.lang.System.exit(int status) to return a non-zero status code.

Comments

2

I guess you are looking for System.exit(int retValue)

Comments

0

yes , its true , you should call the function from the main with the class object .. or declare the function as static and call from main to do the work

Comments

0

Yes, The "main" function is the start of execution for your program, it's a "special" function which serves as the entry point to the application - you are not supposed to call it from other code and it does not return a value

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.