Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java package name convention failure

I'm just coming up the learning curve for Java SE & have no problem with the usual Java convention for package names, e.g. com.example.library_name_here.package_name_here

Except.

I've been noticing a failure to abide by this in some fairly well-known packages.

  • JLine: jline.*
  • JACOB: com.jacob.* (there is no jacob.com)
  • JNA: com.sun.jna.* (disclaimer on the site says NOTE: Sun is not sponsoring this project, even though the package name (com.sun.jna) might imply otherwise.)

So I'm wondering, are there instances where the usual reverse-domain-name convention breaks down, and there are good ways to get around it? The only cases I can think of revolve around domain-name ownership issues (e.g. you change the project hosting/domain name, or there's already a well-known package that has "squatter's rights" to your domain, or your ownership of the domain runs out & someone else snaps it up).

edit: if I use my company's domain name, and we are bought out or have a spin-off, what should we do with package names? keep them the same or rename? (I suppose renaming is bad from the point of view that compiled classes referring to the package then lose)

like image 328
Jason S Avatar asked Jan 07 '09 16:01

Jason S


3 Answers

It's a naming convention. There's no real requirement or even expectation that the package name maps to a domain name.

like image 118
sblundy Avatar answered Sep 23 '22 23:09

sblundy


The general idea is that two organizations would not own the same domain, so using the domain name as part of the package ensures that there are no namespace clashes. This is only a recommendation however.

There is a good reason for someone to have packages in the sun namespace. If they are providing an implementation of a public API, it's often necessary to implement the classes in the API's namespace.

like image 31
Martin OConnor Avatar answered Sep 23 '22 23:09

Martin OConnor


If you're making your way up the Java learning curve, I would worry more about making your packaging structure clear so you can easily find the class you are looking for.

like image 35
James Camfield Avatar answered Sep 21 '22 23:09

James Camfield