首页 > 编程语言 > 详细

Java Primitives and Bits

时间:2017-04-20 19:40:04      阅读:235      评论:0      收藏:0      [点我收藏+]

技术分享

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.

 

Java Primitives and Bits

原文:http://www.cnblogs.com/codingforum/p/6740260.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!