• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

== operator

 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all

please let me know the functioning of == operator in refrence of object variable. Please specify example also
 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "==" operator is used to determine if two references refer to the same object when object variables concerned.
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The == operator will check for reference equality whereas the .equals method will compare the actual values.

In the following code, "Different Reference" will be printed out.



Here's a good link.
 
Gaurav Pavan Kumar Jain
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your suggestion
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By default equals() would also check for reference equality unless it is overridden.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use == operator to compare two primitives,or to see if two references refer to the same object.
Remember ,the == operator cares only about the pattern of bits in the variable.The rules are the same whether the variable is a reference or primitive.

Example : (1) Comparing two primitives

int a = 9;
byte b = 9;
if( a == b) { // true }

(2) Comparing two references

Zoom a = new Zoom();
Zoom b = new Zoom();
Zoom c = a;
if(a == b) { // false }
if(a == c) { // true }
if(b == c) { // false }

regards
SADASIVAKUMAR UTTI
SCJP1.4
 
reply
    Bookmark Topic Watch Topic
  • New Topic