Variable naming convention

Discussion in 'Java' started by Unpredictable, Jan 3, 2006.

  1. Can any one tell me why variable names in Java should not begin with a
    digit?
    Unpredictable, Jan 3, 2006
    #1
    1. Advertising

  2. Unpredictable wrote:
    > 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?
    Thomas Schodt, Jan 3, 2006
    #2
    1. Advertising

  3. Unpredictable

    NullBock Guest

    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.
    NullBock, Jan 3, 2006
    #3
  4. Unpredictable wrote:
    > 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.
    Malte Christensen, Jan 3, 2006
    #4
  5. Unpredictable

    Roedy Green Guest

    On 3 Jan 2006 06:36:32 -0800, "Unpredictable"
    <> 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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Jan 3, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick

    Which c# naming convention?

    Rick, Jan 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,761
    Paul Glavich
    Jan 19, 2004
  2. Peng Yu
    Replies:
    3
    Views:
    1,066
    Simon Forman
    Sep 21, 2009
  3. Peng Yu
    Replies:
    0
    Views:
    285
    Peng Yu
    Nov 19, 2009
  4. Chris Rebert
    Replies:
    2
    Views:
    350
    Gregory Ewing
    Nov 21, 2009
  5. Peng Yu
    Replies:
    1
    Views:
    331
    Lie Ryan
    Nov 22, 2009
Loading...

Share This Page