sharath
sharath

Reputation: 123

difference between java project and java package

If we happen to build a java application using IDE it asks us to create a java project. When we look into the directory structure a folder gets created on the name of the project, similar to a package. So what exactly is the difference between the two. Also can we access a file/method/variable in one project from another project? I am a newbie in java please help me.

Upvotes: 2

Views: 12591

Answers (3)

amrendra
amrendra

Reputation: 19

A project contains all necessary things which are needed to run your source code be it dependent jars ,static files etc and it is a top level directory in your folder structure.

A package on the other hand is a part of project where a particular set of java files(depending upon logic) or may be some other types files are grouped together to perform a particular type of business task.

Upvotes: 1

Thilo
Thilo

Reputation: 262464

A "package" is a group of Java classes. All their source files are kept in the same file system directory, and they are marked with the package keyword. You use packages to enable the member classes to work closely together (without having to make the necessary methods/fields completely public).

A "project" is something your IDE uses to keep track of your code. This is not something that is part of Java itself.

If and how you can share code between projects depends on your IDE (there are quite a few of them, and they all work differently).

Upvotes: 2

F. Stephen Q
F. Stephen Q

Reputation: 4306

A project is an IDE-level grouping; its a set of source files, configurations, assets, ect. that make up a working application.

A package, on the other hand, is a grouping of related classes/source files. It is a way of organizing your code, and also works as the addressing scheme used by Java to find code you are importing.

Upvotes: 5

Related Questions