Java allows identifier to start with or contain $ (dollar sign).
e.g int a$b;
But why # is not allowed in an identifier? What is the specific reason? Is # an operator or something in Java?
e.g int a#b;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’d say that it is a combination of readability and the historical antecedents of the language. Remember that the Java syntax was designed to be easy-on-the-eye for C and C++ programmers. (And as @dan04 points out, the
#character is significant in most dialects of C and C++.)Incidentally, while
$is technical legal in Java identifiers, it is reserved for use by compilers, code generators and other things. If you use$in identifiers in your source code, you risk getting into trouble with collisions with synthetic identifiers produced by (for example) thejavaccompiler.