Reviewing JAVA concepts. | Techbirds

Interfaces are the blueprints and Abstract are partially implemented classes

Object class is the father of all classes , specially used to hold the object of that class whose type is unknown to us.

equal() method is used to compare content of two strings whereas  == used to compare references

there is always a heap area under which a pool is maintained. Strings have special pool known as string pools where all sting literal i.e. ” LITERALS” (within double quotes ) are stored.

when two strings are initialised using same literal, they reference to same literal

but not when instantiates using new keyword, in which case they reference differently.

reference variable is stored in non pool area that is heap itself.

but the same equal method  can be used in user defined objects for comparisons.

in that case we need to do two things for sure:

override equal method. :  is used to match the data structure elements that is fields to be matched in overriding.

override hash code.: since two similar objects are created via new operator they will have different reference but we must override hash code method so that we can achieve the same task that we see in two strings initialised with similar literals refer to same object.

every newly created object of user defined class is stored in bucket and when they are referenced they produce a hash code one object must create same hash code every time and keyed(indexed to the same) element until next run. so  hash code overriding help us do that effectively.

hosh code: an integer that key to an element in the bucket.

367 total views, 2 views today

Share this Onfacebook-7021665twitter-2733731linkedin-3916476google-9173702