What Package Naming Convention Do You Use for Personal/Hobby Projects in Java

What package naming convention do you use for personal/hobby projects in Java?

If you're just doing personal projects where nobody else will use the code, then you can make up a package name that you like. Don't make up something that starts with com. or net. or other top-level domain though, because that would imply that you own the domain name (ie. using com.john as your package name just because your name happens to be John is not a good idea).

If you're going to give the code to anybody else, you should use a globally unique package name, which according to Java conventions means you should register and use a domain name.

How to name package of my own project?

You can choose any naming convention you like for your personal, private projects.

However I would suggest sticking to the standard Java naming conventions as much as you can:

  • It will help avoid namespace collisions if you ever publish your code in the future
  • It's always good to follow standard practices (if only to maintain good habits!)

Java package naming

The domain-name-backwards convention is there to prevent name collisions. Two different companies with the same product name will have different namespaces so everything works fine.

If you don't have a domain then you need to choose a name that is meaningful to you and will not collide with anything else. That's OK; it just means very slightly more work for you to make sure that there isn't an existing product with the name you want, and there may be difficulties if there ever is a name collision.

You won't be the first to do this: the JMockit library is all in the "mockit" namespace with no "com" or "org" prefix.

How to name a Java package as a student

The idea of naming your packages is would you ever want to use your packages with third party packages yours should be unique to prevent duplicate classnames in the project. Also unique package name is required would you ever upload an apk to google play store.

For college I think you are safe enough using the suggested package-name as long as you use both name and surname. For personal projects you could use your github uri, which by default is unique, but you could also consider buying a domainname and use that one.

What's the convention for java package names without a domain association?

If you are going to be distributing a lot of stuff, I would really suggest getting a domain name. Another alternative however would be to use your e-mail: e.g. bob@gmail.com would become com.gmail.bob. This is less common than using domain names but is still done by some and still ensures uniqueness.

Are there best practices for (Java) package organization?

Package organization or package structuring is usually a heated discussion. Below are some simple guidelines for package naming and structuring:

  • Follow java package naming conventions
  • Structure your packages according to their functional role as well as their business role

    • Break down your packages according to their functionality or modules. e.g. com.company.product.modulea
    • Further break down could be based on layers in your software. But don't go overboard if you have only few classes in the package, then it makes sense to have everything in the package. e.g. com.company.product.module.web or com.company.product.module.util etc.
    • Avoid going overboard with structuring, IMO avoid separate packaging for exceptions, factories, etc. unless there's a pressing need.
  • If your project is small, keep it simple with few packages. e.g. com.company.product.model and com.company.product.util, etc.
  • Take a look at some of the popular open source projects out there on Apache projects. See how they use structuring, for various sized projects.
  • Also consider build and distribution when naming ( allowing you to distribute your api or SDK in a different package, see servlet api)

After a few experiments and trials you should be able to come up with a structuring that you are comfortable with. Don't be fixated on one convention, be open to changes.

Do I ought to follow naming conventions for Java packages?

Conventions are not mandatory but help

  • YOU to create bettter code and
  • OTHERS to understand it easier:

According wikipedia:

Reasons for using a naming convention (as opposed to allowing programmers to choose any character sequence) include the following:

  • to reduce the effort needed to read and understand source code
  • to enable code reviews to focus on more important issues than arguing over syntax and naming standards.
  • to enable code quality review tools to focus their reporting mainly on significant issues other than syntax and style preferences.
  • to enhance source code appearance (for example, by disallowing overlong names or unclear abbreviations).


Related Topics



Leave a reply



Submit