Question about Java character set encoding

In the Java language, which of the following questions about character set encoding (Character set encoding) and internationalization (i18n) are correct?

  A. Each Chinese character occupies 2 bytes, and each English character occupies 1 byte

  B. Assuming that the characters in the database are GBK-encoded, then the web page that displays the database data must also be GBK-encoded.

  C. Java's char type, usually saves a character in UTF-16 Big Endian.

  D. The common method to realize international application is to use the ResourceBundle class

Answer: CD

Parse:

A is obviously wrong. Java always uses Unicode encoding, and each character, whether Chinese or English, occupies 2 bytes.
Java's class file is encoded as UTF-8, while the virtual machine JVM is encoded as UTF-16
Under UTF-8 encoding, one Chinese occupies 3 bytes, and one English occupies 1 byte
B is also incorrect. It can be converted between different encodings. The usual process is as follows:
Decompose the string S into a byte array in its own encoding, and re-encode the byte array into a string in the encoding you want to output.
例:String newUTF8Str = new String(oldGBKStr.getBytes("GBK"), "UTF8");
C is correct. A character is usually stored in UTF-16 in the Java virtual machine
D is also correct. ResourceBundle can selectively read the properties file with the suffix corresponding to Local according to the difference of Local, in order to achieve the purpose of internationalization.
 
To sum up, the answers are C and D.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325106374&siteId=291194637