Site icon TestingDocs.com

Create Java Package in Eclipse IDE

Overview

This article demonstrates the steps involved to Create Java Package in Eclipse IDE. Eclipse IDE should be installed on the machine.

Environment

We use the below environment in this tutorial:

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:

Create New Java Project in Eclipse

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

Eclipse Tutorials on this website can be found at:

https://www.testingdocs.com/eclipse-tutorials

For more details on the Eclipse IDE, visit the official website

https://www.eclipse.org

Exit mobile version