13
public class WrapperTest {
    static {
        print(10);
    }

    static void print(int x) {
        System.out.println(x);
        System.exit(0);
    }
}

In the above code System.exit(0) is used to stop the program. What argument does that method take? Why do we gave it as 0. Can anyone explain the concept?

palacsint
  • 28,416
  • 10
  • 82
  • 109
Warrior
  • 39,156
  • 44
  • 139
  • 214

4 Answers4

30

From the JAVA Documentation:

The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

And Wikipedia adds additional information.

Xn0vv3r
  • 17,766
  • 13
  • 58
  • 65
7

It's the return value that the Java process will report to the calling process.

It hasn't really got a precise definition, but the usual convention is that 0 means success and any non-zero value represents a failure.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
3

The argument is the return code which the java process will return (0 means "successful"). It can be used when a Java program is a part of a batch script, or by build tools such as Ant.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
3

Have a look here

The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

John
  • 1,210
  • 5
  • 23
  • 51
hhafez
  • 38,949
  • 39
  • 113
  • 143