Should Java class name duplicate package name?

I would prefer to be explicit (and perhaps verbose) to being concise (and perhaps ambiguous).

Your example re. Dispatcher / Event is a good one. If you're unlucky, you'll end up having to fully qualify each occurrence of these to resolve any ambiguities.

In such a scenario you'll end up either with a lot of verbose code, or restructuring your code such that conflicting classes don't co-exist (conflicts may actually act as an indicator that unrelated entities are co-existing, but that's another discussion)


I would also definitely go for the less ambiguous names. Using any names which might conflict with other packages also:

  • causes problems for the human reader of the code. If I see "Event" then I may assume it's a common Java library and the only way to resolve this is to read back to the import statement.
  • causes problems for IDEs. Eclipse, for example, sometimes "helpfully" guesses the most likely package. List, Element, Attribute, etc. may be imported from packages you never even knew existed! And it can be a surprising amount of wasted time to debug this.

I'll definitely go for the first one, that is, StatisticsDispatcher and StatisticsEvent because the words Dispatcher and Event used alone could mean a lot of things (particularly in Java EE).