File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes == operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "== operator" Watch "== operator" New topic
Author

== operator

Gaurav Pavan Kumar Jain
Ranch Hand

Joined: Mar 19, 2007
Posts: 168
hi all

please let me know the functioning of == operator in refrence of object variable. Please specify example also
Qunfeng Wang
Ranch Hand

Joined: Jan 28, 2005
Posts: 433
The "==" operator is used to determine if two references refer to the same object when object variables concerned.


To be or not to be. It's a question.
Saket Barve
Ranch Hand

Joined: Dec 19, 2002
Posts: 229
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

Joined: Mar 19, 2007
Posts: 168
Thank you for your suggestion
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
By default equals() would also check for reference equality unless it is overridden.
sadasiva kumar
Ranch Hand

Joined: Oct 30, 2003
Posts: 91
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


SADASIVAKUMAR UTTI, SCJP1.4
A bend in the road is not the end of the road ... unless you fail to make the turn.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: == operator