Java Notes

Directories and Files

Put all source files into a directory, one class per file

When you start a new project, create a new directory for the source files. The directory name should be lowercase letters, with no blanks or other punctuation. The directory is used as the package.

Each class should be defined in its own .java file

Put each of your classes in its own file. It's easy to do. Here are a couple of minor rules.

There are some exceptions (inner classes), but this is the general rule that applies to almost all Java programming.

It's possible to put more than one class in a file and have everything work. I did this for a long time for small programs, but have given it up because it doesn't scale up as you create larger programs and use more better development tools. A common development tool, Ant, works best when each class is in its own source file.

Packages

Multiple classes of larger programs are usually grouped together into packages. See Packages - Defining for how and why to use packages.