importing has nothing to do with finding the classes.
importing is simply a way to tell the compiler that when you say, for example, "List", you really mean "java.util.List". The compiler always needs the fully qaulified class name (that is, including the package) to find a class, and all the java.lang, java.util, etc. are found in rt.jar.
It's simply a rule of the language that java.lang.* is always implicitly imported. Remember, that doesn't do anything for FINDING the class. It just saves us typing and keeps the code less cluttered.
Importing has ZERO effect at runtime. All it does is tell the compiler that "List" really means "java.util.ArrayList". That's all. NO effect on the generated .class file. NO effect at runtime.
Having said that, as a matter of style and clarity, it's generally considered best practice to import individual classes, rather than entire packages.
Sometimes, for a common package where I'm using, say, five or more classes, I'll just import the whole thing--usually just java.util, java.io, java.sql.
Utimately it's a matter of personal preference and coming up with a standard that everyone on your team can live with.
> using java.lang.* will load all unnecessary classes
> and its a performance issue ,
No, it absolutely is NOT. You are completely wrong.
Importing has ZERO effect at runtime, and minimal (probably unobservable) effect at compile time.
If you don't believe me, compile the same code with various combinations of things imported and not. You'll get exactly the same .class files every time.
> use java.lang.Util.xxx
> for any Util class to import its better way to
> increase performance .
No. Absolutely not. No effect on performance.
Java comes with thousands of classes that are organized in packages (similar to files and directories on you disk). Some packages include classes responsible for drawing, while other have classes for the Internet access, and so on. For example the class String is located in the package called java.lang, and the fully qualified name of this class is java.lang.String.
Java compiler only knows where to findclasses that are located in the package java.lang, but there are many other packages with useful classes, and it抯 your responsibility to let the compiler know where the classes that are used in your program live.
Please note, that nothing is actually imported into you program: it抯 just a name resolution mechanism that helps compiler in finding classes and make your program more readable.
I Think this is the best answer for your Query.
> Please note, that nothing is actually imported into
> you program: it抯 just a name resolution mechanism
> that helps compiler in finding classes and make your
> program more readable.
> I Think this is the best answer for your Query.
Yes. And it's what I've been saying all along, and it's the opposite of what you've been saying up until now.
> But what the u should remember is .* doesn't load
> each and every class in that root package like Lang,
> it has so many sub classes like Util ..etc will not
> be loaded its fact u should agree that ..
java.util is not a subpackage of java.lang. There is no java.lang.util.
If you're saying that importing * in a package does not import any "subpackages" (which don't really exist in Java anyway), then yes, you're correct.
> actually instead of load i should have use "SEARCH"
Right. Explicit imports--like java.util.List--tell the compiler precisely which package List is in. On-demand imports (I think that's what they're officially called)--like java.util.*--tell the compiler where to search for the List class.'
> may i know ur complete name?
Jeff Verdegan. It used to be visible in my profile, but I think Sun changed that.