I'm trying to get in the practice of using packages for my HW assignments and my personal projects. As a student of a university would it be proper for me to use edu.university_name.my_name.package_name?
As for personal projects it seems a lot of people are recommending that one should use their GitHub domain. If I one day plan on using my personal code in an application would using my GitHub domain be a proper way to name a package?
Just looking for a little advice
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.
Your naming convention edu.university_name.my_name.package_name looks fine.
For other purposes I recommend you to use the domain you would like to use one day, e.g. org.steveclark.package.
An Internet domain (like a GitHub domain) is unique. A family name is generally not unique . So I would recommend you to use a name that you know is unique across Internet.
Related
I can't find a Q/A on SO that answers my exact question, so I figure I'd post it and see what comes back.
As far as the naming convention goes for Java packages, I understand that it's supposed to be the reverse domain name: com.whatever.stuff and I get the rules about no mixed case, hyphens, keywords, etc.
I've also read section 7.7 (Unique-Package-Names) of the Java Language Specification. As far as I can tell, the rules from Java are to use the reverse domain to insure uniqueness... and if you don't have one, go get one:
You form a unique package name by first having (or belonging to an organization that has) an Internet domainname, such as sun.com. - Section 7.7
So if I'm not interested in shelling out the money for a domain name, I don't belong to a company whose name I can piggyback off of, is there any part of the naming convention that I'm missing that should be followed? I'm thinking I can just go name it whatever unique name I feel like at this point, but I was just wondering if I was missing anything.
Note: I would like to release my package for other developers to use, so I didn’t want to just do something that worked on my system, but something more standard if possible.
I added the android tag because the java packages I'm going to be writing are going to be used in an Android application, wasn't sure if there were different opinions from android developers.
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.
One convention is to use the domain name of the hosting provider, e.g.
com.github.myrepositoryname
net.sf.sourceforge.myproject
com.googlecode.myproject
Benefits:
your package namespace will be unique, since the hosting provider won't have two projects of the same name
it's only as expensive as the host's costs, many of which are free
it can be an easy way to fulfil Sonatype's requirements if you want to get your project into Maven Central
Drawbacks:
if you decide to change providers, you either have package structures which are out-of-date, or you introduce backward-incompatible changes to keep the source in line with your new provider
Domain names can be had for free.
For example dyn.com offers free domain names of the form 'whatever.dyndns.org' at http://free.domain.name/
If you are the only coder, you can just use your name.
My name is Jannis Froese, so I would use
jannisfroese.projectname.stuff
or if you want to stay with 'valid' domain names
localhost.jannisfroese.projectname.stuff
(localhost is a reserved top level domain)
Of course this only works if your name is sufficiently unique, so that a collision is unlikely enough
In a professional environment, the convention is to use reverse domain. In an environment that's more associated with yourself, you can use org.projectname.packagename.*.
It's a convention, not a hard and fast rule. You're free to use whichever domain naming style you like.
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.
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.
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.
From what I understand Java packages often use a company's website as a package namespace.
For example if stackoverflow had a Java widget library it might be called com.stackoverflow.widget.
But what happens if you use an obscure TLD. Is info.example.widget acceptable?
Sure, no problem. Whatever your company's domain name and whatever its TLD is, reverse the order of its components for your Java packages.
The intent of using a domain name is that it helps ensure uniqueness using something that pretty much any organization will already have. That means that no one really needs to be 'responsible' for doling out uniques IDs for package names (or that something ugly like the GUIDs used by COM don't need to be used).
So even if your domain name is obscure, by all means use it - it's still unique.
I have a hobby opne source Java project hosted at google code (linkset).
May I use a prefix "com.google.code.linkset" as a package name for this project?
P.S.
I dont own "org.linkset" domain :( but i like the name :)
the name of your packages does not have to reflect the domain it's hosted at.
I think using com.google prefix will mislead your users into thinking the code was developed at google. don't do it unless you want to handle the backfire from your users when they realize it's not.
Since it would be misleading as Omry already mentioned, why not use org.lbownik.util.linkset?
You can use pretty much anything as a package name, provided that it respects the java spec (no keywords, not starting with a number ...)
But really you shouldn't unless you work at Google!
If you name your package com.google.code.linkset it is possible that sometime in the future you will receive a "cease and desist" letter from Google's lawyers, citing your package name as infringing Google's registered trademarks.
EDIT
If you ever do receive such a letter, do not ignore it based on some amateur legal theorizing you read on some website. If you want to resist the demand, you should first talk to a professional lawyer.
I think using com.google in your domain is a mistake, since it will imply that your project is owned/endorsed by Google. However, people have been using net.sourceforge in their Sourceforge-based projects for years, and this is really the same thing. I didn't think that was a good idea, either. So while you can use com.google in your domain, I think it's a bad idea and you should use something else.
If you don't have a somewhat authorative domain-like name for the project, use something that obviously recognizable as not a reversed domain!
Technically, you should be able to use:
hobby.code.linkset
Have a look for example at junit and antlr. It's preferred to use a true hierarchical organization, but for a small hobby project you can start with a name such as this. You should be prepared to later on refactor your code to a real domain, once you have settled and the project grows.
I've read the syntax conventions for naming Java packages, and I know the general rule of thumb, but what if you've just started building your application, you haven't chosen a license, and it is a personal project? It doesn't make sense to throw in "com.mycompany" or "org.myorganization" if that is not the case. Does anyone have suggestions for this?
Many Java books and online examples just use the name of the book or project, i.e., ejb3inaction.* or tutorial.*.
I usually just go with something like lastname.firstname.<other packages>. The package name should just be unique, and the combination of your last name and first name is probably unique enough (if you have a common name, throw in a middle initial or a middle name or something like that).
Perhaps org.{myname} ?
I don't think it particularly matters for personal projects. In fact I've seen commercial (in-house) projects flout this rule and simply call their packages {servicename} or similar (which I don't particularly like). The packaging rules are designed to prevent name clahes when sharing code cross-enterprise (or organisation) and consequently for personal projects you can use most anything.
Java packages are just for namespacing. Call it whatever you want! Think of something that will be useful to you later on when you want to remember what this code was supposed to do.
how about org.{projectname}? Think about some open-source projects (e.g. org.hibernate, org.springframework and org.junit) ... did they start this way because it was the name of the website, or the name of the project itself?
Besides, re-factoring is so trivial these days, just name it whatever you want.
What about name.yourname.myproject or net.sf.myproject or com.googlecode.myproject or simply myproject.
As long as you don't make your code public, it's not that important actually (and you can easily refactor it later before releasing your code if you need to). Once people start using your code, it's another story...
In the case you might also think about sharing the project (making it an open-source project), to open an project entry, in that case you can use something like 'net.sf.{project-name}.*', be careful here, that the project-name, must be the unix name, of the project (at least then you follow the rules correctly :)
SourceForge
Java Net
Google Code
Launchpad
JavaForge
Tigris.org
I generally use nl.myname.myapp for all personal projects. There is no rule against open sourcing something that uses your personal name. If you decide to make the project bigger and create a web site for it you can always rename the packages if you really want to.