Import, although the name does not "import" anything, it just allows you to call classes without a full name.
To clarify if I do import java.util.ArrayList; , now I can refer to the ArrayList class as an ArrayList . If I do not, I can still use the class, I just need to call it java.util.ArrayList .
If you import entire packages using * , the worst thing that can happen is a name collision, so you should use the full name to refer to the Java class, but it does not use more memory at runtime.
Classes in java.lang automatically "imported".
Java 1.5 introduces static imports , which allows programmers to refer to imported static members as if they were declared in a class that uses them. They should be used sparingly. Acceptable use is importing JUnit Assert methods. For example, with traditional imports:
import org.junit.Assert; ... Assert.assertEquals(expected, actual);
With static import:
import static org.junit.Assert.assertEquals; ... assertEquals(expected, actual);
source share