Why do variable names often start with the letter 'm'?
JavaAndroidNaming ConventionsJava Problem Overview
Looking at the Android tutorials such as the Notepad tutorial, I noticed that almost all variables are named starting with the letter 'm'. What convention is this, and where does it originate from?
Java Solutions
Solution 1 - Java
It stands for member. I personally find this convention unhelpful, but it's subjective.
Solution 2 - Java
See [Code Style Guidelines for Contributors: Follow Field Naming Conventions][1]. The use of the "m" prefix is more specific that simply denoting a "member" variable: It's for "non-public, non-static field names."
[1]: http://source.android.com/source/code-style.html#follow-field-naming-conventions "Code Style Guidelines for Contributors: Follow Field Naming Conventions"
Solution 3 - Java
According to Android source code documentation:
- Non-public, non-static field names start with m.
- Static field names start with s.
- Other fields start with a lower case letter.
- Public static final fields (constants) are ALL_CAPS_WITH_UNDERSCORES.
Note that this is for writing Android source code. For creating Android apps, the Google Java Style Guide may be more helpful.
Solution 4 - Java
The m is here to indicate a member variable.
It has 2 huge advantages:
- If you see it, you instantly recognize it as a member variable.
- Press m and you get all members via the auto completer. (This one is not in the other answers)
Solution 5 - Java
'm' means member of the class. So, if you don't use IDE to highlight your members, then you will understand that it is a member by it's name
Solution 6 - Java
As already answered this prefix indcates that a variable is member.
Somtimes people use other prefixes if you discover some variables starting with 'i' or 's' it could also be a variant of the Hungarian Notation
Solution 7 - Java
'm' means the variable is a member variable of the class...
Solution 8 - Java
not only in java, I've seen similar convention in cocos2d+box2d samples where some of the variables start with m_, but others don't, very confusing.
b2World* world;
GLESDebugDraw *m_debugDraw;
I guess to differentiate C++ box2d variables from Obj-C variables.