在实际编程中可以不用关注JVM中使用的是什么编码,而只需要关注自己输出需要采用的编码,JVM会根据你设置的编码正确操作。
1、String采用的是什么编码?
很多厂家根据规范实现了JVM,JVM只说明了String应该符合Unicode编码。Unicode编码只是一种编码模型,utf8,utf16,utf32都属于Unicode模型
,具体的信息参阅http://www.cnblogs.com/YDDMAX/p/5360709.html
2、为什么JAVA中Char是两个字节?
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.
时间: 2024-10-06 01:25:09