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:

If you enjoy this Java programming article, please share with friends and colleagues. Follow the author on Twitter for the latest news and rants.

Editorial page content written by Neil Coffey. Copyright © Javamex UK 2021. All rights reserved.