Solved

Why Interface? What is Interface?

Posted on 2006-11-19
8
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

749 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