BENDU_APPARAO Posted February 9, 2012 Report Posted February 9, 2012 difference between == and equals() first do not confuse with [b]= (assignment operator) [/b] and [b]== (comparison operator)[/b] [u][b]== operator[/b][/u] Java lo eppudinaa object ni create chesthy (using new operator or class.forname ila ) ... java aa object ni JAVA HEAP meomory lo create chesthadi .... aa memory ni access chesyadaniki manaki oka reference isthudni [b]Employee solluEmployee = new Employee();[/b] ikkada new Employee() ki heap memory lo space create ayyi dhaniki oka reference create ayyi adi solluEmployee anee reference lo store avuthundi (reference is always left side of =) now == antee adi reference of the objects are pointing to same object in heap memory ani check chesthundi ....... now if I say [b]Employee[/b] [b]wasteEmployee = solluEmployee ; (pointing to old object) ... and if(solluEmployee == wasteEmployee) this is true......[/b] now if I say [b]Employee[/b] [b]wasteEmployee = new Employee(); (kotha object creating)[/b][b]... and if(solluEmployee == wasteEmployee) this is false......[/b] [u][b]equals() method....[/b][/u] equals() method anedhi Super class Object class lo untundi so by default anni classes ki vosthudi (Y it is in Object class???) .... idhi chala simple content of the object check chesthundi ......(general ga manam override cheyali to check our objects are equal) ...... so ikkada oka employee id [b]1001[/b] anukooo now if I am comparing this employee object with another employee object to see both object are related to same employeee ...... now i can say [b]employee.id.equals(anotheremployee.id); [/b] Quote
arrehman Posted February 10, 2012 Report Posted February 10, 2012 mostly andhariki == and equals gurinchi thelisuntadi.. = gurinchi baaga explain chesav.. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.