I am new to java. I want to know when I write
import {SOME_PACKAGE_NAME}
where does it search for the folder? Is there any general folder or mapping file where it search for given package?
I am new to java. I want to know when I write
import {SOME_PACKAGE_NAME}
where does it search for the folder? Is there any general folder or mapping file where it search for given package?
All the directories of your project and from Jar's will be added to class path. From there classes being imported from the classpath
.
You will see errors if compiler doesn't found them at compile time.
If they are not found at runtime ClassNotFoundException's/NoClassDefFoundError
's based on the case occurs.
Imports in Java don't have the same semantics as require
or similar in dynamic languages. They do not point to folders or modules; they are just used for type name resolution: to convert a simple name into a fully qualified name. It is equivalent to use the full name in code:
new java.util.ArrayList<>();
Where the compiler will locate the definition of java.util.ArrayList
or any other class is not specified and in practice it will be either in the JRE library, a JAR added to the compiler's classpath, or inside the same source code project as a .java file.
Note particularly that the location of the class during compilation may be completely different than at runtime: when you compile code for a Java EE container, locally you'll have an archive of the Java EE interfaces to refer to, but at runtime these will be classes provided by the container.