File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what makes a legal identifier? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what makes a legal identifier?" Watch "what makes a legal identifier?" New topic

what makes a legal identifier?

YekSoon Lok

Joined: Nov 29, 2001
Posts: 4
I am preparing for my SCJP and I just make a small observation
for "what makes a legal identifier?"
if you have previous experience in C++ and some form of Unix scripting (like Perl), you will know that
1. in C++, identifiers can start with "_" , the underscore
2. in Perl, identifiers start with "$", dollar sign.
and of course, most of you knows that identifiers can start with
a character.
Now, combine the 3 and u have a guideline for "what makes a legal identifier" or "what is a legal declaration?"
1. can start with characters
2. can start with underscore
3. can start with dollar sign
anything outside of this will not be correct?
is this observation right?
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
In addition, no special characters (for example *, @) can appear anywhere in a legal identifier.
for example, _addd@ will not be accepted.
[This message has been edited by Shyamsundar Gururaj (edited November 29, 2001).]
Jim Hall
Ranch Hand

Joined: Nov 29, 2001
Posts: 162
And don't forget the obvious. An identifier cannot be a keyword or reserved word.
Also an identifier can be the same name as the class or methods in the class without causing a compile error. Of course you probably wouldn't want to do this.
public class Test
public static void main(String[] args)
int Test = 1;
int amethod = 2;
public void amethod(){}

[This message has been edited by Jim Hall (edited November 30, 2001).]
I agree. Here's the link:
subject: what makes a legal identifier?
It's not a secret anymore!