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…
Month: April 2020
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.…
String’s immutability in Java explained
String is immutable in Java. An immutable class is simply a class whose instances cannot be modified. All information in an instance is initialized when the instance is created and the information can not be modified. There are many advantages of immutable classes. This article summarizes why String is designed to be immutable. This post illustrate the immutability concept…
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…
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…
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…