How to exit from a program in java?

3 answer(s)
Answer # 1 #

In Java, use System.exit(0); to terminate the program immediately. The argument 0 indicates normal termination.

[5 Month]
Answer # 2 #

Alternatively, a program can exit naturally after completing the main method or return statements from methods.

[4 Month]
Answer # 3 #

In GUI programs like Swing, closing the JFrame using setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) also exits the program.

[4 Month]