Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a replacement for EXIT_SUCCESS and EXIT_FAILURE in Java?

Tags:

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

like image 950
Muthu Ganapathy Nathan Avatar asked Aug 14 '11 11:08

Muthu Ganapathy Nathan


People also ask

Which header file defines EXIT_SUCCESS and EXIT_FAILURE?

The value of EXIT_SUCCESS is defined in stdlib. h as 0; the value of EXIT_FAILURE is 8.

Is there a return 0 in Java?

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.

Can we use Exit 0 in Java?

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.

What is the difference between Exit 0 and Exit 1 in Java?

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.


1 Answers

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.

like image 177
JB Nizet Avatar answered Sep 20 '22 17:09

JB Nizet