1
class CHar
{
    public static void main(String []l)
    {
        char j='\u0000';
        System.out.println("value of char j="+j);
    }
}

When I print the value of j then it prints nothing it means null value, but java dic says the default value of char is '\u0000' with which I agree, but the default value should be print. Instead of printing the default value it prints

C:\Users\Mohit-Pc\Desktop\Java Array>java CHar
value of char j=

That it is nothing means null. I'm still confused, whether I use instead of char default value, null then it generates an error:

CHar.java:5: error: incompatible types: cannot be converted to char char j=null;

demongolem
  • 9,474
  • 36
  • 90
  • 105
user7344668
  • 37
  • 2
  • 7

1 Answers1

4

A char with value 0 is the NUL character. It is a non-printing character and does not display as anything. Traditionally, C-style strings use a NUL character to mark the end of a string.

Note that the NUL character is different from the Java null. NUL is a primitive char value, while null is a reference value. The char type cannot hold a value of null, but an object type like java.lang.Character can.

If you want to print the numeric value of a char, cast it to int first.

Daniel Pryden
  • 59,486
  • 16
  • 97
  • 135