char

It's a 16-bit Unicode character. The minimum value of the char data type is $'\symbol{92}u0000'$ (0). The maximum value of the char data type is $'\symbol{92}uffff'$. Default value is $'\symbol{92}u0000'$.


\begin{lstlisting}
class CharExample {
public static void main(String[] args) {
\par
char letter = '\u0051';
System.out.println(letter);
}
}
\end{lstlisting}

You get the output Q because the Unicode value of Q is $'\symbol{92}u0051'$. Here is another example:


\begin{lstlisting}
class CharExample {
public static void main(String[] args) {...
...
\par
char letter2 = 65;
System.out.println(letter2);
\par
}
}
\end{lstlisting}

When you print $\lstinline{letter1}$, you will get 9 because $\lstinline{letter1}$ is assigned character '9'. When you print $\lstinline{letter2}$, you get A because the ASCII value of 'A' is 65. It's because java compiler treats the character as an integral type.