I know that using System.exit (0) can end a java program, for example, if I have a JFrame window, it will close and close the program, but I wonder how many other ways can I close and the program will be completed? Including when an error occurs, will the program be closed and the JFrame will be closed?
Another way to terminate a Java program is to execute the last statement in Java code. Also, when a java.lang.OutOfMemory error occurs, the program aborts abnormally. This happens when the Java virtual machine cannot allocate an object because it does not have memory and the garbage collector cannot make more memory available.
To add to other answers:
Java , , (System.exit(), Runtime.exit(), Runtime.halt() , , ).
, System.exit() (, JFrame EXIT_ON_CLOSE).
, :
main() ( , void() main )
System.exit()
?
JFrame , onClose(), System.exit(0), .
GUI Swing, JFrame.
JFrame
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
, .
Java- . java.exe ( )
You can also use Application.exit ().