Creating classes in Netbeans

I have a bit of experience with Netbeans, I am currently using Netbeans 6.5 RC. I create a new project and then when I go to add a new class to the "default package" it says at the bottom of the dialog box that it is highly recommended that I don't place java classes in the default package.



First, I wonder why it is recommended that I don't do this.



Second, to follow this recommendation, do I just add a new package to the project (for example, add a package called HelloClasses) and then add my classes to that package (putting "package HelloClasses;" at the top of each class in that package)?

Second, yes.

You use packages to organize your code, for yourself and for other people using your code. Also packages separate your classes from similarly named classes in other libraries.

Thank you… now why couldn't Netbeans have just said that… ha!

There is an even better reason to not use the default package: classes in other packages will be unable to access them.



Not having a package name means the class loader won't be able to distinguish beween a class in the same package and a class in the default package. So, in order to avoid that ambiguity, the class loader won't look for classes in the default package at all when importing classes without explicit package declaration, but only for classes in the same package.