Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Program Organization  RSS feed

 
Landon Blake
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an idea for a program I would like to write, but I'm not sure how to organize my class files. Do I need to keep them all in one folder, or can I store different classes in different folders? Will it cause a problem if a class file in one folder references another object whose class file is in a different folder? Must the class file for the referenced object be in the same folder? Does everything have to go in the same bucket?
Thanks,
Landon
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java has the "package" concept. Package structures for source code files (generally) match the directory structures. So if you see the first line of a Java source file or JavaDoc says "package com.mycompany.myproject;" the developer probably has the file in a directory structure com/mycompany/myproject. The directory above that one is where you point the compiler. I keep my source in something like d:/java/src/com/saxman/logger/Logger.java and change my current directory to d:/java/src to run the compiler. If you use an IDE it probably has a source directory setting per project.
Why have more than one package? One reason is just to help organize your files. It might be tough to work with 300 Java files in one directory, but easier to break them up in functional areas. It also helps avoid class name collisions. Look down the JavaDoc (next time Sun's site is up) and see how many duplicate names there are. Other reasons get into kinda high falutin theory and practice about managing change, deployments, dependencies, and so on. I love to spout on and on about such stuff, but I'm guessing it's more than you want right now. Correct me if I'm wrong!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!