Java char Data Type

Char Data Type ?

Character data type is used for storing character in a variable(char type). Keyword used for character data type is char.

Char data type :

Characters typically requires 1 byte of memory space and ranges from -128 to 127 or 0 to 255. char ch = 'A';

java offers a predefined data type that is one byte in size, which can hold exatly one character such as ‘a’ or ‘A’. To declare a variable of type char.

     char myword[] = { 'e','C','O','D','I',N','G', 'S','c','H','O','O','L','\0' };
    char myword[] = "aimtocode"; 

Example 1:

Output :

ch1 and ch2: X Y!

Example 2:

Output :

Press any key to continue . . .

Example 3:

Output :

character1 and character2: R S
Press any key to continue . . .