my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Simple question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Simple question" Watch "Simple question" New topic
Author

Simple question

Dean Oso
Greenhorn

Joined: Jul 13, 2003
Posts: 9
Hi,
can somebody tell me the rules for a valid varible or method name? I have Kathy Sierra & Bert Bates book but havent seen it documented in there?

thanks,
Dean
Damien Howard
Ranch Hand

Joined: Apr 01, 2003
Posts: 456
Actually, they have it in there, but not in the actual text, why I don't know. It took me a while to find as well.
Anyway, you can find it in the glossary, but I'll just tell you the rules.
All method/var names must begin with either a letter, $, or _ (underscore) and the rest of the var/method name can only contain letter, numbers, $ or _ It does not matter if you use upper or lowercase but you must be consistent as Java is case sensitive.
ex.
$5gf
_fd_
f54
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
In real life you may need to know that an identifier is a sequence of Java letters and Java digits, the first of which must be a Java letter.
If something is considered a letter or digit in a human language, you can probably use it in identifiers. This allows programmers to use identifiers in their programs that are written in their native languages.
The currency symbols $, pound sign ('\u00a3') and yen sign ('\u00a5') are Java letters. See Character.isJavaIdentifierStart(char) and Character.isJavaIdentifierPart(char).
Java letters from the first 128 Unicode characters are $ A-Z _ a-z

[ July 13, 2003: Message edited by: Marlene Miller ]
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Dean
I guess that you are already aware of this but justincluding it for the sake of completeness
Reserved words and keywords and true,false and null(constants) can not also be used as a valid identifier.
La Vish
Ranch Hand

Joined: Apr 17, 2002
Posts: 158
Have a look at what JLS says
Here


La Vish
SCJP 1.4, President 60s Club
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple question