In a C program, I generally use EXIT_SUCCESS
or EXIT_FAILURE
in exit()
function to improve clarity and understandability of the program.
But in System.exit()
I couldn't use these MACROS.
I can define my own interface as
public interface ReturnValues {
public int EXIT_SUCCESS = 0;
public int EXIT_FAILURE = 1;
}
Other than my own implementation, is there any other way in java to use these Macros? (like using predefined library class variables or by implementing predefined interface etc..)
The value of EXIT_SUCCESS is defined in stdlib. h as 0; the value of EXIT_FAILURE is 8.
return 0 –> successful termination. return 1 or any other non-zero value –> unsuccessful termination. Returning different values like return 1 or return -1 or any other non-zero value means that program is returning error.
exit(0) method terminates JVM which results in termination of the currently running program too. Status is the single parameter that the method takes. If the status is 0, it indicates the termination is successful.
System. exit function has status code, which tells about the termination, such as: exit(0) : Indicates successful termination. exit(1) or exit(-1) or any non-zero value – indicates unsuccessful termination.
No, there is no predefined constants in Java for SUCCESS and FAILURE. Certainly because there might be several different kinds of failures, depending on each specific application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With