Java and Java escape characters

Source: Internet
Author: User

Java and Java escape characters

Escape Character refers to the combination of some common characters to replace some special characters. Because its combination changes the meaning of the original character representation, it is called "escape ".
Common escape characters:
\ N press enter (\ u000a)
\ T horizontal tab (\ u0009)
\ B space (\ u0008)
\ R line feed (\ u000d)
\ F form feed (\ u000c)
\ 'Single quotes (\ u0027)
\ "Double quotation marks (\ u0022)
\ Backslash (\ u005c

Example:

String greeting = "Good Morning !! \ N"


What are escape characters in java and why should they be escaped?

Take the "\" symbol as an example. There are many operations in JAVA, such as file operations. The path must be used, such as com \ mypackage \ xxx. xml, this path is generally represented in the form of a string, but the problem arises. JAVA does not know whether your \ number is the meaning of the next layer in the path or the meaning of the string.
Therefore, the correct method should be com \ mypackage \ xxx. xml.
For example, if we press enter directly in the middle of the string, java will not wrap the string, because he doesn't know if you want to write the code in two lines or split the string into two lines for display, you need to add \ n escape characters in the middle of the string to wrap the string.
In short, the meaning of escape characters is to avoid ambiguity, which is not allowed by all programming languages.

In java, what is the Escape Character \'?

I cannot remember specific characters with special meanings
Output "\" requires: System. out. println ("\\");
Output ": System. out. println ("\"");

In some methods, when passing parameters is special characters.
Output can be directly output, but some parameters must be \. Otherwise, errors may occur.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.