1. Character type (2 bytes)
single quotation marks are used to denote character constants. For example ' A ' is a character, it is differentfrom ' A ', and' a ' represents a string containing a single character
Char types are used to represent characters in a Unicode encoded table
Unicode encoding is designed to handle all text in a variety of languages, it accounts for 2 bytes and can have 65536 characters;ASCII The code occupies 1 bytes and is allowed to have a number of characters, which is the Unicode encoding table of characters
Char Echar = ' a ';
Char CChar = ' medium ';
Unicode has encodings from 0 to 65535 , and they are usually used from ' \u0000 ' to ' \ The hexadecimal value between UFFFF ' is represented (the prefix is u for Unicode)
char c = ' \u0061;
The Java language also allows the use of the escape character ' \ ' to convert subsequent characters to other meanings,
char c2 = ' \ n '; represents a newline character.
Escape character |
Meaning |
Unicode Value |
\b |
BACKSPACE (backspace) |
\u0008 |
\ n |
Line break |
\u000a |
\ r |
Enter |
\u000d |
\ t |
tab (tab) |
\u0009 |
\“ |
Double quotes |
\u0022 |
\‘ |
Single quotation marks |
\u0027 |
\\ |
Back slash |
\u005c |
2.boolean type (one bit, not one byte)
The Boolean type has two values,true and false, and cannot be 0 or not 0 Integer instead of true and false , which differs from the C language.
Boolean types are used to determine logical conditions and are generally used for program flow control .
Boolean flag;
Flag = ....;
if (flag) {
True Branch
} else {
False Branch
}
3. Code to indicate :
Public classtestchartype{ Public Static voidMain (string[] agrs) {CharC1 = ' A '; CharC2 = ' Medium '; CharC3 = ' \ n '; SYSTEM.OUT.PRINTLN (C1); System.out.println (C2); System.out.println (C3); //character A is forced to convert to an ASCII value inti = c1 + 1; System.out.println (i); CharC4 = (Char) I; System.out.println (C4); //Cycle Print A-Z for(intj=0;j<26;j++){ Chartemp = (Char) (c1+j); System.out.print (temp); } System.out.print ("\ n");//line Break//Boolean type Booleanb =true ; if(b) {System.out.println ("Boolean type"); } }}
"Java" java_08 character and Boolean values