Programming & Scripting Tutorials

Java: final



"final" is a very useful keyword in Java, it creates constant values.
If you don't know what a constant is, its a value that you cannot change, EVER.
You declare and initialise a 'final' constant like this:

final int var1 = 12;


Because its a constant we would get an error if we did this:

final int lol = 12;
lol = 77;

Just remember you can't change constants, they are UNCHANGABLE AFTER INITIALISATION!
You can remember this as a 'final' is final, once you set it it's unchangeable.
Constants are very useful in Java, as you can make sure that a value is not changed, and never will be changed; they also help protect against hack attacks as they can never be changed.


This Java tutorial was written by


Back to Java

Advertisement: