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

Similar Programs Chapter Last Updated
Java String Example Program Data Types 19-06-2016
Primitive Datatypes In Java Example Data Types 17-06-2016
Enum In Java Example Data Types 28-04-2016
Java Short Example Program Data Types 10-06-2016
Java Long Example Program Data Types 15-07-2016
Java Int Example Program Data Types 06-07-2016
Int Array In Java Example Program Data Types 09-06-2016
Java Float Program Example Data Types 28-03-2017
Java Double Example Program Data Types 28-03-2017
Java Byte Example Program Data Types 28-03-2017
Java Boolean Example Program Data Types 28-03-2017

1