Java Char Example Program
Chapter:
Data Types
Last Updated:
28-03-2017 17:34:24 UTC
Program:
/* ............... START ............... */
public class JavaCharExample {
public static void main(String[] args) {
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);
}
}
/* ............... END ............... */
Output
Value of char variable ch1 is :a
Value of char variable ch2 is :A
Notes:
-
char is 16 bit type and used to represent Unicode characters.
- Range of char is 0 to 65,536.
- char <variable name> = <default value>;
- Java provides wrapper class Character for primitive data type char.
- The Character class offers different methods for manipulating characters.
- The Character class offers a number of useful class (i.e., static) methods for manipulating characters.
Tags
Java, Char