Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do people create directory structures like edu.mit.stk in Java?

Tags:

java

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?

like image 667
sdasdadas Avatar asked Jan 18 '13 18:01

sdasdadas


3 Answers

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

like image 169
JohnnyO Avatar answered Oct 12 '22 20:10

JohnnyO


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.

like image 35
Oliver Charlesworth Avatar answered Oct 12 '22 19:10

Oliver Charlesworth


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.

like image 2
Madbreaks Avatar answered Oct 12 '22 20:10

Madbreaks