• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

System.exit(0);

 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why dos programs don't need to call System.exit() and windows programs need to call System.exit()???
 
Rufus BugleWeed
Ranch Hand
Posts: 1551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was working through an example program that called System.exit(). I commented it out. Assuming you are not running a complicated multi-threaded program, when the program goes out the bottom of main(), the JVM will take care of the shut down sequence.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A java program terminates when there is no more non-daemon thread running. The AWT event handling thread is a non-daemon thread, so you either have to stop it (though I don't recall how to do that) or to call System.exit().
 
Benjoe Reyes
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in an applet you don't need to call System.exit(o) because the program terminates when you shut down the applet. but an application doesn't do so... if you closes the window press the 3-fingered salute (ctrl+alt+del) and you will see a java application still running. it'll cost your ram. so call System.exit(0) use the windowsadapter so when you close the window it also shuts down the program
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not a function of whether it is an applet or an application. It is a function of whether it is a GUI (AWT or Swing) program or not.

If it is not a GUI program, the program will end when all the non-daemon threads end (usually main() although not always). System.exit() is not required.

In an applet, the browser closes the GUI program.

In a GUI application you, the programmer, have to close the program by using System.exit().

Actually, if I recall correctly, Swing has this functionality built in but the older AWT stuff does not.
 
John Dale
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swing added setDefaultCloseOption(EXIT_ON_CLOSE) to JFrame in Java 1.3.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic