System.exit()
is usually not the best way, but it depends on your application.
The usual way of ending an application is by exiting the main()
method. This does not work when there are other non-deamon threads running, as is usual for applications with a graphical user interface (AWT, Swing etc.). For these applications, you either find a way to end the GUI event loop (don't know if that is possible with the AWT or Swing), or invoke System.exit()
.