Solved

import confusion!!

Posted on 2006-06-28
12
383 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
  • 2
  • 2
  • 2
  • +5
12 Comments
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 100 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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 150 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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…

803 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