Class Loading in JVM

橙三吉。 提交于 2019-12-06 10:38:44

These are pretty much basic questions about JVM and Google could surely help you with answers.

For some of your questions (especially for the questions about the actual loading process), you could look here, for example: http://www.securingjava.com/chapter-two/chapter-two-7.html

On short, at the beginning, just the basic (and trusted) classes are loaded by the JVM. Next, other classloaders (for example the bootstrap classloader) are created as required and they will load some more classes. Before a class can be successfully loaded, all the classes it depends on must be loaded.

A loaded class is stored in memory in various forms (this is JVM specific), but a Class object is always exposed. Everything inside the class (methods, variables etc.) gets loaded. This doesn't mean that the class is also compiled (compilation happens later, when a method needs to be executed).

Allocation of method variables happens either on stack (for primitives) or on heap.

Initialization of static variables and execution of static blocks happens right after the class is loaded, before any instances of it are created.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!