According to a Google search, if you create a directory called ~/.kde/shutdown, and put a program in there, it will be run on shutdown. (http://linux.derkeiler.com/Mailing-L...4-08/2313.html
To use that, You would need to write a program that would connect to your program and tell it to save its data. This might be a little more difficult in Java, depending on how you're running the program, but there are some IPC tools to help you with that (http://www.velocityreviews.com/forum...c-in-java.html
However, nothing beats auto-saving: if you kill the X server with ctrl+alt+backspace, then all your programs will die, and if the program crashes then you've lost all your data anyway. My advice would be to periodically save to a fixed auto-save file, and then load from that if it exists. (This is more or less what Firefox does; even if you kill the program, you can still start it again right from where you left off.) Of course, that could be impractical for your application since I don't know what size of program you're dealing with.
Hope that helps,
—Robert J Lee