Why are Java source files included in the directory structure?

as we suppose i am creating a java project with the following classes

  • com.bharani.ClassOne
  • com.bharani.ClassTwo
  • com.bharani.helper.HelperOne
  • com.bharani.helper.support.HelperTwo

with files placed directly under the 'src' folder

  • CSI /ClassOne.java
  • CSI /ClassTwo.java
  • CSI /HelperOne.java
  • CSI /HelperTwo.java

and compile them with the command

$ javac -d classes src / *. java (assuming class directory exists)

The compiler compiles these files and puts the class files in the appropriate subdirectories inside the "classes" directory, like this

  • Classes / com / Bharani / ClassOne.class
  • Classes / com / Bharani / ClassTwo.class
  • Classes / com / Bharani / helper / HelperOne.class
  • Classes / com / Bharani / helper / support / HelperTwo.class

Because the specification indicates that classes should be included in the appropriate directory structure. Good.

My question is:. When I use an IDE such as Eclipse or NetBeans, they also create a directory structure for the source code directory (here also the src directory). Why is this? It is necessary? Or is it just a convention?

Thanks.

+1
java conventions directory-structure
source share
3 answers

Mostly convention. For the source, it makes sense to reflect the binary structure.

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

Saving the source in only one folder is great for small projects, but as soon as you have a larger project (hundreds of classes), grouping the source into packages makes things more manageable.

+4
source share
 Is it mandatory? 

Not

 Or, is it just a convention? 

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

I always thought the Java package was a bit broken:

he seems hieratic, but it is not.

it is a simple (unique) prefix for defining individual namespaces.

+4
source share

I thought it was necessary, but your experience suggests otherwise. In any case, this is just common sense, isn't it? Large projects have so many source files - why is life complicated by the fact that you have different structures for your source and your class files?

+1
source share

All Articles