Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the default value of char?

Tags:

java

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?

like image 864
user1298336 Avatar asked Mar 28 '12 14:03

user1298336


People also ask

What is default value of char in C?

The default value of Char is the character with a code point of 0.

What is the default value of char and Boolean?

Default value is false . Can be a Boolean object representing true or false , or can be null . Default value is null .

What is the null value for char?

The null character (also null terminator) is a control character with the value zero. It is present in many character sets, including those defined by the Baudot and ITA2 codes, ISO/IEC 646 (or ASCII), the C0 control code, the Universal Coded Character Set (or Unicode), and EBCDIC.


1 Answers

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.

like image 105
Óscar López Avatar answered Sep 21 '22 08:09

Óscar López