I am writing an application program using swing. I need to exit from the application by clicking the JButton for that can i use System.exit() or sh
Generally speaking the only time you need to do a System.exit(n) is if you want to exit a command line program with an error code so that anything that is monitoring the program can detect the error code.
This is most useful for example, if you are writing a program designed to be run from a shell script.
As other replies say though, if you are using threads then you must make every effort to shut them down gracefully before considering a System.exit(n)