Loading...
Java

Char Literals

  1. A char literal can be represented as single character with single quotes.
    Example:
    1. char c=’a’; //(valid)
    2. char c=”a”; //(invalid)
    3. char c=a; //(invalid)
    4. char c=’abc’; //(invalid)
  2. Char literal can also be specified as integral literal. It represents Unicode of that character.
    Integral literals can specify either in decimal or octal or hexa decimal but allowed values range is 65535.
    Example:
    1. char c=54; //(valid)
    2. char c=65534; //(valid)
    3. char c=65536; //(invalid)
  3. Char literal can represent by Unicode representation which is nothing but ‘\uxxxx’ (4 digit hexa decimal number).
Escape CharacterDescription
\nNew Line
\tHorizontal
\rCarriage Return
\f Form Feed
\bBack Space Character
\’Single Quote
\”Double Quote
\\Back Space
Leave a Reply

Your email address will not be published. Required fields are marked *