http://www.land-of-kain.de/hnc4java/
Hungarian Naming Convention for Java
@for Java Developers
@author Kai Ruhl
@since 1997-07
Intro
A HNC, or hungarian naming convention (hungarian because reportedly the first inventor was hungarian programmer Charles Simonyie at Microsoft), is the methodology of prefixing variables with one or more letters to indicate their type. The Sun Coding Conventions do not use HNC.
The HNC variant presented in this article applies only to variables, not to methods; methods should make their type clear thru their names, e.g. isXXX for booleans, getXXXValue for numericals, etc. It is designed for ease of application and minimal visual clutter, which results in the usage of as few letters as possible.
The HNC for Java
Letter | Description | Example | |||
---|---|---|---|---|---|
a<x> | Array of <x> | Object[] aoVals | |||
b | byte, short | byte bVal | |||
c | char | char cLetter | |||
d | double | double dVal | |||
e | Enumeration, Iterator | Enumeration eVals | |||
f | float | float fVal | |||
g | GUI component | JComboBox gChoice | |||
h | Hashtable, HashMap | HashMap hData | |||
i | int | int iVal | |||
j | - | - | |||
k | - | - | |||
l | long | long lDate | |||
m | - | - | |||
n | Numerical (Date, Dimension, BigInteger, ...) | BigDecimal nVal | |||
o | Object (whenever nothing else applicates) | MidiChannel oChannel | |||
p | - | - | |||
q | - | - | |||
r | - | - | |||
s | String, StringBuffer | String sLine | |||
t | boolean (truth value) | boolean tRunning | |||
u | - | - | |||
v | Vector, ArrayList | ArrayList vData | |||
w | - | - | |||
x | - | - | |||
y | - | - | |||
z | - | - |
然后是ibm上关于命名的一个文章:
http://www-128.ibm.com/developerworks/library/ws-tip-namingconv.html
Java naming conventionsMake your life easier ![]() | ![]() |
![]() |
Level: Introductory Scott Ambler (scott.ambler@ronin-intl.com), President, Ronin International 13 Jul 2000 In this first tip from Scott Ambler, he presents some guidelines for naming various Java elements, to make your job easier. Use full descriptors that accurately describe the variable, field, or class For example, use names like
Use terminology applicable to the domain If your users refer to their clients as customers, then use the term
Use mixed case to make names readable You should use lowercase letters in general, but capitalize the first letter of class names and interface names, as well as the first letter of any non-initial word.
Use abbreviations sparingly and intelligently This means you should maintain a list of standard short forms (abbreviations), you should choose them wisely, and you should use them consistently. For example, if you want to use a short form for the word number, then choose one of
Avoid long names (15 characters max is a good idea) Although the class name
Avoid names that are too similar or that differ only in case The variable names
Capitalize the first letter of standard acronyms Names will often contain standard abbreviations, such as SQL for Standard Query Language. Names such as
|