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:
- Applying final keyword for a class, in class definition.
- Applying in a method definition.
- Using final keyword in a variable definition.
- 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