What is the character set (Charset)
- A character set is a collection of characters. Generally contains the characters of a language. For example, GBK character set that contains all the commonly used Chinese characters. ASCII is a character set contains English characters.
- Java is a character in the char, char is the character shorthand.
What is the encoding (Encoding)
- char represents a character, char is digital in nature. The digital maps to character, called encoding.
- Map one character set to digital, it is to give this character set encoding. Is a standard coding, all computer systems perform in accordance with a coding standard.
- Sometimes coded character sets and mix.
Common character sets Introduction
- ASCII code, ASCII table: https://baike.baidu.com/item/ASCII/309296#3
- Unicode includes all commonly used characters in the world, there are several coding, including UTF-8 (8-bit Unicode Transformation Format), UTF-16 and the like.
- Unicode, GBK and all common character sets, will be compatible with ASCII. For example, the character A in all of these conventional character set, the corresponding figures are 65.
public class ComplexChar { public static void main(String[] args) { int a = 65; char cha = (char) a; char hhh = '\u4239'; System.out.println(cha); System.out.println(hhh); } }
Java set of characters
- Java is used in the UTF-16 encoded Unicode.
- UTF-16 with a 16 bit, i.e., 2 byte, which is the reason the two byte char account. When the char into digital time, needed int.
ASCII code, and the escape character (escape character)
- How to output special characters:
- ASCII code + char, may need to find the corresponding digital character by ASCII table. This number is converted to char, and then outputs the char.
- Escapes. Escape character is used to assign, which may be used in a string as a character string.
- Escape syntax and common escape character:
- \ N newline character (new line)
- \ T Tab
- \" Double quotes
- \ UXXXX unicode character encoding corresponding
public class ComplexCharInString { public static void main(String[] args) { // \t制表符 \"双引号 \n换行(new line) String content = "a\tb\"\tc\n\td\t"; String align = "1111222233334444"; System.out.println(content); System.out.println(align); } }
String "addition"
- The variable string is inserted in the output
- And adding strings may be any type, it will be the value of the character spliced to the string;
- Strings can also be used + = operator to splice;
- String addition operator compliance additive operators own priority.
- The basic data types string is not in Java
- The name is a string type String ;
- Although the basic data type String is not Java, but also can use a similar syntax: String str = "abc"; to create. Initially it as a basic type, easier to understand.
- String is not a reserved word in Java.
- String addition does not change the value of the original String variable, use an assignment change its value
public class StringConcat { public static void main (String [] args) { int String = 999; // String not the basic data types, nor keywords and reserved words. But you can use a similar syntax. System.out.println (String); String zifuchuang = "String declaration string!" ; System.out.println (zifuchuang); int A = 10 ; int B = 20 is ; int C = A + B; the System. Out.println ( "A + B =" + C); Boolean aBiggerThanB = A> B; System.out.println ("a> b is" + aBiggerThanB + "a." ); System.out.println ( "B + a =" + a + B); // here will be a first character string and the foregoing are connected. System.out.println ( "A + B =" + (A + B)); System.out.println ( "* B = A" + A * B); } }
public class the stringvariable { public static void main (String [] args) { // Although the basic data type String is not Java, but also can use a similar syntax: String str = "abc"; to create. int a = 10 ; String str = "is a value" ; str = str + a; // assignment changes the value of str. System.out.println (STR); String s2 = "is a value" ; System.out.println (s2 + a); // adder itself does not change the value of s2. System.out.println (S2); } }