开发者

Does JVM loads all used classes when loading a particular class?

开发者 https://www.devze.com 2023-02-26 21:24 出处:网络
When JVM loads a class A开发者_运维百科, does it load all of the classes used within A? And I\'m wondering if import declarations are matter somehow to the loading process?

When JVM loads a class A开发者_运维百科, does it load all of the classes used within A?

And I'm wondering if import declarations are matter somehow to the loading process?

The link to JLS would be appreciated.


Import and class loading are unrelated. The former just saves typing: it allows you to use the short class name rather than the fully-resolved class name in your code.

Classes are loaded by the JVM when they're used for the first time.


import merely helps the programmer. When the class file is compiled the Qualified Name of the variables is stored in the .class file so the JVM knows what it needs to load.

http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html#21410 section 2.17.1 "Virtual Machine Start-up"


Importing a class is marker for the user and the compiler. Using import does not load classes. JVM loads class only when it referenced and if the classes are not required then the class does not load it on compile time or runtime.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号