標籤:mos sign flow fit tac 關注 was its and
在實際編程中可以不用關注JVM中使用的是什麼編碼,而只需要關注自己輸出需要採用的編碼,JVM會根據你設定的編碼正確操作。
1、String採用的是什麼編碼?
很多廠家根據規範實現了JVM,JVM只說明了String應該符合Unicode編碼。Unicode編碼只是一種編碼模型,utf8,utf16,utf32都屬於Unicode模型
,具體的資訊參閱http://www.cnblogs.com/YDDMAX/p/5360709.html
2、為什麼JAVA中Char是兩個位元組?
參閱http://stackoverflow.com/questions/3956734/why-does-the-java-char-primitive-take-up-2-bytes-of-memory
When Java was originally designed, it was anticipated that any Unicode character would fit in 2 bytes (16 bits), so char and Character were designed accordingly. In fact, a Unicode character can now require up to 4 bytes. Thus, UTF-16, the internal Java encoding, requires supplementary characters use 2 code units. Characters in the Basic Multilingual Plane (the most common ones) still use 1. A Java char is used for each code unit. This Sun article explains it well.
JAVA中的編碼分析