Java variable names

In our introduction to variables, we gave an example of how to name a variable. We mentioned that a name should clearly indicate what the variable represents. But there a few restrictions on variable names and, more importantly, there are various conventions.

There aren't in fact so many restrictions on variable names. But a key one is that they cannot contain spaces; another is that they cannot start with a number. There are also restrictions on what symbols can be used in variable names. But in general, if you don't try and put silly characters and symbols in your variable names (you really don't need to...), then you won't need to worry about what is and isn't allowed.

Beyond the actual restrictions, as mentioned, it's common to apply some variable name conventions so that you end up using a name in a format that programmers are generally used to reading. In general: