/*
Java char Example
This Java Example shows how to declare and use Java primitive char variable
inside a java class.
*/
public class JavaCharExample {
public static void main(String[] args) {
/*
* char is 16 bit type and used to represent Unicode characters.
* Range of char is 0 to 65,536.
*
* Declare char varibale as below
*
* char <variable name> = <default value>;
*
* here assigning default value is optional.
*/
char ch1 = 'a';
char ch2 = 65; /* ASCII code of 'A'*/
System.out.println("Value of char variable ch1 is :" + ch1);
System.out.println("Value of char variable ch2 is :" + ch2);
}
}
Value of char variable ch1 is :a
Value of char variable ch2 is :A
Press any key to continue . . .
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.