The answers depend on exactly what you're saying -- it's really hard to tell. "Unload a class" has a very specific Java meaning, but I think you're using it to mean something utterly different.
If you are running a free-standing background process written in Java, and you want to kill that process, then the cleanest way would be to have that background process listen for a connection on a local socket, and when it reads a
String like "QUIT" on that socket, it calls System.exit . Then you can write a program to stop the first program just by connection to that socket and printing "QUIT".