Results 1 to 8 of 8
Thread: Interface - Implementation link
- 10-03-2012, 05:56 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
Interface - Implementation link
How does an API know which implementation to use? For example, if I am using the JDBC API in my code, how does the JVM know to call the correct implementation of this API. Let's say I have two driver jars that implement this JDBC API in my classpath. Which one will get called? Is this based on the DriverManager?
- 10-03-2012, 06:01 PM #2
Re: Interface - Implementation link
I would recommend providing an example that demonstrates exactly what you're talking about. You might want to use the List interface as an example.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-03-2012, 06:20 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Interface - Implementation link
For JDBC it's the DriverManager.
Each JDBC implementation has a different connection String.
MySQL = jdbc:mysql
Derby = jdbc:derby
Oracle = jdbc:oracle
etc etc.Please do not ask for code as refusal often offends.
- 10-03-2012, 06:40 PM #4
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
Re: Interface - Implementation link
Thanks for the prompt reply. It makes sense now. Can you tell me how this interface-implementation works for JAX-RS -- Jersey? Sorry if i am asking too much.
- 10-04-2012, 09:36 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Interface - Implementation link
Aren't the implementations called something different?
In whatever setup file you define what implementation you are going to use (similar to defining which JDBC driver in your connections string).
Exactly how generally depends on your framework.Please do not ask for code as refusal often offends.
- 10-05-2012, 08:39 AM #6
Arma virumque cano
- Join Date
- Oct 2012
- Location
- Indianapolis
- Posts
- 20
- Rep Power
- 0
Re: Interface - Implementation link
In order to fix this problem, you could ONLY import the required class:
Another way is to instanciate the class with the full class name:Java Code:import java.sql.Datasomething; import com.jdbc.mysql.Driver;
This way, there are no mixups.Java Code:com.jdbc.mysql.Driver myDriver = new com.jdbc.mysql.Driver();
Sometimes, old versions and new versions of the same class may exist together. I am not sure how netbeans resolves it.Last edited by AeneasTroy; 10-05-2012 at 10:06 AM.
- 10-05-2012, 09:35 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Interface - Implementation link
That's not how you use either of the examples the OP has given.
JDBC does not work like that (you never import the actual Driver you are using, that's the job of the DriverManager or DataSource), and neither do the other similar frameworks (like JAX-RS, or any of the XML stuff).Please do not ask for code as refusal often offends.
- 10-05-2012, 10:23 AM #8
Arma virumque cano
- Join Date
- Oct 2012
- Location
- Indianapolis
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
interface implementation issue
By sat123stud in forum New To JavaReplies: 1Last Post: 08-29-2011, 09:00 AM -
ItemStateChanged Interface Implementation
By collwill in forum New To JavaReplies: 3Last Post: 04-19-2011, 04:36 AM -
Interface Implementation
By Samyx in forum New To JavaReplies: 3Last Post: 12-02-2009, 12:20 PM -
Interface and implementation erorr
By mihael in forum Advanced JavaReplies: 1Last Post: 12-07-2008, 11:06 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks