*
The moose likes Beginning Java and the fly likes Interfaces and its implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interfaces and its implementation" Watch "Interfaces and its implementation" New topic
Author

Interfaces and its implementation

laks subramanian
Greenhorn

Joined: Feb 05, 2002
Posts: 17
hi gang,
Can somebody explain whats an interface, its purpose, uses etc with some simple code example.
thanks.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Hello,
A quick search on this forum for "interface" in the subject line will result in lots of links to discussions covering this very question. The search page link is at top right of this page.
Good Luck.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Also, the Interfaces and Packages section of Sun's Java Tutorial describes the concept well.
[ April 10, 2002: Message edited by: Dirk Schreckmann ]
Kareem Qureshi
Ranch Hand

Joined: Mar 14, 2002
Posts: 102
Hi ls,
Interfaces are also known as behavioural inheritence because when you are implementing the interface you are actaully implementing its behaviour, means that you are providing implementation to the methods provided in the interface and you have to provide implementation to all the methods of the interface. And this also a way of providing the abstract behaviour which we cannot provide through the actual inheritence by using the super classes.
Interfaces are used where certain behaviour is needed by the objects but it need not necesarily be part of class, like example in AWT we have various Listener interfaces which provide fuctionality or behaviour of certain kind to all the component objects which may be needed by the component to perform some action, but they need not be part of the class.
This way certain actions common to all the different kinds of objects is abstracted in interfaces and when ever they need to have that behavour they can implement and override them and provide their own behavoiur.
Like in c++ we dont have multiple inheritance in Java so Interfaces help in providing kind of multiple inheritence in Java.
Example the WindowListener in AWT package it is provides signature for different kinds of window operations we can have like windowclosing, windowclosed etc whichever class wants windows behavoiurs they can implement the windowListener interface and override the method they want to use in their own way.
Also please go through the JLS for other techincal details
Hope this helps
Kareem
laks subramanian
Greenhorn

Joined: Feb 05, 2002
Posts: 17
hey kareem
thanks for the explanation. i gotcha.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interfaces and its implementation