Naming convention for utility classes in Java

Posted by Zarjay on Stack Overflow See other posts from Stack Overflow or by Zarjay
Published on 2010-04-20T16:10:28Z Indexed on 2010/04/20 16:13 UTC
Read the original article Hit count: 287

When writing utility classes in Java, what are some good guidelines to follow?

Should packges be "util" or "utils"? Is it ClassUtil or ClassUtils? When is a class a "Helper" or a "Utility"? Utility or Utilities? Or do you use a mixture of them?

The standard Java library uses both Utils and Utilities:

  • javax.swing.Utilities
  • javax.print.attribute.AttributeSetUtilities
  • javax.swing.plaf.basic.BasicGraphicsUtils

Apache uses a variety of Util and Utils, although mostly Utils:

  • org.apache.commons.modeler.util.DomUtil
  • org.apache.commons.modeler.util.IntrospectionUtils
  • org.apache.commons.io.FileSystemUtils
  • org.apache.lucene.wordnet.AnalyzerUtil
  • org.apache.lucene.util.ArrayUtil
  • org.apache.lucene.xmlparser.DOMUtils

Spring uses a lot of Helper and Utils classes:

  • org.springframework.web.util.UrlPathHelper
  • org.springframework.core.ReflectiveVisitorHelper
  • org.springframework.core.NestedExceptionUtils
  • org.springframework.util.NumberUtils

So, how do you name your utility classes?

© Stack Overflow or respective owner

Related posts about java

Related posts about naming-conventions