Hungarian Notation for Java
a – argument b – byte (8-bit integer) c – char (remember: a byte and a char are not the same in Java) d – double (64-bit IEEE-754 floating-point number) e – enum f – float (32-bit IEEE-754 floating-point number) g – global (static, really) h – has-a (instance variable, i.e., this object has a value) i – int (32-bit integer) j – k – constant (i.e., final) l – long (64-bit integer) m – n – number of (i.e., how many) o – Object (usually followed by a class name) p – Point q – r – Rectangle s – t – Throwable (often followed by a class name) u – String (think Unicode) v – array (think vector, but not the infernal JDK Vector) w – word (short 16-bit integer, the wordsize on the CPUs K&R used) x – Exception (often followed by a class name) y – yes-or-no (i.e., boolean) z – size
The order of prefix elements works like this: [agh ][k ][v ][bcdefilnoprtuwxyz]
The first group indicates where the variable came from. Is it an argument (a), a static variable (g), an instance variable (h), or a local variable (no prefix)?
The second group indicates whether you can change the variable’s value. Is it a constant or final variable (k), or not (no prefix)?
The third group indicates whether the variable is an array, and, if so, how many dimensions it has. Is it an array (v, where there is one v for each dimension of the array), or not (no prefix)?
The fourth group indicates the variable’s type, where most of the prefixes are highly mnemonic. For the ones that are less so: sorry, we tried, but there are only 26 letters to work with. There are some special cases that aid in succinctness: n z.
Note that some of Java’s standard classes have their own prefixes, so you can simply write p instead of oPoint, or u instead of oString.
Objects that wrap Java’s intrinsic types, for example Integer, are written by prefixing o onto the prefix for the intrinsic type, as in oi.
The n prefix is easily overused, and is often confused with z. n and z are assumed to indicate int values. If you need them to be something else, prefix them with their physical types, e.g. bn or lz.
If you use generics, prefix a generic type name with an underscore. And use a real word for the generic type, instead of the single-letter convention, so you can remember what the name means tomorrow, and your co-worker can understand what it means today. Some IDEs and syntax checkers will complain about this, but the single-letter convention was always a bad idea. Besides, you are the boss, not it.
Don’t worry if some of your prefixes become quite long. The alternative is worse.