wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes when to use interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "when to use interface" Watch "when to use interface" New topic
Author

when to use interface

ahamed irshad
Ranch Hand

Joined: Feb 26, 2010
Posts: 31

hi to all,

i know the concept of interface.but i have no clear cut idea about when should i use interface.thanks in advance

You can do anything, but not everything
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

There are many reasons why you might want to use an interface.

One example is to decouple "how a service looks" from the actual implementation, which allows you to have different implementations (that all "look the same" from the outside). A client program (that uses the service) is programmed against just the interface, so that different implementations can be plugged in at runtime. An example of this are JDBC drivers. In your program that uses JDBC, you just use the interfaces (for example Connection, Statement, and ResultSet). The JDBC driver implements those interfaces with classes that are for a specific database (for example Oracle or MySQL), but the client program doesn't need to know the actual implementation classes.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: when to use interface
 
Similar Threads
isolation-level and ordering-number
To Ajax or Not
to Inclue jsp page in another using jsf
Statement and PreparedStatement
continue statement...