Cloneable in Java

Cloneable interface is one of the mistake in design in Java. At least I think so ­čÖé A class should be implementing Cloneable interface if that class wants to be cloned along with overriding clone() method from Object class. This combination of compulsion makes it quite unusual to implement. Code below: public class Student implements … More Cloneable in Java

Comparable vs Comparator

Comparable and Comparator both the interfaces are used to sort Collection of objects in certain order. Implementing Comparable interface allows us to achieve default or natural ordering where implementing a Comparator allow us to sort Collection in other than natural ordering.   Comparable interface imposes a total ordering on the objects of each class that … More Comparable vs Comparator

Functional Interface in Java

In Java, functional interfaces are those interfaces who has exactly one abstract method.┬á @FunctionalInterface is not a mandatory annotation to be used to make any interface a Functional Interface. Its just an informative annotation type used to indicate that an interface type declaration is intended to be a┬áfunctional interface. Since┬ádefault methods┬áhave an implementation, they are … More Functional Interface in Java

Factory Design Pattern

Factory design pattern belong to the Creational design pattern category which explain how the objects are created. Factory Design Pattern comes with different flavors and we use the flavor as per our convenience. The very common example of Factory design pattern can be found in Spring. Creation of beans in Spring container is done using … More Factory Design Pattern

Singleton Design Pattern

Singleton Design Pattern belong to creational design pattern family and singleton design pattern is used when there is a need of only one instance of class in one container. Like one organization can have only one CEO in company.┬áThe singleton pattern is one of the simplest design patterns. It contains only one class which is … More Singleton Design Pattern