JavaK Your free source for Java Knowledge! AFRIKAANS  
     
  Homepage Contact Us Articles Projects Q and A Links  
     
 

Escape Characters

These special characters allow you to format strings in different ways. As your programming skills increase, you will find a time where you wish you had more control over the output of your programs. Escape characters is one way of manipulating the format of your program output, especially if you are doing console programming. Theses skills are also quite handy when you are doing report writing in your programs as they can be used to manipulate any string value.

First, we need a short list of these characters and then we will look at ways of using them. The following tables lists a few of the most commonly used escape characters in the Java programming language :

SequenceDescription
\bBackspace
\tHorizontal tab
\nNewline
\fForm feed
\rCarriage Return
\"Double quote
\'Single quote
\###Octal character
\u####Unicode character


Assorted sample code for using escape characters.
                        \t
                        The following statement will result in this output : The     big     bad     brown   bear!
                        System.out.println("The\tbig\tbad\tbrown\tbear!\t");
                        \"
                        The following statement will result in this output : "This string is quoted!"
                        System.out.println("\"This string is quoted!\"");
                        \n
                        To output FOUR blank lines you will use the following statement :
                        System.out.println("\n\n\n");
                        \n
                        To break apart an output string you will use the following statement :
                        System.out.println("123\n456");
                      





The Author
This article about
Java Escape Characters was freely contributed by Ewald Horn to JavaK in the interest of all Java students. Please visit JavaK for more free Java articles. The author also maintains another website at www.nofuss.co.za.