File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "user interface VS API" Watch "user interface VS API" New topic

user interface VS API

jacob deiter
Ranch Hand

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

Joined: Jul 08, 2003
Posts: 24199

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: 580
arraylist is implemetation of list interface.Then I can say,sun java ,by default given the implemetation?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
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

Joined: Oct 27, 2005
Posts: 20274

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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: user interface VS API
It's not a secret anymore!