Coding Conventions

Introduction

To improve the readability and to ease maintenance of the PDFBox code there are a small number of coding conventions.

Indentation

Use 4 spaces for indentation. No tabs!

Brackets

Place open braces on the line after the declaration, for example:

public class Foo extends Bar
{
    public static void main(String args[])
    {
        try
        {
            for (int i = 0; i < args.length; i++)
            {
                System.out.println(Integer.parseInt(args[i]));
            }
        }
        catch(NumberFormatException e)
        {
            e.printStackTrace();
        }
    }
}

Line Wrapping

Wrap lines longer than 100 characters. For wrapped lines, either use an indent of 8 characters or align with the expression at the same level on the previous line.

Declarations

Within a class or interface, definitions should be ordered as follows:

  • Class (static) variables
  • Instance variables
  • Constructors
  • Methods

Imports

Do not use package imports (for example import import java.util.*;)

Other

For other cases, we try to follow Sun's code conventions as much as possible.

For Eclipse Users

Eclipse users may download this preferences file: pdfbox-checkstyle-5.xml and import this into Eclipse. (Window->Preferences, go to Java->Code Style->Formatter and click "Import..."). Once you have done this you can reformat your code by using Source->Format (Ctrl+Shift+F).

Also note that Eclipse will automatically format your import statements appropriately when you invoke Source -> Organize Imports (Ctrl+Shift+O).