Character Literals in Java Programming
Previous | Home | Next |
A character literal is expressed as a character or an escape sequence, enclosed in ASCII single quotes.
A character literal is always of type char.
Character literals are constant valued character expressions embedded in a Java program. Java characters are sixteen bit Unicode characters, ranging from 0 to 65535.
Character literals are expressed in Java as a single quote, the character, and a closing single quote.
e.g '$'
'p'
'9'
Character literals have the type char, an unsigned integer primitive type. Character literals may be safely promoted to larger integer types such as int and long.
Character literals used where a short or byte is called for must be cast to short or byte since truncation may occur.
int one = '1';
int zero = '0';
System.out.println("120? " + one + '2' + zero );
System.out.println("1002? " + 100 + '2' + 0 );
Previous | Home | Next |