My understanding is that the PermGen (in some sense) holds the class code in memory. Often we have lots of jar files referenced our classpath. When a jar file is included in the classpath (say in the lib directory of tomcat), are all the classes of all those jars automatically loaded into the PermGen?
In a similar question, once a class of a jar file is used, does PermGen load all the classes in that jar file, or just the class that is used (and then later load the rest of the class files when necessary)?
This depends to some degree on the implementation of the classloader and the JVM - the Java Virtual Machine specification says this:
This specification allows an implementation flexibility as to when linking activities (and, because of recursion, loading) take place, provided that the semantics of the Java programming language are respected, [...]
For example, an implementation may choose to resolve each symbolic reference in a class or interface individually, only when it is used (lazy or late resolution), or to resolve them all at once while the class is being verified (static resolution). This means that the resolution process may continue, in some implementations, after a class or interface has been initialized.
In practice, no sane implementation should automatically load everything in a JAR file just because one class in the file is loaded, let alone just because it's on the classpath.