views:

37

answers:

3

Hi folks,

I'm a beginner in programming web apps with jee. How do you name your packages?

I often saw stuff like com.abc.commons... is there a standard or a common way to do that?

cheers


Thanks to seanizer, I gonna use your approach: com.mycompany.myproject.api

+2  A: 

Yes, see the Sun Naming Conventions.

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.

Examples:

  • com.sun.eng
  • com.apple.quicktime.v2
  • edu.cmu.cs.bovik.cheese
Péter Török
A: 

The customary way is to do your own domain backwards, as this is a pretty good guarantee that others do not accidentially use those package names.

Thorbjørn Ravn Andersen
+1  A: 

These parts usually enter into my package names

  1. Domain name (your's or your company's / customer's) backwards
  2. Project name
  3. Artifact name (api, client, test etc.)
  4. Functionality

example:

com.mycompany.myproject.api.services
// contains service interfaces for project myproject

com.mycompany.myproject.common.util.string 
// contains string-related utility classes that reside in a library module
// that will be used by several other artifacts

One good practice is to have a common root package that is distinct for an individual project (jar etc). For example: in the jar myproject-api.jar , the root package would be com.mycompany.myproject.api. That way you always know where to find your classes.

seanizer