Java Identifiers
legal identifiers must be composed of only Unicode characters,
numbers, currency symbols, and connecting characters (like underscores).
■ Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifiers cannot start with a number!
■ After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers.
■ In practice, there is no limit to the number of characters an identifier can
contain.
■ You can't use a Java keyword as an identifier. Table 1-1 lists all of the Java
keywords including one new one for 5.0, enum.
■ Identifiers in Java are case-sensitive; foo and FOO are two different identifiers.
Sun's Java Code Conventions
■ Classes and interfaces The first letter should be capitalized, and if several words are linked together to form. the name, the first letter of the inner words should be uppercase (a format that's sometimes called "camelCase").
■ Methods The first letter should be lowercase, and then normal camelCase
rules should be used. In addition, the names should typically be verb-noun
pairs.
■ Variables Like methods, the camelCase format should be used, starting with a lowercase letter. Sun recommends short, meaningful names, which sounds
good to us.
■ Constants Java constants are created by marking variables static and
final. They should be named using uppercase letters with underscore
characters as separators:
■ If the property is not a boolean, the getter method's prefix must be get. For example, getSize()is a valid JavaBeans getter name for a property named
"size." Keep in mind that you do not need to have a variable named size(although some IDEs expect it). The name of the property is inferred from the
getters and setters, not through any variables in your class. What you return
from getSize() is up to you.
■ If the property is a boolean, the getter method's prefix is either get or is. For example, getStopped() or isStopped() are both valid JavaBeans names for
a boolean property.
■ The setter method's prefix must be set. For example, setSize() is the valid
JavaBean name for a property named size.
■ To complete the name of a getter or setter method, change the first letter of the property name to uppercase, and then append it to the appropriate prefix
(get, is, or set).
■ Setter method signatures must be marked public, with a void return type
and an argument that represents the property type.
■ Getter method signatures must be marked public, take no arguments, and
have a return type that matches the argument type of the setter method for
that property.
JavaBean Listener Naming Rules
■ Listener method names used to "register" a listener with an event source
must use the prefix add, followed by the listener type. For example,
addActionListener() is a valid name for a method that an event source
will have to allow others to register for Action events.
■ Listener method names used to remove ("unregister") a listener must use
the prefix remove, followed by the listener type (using the same rules as the
registration add method).
■ The type of listener to be added or removed must be passed as the argument
to the method.
■ Listener method names must end with the word "Listener".
numbers, currency symbols, and connecting characters (like underscores).
■ Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifiers cannot start with a number!
■ After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers.
■ In practice, there is no limit to the number of characters an identifier can
contain.
■ You can't use a Java keyword as an identifier. Table 1-1 lists all of the Java
keywords including one new one for 5.0, enum.
■ Identifiers in Java are case-sensitive; foo and FOO are two different identifiers.
Sun's Java Code Conventions
■ Classes and interfaces The first letter should be capitalized, and if several words are linked together to form. the name, the first letter of the inner words should be uppercase (a format that's sometimes called "camelCase").
Dog
Account
PrintWriter
For interfaces, the names should typically be adjectives likeAccount
PrintWriter
Runnable
Serializable
Serializable
■ Methods The first letter should be lowercase, and then normal camelCase
rules should be used. In addition, the names should typically be verb-noun
pairs.
■ Variables Like methods, the camelCase format should be used, starting with a lowercase letter. Sun recommends short, meaningful names, which sounds
good to us.
■ Constants Java constants are created by marking variables static and
final. They should be named using uppercase letters with underscore
characters as separators:
MIN_HEIGHT
JavaBean Property Naming Rules■ If the property is not a boolean, the getter method's prefix must be get. For example, getSize()is a valid JavaBeans getter name for a property named
"size." Keep in mind that you do not need to have a variable named size(although some IDEs expect it). The name of the property is inferred from the
getters and setters, not through any variables in your class. What you return
from getSize() is up to you.
■ If the property is a boolean, the getter method's prefix is either get or is. For example, getStopped() or isStopped() are both valid JavaBeans names for
a boolean property.
■ The setter method's prefix must be set. For example, setSize() is the valid
JavaBean name for a property named size.
■ To complete the name of a getter or setter method, change the first letter of the property name to uppercase, and then append it to the appropriate prefix
(get, is, or set).
■ Setter method signatures must be marked public, with a void return type
and an argument that represents the property type.
■ Getter method signatures must be marked public, take no arguments, and
have a return type that matches the argument type of the setter method for
that property.
JavaBean Listener Naming Rules
■ Listener method names used to "register" a listener with an event source
must use the prefix add, followed by the listener type. For example,
addActionListener() is a valid name for a method that an event source
will have to allow others to register for Action events.
■ Listener method names used to remove ("unregister") a listener must use
the prefix remove, followed by the listener type (using the same rules as the
registration add method).
■ The type of listener to be added or removed must be passed as the argument
to the method.
■ Listener method names must end with the word "Listener".
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7899089/viewspace-623239/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle identifiers :Database NameOracleIDEDatabase
- Oracle identifiers :DBIDOracleIDE
- Oracle identifiers :Global database nameOracleIDEDatabase
- Oracle identifiers :SID (System Identifier)OracleIDE
- QTP的3類順序標識(Ordinal Identifiers)QTIDE
- JSnaughty: Recovering Clear, Natural Identifiers from Obfuscated JS NamesJSIDE
- [20170618]12c 支援更長的 identifiersIDE
- Altium designer 從原理圖更新至PCB時出現提示:failed to match * of * components using unique identifiersAIIDE
- 【JAVA】java使用Java
- JAVA(三)JAVA常用類庫/JAVA IOJava
- Java 解惑(Java Puzzler)Java
- Java打劫(The Java Heist)Java
- JAVA java學習(24)——————java修飾符Java
- Java 陣列、Java 日期時間、Java 正規表示式、Java 方法Java陣列
- Java 安全之Java AgentJava
- 淺析Java反射--JavaJava反射
- Java 8 + 10 = Java 18Java
- 【Java】A Guide to the Java ExecutorServiceJavaGUIIDE
- 【Java】The Java Headless ModeJava
- 【Java筆記】Java JDKJava筆記JDK
- JAVA面試題 java部分Java面試題
- java基礎-java NIOJava
- java之JAVA異常Java
- java日期 java陣列Java陣列
- Java from SUN & Son of JavaJava
- java Java與編碼Java
- Treasure Of JAVA——JAVA的資料型別(JAVA面試題)Java資料型別面試題
- Java筆記-Java反射(二)Java筆記反射
- Java基礎類庫【Java】Java
- Java學習—java-RedisJavaRedis
- Java:Java的物件導向Java物件
- java分散式(java入門)Java分散式
- Java基礎系列—Java反射Java反射
- 《Java專欄》— 初學JavaJava
- 【java基礎】--Java列舉Java
- JAVA面試題-CORE JAVA部分Java面試題
- java "|"Java
- JavaJava