#Nesting packages?

1 messages · Page 1 of 1 (latest)

slate ledge
#

Hello I am very new to Java, and am trying to figure out how to structure my packages. I am a C# developer, so I am used to namespaces.
Every time I try to nest a package it just goes into the src/ directory and doesn't nest at all 🤔
(I'm using Java 19 SDK with Eclipse IDE)

My hierarchy looks like this:
src/
languages
Main.java

And I want it to look something like this:

src/
languages
Main.java
languages.models
Language.java

Right clicking the languages package to create it did not work, nor did it work when I did a "Go Into" then created the new package.

Thanks in advance!

obtuse skyBOT
#

<@&987246527741304832> please have a look, thanks.

obtuse skyBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

surreal fable
#

in Eclipse, you should write the full name in the dialog

Create Package (or something like this) -> write "languages"
Create Package -> write "languages.models"

#

the difference between C#'s namespaces and Java's packages, is that packages are obligatory to follow a folder hierarchy, while in C# you can have folders not corresponding to the namespace hierarchy

in Visual Studio, when you create folder structures, namespaces are automatically created based on the folders hierarchy

#

other thing in java (I dunno about C#): you should have a "canonical package", this package represents your app name

example:
org.xqgamers.appname
com.renankogan.mylib
(the name convention as you can see is a "inversed url")

this is important, because packages are what java uses to disambiguate between two classes with same name

so, your folder structure should be:

/src/
----/(org or com or net or other domain)/
    ----/(your name or your company)/
        ----/(name of you app or library)/
            ----Main.java
            ----/languages/
                ----/models/
                    ----Language.java
#

also, this server is sponsored by JetBrains jetbrains, so we recommend you using IntellijIDEA IntelliJ instead of Eclipse

slate ledge
#

Thank you for the help 😁 I'll check it out

obtuse skyBOT
#

Closed the thread.