Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: How does the == operator work when comparing int?

Tags:

java

Given this Java code:

int fst = 5;
int snd = 6;

if(fst == snd)
    do something;

I want to know how Java will compare equality for this case. Will it use an XOR operation to check equality?

like image 299
Arpssss Avatar asked Jul 13 '12 21:07

Arpssss


1 Answers

Are you asking "what native machine code does this turn into?"? If so, the answer is "implementation-depdendent".

However, if you want to know what JVM bytecode is used, just take a look at the resulting .class file (use e.g. javap to disassemble it).

like image 60
Oliver Charlesworth Avatar answered Sep 29 '22 00:09

Oliver Charlesworth