The Mystery of character

Source: Internet
Author: User

character, from the literal understanding, is some char type of East, but put in the program, the extension of a variety of interpretation methods

1. Escape character

In the program, when is the escape character interpreted by the compiler? Its interpretation time can be understood as before compiling, the compiler first to the escape character substitution.

For example, the following program segment:

(a)//\u0022 is "

System.out.println ("A\u0022.length () +\u0022b". length);

Printing 2

(b) One line of comments is:/*from f:/a/b/c/unit*/

Is this legal? Note that the compiler finds that \u will assume that a Unicode code is followed, and the comment does not follow a four-digit number, and the compiler rejects the compilation

Original aim, read the program, notice the escaped Unicode code, and then convert it to recompile.

Tip: Do not use Unicode escape characters casually, unless forced

2. Special characters of regular expressions

This is an understanding of regular expressions.

String.replaceall supports regular expressions, so it is important to use this function.

Such as: There is already a class of com.javapluzzlers.Me

Me.class.getName (). ReplaceAll (".", "/") + ". Class";

Will it be com/javapluzzlers/me.class after replacement?

Not found after running. Because "." Matches any character in the regular, and replaces it with a string of/////////////.class,

3. URL

Since Java supports tags, will this segment be compiled if there is a http://blog.csdn.net-like statement in the program segment? The answer is yes.

Because http: is understood as a label, and//blog.csdn.net is interpreted as a comment, there is clearly no grammatical error.

4, the parameter number character

Examine the next stringbuffer.

StringBuffer SF = new StringBuffer (' M ');

Sf.add ("a");

System.out.println (SF);

Print What? Would it be MA?

The view API finds that StringBuffer does not have a constructor with a parameter of char, but there is a constructor with a parameter of int, so the declaration statement actually declares a buffer with a size of ' M ' (77).

The Mystery of character

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.