Questions about the Java Character set encoding

Source: Internet
Author: User

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

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

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

The char type of C.java, which usually holds a character in the form of UTF-16 Big endian.

D. The most common means of achieving international application is to use the ResourceBundle class

Answer: CD

Analytical:

A is obviously wrong, Java is all Unicode encoded, and each character occupies 2 bytes in both Chinese and English characters. Java's class file is encoded as UTF-8, and the virtual machine JVM is encoded as UTF-16UTF-8 encoding, a Chinese account of 3 bytes, an English account of 1 byte B is also incorrect, different encodings can be converted, The usual process is to decompose the string s in its own encoding into a byte array, and then recode the byte array into a string in the encoding you want to output. Example: String newutf8str = new String (Oldgbkstr.getbytes ("GBK"), "UTF8"); C is correct. It is also correct to save a character D in a Java virtual machine, usually using the UTF-16 method. ResourceBundle is able to selectively read the properties file corresponding to the local suffix according to local, in order to achieve the internationalization goal. In summary, the answer is C and D.

Questions about the Java Character set encoding

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.