Java - Constant

> Procedural Languages > Java

1 - About

The names of constant fields are in upper-case letters.

By convention, the names of constant values are spelled in uppercase letters. If the name is composed of more than one word, the words are separated by an underscore (_).

Advertising

3 - Implementation

3.1 - static final

You can create a class variable A constant member is defined with the modifier static and final.

final class Constants {
 
    static final char BACKSPACE = '\b';
    static final char COMMA = ',';
    ....
}

And import it in your other class, if you don't want to use the qualified name:

import static gerardnico.Constants.*;

3.2 - enum

lang/java/constant.txt · Last modified: 2017/09/17 17:36 by gerardnico