2

Is java char big endian in JVM memory [stack/heap]? That is is it UTF-16 LE or UTF-16 BE?

I think It really shouldn't matter that much and it is upto JVM implementation and keeps the native chip order for perf. reasons. That is LE for intel etc. Is that correct?

Or is it specified in Java spec. itself?

4

4 に答える 4

7

The class file format specifies that all items must be in big-endian. http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html

I haven't checked but I suspect JNI spec also talks about the endian-ness and I suspect it is in big-endian.

于 2012-12-29T00:28:06.327 に答える
2

Java, the language, is endianness-agnostic. (The JVM implementation probably uses the hardware endianness.)

Varying ways of converting characters to a byte sequence have fixed endiannesses, though, e.g. DataOutputStream.

于 2012-07-26T09:29:49.113 に答える
0

It's not specified by the VM spec and is up to the VM how to handle it.

And since there's no direct way to re-interpret char as two byte values you can't even see the result of the decision from a Java program (any Java application will act exactly the same on a conforming VM, independent of the endianness of the VM).

于 2012-07-26T09:29:02.393 に答える
0

A single char is either little-endian or big-endian based on your processor's hardware. Most Intel/AMD/ARM processors use little-endian and Sparc/Alpha use big-endian.

The UTF-16 encoding is how Java stores codepoints (characters up to 0x1FFFF) in Strings. The UTF-16LE encoding refers to how such a string can be written to a file.

于 2012-07-26T09:29:47.460 に答える