Why do Java source files go into a directory structure?

点点圈 提交于 2019-12-06 06:37:09

Mainly convention. It makes sense for the source to mirror the binary structure.

Also, if you have two classes with the same name (but in different packages), how would you store the source if not in different directories?

Keeping the source in just one folder is fine for small projects, but once you have a larger project (hundreds of classes), grouping the source into packages makes things far more manageable.

Is it mandatory? 

No

Or, is it just a convention?

Yes, to reflect your package structure in your source tree.

I always thought that Java's package is a little bit broken:

it seems to be hierachical, but it is not.

it is a simple (unique) prefix to define seperate plain namespaces.

I thought it was mandatory, but your experience suggests otherwise. Either way, it's just common sense, right? Large projects have so many source files - why make life more complicated by having different structures for your source and your class files?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!