wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Legel Identifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Legel Identifiers" Watch "Legel Identifiers" New topic
Author

Legel Identifiers

Inderjit Singh
Greenhorn

Joined: Dec 02, 2006
Posts: 13
Technically,legal identifiers must be composed of only Unicode Characters, Numbers, Currency symbols and connecting characters like underscores.
my questions are questions..

1.Please tell exactally which charaters we can use and which characters comes under unicode characters?



2. These are legal or illegal and why?

int e#;
int :b;
int d-;
int .f;

please tell me with reason..
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
well!!!

The all 4 options shown by you are not
legal identifiers....bcoz the first option has
# in it which is illegal.second option start with ( which is not allowed
the third option start with letter but preceded by (-)
so this is also not allowed and finally fourth option has dot
which is too not legal....by legal what i mean here
is ,it must be a character which can preeced a underscore ,or underscore
or a currency symbol ....and you asked about
unicode it is as u000 format...........
i hope it helps...................
Inderjit Singh
Greenhorn

Joined: Dec 02, 2006
Posts: 13
Originally posted by dhwani mathur:
well!!!

The all 4 options shown by you are not
legal identifiers....bcoz the first option has
# in it which is illegal.second option start with ( which is not allowed
the third option start with letter but preceded by (-)
so this is also not allowed and finally fourth option has dot
which is too not legal....by legal what i mean here
is ,it must be a character which can preeced a underscore ,or underscore
or a currency symbol ....and you asked about
unicode it is as u000 format...........
i hope it helps...................


It means we can only use..
a-z
A-Z
0-9
$
_
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Good style does not allow the use of $ in identifiers, even though it is legal. The JLS says: -

The $ character should be used only in mechanically generated source code or, rarely, to access preexisting names on legacy systems

[ July 31, 2007: Message edited by: Peter Chase ]

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Inderjit Singh
Greenhorn

Joined: Dec 02, 2006
Posts: 13
Thanks for reply

Its ok that these all are illagal. My Question is that exactally which charaters we can use for naming identifiers. Like..

A-Z
a-z
0-9
$
_

or any else?


In book, its written that we can use string connector like underscore. Is their any other string connecter exist in java..?
Is their any other character except above mentioned? please reply...
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
Hey Inderjit!!

Here string connectors means,
two strings joined with an underscore as
shown below with example.

int Balance_in_Account;

what it actualy means that if you want to
write some meaningfull names which are long
enough
so you can use a underscore in between so as to
make it readable and meaningful.


i hope this helps.......
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by dhwani mathur:
int Balance_in_Account;


That's legal, but better style is: -

Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
All of the rules that I have seen say:

1) the first character of a name can be a-z,A-Z,$, or _

2) subsequent character positions can also use 0-9


------------------------
Bob
SCJP - 86% - June 11, 2009
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Legel Identifiers