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 implements it. This ordering is referred to as the class’s natural ordering and … Continue reading 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 not abstract. Note: – If an interface declares any method of … Continue reading 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 Factory design pattern only. The implementation is really simple. Create … Continue reading 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 responsible to instantiate itself and it make sure it creates … Continue reading Singleton Design Pattern

Command Design Pattern

This is kind of Behavioral Design Pattern(BDP) and as per the BDP definition, “Behavioral patterns describe how the objects behave when they interact with each other” and as the name explain this design pattern is used when we give command to some one else to get our job done. Example: When you visit any restaurant, you place an order to waiter not to cook and its … Continue reading Command Design Pattern