aspose file tools*
The moose likes Beginning Java and the fly likes interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "interface" Watch "interface" New topic
Author

interface

shanker sothi
Greenhorn

Joined: Oct 19, 2003
Posts: 4
Please can you briefly explain the concept behind interfaces?
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
Hi Shanker
Have a read of this article. Does that help any?
Michael


"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
Interfaces are useful when you know WHAT something should do, but not HOW is should do it. They are used to create a standard programming interface for a particular task on a variety of objects.
For example, the Comparable interface in Java defines a single method - compareTo. We know if we want to compare two objects we need a compareTo method. But, we can't know how to compare all possible objects! So, the Java designers created the comparable interface the defined the API for comparing, specifically the compareTo method.
Now anyone who designes a class can allow anyone else to compare different objects of that class by implementing the Comparable interface. When we implement an interface, we are required to provide method bodies (the working code) for all methods defined in the interface. Therefore, if I design a class and I want others to be able to compare objects of my class, I have my class implement the comparable interface and I provide the details on how to compare two of my objects and determine if one if greater than, less than, or equal to another.
For the user of classes, implementing interfaces guarantees that my class supports the methods defined in the interface. You can think of interfaces as contracts. If I implement an interface, I guarantee that my class will contain the methods in the interface, and you guarantee that you will call the methods based on the details outlined in the interface.
Does this help?


Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
shanker sothi
Greenhorn

Joined: Oct 19, 2003
Posts: 4
Thanks
Michael Fitzmaurice
Tom Blough
shanker.
Firstman Lastman
Greenhorn

Joined: Oct 26, 2003
Posts: 1
Am realy impress by the way this has been responded to especially Tom Blough Tom Blough You really cool.Thank you
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
"Firstman Lastman",
Welcome to JavaRanch. We don't have many rules here, but one we do have is a naming policy. Please edit your display name to comply with this policy. Thank you in advance for your cooperation, and we look forward to seeing you around the Ranch.
[ October 26, 2003: Message edited by: Jason Menard ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: interface