user1006819
user1006819

Reputation: 69

Relation between package and a sub package in Java

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

Upvotes: 6

Views: 1040

Answers (3)

uthra
uthra

Reputation: 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

Upvotes: -1

Yuhua Liu
Yuhua Liu

Reputation: 31

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.

Upvotes: 0

Mark Rotteveel
Mark Rotteveel

Reputation: 109261

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.

Upvotes: 10

Related Questions