This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes user interface VS API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "user interface VS API" Watch "user interface VS API" New topic
Author

user interface VS API

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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!


[Jess in Action][AskingGoodQuestions]
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
arraylist is implemetation of list interface.Then I can say,sun java ,by default given the implemetation?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
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).


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: user interface VS API
 
Similar Threads
How can you make an array grow
Deque
interface problem - !@#$%^&*
Example of Interface extending another Interface in Java API
A Connection question