Sunday, August 26, 2012

Java Class Loaders Notes

Class loaders are hierarchical. Child class loaders ask parent to load the class, if parent is not able to then child loads the class, there by maintaining uniqueness. All classes loaded by parent are accessible to child class loaders, but opposite is not true. Question arised in my mind: Child asked the parent to load the class, but due to some issue, parent was not able to load, so child loads it in the JVM. At some point later parent needs that class and obviously parent cannot see what child class loaders' classes are loaded in JVM, so would the parent too loads that class in the JVM? What happens to the uniqueness of the same class?

See NoClassDefFoundError which also occurs at run-time but was available at compile time, obviously forgot to specify it in run time classpath. ClassNotFoundException occurs also occurs at run-time, but you are loading it explicitly using Class.forName and it is not found in JVM, which you have mentioned it right. So in both cases the class is not found at run-time in JVM.

No comments: