Interface in Java has remains a complex topic for many beginners to understand. First thing which puzzles many programmers is the fact that
you cannot define any method inside interface, it just declaration. By rule, all method inside interface must be
abstract (Well, this rule is changing in Java 8 to allow lambda expressions, now interface can have one non abstract method, also known as default method). So, if you can't define anything,
Why we need interface? what's the use of interface, if we are anyway going to write a class and override them to provide behaviour, Can't we declare those methods inside class itself without using interface etc. Well, if you are thinking in terms of behaviour than you are really missing the point of interface. I think one has to read
Effective Java, to understand best use of interface. Interface is great to declare Type, they promote code reusability, and they are the real driver of polymorphism in Java. Interface also allows
multiple inheritance in Java, which makes it possible for a class to become
Canvas, as well as
EventListener, which is used to draw graphics as well as to to process events. In this post, I will share few points, which will help you to understand what is the actual use of interface in Java. By the way, if you are confused between abstract class and interface, then you may want to read my previous post on difference between interface and abstract class in Java.