Java Package Vs Folder-Structure? what is the difference

"Packaging helps us to avoid class name collision when we use the same class name as that of others. For example, if we have a class name called "Vector", its name would crash with the Vector class from JDK. However, this never happens because JDK use java.util as a package name for the Vector class (java.util.Vector). So our Vector class can be named as "Vector" or we can put it into another package like com.mycompany.Vector without fighting with anyone. The benefits of using package reflect the ease of maintenance, organization, and increase collaboration among developers. Understanding the concept of package will also help us manage and use files stored in jar files in more efficient ways."

check out http://www.jarticles.com/package/package_eng.html for more information on packages


Basically there is no difference, both are the same.

In both the cases, the folder structure will be src/com/utils.

and in both the cases, you will need to mention

package com.utils;

as first line in the class

Since it doesn't have any difference practically, it won't make any difference to ant script.


If you configured stuffs correctly. Adding a folder inside src, is same as adding a package from File > New Package.

So, it's up to you, whatever feels comfortable to you -- add a folder or create a package. Also, when you put stuffs under src the package name starts from subfolder. So, src/com/naishe/test will be package com.naishe.test.