Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures


Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips


Submit News
Search the site here...
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Directories and Files

JavaFAQ Home » Java Notes by Fred Swartz Go to all tips in Java Notes by Fred Swartz

Bookmark and Share

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.

  • Make sure all classes (.java files) are in the same directory (folder).
  • You need separate import statements for each class.
  • You may have to compile a class that is referenced before the class that uses it. Whether you have to do this or not depends on which devopment system you're using.
  • When you run the program, you may have to have the class that contains main(. . .) be visible in your development system (depends on the development system.

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.


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

 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search

Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy