Does import make my class bigger? Does it actually compile the imported class or package into my code?

Questions by krishna_darl   answers by krishna_darl

Showing Answers 1 - 4 of 4 Answers

Seetha Ram Janapala

  • May 22nd, 2006
 

import statement doesn't make your class bigger. Why because, importing a class means that to tell the compiler to load the specified class into memory during compilation. If you specify more classes in import statements, your class will take little bit more time to compile, because loading these classes into memory during compilation will take some time. The import statement won't compile the specified classes into your code. You need not worry about the size of your program, it will not be increased with import statements at all.

  Was this answer useful?  Yes

Seetha Ram Janapala

  • May 22nd, 2006
 

     import statement doesn't make your class bigger. Why because, importing a class means that to tell the compiler to load the specified class into memory during compilation. If you specify more classes in import statements, your class will take little bit more time to compile, because loading these classes into memory during compilation will take some time. The import statement won't compile the specified classes into your code. You need not worry about the size of your program, it will not be increased with import statements at all.

  Was this answer useful?  Yes

Jitender

  • Jun 21st, 2006
 

There is no runtime cost from using an import statement The compilation process can take a little more time with an import statement The compilation process can take even more time with a wildcard import statement For improved readability, wildcard import statements are bad practice for anything but throwaway classes The compilation overhead of non-wildcard import statements are minor, but they give readability benefits so best practice is to use them

  Was this answer useful?  Yes

Hi

Once a class is declared in import statment, during compilation of the class which imported, the compiler checks whether imported class is compiled if not then ClassNotFoundException is thrown.

During compilation time if referred class is found then compilation is done smoothly.

During runtime if that imported class is not found then NoClassDefFoundError is thrown.

Yes wildcard import will take a bit more time compared to opposite.

The imported classes or not loaded at compile, only at run-time if only that class is referred in the code.

I hope it is clear.

Thanks

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions