Lets say , there are some import statements in a class. When the byte code is generated for that class, what happens to these import statements.
If the import statements are ignored during runtime, how are the dependencies on that classes methods resolved during runtime.
The purpose of import statements is just to make life easier for the human readers (and authors) of the code. Thus they are replaced by references to the fully qualified class/method names in the bytecode. And unused import statements are ignored.
import
statements are only there for the compiler so it knows what class names (or static method names) you can access unqualified in your code (i.e.MyClass
instead offoo.bar.MyClass
). Behind the scenes this is just used to resolve to the fully-qualified class names which are then used in the bytecode as well.import in Java is just a shorthand
so that if you import
java.util.*
you don't have to writejava.util.ArrayList
in your code but can writeArrayList