Which of these Java conventions has higher priority?

Declaring final variables together at the top of the class.

or

Limiting scope of those variables by declaring within their respective methods.

Jon Skeet
people
quotationmark

It's not a matter of convention - it's a matter of what's logical state in the object.

If a variable is logically part of the state of an object, it should be declared as a field - and yes, conventionally put at the top of the file.

If it's only part of the local state of the method, then it would be mad to declare it as a field. This isn't in conflict with the convention of where you put fields - it's simply a matter of choosing whether it's a field or a local variable.

Within a method, I see a lot of novice Java programmers declaring all their variables at the top of the method - whereas a more useful habit in my view is to declare a variable as late as possible, and with as small a scope as possible.

people

See more on this question at Stackoverflow