Java and Endian-ness (was Re: PPC or i386 ?)

Duke Robillard yellowdog-general@lists.terrasoftsolutions.com
Wed Mar 10 12:40:02 2004


From: Clinton MacDonald <clint.macdonald@sbcglobal.net>
Geert Janssens wrote:

 >> On a sidenote, I don't know Java enough to say whether or not endian
 >> issues can still arise when writing java programs. I assume that these
 >> issues should be dealt with in the runtime library for each specific
 >> platform, and thus neither programmer, nor user should be concerned.

 >Though I am largely ignorant, I believe that Java programs are written
 >for what is termed a "virtual machine." As such, the virtual machine is
 >coded to appear to be identical on all platforms (though Microsoft has
 >tried to work around that with their extensions to Java). Therefore, I
 >assume the "endianess" taken into account.

The JVM (Java Virtual Machine) is big-endian.  So, binary data created
by a JVM somewhere will be big-endian, no matter what machine the JVM
was running on.  A JVM running on a PPC can read binary data created
by a JVM running on an x86.  In that sense, Java handles the problem.

However, if you've got a Java program that wants to read binary data
created by a C program, you've still got the old "endian" worries.

I expected to find a class in the Java IO streams stuff to convert
little endian data into Java compatible big endian, but I didn't.
It's pretty easy to write, but I'm surpised it's not in Sun's java.io.*
package.

Duke