2 - File Names
Java Code Conventions
1.1 Why Have Code Conventions
Code conventions are important to programmers for a number of reasons:
80% of the lifetime cost of a piece of software goes to maintenance.
Hardly any software is maintained for its whole life by the original author.
Code conventions improve the readability of the software, allowing engineers to
understand new code more quickly and thoroughly.
If you ship your source code as a product, you need to make sure it is as well packaged
and clean as any other product you create.
For the conventions to work, every person writing software must conform to the code
This document reflects the Java language coding standards presented in the Java Language
Specification, from Sun Microsystems, Inc. Major contributions are from Peter King, Patrick
Naughton, Mike DeMoney, Jonni Kanerva, Kathy Walrath, and Scott Hommel.
This document is maintained by Scott Hommel. Comments should be sent to
This section lists commonly used file suffixes and names.
Java Software uses the following file suffixes:
3 - File Organization
Common File Names
Frequently used file names include:
A file consists of sections that should be separated by blank lines and an optional comment
identifying each section.
Files longer than 2000 lines are cumbersome and should be avoided.
For an example of a Java program properly formatted, see “Java Source File Example” on page
Java Source Files
Each Java source file contains a single public class or interface. When private classes and
interfaces are associated with a public class, you can put them in the same source file as the
public class. The public class should be the first class or interface in the file.
Java source files have the following ordering:
Beginning comments (see “Beginning Comments” on page 2)
Package and Import stat