Boolean and Char Data Type in Java
In this class, We discuss Boolean and Char Data Type in Java.
The reader should know about integer and floating point data types in java. Click Here.
Boolean:
The boolean data type will take only two values. True or false.
boolean a = true;
The variable a is taking the true value.
Character:
The character data type is used to store a character.
Example:
char b =’A’;
b is a variable of type character.
The variable b will hold a character in upper case A.
We use single quotes to represent characters in java.
The character data type will take 2 bytes of memory.
Computers are capable of storing binary digits.
To store a character, we need to convert the character to binary.
Each character should assign a unique number.
We need a standard for the conversion of characters.
Java uses 16-bit Unicode characters.
List of 16-bit Unicode characters: Click Here
The upper case A is given a decimal value of 65.
The above link shows in hexa decimal value.
The hexa decimal value for upper case A is 0041.
If we convert the hexadecimal 0041 to decimal, we get 65.
The below program shows the example to display the value 65 to upper case A.
char x = ‘A’;
int b = (int)x;
System.out.println(b)
Output: 65