COME ON I HEARD "YOU CAN SPECIFY WHAT CLASS SHOULD DO,NOT HOW".BUT WITHOUT INTERFACE ,EXTREME JAVA PROJECTS CAN BE MADE!! WHY TO MAKE COMPLICATION USING INTERFACE?
An interface defines a set of methods that must be implemented by any class that implements the interface. Eg You could define an interface with a calculateArea method. Then define all kinds of shape classes (Square, Circle etc) that implement the interface. Those classes may have a common Shape superclass, but you could also define "Building Plot or "PlayingField" classes that implement calculateArea but are not subclasses of Shape. Now you can call calculateArea for any instance of any of those classes without needing to know anything else about them. It's a way around not having multiple inheritance.
Here is an excellent tutorial on the subject
In Java 8 interfaces with just one method ("functional interfaces") are an essential part of how lambdas have been added to Java without breaking anything.
Edited 2 Years Ago by JamesCherrill
interfaces aren't used to make complications. actually, they make working on your project a lot easier.
if you don't understand why developers write to interfaces rather then to implementations, you haven't worked on very large projects yet.
let's say you have to write the front-end for an application, and you have to use several libraries from external parties. only problem: your code must be finished on august 4th, must be completely functional, tested and presented to your client, and the developers who are responsible for those external libraries, don't start writing/implementing them until october.
so, you write your code on their interfaces, and make your code so, that later on all you need to change is one line in a properties or xml file, rather than to rewrite/recompile your entire application.
^^ That is an excellent example stultuske, I never got interfaces and most of the time I just simply ignore them (PHP) but your example shows how they can be useful.
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...
Hi I'm having a problem implementing a mini shopping cart drop down in the header to show the user all the products they have in their shopping cart. It seems the only solution for this is Ajax, and I've looked all over and can't find anything that I could possibly ...
Hi. Im using vb 2010. I want to dynamically add textboxes to my form by clicking on a button. I've google searched and so far this code worked:
Private Sub btn_addline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_addline.Click Dim txtB1 As New TextBox Dim i For i = ...