NAME of JAr LANG and UTIL package classes

MY question is that in which jar file are classes related to lang package and util package present.
[113 byte] By [JAVA_RULZa] at [2007-11-26 20:42:26]
# 1
rt.jar. But you don't need to put that on your classpath or anything.
jverda at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 2
than how is that lang packages classes are imported by default but to use util package classes we have to import them
JAVA_RULZa at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 3

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.

jverda at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 4
thanks i got it.Does this have performance overheads(Runtime). is it good idea to useimport java.xxx.* or import individual class names.
JAVA_RULZa at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 5

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.

jverda at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 6
hi, actually wt happpens is if u use java.lang.* then it will load only classes under lang package but not classes under subpackages.i.e Util is a sub package to lang so when u use java.lang.* it wont load Util package . thats why we have to explicitly call import java.Util.*.
N.V.SaiRama at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 7
> i.e Util is a sub package to lang No, it's not.
jverda at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 8
> hi, actually wt happpens is if u use java.lang.* then> it will loadIt doesn't "load" anything.
jverda at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 9
using java.lang.* will load all unnecessary classes and its a performance issue , use java.lang.Util.xxx for any Util class to import its better way to increase performance .
N.V.SaiRama at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 10

> 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.

jverda at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 11

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.

N.V.SaiRama at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 12
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 ..
N.V.SaiRama at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 13
ofcourse compiler wont load any class i agree but we should tell the compiler the right place to search those classes , using complete directory structure like java.lang.Util.ArrayList; ok
N.V.SaiRama at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 14

> 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.

jverda at 2007-7-10 2:02:03 > top of Java-index,Java Essentials,New To Java...
# 15

> 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.

jverda at 2007-7-21 18:01:32 > top of Java-index,Java Essentials,New To Java...
# 16
I have searched google on this issue and i found that it has no perormance issues.
JAVA_RULZa at 2007-7-21 18:01:32 > top of Java-index,Java Essentials,New To Java...
# 17
> ofcourse compiler wont load any class i agree but we> should tell the compiler the right place to search> those classes , using complete directory structure> like java.lang.Util.ArrayList; okWhich is exactly what I've been saying from the
jverda at 2007-7-21 18:01:32 > top of Java-index,Java Essentials,New To Java...
# 18
actually instead of load i should have use "SEARCH" key word but unfortunately i wrote that i recovered ...THANK U MR JVERD may i know ur complete name?
N.V.SaiRama at 2007-7-21 18:01:32 > top of Java-index,Java Essentials,New To Java...
# 19

> 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.

jverda at 2007-7-21 18:01:32 > top of Java-index,Java Essentials,New To Java...