R
Razvan
Hi,
Why does the main() function in java returns void ? In C/C++ this is
considered BAD style. Why the Java designers took this approach ?
I am not contesting the decision as I am a newcomer in Java, but I
would like to know why this design decision was made.
With this approach the only way to return some values to the OS (or
JVM, which can return it to the OS) is to call System.exit(). But a
plain "return" won't work. Is this the real intention - to disallow
the use of "return" for sending an exit code to the OS ? Is so, why do
that ?
I am trying to give my own explanation to this; if I am wrong please
correct me.
In C/C++ if you wanted to exit the application you had to use the
exit() function with the exception of the main() function where the
return() function would do the job. For consistency reasons, in Java,
you must always call System.exit() when returning a value to the OS
while the plain return() function can only be used to transfer values
between function calls (but not to the underlying OS).
Regards,
Razvan
Why does the main() function in java returns void ? In C/C++ this is
considered BAD style. Why the Java designers took this approach ?
I am not contesting the decision as I am a newcomer in Java, but I
would like to know why this design decision was made.
With this approach the only way to return some values to the OS (or
JVM, which can return it to the OS) is to call System.exit(). But a
plain "return" won't work. Is this the real intention - to disallow
the use of "return" for sending an exit code to the OS ? Is so, why do
that ?
I am trying to give my own explanation to this; if I am wrong please
correct me.
In C/C++ if you wanted to exit the application you had to use the
exit() function with the exception of the main() function where the
return() function would do the job. For consistency reasons, in Java,
you must always call System.exit() when returning a value to the OS
while the plain return() function can only be used to transfer values
between function calls (but not to the underlying OS).
Regards,
Razvan