Often, in libraries especially, packages contains classes that are organized around a single concept. Examples: xml, sql, user, config, db. I think we all feel pretty naturally that these packages are correct in the singular.


However, if I have a package that actually contains a collection of implementations of a single type - such as tasks, rules, handlers, models, etc., which is preferable?




  • 11
    singular just like database table names should always be singular but for different reasons. Look at any popular standard library like Java or Python for example.
    – user7519
    May 12, 2011 at 18:39
  • 1
    @Jarrod Roberson: Please post your answer as an answer so we can upvote it properly.
    – S.Lott
    May 12, 2011 at 18:43
  • @Jarrod gonna need some examples, since in standard libraries most classes fall into the first category I listed.
    – Nicole
    May 12, 2011 at 19:03
  • @Renesis Take a look at my updated answer. May 12, 2011 at 19:19
  • @Matthew - I like it. You've expressed what I suspected but wasn't sure how to codify.
    – Nicole
    May 12, 2011 at 19:23

2 Answers 2


Use the plural for packages with homogeneous contents and the singular for packages with heterogeneous contents.

A class is similar to a database relation. A database relation should be named in the singular as its records are considered to be instances of the relation. The function of a relation is to compose a complex record from simple data.

A package, on the other hand, is not a data abstraction. It assists with organization of code and resolution of naming conflicts. If a package is named in the singular, it doesn't mean that each member of the package is an instance of the package; it contains related but heterogeneous concepts. If it is named in the plural (as they often are), I would expect that the package contains homogeneous concepts.

For example, a type should be named TaskCollection instead of TasksCollection, as it is a collection containing instances of a Task. A package named com.myproject.task does not mean that each contained class is an instance of a task. There might be a TaskHandler, a TaskFactory, etc. A package named com.myproject.tasks, however, would contain different types that are all tasks: TakeOutGarbageTask, DoTheDishesTask, etc.

  • 16
    For a similar question, see english.stackexchange.com/q/25713. A category is analogous to the singular and a type is analogous to the plural. May 17, 2011 at 15:11
  • 6
    The very link you provided shows an exception to this rule. beans is plural, however java.beans contains all kind classes related to JavaBeans. Sep 18, 2012 at 12:11
  • 1
    So essentially name a package plurally if it has classes that really do serve different puprposes or whatever, but which are just similarly-themed, and name a package singularly if it just contains classes that heavily focus on coming together as a sort of "meta-class" for a single purpose? Oct 22, 2013 at 18:09
  • 4
    @SkyDan's comment points out something very important that is being entirely overlooked here. It appears to me that the plural naming of "java.beans" was actually a mistake, and it should instead have been named "java.bean", singular. Nov 21, 2015 at 22:14
  • 11
    @VickyChijwani @SkyDan since JavaBeans™ is a trademark, they probably wanted to keep the name as-is to refer to the technology itself, and hence they used java.beans.
    – Hejazi
    Jul 28, 2016 at 7:52

This probably depends on a specific language. In .NET (C#) it most definitely should be a plural if a namespace-type name collision is likely (the type name expected but namespace found error). I've dealt with this, it's not pleasant and results in over-qualifying type names all over the code. Example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.