• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Quickly...valid variable names

 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Working through the deitel book and I'm back in chapter 2 reviewing the questions. With regards to variable names I said all these were valid
_under_bar_, m928134, t5, j7, her_sales$, his_$account_total, a, b$, c, z, z2, h22

I said all these were invalid 3g, 87, 67h2, h22, 2h.

Am I correct?
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct, except for one thing....h22 is a valid variable .
In your answer it seems to appear as both valid and invalid, which i'm sure is just a mistake and wanted to point it out to you .
 
Matt Kidd
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes...typo on my part. Meant to put h22 up with the valid ones. Okay back to the book.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While you're reading that book, I recommend that you frequently take a look at The Java Language Specification. Section 3.8 on identifiers answers your question.
Another strategy to answer such questions, that I strongly recommend, is that you don't fully believe what the book or anybody here says, and you write a quick test program to answer the question(s).
Good Luck.
 
reply
    Bookmark Topic Watch Topic
  • New Topic