What is a Comparable Interface?

What is a Comparable Interface?

What is a comparable interface – Coders can also order objects using java comparable interface. And rather than any type of class for that object. As a result, java uses user-defined class for this interface.

You can find java comparable interface inside the java.lang package since it is located inside that package. Therefore it contains only 1 method which seems like to be CompareTo(objects). Furthermore the interface provides single sorting element on a single data member only. So For an example it may be rollno, name, age or anything else.

compareTo(Object obj) method

Therefore to compare the current object with the specified object we used the syntax :

public int compareTo(Object obj)

Hence, Here is a list of what the element we can sort :

Continue reading What is a Comparable Interface?

Java Covariant Return Type = Method Overriding

What Is Java Covariant Type?

Howdy Mowdy People? Have you ever override a method by changing its return type? Well for y’all that is already a pro in Coding may know this type of overriding, but for those who is still  a green horn in coding, just like me :’D maybe. This kind of method overriding is called Java Covariant Return Type, which is not available until Java5 came out.

Here ok, let me just show you a simple presentation of this Covariant Type :

Continue reading Java Covariant Return Type = Method Overriding