79

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.*
Martin Schröder
  • 4,176
  • 7
  • 47
  • 81
Oleksii Kolotylenko
  • 1,021
  • 1
  • 8
  • 9
  • possible duplicate of [What is the convention for word separator in java package names?](http://stackoverflow.com/questions/3179216/what-is-the-convention-for-word-separator-in-java-package-names) – Martin Schröder Aug 04 '15 at 14:58
  • 9
    No, this is not a duplicate of that as in this article I'm interesting about the reason of such conventions. – Oleksii Kolotylenko Jan 02 '16 at 12:42

3 Answers3

120

Directly from Oracle Docs

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

gtgaxiola
  • 9,241
  • 5
  • 42
  • 64
  • 15
    Package names are also used in conjunction with filesystem directories, which often have restrictions on character case themselves. – Will Sep 21 '12 at 16:25
  • 14
    Who uses a file system without upper case support? You have either ext3, NTFS or the mac thing, we are not in the nineties anymore – Mike76 Sep 01 '16 at 21:18
  • 5
    "to avoid conflict with the names of classes" -> You cannot confuse com.site.myName with class name because in case of class, it would be com.site.MyName (starting with capital letter). So there is no logic in favour of "myname" approach. I think "myName" is better because it is easier to read. E.g. "com.marvel.movies.gardiansofthegalaxy" – JRr Aug 23 '17 at 08:38
  • yes, theoretically. But not practically. It's actually pity that it's just a convention.I came here because I need to change my colleague's code and he uses a package name in the form `company.AppName.something.else`. Once you allow upper case letters someone will use them the wrong way. If I now wanted to add a class `company.AppName`, I'd need to rename the whole package - which I'll probably do anyway, sooner or later. ;-) BTW, isn't remoteFileSystemSynchronization a bit too long for a package name anyway? – tomorrow Jul 11 '18 at 09:02
  • 3
    In your case, AppName isn't lowerCamelCase as @joro indicates (in your case, I would probably strangle the person who created the AppName, just as I wanted to strangle someone in our company who created classes starting in lower cases...). I'm part of the developpers thinking that com.pany.app.tableOfContents is easier to read than com.pany.app.tableofcontents (or com.pany.app.toc). And com.pany.app.table.of.contents is even worse... – Nedorot Aug 17 '18 at 15:34
  • Also, consider the class under such a Capitalized package vs an inner class. Quite confusing, eh? e.g. my.app.Service.Executor – Brendan Kim Apr 11 '19 at 17:06
  • Actually, examples in the Java Specification break this convention : you find `package pointsUser` as an example in § 6.6. It seems that it came as an second thought (using the same conventions as for functions and variables would have been fine too). – khaemuaset Feb 24 '23 at 10:52
43

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

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • True @Jon! same goes for Class Names starting with Upper Case – gtgaxiola Sep 21 '12 at 16:23
  • so basically, a package sub-part name beggining with lower case and further words in upper case (like methods) will have no chance to collide with classes as long they all begin in uppercase right? :), but most importantly, that would be the only problematic collision related to it, as I cant see a package sub-part name colliding with a method name... – Aquarius Power Nov 15 '16 at 18:27
  • The convention was move to: https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-namespaces – Flimtix Jun 09 '22 at 10:35
1

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.

nanosoft
  • 2,913
  • 4
  • 41
  • 61