Every time I look at some Java source code, I find myself surfing in a folder that has folder that has folder that has folder in it etc. Why does Java require so many nested folders, which have nothing else in them except the new subfolder?
For example: https://github.com/halfninja/android-dragcontrol3d/tree/master/src/uk/co/halfninja/android That's probably not the worst example, but there are two folders "uk" and "co" that just don't make sense. I see this in Java sources only!
And for example minicraft: http://www.ludumdare.com/compo/ludum-dare-22/?action=preview&uid=398
import com.mojang.ld22.gfx.Font; import com.mojang.ld22.gfx.Screen; import com.mojang.ld22.gfx.SpriteSheet;
Why not just write:
import gfx.Font; import gfx.Screen; import gfx.SpriteSheet;
That's so much cleaner.
(I have never programmed in Java.)
Nested subfolders allow you to organize and secure layers for yourself or your organization (if you have Admin permissions).
A folder stored within another folder. Technically, the nested folder is a "subfolder," and subfolders can also contain subfolders and so on up to a maximum level. After three or four levels, it becomes cumbersome for users to deal with. See folder, files vs. folders and Win Folder organization.
Describes the Java™ source tree. When you create an API project, it is set up as a Java project with separate folders for source and class files. The source folder is named src . It contains the Java code of the application.
A Java package is like a directory in a file system. In fact, on the disk a package is a directory. All Java source and class files of classes belonging to the same package are located in the same directory. Java packages can contain subpackages.
These are there to prevent conflicts with other jars. Having something like the company url in the package name makes it likely to be unique enough to not conflict with someone else's package and classes.
Your example is a good one, since it seems pretty reasonable to imagine two people thinking of using "gfx" as a package name and with classes like Font or Sprite. Now, if you wanted to use both of them, how could you since the package and class name would be the name?
Your way is cleaner, but it assumes nobody else in the world is ever going to create a package called gfx
, which is a pretty weak assumption. By prepending your reversed domain name, you create a unique namespace that avoids collisions.
This fits perfectly with the "culture of sharing" that pervades Java programming, in which applications typically combine large libraries from many sources.
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