In theory an identifier can be any length. It has to start with a letter, an underscore or a dollar sign. It's proper naming convention to start with a small letter, and then for every new word in the identifier, capitalize the first letter. An example is "numberOfHouses". You don't have to follow this rule, but most Java programmers do. Whatever you choose to stick with, you must do it consistently. If you start one variable with a small letter, do the same for all the other ones as well.
Except for the first letter, you can use any characters besides those used as operators in Java (ex. +, -, /, *). However, unless you have a very good reason to use signs, it's usually best to go with letters, digits and the underscore.
It's important to take notice of the fact that in Java, numberOfHouses is not the same as NumberOfHouses. Java is case sensitive, so pay special attention to this when naming an identifier.
There are also some words that cannot be used, mainly Java keywords. Examples are private, while, if, do, int, long and char. When you put together a name yourself, you are almost guaranteed to be safe, so this is very easy to avoid. Examples could be num1, num2 etc.
You should always choose names for variables that clearly says what kind of data they hold. In "numberOfHouses", there is no doubt that this variable will hold an unknown number of houses. If I named the variable "house", there could be confusion as to what data this variable holds. It could be concerning owners, colors, decorations, building dates, construction and so on. If you know what the data is by reading the variable, it's a good name.
Java source code is in Unicode, and this means that you can use any character defined within the Unicode character set. You can name your variables with Russian, Norwegian, or German characters. The reason for this is because even though you write the source code in ASCII characters, the source code is converted to Unicode characters internally, before it's compiled.
That being said, it's very important to choose good names for your variables. The Java naming conventions are very straight forward, and by following the few rules above you'll be in the safe zone. If you are confused about choosing appropriate names, it might help to picture someone else reading your source code. Would they understand the different identifiers, and what they stand for? Have you been consistent in using the same capitalization all around? Have you avoided the Java no-no keywords? If yes, then you're most likely on the right track!
Published by Cloudage
I am a student studying and tutoring in math, chemistry and physics. View profile
- Picture Name Cards for Thanksgiving the Dinner TableIn place of a name card at each seat try using a fun photo of your family or guest. Even if you aren't having a formal dinner these name cards are a great way to include everyone in this day of thanks.
- The Chinese American Without a Chinese NameHow an Asian American "lost" her Asian name, and still embrace her culture and heritage.
- Baby Names - Tips on How to Choose the Best Name for Your BabyChoosing the right name for your baby is an important decision: The name you pick will be what your child is known as for the rest of his or her life. Here are a few ways to avoid making some of the more common mist...
- Choosing That Perfect Baby NameFinding a baby name can be stressful to prospective parents. After all, this name will travel with your child throughout his life. The following article will make this momentous decision just a little easier.
Online Resources for Choosing a Baby Name What's in a name? Some say....a lot, if not everything. Names are important. New parents often find they are selecting between several different names. Here are some great onlin...
- Popular Baby Name Websites
- No Same-Name: Why Children Should Not Be Named After Parents or Other Family Members
- Individualistic and Collectivistic Influences on the Name-Letter Effect
- Tips on Registering a Good Domain Name
- Choosing a Baby Name
- The Perils and Politics of Picking a Name for a New Baby
- Choosing Who to Register Your Domain Name With
- You can use any Unicode character in Java.
- Avoid Java keywords such as private, if, else, and while.



