Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should java package name be lowercase?

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.*
like image 776
Oleksii Kolotylenko Avatar asked Sep 21 '12 16:09

Oleksii Kolotylenko


People also ask

Should package name be Camelcase in Java?

The package names do not follow camel casing or underscores or hyphens package naming convention.

Should package names be singular or plural Java?

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.

Is package name necessary in Java?

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.

What is the case used for a package in Java?

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".


3 Answers

Directly from Oracle Docs

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

like image 50
gtgaxiola Avatar answered Oct 13 '22 10:10

gtgaxiola


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 :)

like image 28
Jon Skeet Avatar answered Oct 13 '22 09:10

Jon Skeet


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.

like image 21
nanosoft Avatar answered Oct 13 '22 09:10

nanosoft