Java Package Vs Folder-Structure? what is the difference

I would like to know What are the difference between folder-structure and package used in Eclipse IDE for Java EE development.

When do we use which one and why?.

Whats should be the practice

  • create a folder structure like src/com/utils and then create a class inside it
  • create a package like src.com.util and then create a class inside it

which option would be better and easy to deploy if i have to write a ant script later for deployment ?

if i go for the folder-structure will the deployment is as easy as copying files from development to deployment target ?


Solution 1:

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.

Solution 2:

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.