Can any one tell me why variable names in Java should not begin with a
digit?
Thomas Schodt - 03 Jan 2006 14:53 GMT
> Can any one tell me why variable names in Java should not begin with a
> digit?
0L, 1F, 2D
how would the compiler be able to tell if those are supposed to be
primitive literals or variables?
NullBock - 03 Jan 2006 14:54 GMT
How would java compilers otherwise know if a string of characters was a
number or a variable? Even if you insisted that variables have at
least one non-digit, you'd still have problems:
1D
Is that a number or a variable?
Walter Gildersleeve
Freiburg, Germany
______________________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green.
Malte Christensen - 03 Jan 2006 15:11 GMT
> Can any one tell me why variable names in Java should not begin with a
> digit?
From java.sun.com:
You must explicitly provide a name and a type for each variable you want
to use in your program. The variable's name must be a legal identifier
(in the glossary) — an unlimited-length sequence of Unicode characters
that begins with a letter. You use the variable name to refer to the
data that the variable contains.
That's why.
Roedy Green - 03 Jan 2006 17:12 GMT
On 3 Jan 2006 06:36:32 -0800, "Unpredictable"
<Kumar.Ganesha@gmail.com> wrote, quoted or indirectly quoted someone
who said :
>Can any one tell me why variable names in Java should not begin with a
>digit?
1. that's the language rule.
2. the compiler will reject a name beginning with a digit.
3. it would have been ambiguous for strings like 0D and 0x00 and 23L
if you allowed those strings to represent both literals and variable
names.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.