Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 973
Mrinmoy Avatar asked Mar 01 '12 05:03

Mrinmoy


People also ask

What is the difference between a package and a folder?

Packages are self-contained Project Files. Everything you need for your Project is saved inside the Package. Which makes it easy to share. Folders are slightly more transparent and accessible.

What is the difference between folder and package in Eclipse?

The difference is the Build Path: whatever folder is under the build path is a JAVA package. If your build path is /src/main/java then src, main, java are folders. If inside /src/main/java , your app is structured like this com/foo/bar/Main. java, then com, foo and bar are packages.

Is package a folder Java?

A Java package is like a directory in a file system. In fact, on the disk a package is a directory. All Java source and class files of classes belonging to the same package are located in the same directory. Java packages can contain subpackages.

What is folder structure in Java?

Folder Structure of Java Projects. When you create a Java project, Application Platform creates a folder structure that contains the following folder types: Source Folders. The source folders contain the Java source files and unit test source code.


1 Answers

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.

like image 67
Nishant Avatar answered Sep 22 '22 21:09

Nishant