Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Why Interface? What is Interface?

Posted on 2006-11-19
8
Medium Priority
?
221 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 80 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 80 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 80 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Assisted Solution

by:jaggernat
jaggernat earned 80 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 80 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

715 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