• Post Reply Bookmark Topic Watch Topic
  • New Topic

identifier  RSS feed

 
Maharana Pratap
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int e#;

Is a legal or illegal identifier?
 
Carey Brown
Bartender
Posts: 3016
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Illegal.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always check the oracle docs. Here it tells you that legal first characters are letters, '$', and '_'. Subsequent characters add in digits.

So a '#' character will always be illegal.
 
Campbell Ritchie
Marshal
Posts: 55788
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a difference between what you can use and what you should use. Identifiers may start with underscore currency symbols or letters, but should start with a letter.
The subsequent characters can be any of the above plus 0123456789 but should be letters and numbers except in constants or package names.
$¢£₹123_45 might get past the compiler but it is not correct style. There are recommendations in the Java® Language Specification but that can be difficult to read.
 
Paul Clapham
Sheriff
Posts: 22521
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to that section of the JLS, you can't use "do" as a variable name because it's a keyword of the Java language. You can, however, use "dо" as a variable name because the second letter of that name is the Cyrillic letter o and not the Latin letter o. That could be a valuable technique for obfuscating your code...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or getting fired.
 
Campbell Ritchie
Marshal
Posts: 55788
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:According to that section of the JLS, you can't use "do" as a variable name . . .
What about “D'oh”?
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:What about “D'oh”?

Now c'mon Campbell. You should know by now that variables start with a lowercase letter.

Winston
 
Campbell Ritchie
Marshal
Posts: 55788
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
Now c'mon Campbell. You should know by now . . .
D'oh!
 
Campbell Ritchie
Marshal
Posts: 55788
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maharana Pratap:

Please tell us whether D'oh is or is not a legal identifier
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!