About Question enthuware.ocajp.i.v7.2.1297 :
Moderator: admin
About Question enthuware.ocajp.i.v7.2.1297 :
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 ?
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 ?
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1297 :
Yes, but since some users had difficulty in displaying it, it was changed to a regular a.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
Re: About Question enthuware.ocajp.i.v7.2.1297 :
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.
-
- Posts: 7
- Joined: Sun Apr 07, 2013 9:45 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1297 :
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?
"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?
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1297 :
Unicode characters are written using \u syntax. For example, \uD800. $ and _ are just ascii characters.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 7
- Joined: Sun Apr 07, 2013 9:45 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1297 :
So @ is valid if written as \u0040 ?
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1297 :
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.
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 35
- Joined: Mon Jul 28, 2014 2:05 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1297 :
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
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
-
- Posts: 35
- Joined: Mon Jul 28, 2014 2:05 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1297 :
what about the question above?
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1297 :
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.
Statement 1 that you've quoted is just an elaboration. Also, it says "includes". It is not an exhaustive list.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 9
- Joined: Fri Jan 31, 2014 8:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1297 :
re special characters, isn't it currency signs in general that are allowed rather than just $. E.g. int £ = 10; is ok?
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1297 :
What happened when you tried it?
If you like our products and services, please help us by posting your review here.
-
- Posts: 9
- Joined: Fri Jan 31, 2014 8:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1297 :
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.
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1297 :
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
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
If you like our products and services, please help us by posting your review here.
-
- Posts: 9
- Joined: Fri Jan 31, 2014 8:26 pm
- Contact:
-
- Posts: 35
- Joined: Mon Jul 28, 2014 2:05 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1297 :
This elaboration confused me. Now it's clear, thank you.admin wrote:Statement 1 that you've quoted is just an elaboration. Also, it says "includes". It is not an exhaustive list.
Who is online
Users browsing this forum: No registered users and 154 guests