在Java中对丙字符大小 [英] Character size in Java vs. C

查看:80
本文介绍了在Java中对丙字符大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在Java中的角色需要两倍的空间来存储在C字符?

Why does a character in Java take twice as much space to store as a character in C?

推荐答案

在Java的字符是16位和C,他们是8位。

In Java characters are 16-bit and C they are 8-bit.

一个更普遍的问题是,为什么会这样呢?

A more general question is why is this so?

要找出原因,你需要看的历史并得出结论/ 的意见的主题。

To find out why you need to look at history and come to conclusions/opinions on the subject.

当C在美国的开发,ASCII是pretty标准那里,你只有真正需要的7位,但与8,你可以处理一些非ASCII字符也是如此。这似乎绰绰有余。许多基于文本的协议如SMTP(电子邮件),XML和FIX,仍然只使用ASCII字符。电子邮件和XML连接code非ASCII字符。二进制文件,插座和流仍然只有8位字节本地人。

When C was developed in the USA, ASCII was pretty standard there and you only really needed 7-bits, but with 8 you could handle some non-ASCII characters as well. It might seem more than enough. Many text based protocols like SMTP (email), XML and FIX, still only use ASCII character. Email and XML encode non ASCII characters. Binary files, sockets and stream are still only 8-bit byte native.

BTW:C可以支持更广泛的字符,但不是普通的字符

BTW: C can support wider characters, but that is not plain char

在的Java开发16位似乎足以支持大多数语言。自此UNI code一直延伸到上面的字符65535和Java不得不增加对codepoints这是UTF-16字符,可以是一个或两个16位字符的支持。

When Java was developed 16-bit seemed like enough to support most languages. Since then unicode has been extended to characters above 65535 and Java has had to add support for codepoints which is UTF-16 characters and can be one or two 16-bit characters.

所以制作字节字节和字符在当时是有道理的一个无符号16位值。

So making a byte a byte and char an unsigned 16-bit value made sense at the time.

BTW:如果您的JVM支持 -XX:+ UseCom pressedStrings 它可以使用的字节字符代替弦乐仅使用8位字符

BTW: If your JVM supports -XX:+UseCompressedStrings it can use bytes instead of chars for Strings which only use 8-bit characters.

这篇关于在Java中对丙字符大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆