Imagine what happens when the letter combination represented by an escape sequence (let's say, \n) must be included as a part of the string value. Let's modify our example, as follows:
<HTML> <BODY> <H1>\n - new line, \t - tab</H1> </BODY> </HTML>
In this case, you can escape the \n sequence by using another backslash, as follows:
String html = "<HTML>" + "\n\t" + "<BODY>" + "\n\t\t" + "<H1>\\n - new line, \\t - tab</H1>"
+ "\n\t" + "</BODY>" + "\n" + "</HTML>";
But, with the changes, it's getting difficult to read and understand the preceding code. Imagine a developer in your team writes such code. Let's see how you could make it more readable.
As a workaround, you can define String constants (say, tab or newLine), assigning the values of \t and \n to them. You can use these constants instead of the literal values of \n and \t in the preceding code. This replacement will make the code easier to read.