Java Articles

Submit Article
Home » Articles » Java » FundamentalRSS Feeds

Backslash Codes

Posted By: Carolyn Perez     Category: Java     Views: 93383

This article explains about Backslash codes available in java with examples.

Backslash codes are characters that cannot be entered from the keyboard and are nonprinting characters. It can be used anywhere you can use a normal character. It is also referred to as escape sequences

The single most important backslash code is \n. It is also referred to as a newline character

Note that the backslash codes are character constants. To assign backslash character to a character variable, you must enclose it within single quotes.

Example of Assigning backslash code to a character variable

char = ch;
ch = '\''; 

Below are the Backslash Codes available in java.

 Backslash Code



tab character ('\u0009') 


new line or line feed character ('\u000A') 


carriage-return character ('\u000D') 


form-feed character ('\u000C') 


alert or bell character ('\u0007') 


escape character ('\u001B') 


control character corresponding to x 


backslash character 


character with octal value 0n (0 <= n <= 7) 


character with octal value 0nn (0 <= n <= 7) 


character with octal value 0mnn (0 <= m <= 3, 0 <= n <= 7) 


character with hexadecimal value 0xhh 


character with hexadecimal value 0xhhhh 

Examples of Backslash Codes

Example 1 : Program that displays use of tab character 

class TabCharDemo
  public static void main(String args[])
System.out.println("Program of \t - " + \t + "character.");


Program of \t -  character.

Example 2 : Program that displays use of newline character 

class NewLineCharDemo
  public static void main(String args[])
System.out.print("This is first line.\n");
System.out.print("This is second line.");
System.out.print("This is third line.");


This is first line.
This is second line.This is third line.


Didn't find what you were looking for? Find more on Backslash Codes Or get search suggestion and latest updates.

Carolyn Perez
Carolyn Perez author of Backslash Codes is from Hartford, United States.
View All Articles

Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

No Comment Found, Be the First to post comment!