final variable java code example

Example 1: what it means when create final variable in java

First of all, final is a non-access modifier applicable only to 
a variable, a method or a class

When a variable is declared with final keyword, its value can’t be modified, 
essentially, a constant. This also means that you must initialize a 
final variable. If the final variable is a reference, this means that 
the variable cannot be re-bound to reference another object, but internal 
state of the object pointed by that reference variable can be changed 
i.e. you can add or remove elements from final array or final collection. 
  It is good practice to represent final variables in all uppercase, using 
  underscore to separate words.

Example 2: what is final in java

Final is used to apply restrictions on class, method, and variable.
The final class can't be inherited, final method can't be overridden,
and final variable value can't be changed. Final is a keyword

Example 3: java final meaning

private final String hello = "Hello World!";
/*
The keyword final states that the variable, method or class
associated will not have it's value changed.
*/

Example 4: final variables in java

public static final String Name = "Jeff";

Example 5: how make a final variable in java

class scratch{
	public static void main(String[] args){
		final pi = 3.14;
	}
}

Tags:

Java Example