• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

identifier

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int e#;

Is a legal or illegal identifier?
 
lowercase baba
Posts: 13081
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76818
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 27450
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or getting fired.
 
Campbell Ritchie
Marshal
Posts: 76818
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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”?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76818
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:
Now c'mon Campbell. You should know by now . . .

D'oh!
 
Campbell Ritchie
Marshal
Posts: 76818
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maharana Pratap:

Please tell us whether D'oh is or is not a legal identifier
 
You showed up just in time for the waffles! And this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic