Assume, that I have class with static methods only. Will class loader load every imported class when loading class to memory? Or it will only load imports when a method from this would need access to it?
Question is whether class loader loads imports when the class is loaded to memory, or just before some methods want to use them.
If it is the first option I would probably need to divide some of my Util classes, to be more specialized.
I think you can test it as follows:
Test 1:
That prints nothing.
Test 2:
Prints:
So, just because you have imported a class does not mean the classloader will load the class into the memory. It loads it dynamically when it’s used.