CSC 207 Grinnell College Spring, 2012
Algorithms and Object-Oriented Design

Files in Java


This reading describes how files are organized in Java, either when using a basic Linux environment or with the Eclipse Integrated Development Environment (IDE) for Java.


When using Java to solve problems, work is usually divided into large pieces, called packages. Within a package, processing is organized into units, called classes. (A longer introduction to packages and classes is available through the reading, an Introduction to Objects.)

Typically, storage of code for packages and classes is organized as follows:


In using Java, most programming efforts utilize one of two basic approaches for managing the work within directories and files:

Each of these approaches has its merits:

Since each of these approaches has its merits, the rest of this reading discusses the details of each in parallel.

As you will see, many ideas of Java and programming are common to both approaches. However, the mechanics are different. One approach may seem simpler for some steps, but the other approach may seem simpler for other steps.

The Course Class in Java

Directory Hierarchies

To illustrate a typical directory structure, consider the class that is part of a Java package course.

Programmer Management for Java Programming Eclipse IDE

The instructor's base directory for Java examples is ~walker/java/examples. That is, within my home directory ~walker, I have a subdirectory java where I put most or all of my Java programs. Within this java, programs are organized according to their uses. Sample programs for this course are located within an examples subdirectory.

The instructor's base directory for eclipse examples is ~walker/workspace/Examples. That is, my home directory ~walker has a subdirectory workspace, and that in turn has a subdirectory Examples for a project called Examples. Unless otherwise specified, the Eclipse integrated environment expects all packages and programs to be within a project subdirectory.

Note that Eclipse maintains a variety of directories, files, and indexes as it supports a wide range of programming capabilities. Do NOT change files within the Eclipse hierarchy manually, but rather rely upon Eclipse to handle all directories and files.

In the example, class has a name similar to the package course, but capitalization matters in both Unix/Linux and Java. The conventions are:
  • use a lower-case first letter for package names;
  • use an upper-case first letter for class names;
  • use the class name as the file name (with a suffix .java);
  • when a package or class name consists of several words, put the words together, capitalizing the first letter of subsequent words (e.g., mathComputations) or connecting the words with an underscore (e.g., math_computations).

Programmer Management for Java Programming Eclipse IDE

The initial directories and files for my copy of program are organized into the following hierarchy:
my directory and file hierarchy for

The packages and files managed by the Eclipse integrated environment are subdirectories of an eclipse environment. (Although these directories and files are utilized, Eclipse handles all of the directory- and file-management. As a user, you just tell Eclipse to create a new project or package or class, and Eclipse handles the details.)
my directory and file hierarchy for

Programmer Management for Java Programming Eclipse IDE

Java programming can proceed directly with the programming managing files, often following these steps:
  • use emacs for editing
  • use a javac command to compile in a terminal window
  • use a java command to run in a terminal window
Eclipse displays an overall project (with its package names and classes) as a list in one window. Clicking on a class title displays the code for editing in another window. Choosing a menu option allows compiling and running a program (with tools to aid identification of syntax errors and debugging.)

At least for the the first part of CSC 207, we will use the Eclipse IDE, since that will provide experience with a widely-used programming environment, and we will be able to experiment with various support tools that are typically available in modern IDEs.

This document is available on the World Wide Web as

created 17 January 2012
last revised 20 January 2012
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at

Copyright © 2011-2012 Henry M. Walker.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License .