How can a package be used which is not the sub-directory of the program?

In this topic, you will learn about, How can a package be used which is not the sub-directory of the program?

In java language, any package executes automatically. if store in a same
directory but if the package store in a different directory use or set class path.

How to set classpath:

Syntax: set classpath <path>
Eg: set classpath D:/my package

  1. The classpath specifies the different directories but after the classpath declaration use the specified directory for package access.

Eg: import mypackage.mypack.*;

2. If the java package stored in a different directory and also cannot specify the path for the java program using -v switch with javac command.

Eg: java –v <package fileName>.java .

Comment below if you have queries related to the above topic, How can a package be used which is not the sub-directory of the program?