Why is the default char value not displayed on the console?

I wanted to know what would be displayed on the console when trying to print the chardefault value . But, unfortunately, I do not see anything on the console. What for?

I should be able to see 0to the right. Since the default value for the char variable is a null character, i.e. '\u0000'(its decimal equivalent is equal 0)? Correct me if I am wrong.

The code:

public class Index {
    static char c;
    public static void main(String[] args) {
        System.out.println("char default value is: "+Index.c);
    }
}

Output console:

enter image description here

+4
source share
3 answers

" 0", U + 0030... U + 0000, , . , 0.

-, :

System.out.println("a\u0009b");

, "a9b"? , U + 0008 , - "a" , .

+10

-, , - ASCII table. 128 , "a" "@", - .

"0" 48.

, Unicode, UTF-8, UTF-16 ..

, , .

, , , "\ u0000" 0.

UTF-8, , .

char zero = '0';
System.out.println(String.format("%d", (int)zero));
System.out.println(String.format("%04X", (int)zero));

, @TomBlodget

ISO-8859-1 . àäöòåééüùù , 127 , US-ASCII ( , ).

OEM437 ? , EGA VGA.

, UTF-8 US-ASCII, .

+4

char \u0000. , 0, : A 65.

static char c = 65;
System.out.println(c);

For your code, if you do System.out.println(c==0);, it will return true, as they are equivalent, as you mentioned.

+2
source

Source: https://habr.com/ru/post/1674256/


All Articles