The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubts K&B Java 1.5 Chapter 1 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Doubts K&B Java 1.5 Chapter 1" Watch "Doubts K&B Java 1.5 Chapter 1" New topic
Author

Doubts K&B Java 1.5 Chapter 1

Cor Takken
Ranch Hand

Joined: May 21, 2007
Posts: 58
On page 5 it says "Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ )". The example of a currency character suggests that the dollar sign is the only allowed character.

This example is actually too restrictive, I have done a short test and other currency signs (like the Euro sign - € -) are accepted as a valid identifier starting character as well. Only specifying the $-character is therefore a bit too suggestive and may lead people to dismiss identifier names as €Amount as incorrect.

Cor


SCJP 1.5
Dolphins are grey, but they dream in colour.
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
Hi cor,
I was wondering, how were you able to type that charecter from the keyboard.
My key board dont have it. :roll: :roll:

I guess K&B would have ment the charecters on keyboard.


Regards,
Durga Prasad
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332


Or just open character map and copy paste it.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14672
    
  11

I think that you're right. The Java Language Specification says that a "Java letter" is a character for which the method Character.isJavaIdentifierStart(int) returns true.
isJavaIdentifierStart will return true for one of the following conditions :
* isLetter(ch) returns true
* getType(ch) returns LETTER_NUMBER
* ch is a currency symbol (such as "$")
* ch is a connecting punctuation character (such as "_").

The Euro symbol being a currency symbol, I think it should be ok to use it.

The authors might have been misleaded by the following line in the specification :
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 preexisting names on legacy systems.


[My Blog]
All roads lead to JavaRanch
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
for example you can search for unicode characters here:
http://www.fileformat.info/info/unicode/
Manfred Klug
Ranch Hand

Joined: Jun 04, 2007
Posts: 377
don't forget, the book explains what is needed for the exam.

But you are free to learn all 46908 possible characters for java identifiers.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8712
Hi Cor,

Manfred is correct!

There are hundreds of nooks and crannies in the Java spec that we don't talk about in the book. We make every attempt to explain about 110% of what you need to understand to do very well on the exam, but we didn't try to recreate aspects of the spec that aren't on the exam.

hth,

Bert


Eliminate fossil fuel subsidies. (If you're not on the edge, you're taking up too much room.)
Cor Takken
Ranch Hand

Joined: May 21, 2007
Posts: 58
Originally posted by Bert Bates:
Hi Cor,

Manfred is correct!

There are hundreds of nooks and crannies in the Java spec that we don't talk about in the book. We make every attempt to explain about 110% of what you need to understand to do very well on the exam, but we didn't try to recreate aspects of the spec that aren't on the exam.

hth,

Bert


Bert,

Thanks, I feel honored that my question deserves your attention. However, by putting the example of a dollar sign explicitly in the book one could get the feeling that the dollar sign is the only one allowed. If the words "for example", or the abbreviation "e.g." would have been added (or some funny line like "your miles may vary" or "place your local currency sign here") the reader doesn't have to learn the 48.000+ characters and the text would suggest that any valid currency sign is allowed (and implicitly invite the reader to pay a visit to the API in question).

Anyway, everything is clear now and you may direct your attention to those subjects which are really urgent.

Thanks to everybody who has contributed.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Doubts K&B Java 1.5 Chapter 1
 
Similar Threads
identifiers
Illegal Identifiers
why $ only ???
valid Identifier
need help here!.. variable declaration