My question is why do people create directory structures with at least one folder named edu, and then another single folder named mit (for example), followed by all their code in a subfolder?
Is this some sort of identifier?
Is the structure actually used by the computer for any reason - or is it just used to help the reader?
If so, how so does it help the reader?
This is done to prevent name collisions. The default rule is to use the reverse of your domain name as the package structure
Thus Google would keep all their code in com.google.*
packages while Microsoft would keep their code in com.microsoft.*
packages. Then, if both companies implement a SearchEngine class, you won't have a naming collision.
Educational institutions do the same thing, so you know that any code in an edu.mit.*
subpackage was likely developed by a group at MIT
The Java convention is to arrange source directories to match the package hierarchy. See e.g. Managing Source and Class Files.
So if you have a class edu.mit.stk.Foo
, then it will be located as edu/mit/stk/Foo.java
.
It's a namespace. It prevents class/package name collisions. Typically it's the company's domain name in reverse (e.g. com.ibm.PackageName
) , but its value is arbitrary and can be anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With