• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Doubts K&B Java 1.5 Chapter 1

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Or just open character map and copy paste it.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for example you can search for unicode characters here:
http://www.fileformat.info/info/unicode/
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 9031
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Cor Takken
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic