Understanding char data type – Computer Sir Ki Class


Lost your password?

Don't have an account ?
Register (It's FREE) ×


Code Learning #JAVA#3848    siteicon   siteicon  

Understanding char data type

The java char data type and its possible values are explained here.

Learning Objectives

  • Declaration and initialisation of char type with different possible values.

Source Code

TC++ #3848

Source Code

Run Output


Code Understanding

char a=0;
Java allows to store the 0 value (null value) also in character type. It doesn’t have special significance is in C/C++.

char b=10;
The non-displayable character values like integer value for control character newline (LF) can also be directly stored.

char c=33;
This is the first displayable ascii character after space which is the character !

char d=65;
This is first uppercase alphabet the decimal value for A.

char e=126;
This is the last 7-bit ascii displayable character ~ .

char f=255;
This is the largest 8 bit character which will be displayed as per the output device capability.

char g=65535;
This is the largest character value to be stored. This will not display anything with normal print commands unless we define proper encoding etc.

char h=’a’;
This is the usual single quote based initialisation of character

char i=’u03C0′;
This is unicode style initialisation. The current case has been shown for character (pi) .


  • char data type in java is unique in terms of having only positive values as against the short integer type data which is also 16 bit but it can have both positive and negative values.

Suggested Filename(s): CharType.java


sunmitra| Created: 19-Mar-2018 | Updated: 19-Mar-2018|