This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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.
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 ]