• Post Reply Bookmark Topic Watch Topic
  • New Topic

Naming conventions for Java packages.  RSS feed

 
matthew peter
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I'm not entirely sure what to name my packages. Sometimes I have to many and it becomes overwhelming. Sometimes I don't have enough and I cannot keep my files organized. What is a good naming convention for Java packages?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All lowercase.

It's also conventional to use a (reversed) domain that you own to prevent collisions. I own bibeault.org, so I can use org.bibeault without fear of colliding with someone else's name (unless they break the rules).

I then follow that with the project name. For example, org.bibeault.bddb (where bddb is the project name -- I'll leave what the acronym stands for up to your imagination), or org.bibeault.blackbox.

From there, the organization depends upon the needs of the project.

Sometimes, you don;t get much choice. The Play! framework, for example, dictates a simplified flatter package structure without much choice for artistic expression.
 
Amir Al Take
Greenhorn
Posts: 15
Java Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
All lowercase.


I disagree with you about this point. Imagine if you give class a name consisting of 3-5 words and all are lowercase, so difficult to read. I highly suggest using Capitalized first letter / word. For example if my class name would be JDBC Generalized Naming Template, you wouldn't name it like jdbcgeneralizednamingtemplate <- very difficult to read. More convenient would be JdbcGeneralizedNamingTemplate <- much easier to read.

Another point I want to add is to give descriptive class names if possible and not giving class names more than 5 words long.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amir Al Take wrote:
All lowercase.

I disagree with you about this point. Imagine if you give class a name consisting of 3-5 words and all are lowercase, so difficult to read. I highly suggest using Capitalized first letter / word.

You seem to have missed that the point under discussion is package names, not class names. Package names are all lowercase, as Bear said. Class names are in camel case, as you said.
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

There is a section in the Java Tutorials about packages, including naming conventions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!