Adding new methods in interface s always break the implementation in class. So Java 8 come up with new feature which propose a mechanism to extend existing interfaces by adding new methods without breaking existing implementation thus, achieved the backward compatibility. Default methods is the feature which helps you to extend existing interfaces . If added method in interface provides the default implementation then no implementing Class get affects. Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older version of those interfaces. An implementing class can override the default implementation defined in implemented interface and add its own implementation. To understand it with example, lets say there is ABC company which wants to launch their smart Radios in market, so they have developed SmartRadio interface(contract) and ABCRadio final product implements all the fu
You always been in confusion to differentiate the differences between these two things. Actually speaking Comparable and Comparator are both the Interfaces in Java. Both are since Jdk version 1.2 means quite old still enough to confuse us so far. Basically, the purpose of these two interfaces is to compare two objects. Now you might wondering why we need another class or interface just to compare objects when we already have equals() method in Object class? So, let me give you some background so you better understand the purpose of existence of these interfaces and eventually we will also see the benefits of each one over another plus when to use which interface. Okay! The Background... I hope you might aware about collection framework in java. Collections are objects in java which does the job of container for objects and which theoretically holds unlimited objects. now typed collections holds only the objects which having same type of which collection is. List, Se