0% found this document useful (0 votes)
2 views

Day 3 Java Naming Conventions

The document outlines naming conventions for programming identifiers, emphasizing readability and clarity. It specifies rules for naming packages, classes, interfaces, methods, variables, and constants, including formatting guidelines and examples. Proper naming helps convey the purpose of identifiers and enhances code understanding.

Uploaded by

royofe6270
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Day 3 Java Naming Conventions

The document outlines naming conventions for programming identifiers, emphasizing readability and clarity. It specifies rules for naming packages, classes, interfaces, methods, variables, and constants, including formatting guidelines and examples. Proper naming helps convey the purpose of identifiers and enhances code understanding.

Uploaded by

royofe6270
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Naming conventions make programs more understandable by making them easier to read.

They can also give information about the function of


the identifier-for example, whether it's a constant, package, or class-which can be helpful in understanding the code.
Identifier Type Rules for Naming Examples
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 com.sun.eng
the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981. com.apple.quicktime.v2
Packages
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 edu.cmu.cs.bovik.cheese
be division, department, project, machine, or login names.
Class names should be nouns, in mixed case with the first letter of each internal word
capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid class Raster;
Classes
acronyms and abbreviations (unless the abbreviation is much more widely used than the long class ImageSprite;
form, such as URL or HTML).
interface RasterDelegate;
Interfaces Interface names should be capitalized like class names.
interface Storing;
run();
Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of
Methods runFast();
each internal word capitalized.
getBackground();
Except for variables, all instance, class, and class constants are in mixed case with a lowercase Copy
first letter. Internal words start with capital letters. Variable names should not start with Copied to Clipboard
underscore _ or dollar sign $ characters, even though both are allowed. Error: Could not Copy
Variable names should be short yet meaningful. The choice of a variable name should be
Variables
mnemonic- that is, designed to indicate to the casual observer the intent of its use. One- int i;
character variable names should be avoided except for temporary "throwaway" variables.
Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for char c;
characters. float myWidth;
The names of variables declared class constants and of ANSI constants should be all uppercase static final int MIN_WIDTH = 4;
Constants with words separated by underscores ("_"). (ANSI constants should be avoided, for ease of static final int MAX_WIDTH = 999;
debugging.) static final int GET_THE_CPU = 1;

You might also like