Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Sun Sep 09, 2012 12:55 pm
by ETS User
Hello, folk, and thank you for the great work.

In this question, the third option says "angstrom", but the comment to it declares "All unicode characters are valid". Did you mean to put there a single unicode letter 0x00E5 ?

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Sun Sep 09, 2012 3:01 pm
by admin
Yes, but since some users had difficulty in displaying it, it was changed to a regular a.
HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Sat Sep 15, 2012 12:23 pm
by Guest
That sort of dries the juice out of the question, doesn'it? The note about "all unicode characters" is useful in any case, and I am grateful.
:-)

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Fri Apr 26, 2013 3:14 pm
by SirZed
Isn't there a contradiction between these statements?
"All unicode characters are valid."
"No special chars except $ and _ are allowed."

The first one would indicate that @ is valid, since it is an unicode character.
Or is there a list of special characters that aren't allowed?

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Fri Apr 26, 2013 5:42 pm
by admin
Unicode characters are written using \u syntax. For example, \uD800. $ and _ are just ascii characters.

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Sat Apr 27, 2013 2:45 am
by SirZed
So @ is valid if written as \u0040 ?

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Sat Apr 27, 2013 7:15 am
by admin
Sorry, I misunderstood your question. I see what you mean. No, it would not be valid.

The complete rule is as follows (added to the explanation now):

As per JLS section 3.8: A valid identifier must start with a Java letter followed by a Java letter or a digit.

A "Java letter" is a character for which the method Character.isJavaIdentifierStart(int) returns true.

A "Java letter-or-digit" is a character for which the method Character.isJavaIdentifierPart(int) returns true.

The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $ character should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems.

The "Java digits" include the ASCII digits 0-9 (\u0030-\u0039).

Letters and digits may be drawn from the entire Unicode character set, which supports most writing scripts in use in the world today, including the large sets for Chinese, Japanese, and Korean. This allows programmers to use identifiers in their programs that are written in their native languages.

An identifier cannot have the same spelling (Unicode character sequence) as a keyword (§3.9), boolean literal (§3.10.3), or the null literal (§3.10.7), or a compile-time error occurs.

-Paul.

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Wed Jul 30, 2014 1:58 am
by pfilaretov
Isn't there a contradiction between these statements?

1. The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024).

2. Letters and digits may be drawn from the entire Unicode character set

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Wed Aug 06, 2014 12:09 am
by pfilaretov
what about the question above?

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Wed Aug 06, 2014 12:34 am
by admin
I don't think there is any contradiction. Specially if you read the complete section in its entirety. It clearly says, "A "Java letter" is a character for which the method Character.isJavaIdentifierStart(int) returns true."

Statement 1 that you've quoted is just an elaboration. Also, it says "includes". It is not an exhaustive list.

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Wed Aug 13, 2014 10:41 am
by boonnick
re special characters, isn't it currency signs in general that are allowed rather than just $. E.g. int £ = 10; is ok?

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Wed Aug 13, 2014 10:52 am
by admin
What happened when you tried it?

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Wed Aug 13, 2014 10:55 am
by boonnick
Well it works, I was really asking about the principle behind it working. If you can confirm that currency signs in general are allowed this would be a useful rule of thumb.

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Wed Aug 13, 2014 7:33 pm
by admin
Although the JLS doesn't specify the rule in these terms, it is clear that all currency signs are valid because they belong fall under the rule:
A "Java letter" is a character for which the method Character.isJavaIdentifierStart(int) returns true.
A "Java letter-or-digit" is a character for which the method Character.isJavaIdentifierPart(int) returns true.

You may check this out : http://docs.oracle.com/javase/specs/jls ... ml#jls-3.8

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Thu Aug 14, 2014 7:28 pm
by boonnick
Ah thanks!

Re: About Question enthuware.ocajp.i.v7.2.1297 :

Posted: Mon Aug 18, 2014 1:50 am
by pfilaretov
admin wrote:Statement 1 that you've quoted is just an elaboration. Also, it says "includes". It is not an exhaustive list.
This elaboration confused me. Now it's clear, thank you.