aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what makes a legal identifier?" Watch "what makes a legal identifier?" New topic
Author

what makes a legal identifier?

YekSoon Lok
Greenhorn

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?
thanks
Anonymous
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.
<code><pre>
public class Test
{
public static void main(String[] args)
{
int Test = 1;
System.out.println(Test);
int amethod = 2;
System.out.println(amethod);
}
public void amethod(){}
}
</pre>
</code>

[This message has been edited by Jim Hall (edited November 30, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what makes a legal identifier?
 
Similar Threads
Errors in Master Exam?!
Java Identifiers
Why a legal identifier cannot include the character #
Naming Conventions
Queries related to K&B SCJP 6 book