Code Style Sun Naming Conventions see http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html Package Names The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981. Subsequent components of the package name vary according to an organization's own internal naming conventions. Such conventions might specify that certain directory name components be division, department, project, machine, or login names. Class and Interface Names Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML). Interface names should be capitalized like class names. Method Names Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Variable Names Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed. Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary "throwaway" variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters. Constant Names The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores ("_"). (ANSI constants should be avoided, for ease of debugging.) Bad Practice Searches for code that represents bad practice Overriding of finalize() The finalize method should not be overridden UpdateUI Calls Normally there is no need to call updateUI, did you mean repaint()? Calls from inside the method updateUI are ok! Mutable public fields Mutable static fields could be changed by malicious code or by accident from another package Final class with final methods There is no need to mark a method in a final class as final. This is implied by the context Call java.lang.System#exit(int) Force Garbage Collection Wrong Logging Abstract class should be named Abstract* Abstract class contains no abstract method Classes that only have private constructors should be declared final Because it's impossible to inherit from a class that has only private constructors the class should be declared final. To minimize false positives the cql checks if all methods are static Utility class should be named *Util, *Helper or *Factory Classes that only have private constructors and only consist of static classes should be named *Util, *Helper or *Factory Constant interface antipattern Do not use interfaces for holding constants. Prefer using final classes Interface declaring Object's methods It's absolutely unnecessary to declare methods from java.lang.Object in an interface Classes without toString/equals/hashCode implementation Each (endpoint) class should override Object#toString(), Object#equals(Object) and Object#hashCode() Use Boolean#valueOf() instead of new Boolean(boolean) Do not instantiate Booleans, use the constants Boolean.TRUE and Boolean.FALSE or use the static factory method Boolean#valueOf(boolean) (boolean)') } }; ]]> Class extending superclass without declaring a new member-method or overriding an existing one There's not much sense for extending a superclass if the extending class contains static methods only Favor composition over inheritance Classes extending classes outside of their own package (or better: classes not written by yourself) is dangerous and can lead to fragile software. Consider usage of composition instead of inheritance [Effective Java Item 26] Don't provide reset methods Classes offering reset methods often indicates poor design quality and usually lead to problems in a multi-threaded context. Loose coupling A method's returntype should be the interface instead of the concrete implementation. Do not refer SwingUtilities2 Since SwingUtilities2 is not a public API you should never refer SwingUtilities2 (or any other sun/com.sun classes) Do not create/throw java.lang.Errors An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. If you'd like to throw an unchecked exception you should throw an exception extending RuntimeException Do not call equals on StringBuilders/StringBuffers Equals is not implemented properly in those classes, new StringBuilder("foo").equals(new StringBuilder("foo")) will return false Do not provide methods with invisible returntypes If a method contains classes in its signature with a lower visibility than the method itself it cannot be used in the context it is intended Do not provide methods with invisible parameters If a method contains classes in its signature with a lower visibility than the method itself it cannot be used in the context it is intended Metric-based Rules Small Method Signatures A method should not have more than 5 parameters (PC=Parameter Count) ','5') }; ]]> Classes with too many Methods/Fields A method should not have more than 10 public methods nor more than 15 fields (PMC=Public Method Count, FC=Field Count). Because enums easily can have more than 15 fields they are excluded ', '10') | { metric('FC', '>', '15') && !modifier('ENUM') } }; ]]> No excessive Inheritance A class should not have more than 4 parents (PARC=PARent Count) ','4') }; ]]> No excessive overriding A method should not be overridden more than 3 times (MOC=Method Overriding Count) ','3') }; ]]> Too many constructors A class should not have more than 5 constructors (CC=Constructor Count) ','5') }; ]]> Unused Code Private Unused Methods Method that are private and unused within the declaring class can be removed. Although the unused filter tries to detect calls done via reflection you should be sure the code is really not accessed by reflection before removing it. Private Unused Fields Fields that are private and unused within the declaring class can be removed. Although the unused filter tries to detect calls done via reflection you should be sure the code is really not accessed by reflection before removing it.