Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why a legal identifier cannot include the character #

 
Krishnamoorthy Sethuraman
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is the identifier e# not a legal identifier for java compiler? The rules for valid identifier given in K&B book are:
----------------------------------------------------------
1. Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifiers cannot start with a number!
2. After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers.
3. In practice, there is no limit to the number of characters an identifier can contain.
4. You can't use a Java keyword as an identifier. Table 1-1 lists all of the Java keywords including one new one for 5.0, enum.
5. Identifiers in Java are case-sensitive; foo and FOO are two different identifiers.
----------------------------------------------------------
Accordingly the identifer e# doesn't come in any of the above 5 category.
So, why is it not a legal identifier?
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess they forgot to add that any special characters other than the currency symbols are not allowed.
 
Kino Lobo
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folk!

1. Identifiers must start with a letter...


The # is not a letter!
By letter we should consider A to z, I guess...

PS.: I'm studying by Head First too...
 
Valentin Jacquemin
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

2. After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers.


In this list there isn't the '#' character...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic