Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / December 2004

Tip: Looking for answers? Try searching our database.

How are java files found?

Thread view: 
jeffc - 09 Dec 2004 03:22 GMT
I installed the JDK.  I have not set my classpath (it is empty).  I tried a
simple program that uses Date from java.util (I import java.util.*).  How
does java know how to find this class - the right directory and archive (or
whatever)?
klynn47@comcast.net - 09 Dec 2004 03:41 GMT
The JSDK when installed has a jar file where the the directories
java/lang, java/util, etc. are archived. It pulls the class files from
there.
jeffc - 09 Dec 2004 04:26 GMT
> The JSDK when installed has a jar file where the the directories
> java/lang, java/util, etc. are archived. It pulls the class files from
> there.

OK, but how does it find that jar file?  What tells it where to look?  I've
got the java bin dir in my path, but other than that I don't know how it
knows where to look.
klynn47@comcast.net - 09 Dec 2004 04:49 GMT
> > The JSDK when installed has a jar file where the the directories
> > java/lang, java/util, etc. are archived. It pulls the class files from
[quoted text clipped - 3 lines]
> got the java bin dir in my path, but other than that I don't know how it
> knows where to look.

I believe that there is a default classpath that is always available to
the compiler and interpreter even if you set a CLASSPATH. If you look
under the jdk directory, you should see the jre directory. In there
there is a directory called lib. In that directory there is a file
called rt.jar. If you look at it's contents with jar -tvf, you should
be able to see the packages.

Note that you also have a file called src.zip if you downloaded the
full JSDK. If you unzip this, you should be able to see the source code
of the most of the classes in the JSDK.
Brett Foster - 09 Dec 2004 09:03 GMT
> I believe that there is a default classpath that is always available to
> the compiler and interpreter even if you set a CLASSPATH. If you look
> under the jdk directory, you should see the jre directory. In there
> there is a directory called lib. In that directory there is a file
> called rt.jar. If you look at it's contents with jar -tvf, you should
> be able to see the packages.

Of course this wasn't the case for JDK 1.1/1.0 where there wasn't a
built in/auto path... Thank god those days are gone! I think. (I have a
soft spot for 1.1.)

To the OP: You can also build your own classloader and specify the
method by which classes are found. :)

Brett

> Note that you also have a file called src.zip if you downloaded the
> full JSDK. If you unzip this, you should be able to see the source code
> of the most of the classes in the JSDK.
Thomas Weidenfeller - 09 Dec 2004 16:19 GMT
> I installed the JDK.  I have not set my classpath (it is empty).  I tried a
> simple program that uses Date from java.util (I import java.util.*).  How
> does java know how to find this class - the right directory and archive (or
> whatever)?

Java actually uses more than one classpath. What you talk about is the
user classpath. There is also the boot classpath (used to load the
classes you are asking about), and the extension mechanism (a particular
directory, used to load optional Java extension).

The user classpath you see is actually the last one which is used to
search for classes. If it is not set explicitly, it implicitly refers to
the current directory. However, it is ignored if you run an application
from a JAR. In this case, the user classpath settings are taken from
information in the JAR's manifest file.

/Thomas

Signature

ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

Starshine Moonbeam - 09 Dec 2004 22:48 GMT
> I installed the JDK.  I have not set my classpath (it is empty).  I tried a
> simple program that uses Date from java.util (I import java.util.*).  How
> does java know how to find this class - the right directory and archive (or
> whatever)?

Because you're telling Java to find it for you and bring it to you with
the import statement.

Signature

Starshine Moonbeam
mhm31x9 Smeeter#29 WSD#30
sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.