1) Yes they will stay loaded. The reasoning is that a class may have:
- Static variables (whose state would be lost).
- Static initializers (which may have side effects).
- Native methods (which may retain static state).
If you allow a class to unload, and therefore possible RELOAD, the side effects from the above would be unacceptable.
2)Only those classes that have been mentioned in some manner are loaded. The foundation classes are loaded as needed.
3)If you are using a classloader other than the bootstrap loader (the normal one), and you remove all references to that classloader, then it will get garbage collected. At that time any classes that it had caused to be loaded will be unloaded. Any class that is loaded by the bootstrap classloader will NEVER be unloaded.
And to top it off a little quote from the JLS:
Strictly speaking, it is not essential that the issue of class unloading be discussed by this specification, as class unloading is merely an optimization. However, the issue is very subtle, and so it is mentioned here by way of clarification.
[This message has been edited by Cindy Glass (edited June 15, 2001).]