see in java , great thing about string is that , string is primary concept in java , means every thing in java is presented by string , you want to print something , you want to show someone that they have created that thing at that time you also need strings , every api is added with the help of strings { means you use text }.
now see two great points about strings . " equals " ....... " == " ! but i am here to show or placing the problems introduced by "equals" and "==" but before this understand why we use them ,
Equals :: equals always deals with the content present in the object , now look at this ,
see if you use equals it will deal with
::: pillion seat
::: light
::: tyre
::: glass
" == " :: now we have "==" in java , it will deal with who is holding , means if EARN is having that car of DUKE have that car ! "==" compares the reference , look at this .
Problem associated with "EQUALS" and "==" :: now the main points comes in , see we have two human "duke" and "earl" now a car is standing in parking and earl takes duke's car and went to market for buying something now duke comes in parking and search his car , and did not find his car and after sometime he saw that earl is using his car , after it they fight with each other , now think how they will solve their problem by "equals" and "=="
now "DUKE" and "EARL" use
::: "equals" for solution and find that and find that they use same content glass , pillion seat , tyre .
::: "==" for solution and finds that they use same car , and drive same car
so in the end , they have no solution and still they are fighting , so we have to override our "equals()" in java .
No comments:
Post a Comment