Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I put a java package into another package?

Tags:

java

netbeans

Using Netbeans, I want to put a package into another package. For example in Visual Studio 2008, I can have folder called "Nodes", and another folder inside of Nodes called "Expressions". How do I do this in Netbeans? I think a package in Java is equivalent to a folder in C#.

like image 508
Blade3 Avatar asked Feb 02 '10 15:02

Blade3


People also ask

Can you have a package inside another package Java?

There is no concept of package with in package. Each package is separate namespace.

How do I import a package from one package to another?

To import the java package into a class, we need to use the java import keyword which is used to access the package and its classes into the java program. Use import to access built-in and user-defined packages into your java source file to refer to a class in another package by directly using its name.

Can Java packages be nested?

In Java, it is possible to define a class within another class, such classes are known as nested classes.

Can we use 2 packages in Java?

You cannot put package declaration twice in the same class. The package statement must be the first line in the source file. There can be only one package statement in each source file, and it applies to all types in the file.


1 Answers

For a package within a package, put the parent name, a period, and then the name of the child's package like so: Nodes.Expressions.

It will appear as it's own separate package in an IDE perhaps, but the folder hierarchy will be as you desire: Nodes/Expressions/[classes etc]

like image 164
defectivehalt Avatar answered Sep 23 '22 13:09

defectivehalt