• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

How Classes Are Loaded

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's say that you have two jar's in your classpath, say a.jar and b.jar.
Now say there is a class, lets call it common.class in both of these jar files.
If you compile a .java file that calls that common class, the compiler will use the common.class file in the first jar it gets to in the classpath.
example. classpath=c:\jars\a.jar;c:\jars\b.jar Then the common.class in a.jar is used.
Now for my question.
If you have two jars in your installed extensions directory, how is the class found?

(ie. the jars are in c:\(java2 jdk)\jre\lib\ext; )
Thanks for your help.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greg,
I don`t know the definitive answer to this, but you could determine which class is used first by a simple experiment.
Create two versions of a class which simply output a message say "using class a(or b)" and run the class which uses the jar and see what message is output first - hence you could deduce what class within the directory is used first.
 
greg philpott
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the suggestion.
The order jar files are looked through by the class loader is alphabetical, so a.jar is looked in before b.jar.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to resolve this using the -verbose:class option, but found some "Loaded class..." messages omit the "from foo.jar" part. Any idea when this option does & does not report where it found a class?

Originally posted by greg philpott:
thanks for the suggestion.
The order jar files are looked through by the class loader is alphabetical, so a.jar is looked in before b.jar.


 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Greg,

I guess you are wrong.
I have experimented on something similar to this.
As far as class files are concerned ,they are taken in the order in which they appear in the classpath.
It could possibly be a.jar's class file because you have given it first in your classpath.Try putting b.jar first in the order.It could solve your doubt as well as mine.
Reply after trying,
With regards,
Marilyn
 
greg philpott
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, It has been ages since this post was first made . . . must be book givaway week in this forum!!!
Marilyn,
You do not understand the original post. Please re-read my first post carefully.

 
reply
    Bookmark Topic Watch Topic
  • New Topic