Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interfaces and its implementation" Watch "Interfaces and its implementation" New topic

Interfaces and its implementation

laks subramanian

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

Joined: Dec 10, 2001
Posts: 7023
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

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
laks subramanian

Joined: Feb 05, 2002
Posts: 17
hey kareem
thanks for the explanation. i gotcha.
I agree. Here's the link:
subject: Interfaces and its implementation
Similar Threads
CapGemini Offer
Math cos wth
Websphere AppServer,Advanced Edition 4.0 on Windows XP professiona version
jakarta commons
Design Pattern