Java Packages

A Package in Java, as the name suggests, groups related types i.e., it can be a group of related classes or related interfaces, etc. We already have built-in packages in Java, but we can also create our own packages to group related classes.

The following are some built-in Java packages:

To import the entire package, use the import keyword:

User-defined Package

Let us now learn how to create a user-defined package in Java. Create a file in D: drive:

The package keyword will be used in our Java program to use the package:

Let us create

Now, compile the file

Compile the package:

The screenshot displays the same command:

Java Packages

Now, a new folder amitpackage will get created. Here’s the screenshot:

Packages folder in Java

Run the

The above file will run successfully and now a class file will be visible in the amitpackage:

Java packages class file

Also, the output “Our Demo class” will be visible on cmd:

Java Packages created successfully

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.

For Videos, Join Our YouTube Channel: Join Now

Java Inheritance
Java Tutorial | Learn Java Programming
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading