Two packages having same class

I have imported following class :-

import org.apache.xerces.parsers.DOMParser;

in my new class and i am instantiating a object of DOMParser

I have added xmlParserAPI.jar and xercesImpl.jar to my classpath .

Now since both of these jar files are having DOMparser class will this create problem in instantiating DOMParser class's Object in the new class.

[411 byte] By [Ravi_Singh83a] at [2007-11-27 7:49:49]
# 1

In your code fully qualify the one you want to use, so if you wanted the one from the xerces package in your code it would look like this.

org.apache.xerces.parsers.DOMParser parser = ...

rather than counting on the import which is dependent on a couple of things like the order they're found in the classpath.

PS.

puckstopper31a at 2007-7-12 19:30:47 > top of Java-index,Java Essentials,Java Programming...
# 2

If they both have that exact same package, then the one that gets loaded will be the one that appears first in the classpath (AFAIK). If it is only the classname that has the same name, and the packages are different, then as long as you are explicit about what you import (i.e. don't use * for both packages containg that class) and/or explicit about which one you are using at which point (i.e. using full.class.path.Classname rather than simply Classname), no it won't be a problem.

There are already a load of cases where the same classname exists in mulitple pacakges e.g.

java.util.Date

java.sql.Date

and many others. Object itself even exists twice (there is one in the CORBA packages I believe).

Those don't cause a problem, as long as you are careful when using both, so this classname should not either.

Edit: Man, am I long-winded.

masijade.a at 2007-7-12 19:30:47 > top of Java-index,Java Essentials,Java Programming...
# 3
> Edit: Man, am I long-winded.Yes. :-)
corlettka at 2007-7-12 19:30:47 > top of Java-index,Java Essentials,Java Programming...
# 4
> > Edit: Man, am I long-winded.> > Yes. :-)Well, finally someone agrees wih me! ;-)
masijade.a at 2007-7-12 19:30:47 > top of Java-index,Java Essentials,Java Programming...