Wednesday, September 17, 2014

What is "final" keyword in java


The "final" is reserved keyword in java, hence can't be used it as a variable name or class name or any method name.
final is used at different places in different contexts. I illustrate the usage and essential meaning of this keyword in different contexts.

 There would be 4 different contexts, they are:

  1. Applying final keyword for a class, in class definition.
  2. Applying in a method definition.
  3. Using final keyword in a variable definition.
  4. It is used to access the variable inside an anonymous class.

Advantages of final keyword:
  • The "final" keyword is used for high performance.
  • Using final for caching the values of variables and objects.
  • It is used for static class binding.
  • It is used to variables which will be involving in multi-threading, since final resources can be accessed safely without any synchronization.
  • It helps the JVM in optimizing the classes, methods and variables.

No comments:

Post a Comment