Escape Sequence

  • April 27, 2022
  • Java
method overloading and method overriding

Java allows us to have certain non-graphic characters in character constants. (non-graphic characters are those which cannot be typed directly from the keyboard, e.g, backspace, tabs, carriage return, etc.). These characters are represented with the use of an escape sequence, which is represented by a backslash(\) followed by one or more characters.

The following table gives a listing of escape sequences:

Escape CharactersDescription
\t to insert a tab in the text at this point.
\’ to insert a single quote character in the text at this point.
\” to insert a double quote character in the text at this point.
\r to insert a carriage return in the text at this point.
\\to insert a backslash character in the text at this point.
\nto insert a new line in the text at this point.
\fto insert a form feed in the text at this point.
\b to insert a backspace in the text at this point.
Example:
class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, world!\r\"Coderzpy\" "); 
    }
}
Output:
Hello, world!
"Coderzpy" 

Note: also read about the Literals in Java

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Leave a Reply

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