Java char value escape

Description

The escape sequences are used to enter impossible-to-enter-directly characters.

Syntax

'\'' is for the single-quote character. '\n' is for the newline character.

Example

For octal notation, use the backslash followed by the three-digit number. For example, '\141' is the letter 'a'.

For hexadecimal, you enter a backslash-u (\u), then exactly four hexadecimal digits. For example, '\u0061' is the ISO-Latin-1 'a' because the top byte is zero. '\ua432' is a Japanese Katakana character.


public class Main {
  public static void main(String[] argv) {
    char ch = '\'';
/*  www. j  a  v a2s . c  o m*/
    System.out.println("ch is " + ch);//ch is '

  }
}

Character is a simple wrapper around a char.

The code above generates the following result.

Escape value list

The following table shows the character escape sequences.

Escape SequenceDescription
\dddOctal character (ddd)
\uxxxxHexadecimal Unicode character (xxxx)
\'Single quote
\"Double quote
\\Backslash
\rCarriage return
\nNew line
\fForm feed
\tTab
\bBackspace




















Home »
  Java Tutorial »
    Java Language »




Java Data Type, Operator
Java Statement
Java Class
Java Array
Java Exception Handling
Java Annotations
Java Generics
Java Data Structures