• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Quickly...valid variable names

 
Matt Kidd
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • 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?
 
nupur dhawan
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
yes...typo on my part. Meant to put h22 up with the valid ones. Okay back to the book.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic