karthikbalaguru said:
Is 'Java Virtual Machine' Big-Endian ?
Or
Is it independent of Endianness ? (That is Bi-Endian)
There are already lots of answers, and I will add one,
that would let you find out the endianess of your
particular JVM, but it takes some java bytecode
knowledge:
Write a java program that defines an integer variable,
with value 0xaabbccdd, and assign it (with cast) to
a short and a byte variable, which you have written
out to System.out.
Then you compile it, and it would write (always, inde-
pendent on endianess) the values for 0xccdd and 0xdd.
Now comes the tricky part:
in the bytecode there exist instructions to convert the
intvalue to a byte/short-value, and you'd have to modify
the class file(*) to do some noop's instead of these
converting instructions. after that you run the code
again, and see if the result has changed.
I haven't tried it myself, but my prediction is, that
on little-endian platform the result would stay the same,
whereas on big-endian platforms it would change to 0xaabb
and 0xaa.
(*) with help of sun's "javap" (to check the results)
you could try+error your way there, or you could
use some disassembler (not a decompiler!) and
assembler.