Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

import confusion!!

Posted on 2006-06-28
12
Medium Priority
?
406 Views
Last Modified: 2012-06-21
for example.. I have two .jar files in my ext. jdom.jar and eva3rt.jar
when i do import org.jdom.*, which one will be imported, because both jar contents org.jdom.

similar confusion when i use implements provided by third party. for example jtapi.jar gives APIs and Xtapi.jar gives its implementation. but in our application we use the APIs. So how this mapping takes place...
 .. infact I'm even confused with my this query.. so anyone can provide me a link from where I can understand these stuffs.

Thanks in Advance..

0
Comment
Question by:RupeshB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +5
12 Comments
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 300 total points
ID: 17007113
The discovery of classes is done sequencely as the jar appears in the classpath.
0
 

Author Comment

by:RupeshB
ID: 17007120
then how to change orders of jars
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 17007215
like this

set CLASSPATH=jdom.jar;eva3rt.jar;.
or
set CLASSPATH=eva3rt.jar;jdom.jar;.

whichever comes first, has priority over the other
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:RupeshB
ID: 17007298
that's ok but not effective way... still waiting for full answer...
0
 
LVL 35

Expert Comment

by:girionis
ID: 17007356
If you put them in the /ext folder I think it will be done alphabetically. If you want different order you will have to take them out of /ext and put them in your user-defined classpath.
0
 
LVL 8

Expert Comment

by:colr__
ID: 17007567
To avoid any amibiguity you should use the fully qualified name of your class in the import. This makes your code easier to read, maintain, and removes any ambiguity.

colr__
0
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17007765
right, but the question is about same package in diferent jars
0
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17007787
If you are using eclipse you can specify the jars for each project,

do you need both these jars in the same project??

if two jars have same package and are in the same project then the behaviour  might not be as you expected.

so wat you can do is seperate your aplication into two projects. in one project add the first jar
and in the second one the second jar. split your apllication based on that. later you can combine both of them using a third project or may be in anyone of the projects
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 17007843
> that's ok but not effective way... still waiting for full answer...

I think you're looking for a little magic - it doesn't exist. The reality is that if you have conflicts in your jars, that's your problem, and you should probably fix that before you worry about the order in which they're loaded (which is, as explained above, the order in which they're "seen" by the JVM).
0
 
LVL 8

Expert Comment

by:colr__
ID: 17007847
mukundha_expert  > your right, I was assuming that the package names just happened to be the same (in which case the class names would be differnet maybe), not that they were actually the same package.
0
 
LVL 13

Accepted Solution

by:
Webstorm earned 450 total points
ID: 17008348
If you want to use both classes, you can try to use 2 different class loaders, and use the one containing the package you want to use.


>> similar confusion when i use implements provided by third party. for example jtapi.jar gives APIs and Xtapi.jar gives its implementation. but in our application we use the APIs. So how this mapping takes place...

The API may have something to know which classes implement it. It may be a configuration file containing fully-qualified class names, or you have to explicitly give this class name when you call the API.
Or you have to direclty use the implementation classes.
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 17009121
Typically the APIs contain abstract base classes and the implementation jar contains the concrete implementations of these. It depends on whether you're calling the functionality (use the implementation jar) or implementing it yourself (use the API jar).
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question