6

Can anyone please let me know the relation between a package and a sub package in java?

M. Justin
  • 14,487
  • 7
  • 91
  • 130

3 Answers3

10

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.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
0

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.

Yuhua Liu
  • 31
  • 1
-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
M. Justin
  • 14,487
  • 7
  • 91
  • 130
uthra
  • 1
  • 2