//iteration method

binarySearch(arr, x, low, high)
        repeat till low = high
               mid = (low + high)/2
                   if (x == arr[mid])
                   return mid
   
                   else if (x > arr[mid]) // x is on the right side
                       low = mid + 1
   
                   else                  // x is on the left side
                       high = mid - 1
//recursive method (divide and conquer approach)

binarySearch(arr, x, low, high)
if low > high
    return False 

else
    mid = (low + high) / 2 
        if x == arr[mid]
        return mid

    else if x > arr[mid]        // x is on the right side
        return binarySearch(arr, x, mid + 1, high)
    
    else                        // x is on the left side
        return binarySearch(arr, x, low, mid - 1)

Polymorphism: any of overloading, overriding, late binding

polymorphism

At run time, objects of a derived class may be treated as objects of a base class in places such as method parameters and collections or arrays. When this polymorphism occurs, the object's declared type is no longer identical to its run-time ty

Late binding of object, referencing superclass object, ie Animal a = new Chicken(); Animal b = new Goat();

?

Standard methods: toString(), equals(), hashCode()

The toString method is used to return a string representation of an object. If any object is printed, the toString() method is internally invoked by the java compiler. Else, the user implemented or overridden toString() method is called. If you override the toString() method of the Object class, it will return values of the object, hence you are not required to write a lot of code.

1) first implementation is when it is called as a method of an object instance

class HelloWorld {
    public static void main( String args[] ) {

        //Creating an integer of value 10
        Integer number=10;
        // Calling the toString() method as a function of the Integer variable
        System.out.println( number.toString() );
    }
}

2) second implementation is when you call the member method of the relevant class by passing the value as an argument

class HelloWorld {
    public static void main( String args[] ) {
        
        // The method is called on datatype Double
        // It is passed the double value as an argument
        System.out.println(Double.toString(11.0)); 
        // Implementing this on other datatypes

        //Integer
        System.out.println(Integer.toString(12)); 

        // Long
        System.out.println(Long.toString(123213123));

        // Booleam
        System.out.println(Boolean.toString(false));
    }
}

The equals() method compares two strings, and returns true if the strings are equal, and false if not.

Tip: Use the compareTo() method to compare two strings lexicographically.

//syntax
public boolean equals(Object anotherObject)

hashCode() returns an integer value, generated by a hashing algorithm