Not entirely sure what you want, but if you're looking for the "shut Java off" path within Safari, it's:
Safari > Preferences > Security > uncheck Enable Java
If you're looking to automate that sequence, that's probably an AppleScript away.
I assume you are using Lion and not "10.5.7" indicated at the bottom of your message?
For what it's worth, here is what I do. I have a Java applet that I use maybe a few time a week. Before opening the applet, I open Java Preferences (/Applications/Utilities/Java Preferences.app) and tick the "Enable applet plug-in…" box. Then I run the applet. Then I untick the box. I don't forget, because I leave Java Preferences open until I am finished. No need to restart Safari or anything.