Say i start the web server(or any other java process), will all the class (metadata like class definition) be loaded at server/process startup even before they are used anywhere in the system or they are loaded at runtime i.e. only while object is getting created or import statement is encountered?
This question is for jdk 8 and jdk 6
First of all, in bytecode, there are no import statements. Bytecode simply uses fully qualified names all over the place.
Then, the default behavior of most JVMs is to do "lazy" loading of classes. Meaning: when you load class A, the JVM will only load those classes that are required to run all the static intializers for A.
So, if A "uses" B and C; then B, C are only loaded when the JVM executes code that needs B resp. C to be loaded.
When writing your own class loader, you could of course do things differently.