• 29 April

    TreeMap in java with examples

    TreeMap class implements Map similar to HashMap. Some important points about TreeMap: TreeMap implements Map interface and extends HashMap class. TreeMap is implemented using Red black tree based NavigableMap. TreeMap is ordered collection and store its elements in natural ordering of keys. Key which you would like to put in TreeMap must implement Comaparable interface or you can […]

  • 29 April

    HashMap in java

    HashMap is hash table based implementation of Map interface. It stores entry in key-value pairs. It maps keys to values. It is one of the most used Collection. Java HashMap HashMap implements Map an interface that maps a key to value. It is not synchronized and is not thread-safe. Duplicate keys are not allowed One […]

  • 26 February

    Difference between Comparator and Comparable in java

    CodeProject One of the common interview question is “What are differences between Comparator and Comparable”. or “How will you sort collection of employee objects by its id or name”.For that we can use two interfaces.i.e. Comparator and Comparable.Before we actually see differences,let me give you brief introduction of both. Comparable interface: Class whose objects to […]

  • 17 June

    Comparator in java

    In this post, we will see how you can use comparator to sort list of objects in java. Comparator: When you want to sort the list of objects of a class,you can use Comparator interface. You don’t need to implement Comparator on the class whose objects need to be sorted. You can create a separate […]

  • 18 June

    Comparable in java

    In this post, we will see  how you can use comparable to sort list of objects in java. Comparable interface: Class whose objects to be sorted must implement this interface.In this,we have to implement compareTo(Object) method. For example: [crayon-6096ef445ee63634202751/] If any class implements comparable inteface then collection of that object can be sorted automatically using […]

  • 18 May

    ArrayList in java

    ArrayList in java is most common Collections data structure along with HashMap which we use very often. Why to choose ArrayList vs Array: Array is fixed length data structure If array is full , you can not add element to it, where as ArrayList in java can dynamically grow and shrink as per our need. […]

  • 17 June

    Method overloading in java

    If two or more methods have same name , but different argument then it is called method overloading. Why you would do that (same name but different argument)? Lets take an example. You want to print salary of employee and sometimes company gives bonus to their employee and sometimes it don’t.So If company don’t give […]

  • 17 June

    Method overriding in java

    If subclass is having same method as base class then it is known as method overriding Or in another words, If subclass provides specific implementation to any method which is present in its one of parents classes then it is known as method overriding Lets start with a real time example: In a small organization,There […]

  • 28 July

    Inheritance in Java

    In this post, we will see about Inheritance in java. It is one of the OOPs principles apart from Abstraction, encapsulation and polymorphism. Introduction The word Inheritance is quite familiar with everyone. In common terms, the word means the bequeathing of property and characteristics from generation to generation. For example, the property or characteristics of […]