Java Naming standards
Sunday, 29 November 2009

 

Packages

 

The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of the English two-letter codes identifying countries

Subsequent components of the package name vary according to an organization's own internal naming conventions. Such conventions might specify that certain directory name components be division, department, project, machine, or login names.

com.sun.eng

com.apple.quicktime.v2

edu.cmu.cs.bovik.cheese

Classes

 

Class names should be nouns, in mixed case with the first letter of each internal word capitalized.

class Raster;
class ImageSprite;

 

Interfaces

 

Interface names should be capitalized like class names.

 

interface RasterDelegate;
interface Storing;

 

Methods

 

Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.

 

run();
runFast();
getBackground();

 

Variables

 

Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.

 

float myWidth;

int   counter;

String firstName;

Constants

The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores ("_").

 

static final int MIN_WIDTH = 4;

static final int MAX_WIDTH = 999;

static final int GET_THE_CPU = 1;