juLY 2008 | LINuX For You | www.
openITis.
com12
S.
G.
GaneSh
The Joy of
Programming
L
ast month, we introduced a problem in Java: given
two integers i and j, the following statement does
not swap the values of two variables correctly i ^=
(j ^= (i ^=...
More
juLY 2008 | LINuX For You | www.
openITis.
com12
S.
G.
GaneSh
The Joy of
Programming
L
ast month, we introduced a problem in Java: given
two integers i and j, the following statement does
not swap the values of two variables correctly i ^=
(j ^= (i ^= j)).
To understand what is happening, let us analyse the
byte code generated for this statement.
How do we get
the byte codes? By using the javap tool on the generated
class file, which will be available in the same directory as
javac (in the bin directory).
javap is a Java dis-assembler
tool that reads the Java class files and dumps the info in
a human-readable form.
First issue the command, javac
Swap.
java and then javap -c Swap; you’ll get the detailed
output with byte codes.
From this output, here is the sequence of byte codes
generated for the statement i ^= (j ^= (i ^= j)):
39: iload_1
40: iload_2
41: iload_1
42: iload_2
43: ixor
44: dup
45: istore_1
46: ixor
47: dup
48: istore_2
49: ixor
50: istore_1
Here is a quick intro on
Less