what's the default value of char?

char c = '\u0000';

When I print c, it shows 'a' in the command line window.

So what's the default value of a char type field?

Someone said '\u0000' means null in unicode; is that right?


The default value of a char attribute is indeed '\u0000' (the null character) as stated in the Java Language Specification, section §4.12.5 Initial Values of Variables .

In my system, the line System.out.println('\u0000'); prints a little square, meaning that it's not a printable character - as expected.


'\u0000' is the default value for a character. Its decimal equivalent is 0.

When you are declaring some char variable without initializing it, '\u0000' will be assigned to it by default.

see this code

public class Test {
    char c;

    public static void main(String args[]) throws Exception {
        Test t = new Test();
        char c1 = '\u0000';
        System.out.println(t.c);
        System.out.println(c1);
        System.out.println(t.c == c1);
    }
}

This code will print true for the last print.


Default value of Character is Character.MIN_VALUE which internally represented as MIN_VALUE = '\u0000'

Additionally, you can check if the character field contains default value as

Character DEFAULT_CHAR = new Character(Character.MIN_VALUE);
if (DEFAULT_CHAR.compareTo((Character) value) == 0)
{

}