I’ve seen examples like this:
public class MaxSeconds { public static final int MAX_SECONDS = 25; }
and supposed that I could have a Constants class to wrap constants in, declaring them static final. I know practically no Java at all and am wondering if this is the best way to create constants.
That is perfectly acceptable, probably even the standard.
where
TYPEis the type,NAMEis the name in all caps with underscores for spaces, andVALUEis the constant value;I highly recommend NOT putting your constants in their own classes or interfaces.
As a side note: Variables that are declared final and are mutable can still be changed; however, the variable can never point at a different object.
For example:
That is legal and
ORIGINwould then be a point at (3, 0).