<p>I would like to save the programs settings every time the user exits the program. So I need a way to call a function when the user quits the program. How do I do that?</p>

<p>I am using Java 1.5.</p>

You can add a shutdown hook to your application by doing the following:
```
```
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
    public void run() {
        // what you want to do
    }
}));
```
```
This is basically equivalent to having a try {} finally {} block around your entire program, and basically encompasses what's in the finally block.
Please note the
caveats
though!