Variable naming convention

U

Unpredictable

Can any one tell me why variable names in Java should not begin with a
digit?
 
T

Thomas Schodt

Unpredictable said:
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?
 
N

NullBock

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.
 
M

Malte Christensen

Unpredictable said:
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.
 
R

Roedy Green

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top