The System.exit() in Java – coding

The java.lang.System.exit() methodology exits present program by terminating operating Java digital machine. This methodology takes a standing code. A non-zero worth of standing code is usually used to point irregular termination. This is analogous exit in C/C++.

Following is the declaration for java.lang.System.exit() methodology:

Attention reader! Don’t cease studying now. Get maintain of all of the necessary Java Foundation and Collections ideas with the Fundamentals of Java and Java Collections Course at a student-friendly value and grow to be business prepared. To full your preparation from studying a language to DS Algo and lots of extra,  please refer Complete Interview Preparation Course.

public static void exit(int standing)

exit(0) : Generally used to point profitable termination.
exit(1) or exit(-1) or another non-zero worth – Generally signifies unsuccessful termination.

Note : This methodology doesn’t return any worth.

The following instance exhibits the utilization of java.lang.System.exit() methodology.

import java.util.*;

import java.lang.*;


class GfG


    public static void main(String[] args)


        int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};


        for (int i = 0; i < arr.size; i++)


            if (arr[i] >= 5)








                System.out.println("arr["+i+"] = " +



        System.out.println("End of Program");




arr[0] = 1
arr[1] = 2
arr[2] = 3
arr[3] = 4

Reference :

This article is contributed by Amit Khandelwal .If you want GeeksforGeeks and wish to contribute, you can too write an article using or mail your article to See your article showing on the GeeksforGeeks main web page and assist different Geeks.

Please write feedback in the event you discover something incorrect, otherwise you wish to share extra details about the subject mentioned above.

Add a Comment

Your email address will not be published.