When are classes loaded in Java?

Your thoughts?


Classes are loaded by "ClassLoaders".

Confused? Chicken before the egg problem?

Yes. Turns out native code/operations are utilized to load initial libraries used by JRE.

Once the main class is located, its dependencies (or the classes it uses) are loaded lazily (dynamically)

This means classes are stored and cached in memory only when they are needed.

This is what makes java a "dynamically compiled" language. Unlike a statically compiled language like C++, Java doesn't compile everything into bytecode upfront. Instead it converts class definitions to byte code and loads them into memory.