Java -Programm Finish Event

Runtime.getRuntime().addShutdownHook(new Thread()
{
    @Override
    public void run()
    {
        //do your stuff
    }
});
JulesG10