Solved

Why Interface? What is Interface?

Posted on 2006-11-19
8
207 Views
Last Modified: 2010-03-31
I have read enough trying to understand what is Java's Interface, why we should use it and also what is the main reason to use it.

I understand, in technical, once i have "implements" one interface class, i have to put the method within that interface class into my program.

Why i should do that? I dont know. Because i that method i still can put it in if i didnt implemnts that Interface.

Cany someone share with me some practical usage of Interface in our real time system development?

thank you.
0
Comment
Question by:wjh7554
8 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 20 total points
ID: 17974634
An interface is largely for the benefit of clients of that interface. It defines *what* a client can expect from an implementer and leaves the *how* to the implementer
0
 
LVL 13

Assisted Solution

by:marchent
marchent earned 20 total points
ID: 17974662
u can implemet more than one interface, where u can only extend a single class
0
 
LVL 24

Assisted Solution

by:sciuriware
sciuriware earned 20 total points
ID: 17974707
You can also 'see' an Interface as a qualification that a class can have.
This qualification may demand some methods to be added.
Other parts of the program may now treat your class as 'seen' by the interface only.

An example:    When you say that your class     "implements ActionListener"
then a button will accept an object of that class as is
and will blindly call the method "actionPerformed()" when the button is pressed.

This is a way to make any object able to handle button clicks.

;JOOP!
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 10

Assisted Solution

by:jaggernat
jaggernat earned 20 total points
ID: 17975397
>>>Cany someone share with me some practical usage of Interface in our real time system development?

say you have a client trying to access some methods. You can expose an interface to the client . the interface  will have the methods which the client can use but the actual implimentations of those methods can be defined in an implimentation class. That implimentation class would impliment the interface and contain the method body. This way the actual  implimentation class remains safe and the client only sees and interacts with the interface.

0
 
LVL 1

Assisted Solution

by:bnblazer
bnblazer earned 20 total points
ID: 17976424
Think of an interface like a car radio.  One can assume that all car radios can tuneStation(), setVolume(), and powerOnOff().  It is just that all car radios do it differently.

In the case of the interface, it is set up so that all car radios do these things, and leaves it up to the individual radio to do it they way they would like to do it.  It is a contract of sorts.  If you implement the interface you are making a contract that all of these CarRadio methods will be used.

Brian
0
 
LVL 3

Expert Comment

by:nishayr
ID: 17976538
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now