0

When I create a stand-alone Java program, which only has one or two java/class files and is not shared with other programs, I never take the time to say org.domain.scripts.purpose in the package name. I typically just make my main class main.Main.

Perhaps this is against protocol, but when duplicating a program in order to fill another small niche requirement (like converting tab delimited to csv or recursively listing files sorted by modify date), I will not be made to rename the package name or to suffer through long package names and paths when I already know what program I am in.

Also little generic classes (like Base64 conversion) are easier to copy from one program to another when they do not have unique package names.

So, what would be a standard generic package name (or is there one)

Edit: I suppose I will go ahead and mention some more reasons. It is easier to diff files or to see if they are identical when they have the same package name. Also, when I need a library to be included, I make a usage note that includes java -cp library:jarfile instead of java -jar and the cp option requires I set the main class name, so I like to have it short there too. Also the stack traces look better that way.

700 Software
  • 85,281
  • 83
  • 234
  • 341

5 Answers5

5

There is no standard generic package name. There are, however, naming conventions to name a package:

  • Package names are written in all lowercase to avoid conflict with the names of classes or interfaces.
  • Companies use their reversed Internet domain name to begin their package names—for example, com.example.orion for a package named orion created by a programmer at example.com.

References:

João Silva
  • 89,303
  • 29
  • 152
  • 158
1

"foo" is what I most often see used for such a purpose.

jhouse
  • 2,674
  • 1
  • 18
  • 17
1

As far as some of the problems you listed with longer package names, most IDEs handle all that for you even when copying from one project to another.

jzd
  • 23,473
  • 9
  • 54
  • 76
  • They certainly make things easier. But they do not make it beneficial to have longer package names. And humans do not always do things in the order that IDEs like. – 700 Software Feb 01 '11 at 22:56
  • @George, I typically use Eclipse and actions like copying and pasting or dragging classes to other packages are handled nicely and automatically. – jzd Feb 01 '11 at 23:08
  • I don't want to be argumentative. But I suppose I will go ahead and mention some more reasons. See my edit. – 700 Software Feb 02 '11 at 16:33
0

That may be fine as long as you don't use code written by another similarly lazy developer :-) Guess what happens if the compiler finds two classes named Base64 in the default package...

Using proper package names is meant to avoid name conflicts. Most modern IDEs make migration of class(es) to a different package a breeze, so I don't think it is an issue. However, once you have a name clash, it becomes a problem if you need to go back and migrate the class in 100 older projects. Or it becomes a problem when you don't, and then you need to fix a bug in all the different versions of the class...

So if you write code for yourself, the simplest choice would be to put it into package net.georgebailey. General utilities can then go into net.georgebailey.util.

Péter Török
  • 114,404
  • 31
  • 268
  • 329
0

I think the closest thing to a "standard generic" package name would be the default package (or the no-package, if you like). Of course this is bad practice, but I understand we're talking about tiny experiments and not production code.

However, one of the major drawbacks of the default package (besides being merely the lack of a namespace) is that you cannot import classes in the default package from a named package.

Therefore, for your experiments, if you just want single-segment package names, go with whatever suits you: test, pkg, main (as you mentioned) or whatever...

Costi Ciudatu
  • 37,042
  • 7
  • 56
  • 92