Java Escape Sequences With Program Example

A character preceded by a backslash () is known as escape sequence. There are total 8 escape sequences in Java which have special meaning to the compiler. When we use an escape sequence in print statement then the compiler interpret it accordingly. All the escape sequences with program example is given below.

Java Escape Sequences With Program Example

Escape Sequence
Description
t
It will insert a tab in the text at this point.
b
It will insert a backspace in the text at this point.
n
It will insert a newline in the text at this point.
r
It will insert a carriage return in the text at this point.
f
It will insert a formfeed in the text at this point.
It will insert a single quote character in the text at this point.
It will insert a double quote character in the text at this point.
It will insert a backslash character in the text at this point.
class EscapeSequences
{
 public static void main(String...s)
 {
  System.out.print("tThe Crazy Programmer");
  System.out.print("nThe Crazy Programmer");
  System.out.print("nThe bCrazy Programmer");
  System.out.print("nThe Crazy Programmerr");
  System.out.print("'The Crazy Programmer'");
  System.out.print("n"The Crazy Programmer"");
  System.out.print("nfThe Crazy Programmer");
  System.out.print("nThe Crazy Programmer");
 }
}  

Java Escape Sequences With Program Example

2 thoughts on “Java Escape Sequences With Program Example”

  1. “very.(),:;[]\”.VERY.\”very@\ \”very\”.unusual”@strange.example.com

    I am using this string to validate an email address in a pattern.
    But i am getting error due to some invalid escape sequence.
    Could you please help on how to put the correct escape sequence for the above string in order to be valid.

Leave a Comment

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