• 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
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

is e# is a valid identifier ot not?

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
give suitable reason please......
 
suresh mandalapu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i mean in cathe seirra scjp 1.5 book it is said that e# is not a valid identifier ..
the reason is # is not a lagal character for making identifiers .. am i correct???
like that if any other such characters are there please tell me..
thanks
suresh
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no e# is not a valid identifier because identifier can start with a letter, underscore or dollar sign and after start it can can contain digits,letter, underscore or dollar sign not #.
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'#' is a special character like *, &, % and so on , you cant used them in defining java keywords . Suppose compiler permits them , then this kind of ambiguity occurred !



So I think Any compiler doesn't permits this kind of Java keywords declarations !

This is not perfect answer, I may wrong , So please correct me Ranchers !
 
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

is e# is a valid identifier ot not ???


You make a sample class and try to compile it
 
suresh mandalapu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@sweety..
no e# is not a valid identifier because identifier can start with a letter, underscore or dollar sign and after start it can can contain digits,letter, underscore or dollar sign not #.

after the first character ,any thing can come...
for example a:sde a%s.der
but it is not said that # cant come after first char.in cathe seirra
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An identifier in java can contain only letters,digits,$ and _.
And identifier cannot start with digits.

so e# is not a valid identifier as its containing # which is not a valid character for identifier.

Refer to Page 5 from SCJP 1.5 by K&B
 
suresh mandalapu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what are the other connecting characters other than _
are . : connecting chars??
please specify if ant are there..
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any currency character is valid.

int �a = 1;

and

int �a = 1;

are valid.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

suresh mandalapu wrote:give suitable reason please......



In K& S book it is mentioned that the "Identifiers must start with a letter, a currency character ($), or a connecting
character such as the underscore ( _ )." I think "#" is the currency character for pound.Then why is "$" accepted as a valid currency character and not "#"
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Payel Bera wrote:
In K& S book it is mentioned that the "Identifiers must start with a letter, a currency character ($), or a connecting
character such as the underscore ( _ )." I think "#" is the currency character for pound.Then why is "$" accepted as a valid currency character and not "#"




Although the hash sign ("#"), is sometimes called the pound sign, it is not the currency character for the British Pound. The BP uses this sign...

http://en.wikipedia.org/wiki/Pound_sign

Henry
 
Payel Bera
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Henry,

Thanks for explaining this. Please let me know that apart from "$" which are the other currency character that can be used as a valid identifier.
Also apart from "_" which are the other separating character that can be used as a valid identifier

Thanks
Payel
 
Sheriff
Posts: 9697
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Payel, you can find all the info in the JLS...
 
Payel Bera
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ankit,

thanks for your explanation.
I hope I can now safely infer that only letters (Aa to Zz), (0-9) and $ and _ are valid characters in a Java identifier.
There are no more currency character and separating character apart from $ and _.
Please correct me if I am wrong..
Thanks in advance.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
though its been long, just would like to add that other currency signs like '£' are also valid identifiers...though you cannot type it directly from keyboard...
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bera,

I have done a testing with this declaration
"private int $₭฿;" it works pretty good.
the currency code you can copy from Currency Code for testing.

 
To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic