For Programmers: Free Programming Magazines  


Home > Archive > Java Help > September 2004 > API question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author API question
Frances Del Rio

2004-09-21, 3:59 pm


there's something about java's API that baffles me... when I put code
like this at the beginning of my programs..

import java.io.*;
import java.util.*;
import java.text.*;

my programs (stand-alone's I compile & run in DOS shell) are located in
my hard drive.. so how does java find these classes? they're not in my
hard drive (I have searched for them, I have SDK and all that installed,
but that does't include all these classes..) classes are up on java.sun,
right???? I find this baffling.. am I missing something here?
(probably..) thank you.. Frances



VisionSet

2004-09-21, 3:59 pm


"Frances Del Rio" <fdr58@yahoo.com> wrote in message
news:2rb61mF17b510U1@uni-berlin.de...
>
> there's something about java's API that baffles me... when I put code
> like this at the beginning of my programs..
>
> import java.io.*;
> import java.util.*;
> import java.text.*;
>
> my programs (stand-alone's I compile & run in DOS shell) are located in
> my hard drive.. so how does java find these classes? they're not in my
> hard drive (I have searched for them, I have SDK and all that installed,
> but that does't include all these classes..) classes are up on java.sun,
> right???? I find this baffling.. am I missing something here?
> (probably..) thank you.. Frances


Now try and search for the file rt.jar
found it?
that is where the classes are.

--
Mike W


Frances Del Rio

2004-09-21, 3:59 pm

ok, I see.. so what are .jar files, exactly?? they contain classes,
right?? in my HD icon assoc'd w/them makes them look like a text file
(is it ok for to open them so I can look?) it is FULL of .jar files in
there, not just rt.jar.. what are all the others? (also tons of .idx
and .zip files.. have no idea what those contain.. see screen-shot at
http://www.francesdelrio.com/java/jar.gif..) talk to me about this
stuff, pls.. thank you very much for yr response.. Frances


Frances Del Rio wrote:

>
> there's something about java's API that baffles me... when I put code
> like this at the beginning of my programs..
>
> import java.io.*;
> import java.util.*;
> import java.text.*;
>
> my programs (stand-alone's I compile & run in DOS shell) are located in
> my hard drive.. so how does java find these classes? they're not in my
> hard drive (I have searched for them, I have SDK and all that installed,
> but that does't include all these classes..) classes are up on java.sun,
> right???? I find this baffling.. am I missing something here?
> (probably..) thank you.. Frances
>
>
>


kaeli

2004-09-21, 3:59 pm

In article <2rb61mF17b510U1@uni-berlin.de>, fdr58@yahoo.com enlightened us
with...
>
> there's something about java's API that baffles me... when I put code
> like this at the beginning of my programs..
>
> import java.io.*;
> import java.util.*;
> import java.text.*;
>
> my programs (stand-alone's I compile & run in DOS shell) are located in
> my hard drive.. so how does java find these classes? they're not in my
> hard drive (I have searched for them, I have SDK and all that installed,
> but that does't include all these classes..) classes are up on java.sun,
> right???? I find this baffling.. am I missing something here?
> (probably..) thank you.. Frances
>


The classes are part of the standard JVM (Java Virtual Machine) that users
get when they install Java.
If a user doesn't have Java, your program won't run.

As to the location of the classes, since they are standard with an intall,
the compiler already knows where to look.
For non-standard classes, the compiler would look at your CLASSPATH, which is
an environmental variable that can be set via OS commands or, for Windows, in
your startup .bat file (I think it's autoconfig.bat or something). In Unix,
you can set it in your .profile.

--
--
~kaeli~
When a clock is hungry, it goes back four seconds.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Andrew Thompson

2004-09-21, 3:59 pm

On Tue, 21 Sep 2004 13:59:35 -0400, Frances Del Rio wrote:

> .. what are .jar files, exactly?? they contain classes, right??


Besides classes though, they might contain a lot of things
relavent to an application. Icons, help files, whatever.
Jar files are a 'specialized' form of zip file, try renaming
one and open it in a Zip program.

I am not actually sure if specialized is the right term here,
..jar's can have a main-class specified in the Manifest.mf stored
in a particular directory of the zip, and can have the classes
indexed and signed, but otherwise they are a zip file.

Here are the JavaDocs for the JarFile class, note how
it inherets directly from ZipFile.
<http://java.sun.com/j2se/1.4.2/docs...ar/JarFile.html>

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Frances Del Rio

2004-09-23, 3:56 am

ok, I have another question about this:

classes I write are in C:\.....\My Documents\myjava

my java SDK/JRE is in C:\java (I renamed SDK folder from
"j2sdk1.4.2_05" to "java" to keep things simple..)

so when I type this into a class I'm writing...

import java.io.*;
import java.util.*;
import java.text.*;

how does my class know where to find the imported classes?? thank you
for yr response.. Frances


VisionSet wrote:

> "Frances Del Rio" <fdr58@yahoo.com> wrote in message
> news:2rb61mF17b510U1@uni-berlin.de...
>
>
>
> Now try and search for the file rt.jar
> found it?
> that is where the classes are.
>
> --
> Mike W
>
>


KC Wong

2004-09-23, 3:56 am

> ok, I have another question about this:
> classes I write are in C:\.....\My Documents\myjava
>
> my java SDK/JRE is in C:\java (I renamed SDK folder from
> "j2sdk1.4.2_05" to "java" to keep things simple..)
>
> so when I type this into a class I'm writing...
>
> import java.io.*;
> import java.util.*;
> import java.text.*;
>
> how does my class know where to find the imported classes?? thank you
> for yr response.. Frances


Take a look at your JDK directory. It contains a subdirectory called "jre" -
it is where the JVM files are. Inside "jre", open "lib" directory. It
contains the file "rt.jar".

Use Winzip or similar programs to open it. Sort on the path... you'll see
rt.jar is the jar file containing all the core classes.

By default the compiler and JVM include this jar in the class path.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com