Java Coding Standard
Naming Methods
Methods should be named using a full English description, using mixed case with the first letter of any non-initial word capitalized. It is also common practice for the first word of a method name to be a strong, active verb. Boolean getters should use ‘is’ or ‘can’ or ‘has’ as a prefix.
Examples:
openAccount()
printMailingLabel()
save()
delete()
canStore()
canPrint()
hasDependants()
Naming Assessor Methods
Getters
Getters are methods that return the value of an attribute. Prefix the word ‘get’ to the name of the attribute.
Examples:
getFirstName()
getAccountNumber()
getLostEh()
isPersistent()
isAtEnd()
Boolean getters should use ‘is’ or ‘can’ or ‘has’ as a prefix.
Examples:
canStore()
canPrint()
hasDependents()
Setters
Setters are methods that modify the values of an attribute. Prefix the word ‘set’ to the name of the attribute, regardless of the attribute type.
Examples:
setFirstName(String aName)
setAccountNumber(int anAccountNumber)
setReasonableGoals(Vector newGoals)
setPersistent(boolean isPersistent)
setAtEnd(boolean isAtEnd)
Documenting Methods
Documenting a method is often the deciding factor as to whether or not it is understandable, and therefore maintainable and extensible.
The Method Header
Every Java method should include some sort of header, called method documentation, at the top of the source code that documents all of the information that is critical to understanding it. This information includes, but is not limited to the following:
What and why the method does what it does. By documenting what a method does others can determine if they can reuse the code. Documenting why it does something makes it easier for others to put the code into context.
What a method must be passed as parameters. Indicate what parameters, if any, must be passed to a method and how they will be used. This information is needed so that other programmers know what information to pass to a method. Use the javadoc @param tag for this purpose.
What a method returns. Document what, if anything, a method returns so that other programmers can use the return value/object appropriately. Use the javadoc @return tag for this purpose.
Known bugs. Any outstanding problems with a method should be documented so that other developers understand the weaknesses/difficulties with the method. If a given bug is applicable to more than one method within a class, then it should be documented for the class instead.
Any exceptions that a method throws. Document any and all exceptions that a method throws so that other programmers know what their code will need to catch. Use the javadoc @exception tag for this purpose.
Include a history of any code changes. Whenever a change is made to a method, document when the change was made, who made it, why it was made and when it was made. This history information is critical for the future maintenance programmers who are responsible for modifying and enhancing the code.
Example :
/**
* Checks a object for "coolness". Performs a comprehensive
* coolness analysis on the object. An object is cool if it
* inherited coolness from its parent; however, an object can
* also establish coolness in its own right.
*
* @param obj the object to check for coolness
* @param name the name of the object
* @return true if the object is cool; false otherwise.
* @exception OutOfMemoryError If there is not enough memory to
* determine coolness.
* @exception SecurityException If the security manager cannot be
* created
**/
public boolean isCool(Object obj, String name)
throws OutOfMemoryError, SecurityException
Services: - Java Coding Standard Homework | Java Coding Standard Homework Help | Java Coding Standard Homework Help Services | Live Java Coding Standard Homework Help | Java Coding Standard Homework Tutors | Online Java Coding Standard Homework Help | Java Coding Standard Tutors | Online Java Coding Standard Tutors | Java Coding Standard Homework Services | Java Coding Standard