Languages
[Edit]
EN

Java naming convention - static final class fields - private and public

5 points
Created by:
AnnLen
1771

1. Overview

All static final class fields in java should be upper case with underscore between words.

2. Sun Microsystems PDF - Java Coding Style Guide

3.3 Field naming
Names of fields being used as constants should be all upper-case, with underscores separating words.
The following are considered to be constants:

  1. All static final primitive types (Remember that all interface fields are inherently static final).
  2. All static final object reference types that are never followed by "." (dot).
  3. All static final arrays that are never followed by "[" (dot).

Examples:

  • MIN_VALUE,
  • MAX_BUFFER_SIZE,
  • OPTIONS_FILE_NAME

Achut Reddy - Server Management Tools Group - Sun Microsystems

Links to this pdf:

3. JDK examples

// java.lang.Boolean
public static final Boolean TRUE = new Boolean(true);
public static final Boolean FALSE = new Boolean(false);
// public static final Class<Boolean> TYPE = (Class<Boolean>) Class.getPrimitiveClass("boolean");

// java.lang.Math
public static final double E = 2.7182818284590452354;
public static final double PI = 3.14159265358979323846;

// java.lang.Character
public static final int MIN_RADIX = 2;
public static final int MAX_RADIX = 36;

References

  1. Naming convention - wiki
  2. Naming convention Java - wiki

Checkout latest findings & news:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Rockstar community members
Thank you for great work 👍