How many ways can a Java program end?

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?

+5
source share
7 answers

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.

+1
source

To add to other answers:

  • If the process hosting the virtual machine is forcibly terminated, your program will automatically disappear.
  • The same thing happens if the plug is connected to the machine that hosts the VM :)
+4
source

Java , , (System.exit(), Runtime.exit(), Runtime.halt() , , ).

, System.exit() (, JFrame EXIT_ON_CLOSE).

+3

, :

  • main() ( , void() main )

  • System.exit()

  • ?

JFrame , onClose(), System.exit(0), .

+2

GUI Swing, JFrame.

  • Swing Dispatch , , .
  • , Event Dispatch, , ( ).
  • . , JFrame, : setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

, .

0

Java- . java.exe ( )

0

You can also use Application.exit ().

-1
source

All Articles