Ilai Tamari
Ilai Tamari

Reputation: 1

Should variables in Java be static final by default (when possible)?

For example, if I have a Stage with Buttons and Panes, should they be declared as static final by default?

Upvotes: 0

Views: 101

Answers (1)

Ashish
Ashish

Reputation: 1917

Static variables mean they are in the application scope. So, all objects of the containing class will have the same value . In other words, static variables belong to class level instead of object level. So, if there are some variables which fulfill this criteria while you are coding, make them static.

Final variables are the ones whose value will not change once initialized. So, if there is any variable whose value is not going to change through the application then make it as final.

Example, constants in a Java file are defined as static final. There can be other cases too.

Upvotes: 2

Related Questions