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.*
The package names do not follow camel casing or underscores or hyphens package naming convention.
singular just like database table names should always be singular but for different reasons. Look at any popular standard library like Java or Python for example.
As you (implicitly) acknowledged, you are not required to declare the name of a package in the case if the default package. Let us put that quibble aside ... The reason for this seeming redundancy is that without a package declaration, the meaning of Java1 source code would be ambiguous.
MyPackageClass.java ", like in the example above. Note: The package name should be written in lower case to avoid conflict with class names. When we compiled the package in the example above, a new folder was created, called "mypack".
Directly from Oracle Docs
Package names are written in all lower case to avoid conflict with the names of classes or interfaces.
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 :)
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 and was in practice by then majority programmers while writing the convention. But yes guidelines would definitely be there before writing conventions. I don't mean its a whimsical work. Guidelines are made so that just by looking at the various elements we should be able to tell if its class, method or package - and via following conventions it has been achieved for so long now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With