Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java return value

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

like image 582
Dung Avatar asked Aug 08 '26 00:08

Dung


2 Answers

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

like image 153
sverre Avatar answered Aug 09 '26 13:08

sverre


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).

like image 23
aroth Avatar answered Aug 09 '26 14:08

aroth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!