The java final keyword can be used for:

  • variables
  • methods
  • classes

The final modifier is used to not overwrite the variable. Normally if you write a program like this:

package P;

import java.io.PrintStream;

class C {

	PrintStream out;
	
	int i;
	
	C() {
		out = new PrintStream(System.out);
		i = 5;
	}

	void start(){
		i = 10;
		out.print(i);
	}
	
	public static void main(String[] args) {
		new C().start();
	}
}

In this case, do I overwrite my variable i, with type int. Because first do I initialize/set the value on 5 and then in the void start() method do I overwrite the variable i with the value 10. So the output of the method will be 10.