411 REFERENCE · Wikibooks
Java Programming/Keywords/char
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
is a keyword. It defines a character primitive type. can be created from character literals and numeric representation. Character literals consist of a single quote character (') (ASCII 39, hex 0x27), a single character, and a close quote ('), such as 'w'. Instead of a character, you can also use unicode escape sequences, but there must be exactly one.
Syntax:
char variable name1 = 'character1';
Code section 1: Three examples.
char oneChar1 = 'A';
char oneChar2 = 65;
char oneChar3 = '\u0041';
System.out.println(oneChar1);
System.out.println(oneChar2);
System.out.println(oneChar3);Output for Code section 1
A
A
A
65 is the numeric representation of character 'A' , or its ASCII code.
The nominal wrapper class is the java.lang.Character class when you need to store a value but an object reference is required.
Code section 2: wrapping.
char aCharPrimitiveType = 'A';
Character aCharacterObject = aCharPrimitiveType;
See also:
Java Programming/Primitive Types
deep