Can anyone please let me know the relation between a package and a sub package in java?
-
See also: https://stackoverflow.com/a/64018076/1108305 – M. Justin May 30 '23 at 20:52
3 Answers
There is no relation between packages and subpackages. It is just a hierarchical structure for the convenience of a developer and has no further meaning to Java itself.

- 100,966
- 191
- 140
- 197
There is no relation between them. package com.stackoverflow in java code just like com/stackoverflow in your operating system. I'm sorry,my English is poor,beg your parden.

- 31
- 1
Relation between the package and a sub-package in Java
As Mark Rotteveel said It is just a hierarchical structure for the convenience of a developer
If you're asking about the relationship between them we might say that parent and child relationship.
A package is like a folder. In Java containing a group of related classes, interfaces, enumeration, and annotation.
Sub-package is nothing but defined inside of another package.
A package may have many sub-packages inside it.
We use packages to avoid name conflicts and to organize your code better, making access easy.
Define package in java:(package must be in the first code of your code)
package packagename;
package packagename.subpackagename;
import packages in java:
import packagename.classname; or import packagename.*;
import packagename.subpackagename.classname; or import packagename.subpackagename.*;
Predefined sub-packages in java:
import java.util.*;
here java is a package and util is a sub-package ( lang,net,util,awt,SQL)
How to run package in notepad
javac packagename\subpackagename\programname.java
javac packagename.subpackagename.programname