Why should java package name be lowercase?

2020-01-27 02:08发布

问题:

Actually this is completely theoretic question. But it's interesting why java specification don't allow uppercase characters letters in package and cause write something like this:

com.mycompany.projname.core.remotefilesystemsynchronization.*

instead of

com.myCompanyName.projName.core.remoteFileSystemSynchronization.*

回答1:

Directly from Oracle Docs

Package names are written in all lower case to avoid conflict with the names of classes or interfaces.



回答2:

But it's interesting why java specification don't allow uppercase characters letters in package and cause write something like this:

The specification allows it just fine. It's only a convention to use all-lower-case.

As gtgaxiola says, this does avoid conflict with type names... in .NET naming conventions this does happen, leading to advice that you do not name a class the same as its namespace. Of course, using camelCase packages would avoid the collision entirely.

I suspect reality is that it wasn't thoroughly considered when creating the package naming conventions. Personally I rarely find it to be a problem - if I end up seeing a package with one element of "remotefilesystemsynchronization" then the capitalization isn't the main thing I'd be concerned about :)



回答3:

Its just another convention - One may ask why class name always has to start with Capital or method name starts with small case and then camel-cased. Java doesn't forces you to use that way. Its just that a set of underlined rules helps huge community as Java developers to write easily understandable code for the majority who follow conventions.

No definite reason can be assigned as such. Its just what felt good while writing the convention. But yes guidelines would definitely be there before writing conventions. I don't mean its a whimsical work. Guidelines might be that just by seeing elements we should be able to tell if its class, method or package and all that matters is - in the conventions it has been achieved.