7 Answers
7

By declaring final static int you will have a single reference to the int variable.And one more important thing is you can not change the value of int once declared final.
If int is not final then you can change the value of variable.
So if you don't want to change change the variable value through out code then you can use final static int.

None of these things are appropriate to int literals in Java, except if the constant value means something (which would be indicated by a name like NUMBER_OF_WOGGLES_IN_A_BOGGLE as opposed to PARAM1)
–
SutchOct 10 '13 at 14:37

One advantage of declaring a static final constant is to prevent multiple references to the same literal value througout the code, which could potentially lead to unwanted variation; e.g. if a programmer inadvertently changes one literal without changing the others.

In your example, I'd question the value of declaring a constant PARAM1 with the value 1, especially if this is private to the containing class and only referenced once. If however, there was some semantic meaning to the literal value then it might be more useful; e.g.

But what if the value of 1 changes?!
–
John FeminellaJan 15 '10 at 10:05

@John: My point is that if PARAM1 is only being used in one place in code private to the class then there's little value in defining it. Overuse of static final constants can make code unreadable IMHO.
–
AdamskiJan 15 '10 at 10:10

2

+1, magic numbers in code should always be defined with a meaningful semantic name to make them readable.
–
PaoloJan 15 '10 at 10:21

1

they are actually PARAM1, PARAM2 ... that's the real names, they are used as indexes for reading params
–
OmuJan 15 '10 at 11:54

In the example you give, I'd say that having the named values is not better than just using the int directly. The parameter is a count, so the int representation of the parameter is just as descriptive as the named version.

This seems to be kind of like when I occasionally come across C code that has things like

#define ZERO 0
#define ONE 1

There's really not much point. In fact, when I see those names used (instead of when I'm looking at the definitions), I get tempted to jump to the defines to make sure the names aren't lying (It's been a long, long time, but, I've actually come across code that had FALSE defined to 1, -1 or something non-zero, for example, which is really, really bad).

Edit: on second look, it appears that the names might indicate which field in the first parameter that are of interest, in which case the names might make more sense - as long as the names have some meaningful tie to the field rather than just the numeric offset. It's hard to say whether or not that's the case, since you might be paraphrasing the code you're really working with.

The "static final int" approach is still useful if you wish to encode multiple values in a single integer using one-hot encoding (whereby you bitwise-OR the different values together).
–
AdamskiJan 15 '10 at 10:08

In this specific case, the final statics are completely useless.
–
jarnbjoJan 15 '10 at 10:20