• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

user interface VS API

 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for Interface ,use have to give implementation.But in API(application Program Interface) even java developer do not give any implementation.How it work?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes the classes that implement an interface are "secret." They're not public classes, and you're not supposed to call them by name.

The JDBC API is an excellent example of this. You call DriverManager.getConnection(String) to get a Connection object that lets you talk to a database based on the contents of that String. DriverManager is a class, and getConnection() is a static method of that class. But Connection is an interface. You do not know the name of the class that is returned. The DriverManager does something (conceptually) like this:



OracleConnection and MysqlConneection are classes that implement Connection. You do not and should not know their names or need to access them diretly.

When you call getStatement() on the Connection, the OracleConnection object would return an instance of OracleStatement, but you're just know that it was something that implemneted Statement, and that's all you'd need to know!
 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
arraylist is implemetation of list interface.Then I can say,sun java ,by default given the implemetation?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes an API is defined in the expectation that the market will provide (one or more) implementations in due course. This is very rare, though, because without an implementation, an API can't be tested realistically. It may happen if an API is ported from another language to Java, though. JSAPI is the only one I can recall that at first didn't have an implementation. I think that APIs developed under the JCP are required to have at least two working implementations.

Then I can say,sun java ,by default given the implemetation?

For an interface defined in the Java class libraries this is generally true, but not always: JDBC is a good example. The only implementation shipped with the JRE is the JDBC/ODBC driver, which doesn't work on all operating systems (admittedly, this changed with Java 6, which does include a version of the Derby database and driver).
 
Rob Spoor
Sheriff
Pie
Posts: 20546
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jacob deiter wrote:arraylist is implemetation of list interface.Then I can say,sun java ,by default given the implemetation?

I would say that Sun has given an implementation. And more than one even - there's also LinkedList and Vector.

Because that's the thing with interfaces - there can be zero to infinite implementations.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic