HashMap in Java

Here is the list of methods available in HashMap class. I have also covered examples using these methods at the end of this post. void clear(): It removes all the key and value pairs from the specified Map. Object clone(): It returns a copy of all the mappings of a map and used for cloning them…

Read More

Comparator interface in Java

Java Comparator interface is used to order the objects of a user-defined class. This interface is found in java.util package and contains 2 methods compare(Object obj1,Object obj2) and equals(Object element). It provides multiple sorting sequences, i.e., we can sort the elements on the basis of any data member. This interface is part of java.util package. We can use…

Read More

Comparable Interface in Java.

Java Comparable interface used to sort a array or list of objects based on their natural order. Natural ordering of elements is imposed by implementing it’s compareTo() method in the objects.This interface is found in java.lang package and contains only one method named compareTo(Object). This ordering is referred to as the class’s natural ordering, and the class’s compareTo() method is referred to as its natural comparison method.…

Read More

Static import in Java

Static import allows you to access the static member of a class directly without using the fully qualified name. To understand this topic, you should have the knowledge of packages in Java. Static imports are used for saving your time by making you type less. If you hate to type same thing again and again then you…

Read More

Different variables in Java.

In this blogpost we will discuss the  different types of variables in Java. But before that lets see the naming conventions which are followed/allowed in Java programming language.  Variables naming cannot contain white spaces, for example: int num ber = 100; (invalid)  Variable name can begin with special characters such as $ and _.  As per the java…

Read More

Overloading vs Overriding in Java.

In this blogpost we will discuss the difference between overloading and overriding in Java. If you are new to these terms then refer the following posts: Overloading vs Overriding in Java Overloading happens at compile-time while Overriding happens at runtime: The binding of overloaded method call to its definition has happens at compile-time however binding of overridden method call…

Read More

Different Access modifiers in Java: private vs protected vs default vs public

There are two types of modifiers in Java: access modifiers and non-access modifiers. The access modifiers in Java specifies the accessibility or scope of a field, method, constructor, or class. We can change the access level of fields, constructors, methods, and class by applying the access modifier on it.  There are four types of Java access modifiers: Private: The…

Read More