Java char keywordThe Java char keyword is a primitive data type. It is used to declare the character-type variables and methods. It is capable of holding the unsigned 16-bit Unicode characters. Points to remember
Why char uses 2 bytes in java?It is because Java uses Unicode system not ASCII code system. What is \u0000 ?The \u0000 is the lowest range of the Unicode system. Examples of Java char keywordExample 1Let's see a simple example of displaying characters. Output: char1: a char2: A Example 2In this example, we provide integer value to char variable. Here, compiler implicitly typecast integer to char and display the corresponding ASCII value. Output: char1: A char2: a Example 3In this example, we typecast the integer value to char explicitly. Output: char1: a char2: A Example 4Let's see an example to represent the char value in Unicode System. Output: char1: a char2: A Example 5In this example, we increment the provided char value by 1. Output: char: B Example 6Let's see an example to break the string in the form of characters. Output: String: javatpoint char: [j, a, v, a, t, p, o, i, n, t] Example 7Let's see an example to invoke the method of the char return type. Output: a
Next TopicJava Keywords
|