Integer
when processors were 16 bit, an int was 2 bytes. Nowadays, it‘s most often 4 bytes on a 32 bits system or 8 bytes on 64 bits system.
Character
- An ASCII character in 8-bit ASCII encoding is 8 bits (1 byte), though it can fit in 7 bits.
- An ISO-8895-1 character in ISO-8859-1 encoding is 8 bits (1 byte).
- A Unicode character in UTF-8 encoding is between 8 bits (1 byte) and 32 bits (4 bytes).
Java uses unicode system. Character in the java class file is encoded with UTF-8 while running in JVM is encoded with UTF-16.
Long & Double
Writing longs and doubles is not atomic in Java.
It‘s not atomic because it‘s a multiple-step operation at the machine code level. That is, longs and doubles are longer than the processor‘s word length. doubles and longs are not read or written to atomically unless they‘re declared volatile.
Java‘s primitive types are guaranteed to be a particular length across all machines. On some 64 bits JVMs nowadays, the operations of longs and doubles are effectively atomic.
时间: 2024-11-11 15:15:48