"=" : is an assignment operator. Everyone got that right.
"==" : is a comparison operator. Everyone got that partly right. If the value types being compared are primitive types (like type int), then the values compared are the actual values assigned to the primitive variables. But if the value types being compared are reference types (objects, arrays, etc.), then the value compared is the value stored by the variable, which is the *reference* to the object, not the actual object data!
Examples using reference types:
Point x, y;
x = new Point(1, 0);
y = new Point(1, 0);
/* both x and y have equivalent object data values (state), but x's value is a reference (relates to a pointer held by the JVM) that refers to an object that is different than the reference held by y. */
System.out.println(x == y); //prints "false"!
//now compare equivalent *references*
y = x; //now y "points" to same object assigned to x
System.out.println(x == y);//prints "true"
2007-03-08 04:38:43
·
answer #1
·
answered by vincentgl 5
·
0⤊
0⤋
in all risk the main important distinction between the two is how the languages, while compiled, are dealt with by ability of the CPU. Java is an 'interpreted' language. extremely, what this implies is that once a Java software is ran it runs off of a "digital gadget." This digital gadget application must be on the laptop for this device to paintings. this could appear like a shy away, yet by way of fact the Java software is often working off the comparable 'digital gadget,' the comparable software must be ported onto the different platform or OS with out any replaced to the code. C++, on the different hand, can't be as actual be ported over onto distinctive structures. in spite of if, a self-sustained C++ software, while compiled will paintings on the laptop with out any extra application. additionally, in view that C++ courses do no longer require any type of digital gadget, the courses tend to load plenty swifter than a Java software. some people have self belief C++ courses are 'swifter' than Java, yet i think of the jury continues to be out on that one.
2016-12-14 12:38:58
·
answer #2
·
answered by ? 4
·
0⤊
0⤋
an easy explanation would be...
= (equal sign) is an assignment operator where you assign a value to a given operand. example a = b, where the value of 'b' is assigned to 'a'. If b has a value of 1 then a also has a value of 1.
== (double equal sign) is a comparison operator where it would always return "true" if the two values being compared are the same and false if they are not. example would be 'a == b' is true only if a = 1 and b = 1.
2007-03-06 11:10:21
·
answer #3
·
answered by DropZite 3
·
0⤊
0⤋
starwarsdude tells the truth.
== is used for a test, and will return a true (1) or false (0) dependent on whether the values are in fact equal.
"a == b" is checking if a is equal to b. if a is NOT equal to b, this will return a 0. otherwise, it will return a 1. The 0 and 1 are not used as numerical values so much as binary true/false.
2007-03-06 11:09:12
·
answer #4
·
answered by winterbourne_nova 2
·
0⤊
0⤋
= is for assigning a value
int a = 4;
== is for comparing
if(a==4){
2007-03-06 11:04:38
·
answer #5
·
answered by Anonymous
·
0⤊
1⤋
How about the new one ===, which is exactly equivalent to.
2007-03-06 16:40:38
·
answer #6
·
answered by Anonymous
·
0⤊
0⤋