Java

Escape Sequence in java with Examples using NetBeans

What is an Escape Sequence in Java?

In the Java programming language, surely you are still foreign and confused about what is meant by an Escape Sequence, Escape Sequence in java itself is actually a pair of characters that are considered as single characters, java Escape Sequences are not considered as Strings, but as special characters, these characters cannot be typed directly by a keyboard.

In this tutorial, we will explain briefly about using Escape Sequence in Java, for that, please pay attention to the following tutorial.


Types of Escape Sequence in java:

There are 10 types of Escape Sequences in Java and each has its own function, the following is a table that describes the types and descriptions of these pairs of characters.

Java Escape Sequence descriptions
\ddd Octal character (ddd)
\uxxxx Hexadecimal Unicode characters (xxxx)
\’ single-quote
\” Double quote
\\ Backlash
\r Carriage returns
\n New line (line feed)
\f Form feed
\t Tab
\b Backspace



List of Octal character Codes of Capital Alphabets:

Character Octal Character Code
A 101
B 102
C 103
D 104
E 105
F 106
G 107
H 110
I 111
J 112
K 113
L 114
M 115
N 116
O 117
P 120
Q 121
R 122
S 123
T 124
U 125
V 126
W 127
X 130
Y 131
Z 132


List of Octal character Codes of Small Alphabets:

Character Octal Character Code
a 141
b 142
c 143
d 144
e 145
f 146
g 147
h 150
i 151
j 152
k 153
l 154
m 155
n 156
o 157
p 160
q 161
r 162
s 163
t 164
u 165
v 166
w 167
x 170
y 171
z 172


List of Hexadecimal Unicode of Capital Alphabets:

Character Hexadecimal Unicode
A 0041
B 0042
C 0043
D 0044
E 0045
F 0046
G 0047
H 0048
I 0049
J 004A
K 004B
L 004C
M 004D
N 004E
O 004F
P 0050
Q 0051
R 0052
S 0053
T 0054
U 0055
V 0056
W 0057
X 0058
Y 0059
Z 005A


List of Hexadecimal Unicode of Small Alphabets:

Character Hexadecimal Unicode
a 0061
b 0062
c 0063
d 0064
e 0065
f 0066
g 0067
h 0068
i 0069
j 006A
k 006B
l 006C
m 006D
n 006E
o 006F
p 0070
q 0071
r 0072
s 0073
t 0074
u 0075
v 0076
w 0077
x 0078
y 0079
z 007A

In the following Examples, I am using each of the java Escape Sequence characters in the programming.



Java Escape Sequence Examples Using NetBeans:

Example 1: how to use Octal Character (ddd) in java Escape Sequence:

In this example, I am writing a “programming” through octal Alphabet character codes

Output:

Escape Sequence in java


Example 2: Hexadecimal Unicode characters (xxxx) in java Escape Sequence:

In this example, I am writing “programing” through Hexadecimal Unicode Alphabet character codes

output:

Escape Sequence in java

Example 3: how to use single quote \’ in java Escape Sequence:

In this example, I am printing “programming digest” inside a Single Quote using an escape sequence in java, from this example, you will learn how to enclose a word inside a quotes

Output:

Escape Sequence in java


Example 4: how to use Double quote \” in java Escape Sequence:

In this example, I am printing “programming digest” inside a Double Quote using an escape sequence in java, from this example, you will learn how to enclose a word inside a Double quote.

Output:

Escape Sequence in java

Example 5: how to use Backlash \\ in java Escape Sequence:

Output:

Escape Sequence in java


Example 6: how to use Carriage returns \r in java Escape Sequence:

Output:

Escape Sequence in java

Example 7: how to use New line \n in java Escape Sequence:

Output:

Escape Sequence in java


Example 8: how to use Form feed \f in java Escape Sequence:

In this example, I am using form feed \f escape sequence. It is an old procedure and used to demonstrate a page break. The output of the below code depends upon a compiler.

output:

Escape Sequence in java

Example 9: how to use Tab \t in java Escape Sequence:

Output:

Escape Sequence in java



Example 10: how to use Backspace \b in java Escape Sequence:

Output:

Escape Sequence in java

That’s a short tutorial on using escape sequences in Java, if you have any questions, comment below, good luck.

Related Article:

Escape Sequence in C++ with Examples

Fawad

Shahzada Fawad

Related Articles

Leave a Reply

Back to top button