This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Purpose in an interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Purpose in an interface" Watch "Purpose in an interface" New topic

Purpose in an interface

Barry Brashear
Ranch Hand

Joined: Jun 05, 2001
Posts: 303
Can someone explain to me what exactly an interface is and when and why
you would use one?

Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
Try this
Mani vannan
Ranch Hand

Joined: Aug 21, 2004
Posts: 185
The above link colud have given a clear issue on Interface.. Interface is a skeleton, that doesnt have any functionality, but takes shape as it is implemented.

Ben Kittrell

Joined: May 20, 2005
Posts: 6
Wow, great question, hehe.

My advice would be to not try and understand it, unless you think you need it.

But to some it up, and interface allows you to change the implementation, without changing the interface. It also allows you plug different objects in the same hole.

Think of collections.

ArrayList and Vector but implement the List interface. The benifit is that you can have a method that takes a List as an argument, and you can pass an ArrayList or a Vector to it.

What does an Interface do? It ensures that the classes that implement it all have the same methods. This way the compiler can rest assured that the methods it calls on an object will be there.

Kind of hard to grok, but it's an awesome concept.
It is sorta covered in the JavaRanch Style Guide.
subject: Purpose in an interface