Escape sequences in Java

Java 8Object Oriented ProgrammingProgramming

A character preceded by a backslash (\) is an escape sequence and has a special meaning to the compiler.

The following table shows the Java escape sequences.

Escape SequenceDescription
\tInserts a tab in the text at this point.
\bInserts a backspace in the text at this point.
\nInserts a newline in the text at this point.
\rInserts a carriage return in the text at this point.
\fInserts a form feed in the text at this point.
\'Inserts a single quote character in the text at this point.
\"Inserts a double quote character in the text at this point.
\\Inserts a backslash character in the text at this point.

Let us see an example of Character Escape Sequences in Java.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      char ch = '\u039A';
      System.out.println(ch);
   }
}

Output

K
raja
Published on 17-Dec-2018 14:11:55
Advertisements