Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java package naming

Okay, so I'm wanting tips on how to pick a name for my Java packages.

I saw this post: What package naming convention do you use for personal/hobby projects in Java? but this talks about personal projects.

What if for example I wanted to make an API Wrapper, and I develop with others on GitHub? I don't have a domain name.

like image 563
LanguagesNamedAfterCofee Avatar asked Feb 24 '23 23:02

LanguagesNamedAfterCofee


2 Answers

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.

like image 195
Cameron Skinner Avatar answered Mar 06 '23 19:03

Cameron Skinner


The recommendation has always been to start with your domain name backwards, then the project name, e.g. com.mycompany.myproject, and continue on with submodules as necessary.

like image 29
user207421 Avatar answered Mar 06 '23 19:03

user207421