Use of System.exit(0)

Warrior picture Warrior · Jan 19, 2009 · Viewed 68.7k times · Source
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?

Answer

Xn0vv3r picture Xn0vv3r · Jan 19, 2009

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.