aspose file tools*
The moose likes JDBC and the fly likes interface's object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "interface Watch "interface New topic
Author

interface's object

sandeep ep
Greenhorn

Joined: Oct 08, 2006
Posts: 4
hi to everyone,

I had a small doubt on interface topic,that is we can create an object of interface and we can call the methods in the interface like

Statement stmt= con.createStatement();here con is the connection object.

My question is: an interface consists of abstract methods that means that are not fully (or) partially implemented methods.
then how can we create a object to an interface(which is nothing but a 100% abstract class) and how can we call the methods on interface object since there are abstract methods.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Your JDBC driver provides the implementation of these interfaces.

This is common practice in Java. Indeed it is good design to code to the interface, not the implementation. JDBC display's a good reason why too - a Connection object will differ from database to database. Each database will supply its own route to get a connection (some might use a known protocol like TCP/IP, others might use a proprietary protocol like SQL Server's TDS protocol). If we code to the implementation, for example:

We are stuck with Oracle as our database. Indeed we might also be stuck with a particular version of Oracle, if the method of connecting to it changes between version.

If we write to the interface however, we can change the database to our heart's content without changing any code. All we need is a driver for a particular database and our code will work seamlessly.
[ November 15, 2006: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
sandeep ep
Greenhorn

Joined: Oct 08, 2006
Posts: 4
thanks Paul Sturrock
sandeep ep
Greenhorn

Joined: Oct 08, 2006
Posts: 4
thanks Paul Sturrock
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: interface's object