Declare a constant
See Definition of a Constant
To declare a constant in Java you usually use:
public static final type CONSTANT_NAME = value;
Constants are usually public so that object of other classes have access to them. They are usually static so that there is only one copy of the constant no matter how many objects exist. They must be final so that the value won't change. The convention for naming a constant is to use all uppercase letters and underscores between words. You should assign a value when you declare a constant.
Examples:
public static final double PROB_OF_MOVING = 1.0 / 7;
public static final int NUM_STEPS = 10;
public static final String DEFAULT_GREETING = "Hello";
Links to this Page
- Declarations last edited on 21 March 2005 at 3:46 pm by user-11210m8.dsl.mindspring.com
- Definition of a Constant last edited on 21 March 2005 at 3:52 pm by user-11210m8.dsl.mindspring.com