3.3.4. Character Literals

A character literal is quoted in single-quotes ('). All character literals have the primitive data type char.

See the below table for examples of character literals in Java.

			package javatutorial;

			/**
			 * Example usage of Character literals
			 * 
			 * @author f5java.com 
			 */
			public class CharacterLiterals {

				public static void main(String[] args) {
					
					char charType = 'c';
					char charType1 = 'C';
					char charType2 = '1';
					char charType3 = '$';
					char charType4 = '+';
			//		char charType5 = 'AB'; // Invalid values, compiler wont allow 
			//		char charType5 = '-1'; // Invalid values, compiler wont allow
					
					// Print the values
					System.out.println("Valid char value : " + charType);
					System.out.println("Valid char value : " + charType1);
					System.out.println("Valid char value : " + charType2);
					System.out.println("Valid char value : " + charType3);
					System.out.println("Valid char value : " + charType4);

				}

			}