This article demonstrates the steps involved to Create Java Package in Eclipse IDE. Eclipse IDE should be installed on the machine.
We use the below environment in this tutorial:
- Windows 10 Operating System
- Eclipse IDE
What is a Package?
A Java Package groups and bundles related Java types like classes, interfaces, annotations, etc. Packages provide control access and avoid naming conflicts. Developers can group related types into a package so that it would be easy to find and use them in Java code.
The Java platform itself has many packages. These packages group and bundle classes, interfaces, and other types. For Example, all the fundamental classes, interfaces are in the default java.lang package.
Create Java Package
Create a Java Project. Steps to create a new Java project are outlined here:
Select the Project in the Project Explorer.
Choose File >> New >> Package menu option to create a new Java package.
Alternatively, Right-click on the project choose New >> Package from the context menu.
Give a package name and click on the Finish button.
We can also create a package-info.java. Check the checkbox option Create package-info.java on the Create new Java Package window.
A package-info.java file is a home for package-level documentation. It is a way to apply Java annotations at the Java package level.
Package names are defined with all lowercase to avoid conflict with the names of classes or interfaces.
Organizations use reversed Internet domain names to define the package names for their Java projects. For example, com.testingdocs.sample for a package named sample.
A class named HelloWorld is defined in the com.testingdocs.sample package, the fully qualified name of the class would be com.testingdocs.sample.HelloWorld
That’s it. We have created a new Java package inside a Java project using Eclipse IDE. We can create related classes, interfaces, etc in packages.
To create a New Java Class: New Java Class in Eclipse IDE
Eclipse Tutorials on this website can be found at:
For more details on the Eclipse IDE, visit the official website