java.no - Forum
  Search   Recent Topics     Member Listing    Back to home page 
Register / 
Login 
why java interface  
Forum Index -> Java in english
Author Message
nadia

Nybegynner

Joined: 28.sep.2008
Messages: 2
Offline

Hi,

Can anyone tell me what the use of java interface is? An interface is a named collection of method definitions without implementations. So what is the use of interface and when should we use it???
blarsen

Early adopter

Joined: 25.jan.2008
Messages: 23
Offline

By declaring that you (the class) implement a interface you inform the rest of the world (other classes) that you support a specific set of behaviours and that the rest of the world can call specific methods on you.

For instance, a class CarWash can be implemented to perform its work on any class that implements the interface Car. The CarWash does not know what classes out there that might choose to implement Car and it doesn't need to care about that, as long as it knows that on these classes it it safe to call the methods defined in the interface Car (such as closeWindows, driveForward, removeAntenna, getHeight, getWidth).
newjavaor

Jomfru

Joined: 03.jun.2009
Messages: 1
Offline

An interface in the Java programming language is an abstract type that is used to specify an interface (in the generic sense of the term) that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signatures and constant declarations (variable declarations which are declared to be both static and final). An interface may never contain method definitions.
manu007

Jomfru

Joined: 18.apr.2011
Messages: 1
Offline

nadia wrote:
Hi,

Can anyone tell me what the use of java interface is? An interface is a named collection of method definitions without implementations. So what is the use of interface and when should we use it??? 


http://javacodespot.blogspot.com/2011/04/java-programming-interface.html
miteshaegis

Nybegynner

Joined: 14.aug.2012
Messages: 8
Offline

An interface is used in java to outline specific behaviors of a group of classes. These common behaviors translate into methods that are all public and unimplemented. An interface is usually used when it doesn't make sense for something to be a class but it does have general behaviors that other classes should implement.


Business CRM Software
miteshaegis

Nybegynner

Joined: 14.aug.2012
Messages: 8
Offline

Hi All!!!

Interface is a device that unrelated entities use to interact. According to this definition, a remote control is an interface between you and a television set.


Java interface is a device that unrelated objects use to interact with one another. Java interfaces are probably most analogous to protocols. In fact, other object-oriented languages have the functionality of Java's interfaces, but they call their interfaces protocols.


Thanks!!!!!!

Business CRM Software
 
  Forum Index -> Java in english
Go to:   
Powered by JForum 2.1.4 © 2005 - Rafael Steil