File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Quickly...valid variable names Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Quickly...valid variable names" Watch "Quickly...valid variable names" New topic

Quickly...valid variable names

Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 261
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

Joined: Jun 26, 2002
Posts: 71
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 .

Nupur. <br />SCJP2.
Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 261
yes...typo on my part. Meant to put h22 up with the valid ones. Okay back to the book.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
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.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Quickly...valid variable names