An important aspect of the Java programming language is the Escape Sequence which is followed by backslash. There are several things we can do with Escape Sequence. One thing to keep in mind, however, is that you cannot use uppercase letters here, but all letters will be lowercase. The use of Escape Sequence is discussed below such as: -
Escape Sequences | Meaning |
\b | Backspace |
\t | Tab |
\n | New Line |
\" | Double Quote |
\' | Single Quote |
\\ | Backslash |
How to use escape Sequence and these are discussed in detail such as: -
Escape Sequences | Meaning |
\b | Backspace |
\b :- This is used to delete a character. We know that the computer keyboard has a backslash button that allows us to delete any character. Similarly (\b) is used to delete a character in a Java program such as : -
package com.onlineashikhi; |
public class Main { |
public static void main(String[] args) { |
// We Use Backslash \b Here |
System.out.print( "Hello World\b" ); |
} |
} |
Output :-
Hello Worl
Escape Sequences | Meaning |
\t | Tab |
\t :- It is used to give a certain amount of distance. We know that there is a tab button on the computer keyboard by which a certain distance can be given. Similarly (\ t) is used to give a certain distance to something in a Java program. Such us: -
package com.onlineashikhi; |
public class Main { |
public static void main(String[] args) { |
// We Use Backslash \t Here |
System.out.println( "1 \t 2" ); |
System.out.println( "3 \t 4" ); |
System.out.println( "5 \t 6" ); |
} |
} |
Output :-
1 2
3 4
5 6
Escape Sequences | Meaning |
\n | New Line |
\n :- Java (\n) is used to create new lines. We know that new lines can be created in Java (println ()) by Mathhood. However, using (l n) does not require the use of (println ()) Mathhood. Such us: -
package com.onlineashikhi; |
public class Main { |
public static void main(String[] args) { |
// We Use Backslash \n Here |
System.out.print( ("This is first line\nThis is Second line\nThis is third line" ); |
} |
} |
Output :-
This is first line
This is Second line
This is third line
Escape Sequences | Meaning |
\" | Double Quote |
\" : -If you want to give double quotation at a specific place in Java, you have to give backslash double quotation. The program used here I want to give double quotations on both sides. If you want you can give double quotation on one side. The use of (\ ") is given below as : -
package com.onlineashikhi; |
public class Main { |
public static void main(String[] args) { |
// We Use Backslash \" Here |
System.out.print( ("\" Hamidur Rahman Repon \" "); |
} |
} |
Output :-
" Hamidur Rahman Repon "
Escape Sequences | Meaning |
\' | Single Quote |
\' : - The program used here I want to give a single quotation on both sides. If you want you can give a single quotation on one side. The use of (\ ') is given below as : -
package com.onlineashikhi; |
public class Main { |
public static void main(String[] args) { |
// We Use Backslash \' Here |
System.out.print( ("\' Hamidur Rahman Repon \' "); |
} |
} |
Output :-
' Hamidur Rahman Repon '
Escape Sequences | Meaning |
\\ | Backslash |
\\ : - This is used to print a single backslash with double backslashes. If you give more double backslash the backslash will be created in that proportion. Remember that double backslashes create only one backslash. The use of (\\) is given below as : -
package com.onlineashikhi; |
public class Main { |
public static void main(String[] args) { |
\\ We Use Double Backslash \\ Here |
System.out.print( "\\ Hamidur Rahman Repon \\"); |
\\\\ We Use 4 Backslash \\\\ Here |
System.out.print( "\\\\ Hamidur Rahman Repon \\\\"); |
} |
} |
Output :-
\ Hamidur Rahman Repon \
\\ Hamidur Rahman Repon \\
Hopefully, you have understood the Escape Sequence of Java programming very well. You must try to understand the use of Escape Sequence well. These will be needed when we are working on app development in Android Studio. If you want to learn Android apps development Click Here.
If you have any comments or suggestions on this topic,follow Countuct Us page. please let us know. Thanks you
All these issues will be brought to the web site very soon. We are currently working on all these issues. ...
onlineashikhi.com provides good quality services. For details please mail us onlineashikhi@gmail.com to get all our services. I think it will help you a lot of to learn about computers and programs.