Originally posted by Ernest Friedman-Hill:
Peter -- it's a GUI program: he mentions "pressing a button". In that case using the System.exit() method is by far the easiest thing to do.
... unless the program later grows into something more advanced, which does background processing, or requires clean-up on shut-down etc. In which case, System.exit() will stuff it up nicely.
It's not exactly difficult to get a GUI program to exit nicely, without System.exit(). All you need to do is (a) arrange for the code to return when you press the Exit button, and (b) ensure your main window has a parent that you create, and dispose when you're about to exit.
You're right that using System.exit() is an easy way to implement an Exit button in a simple GUI application. I'm hoping to explain why it's not something to get into the habit of.