Java Final VariableLast Updated : 16 Jan 2026 A final variable can be initialized at the time of declaration or in a constructor, but once assigned, it cannot be modified. The final keyword is used to declare constants. Use the final keyword to declare a variable as final. It is treated as constant. Syntax: Characteristics of Final Variables
Final Variable ExamplesFinal Variable as ConstantExampleCompile and RunOutput: Value of PI is: 3.14 Final Variable in Method as ParameterExampleCompile and RunOutput: Value: 77 Final Variables in Instance FieldsExampleCompile and RunOutput: Roll NO: 26 Blank Final VariableA blank final variable in Java is a final variable that is declared but not initialized at the time of declaration. Again, once a final local variable has been initialized, it cannot be set, and any attempts to assign a value to blankfinal result in a compile-time error. Important Points to Remember
Example of Blank Final VariableExampleCompile and RunOutput: Value of goods: 5000 ConclusionOverall, the final keyword in Java provides a powerful mechanism for enhancing code robustness, security, performance, and maintainability by enforcing immutability, preventing unintended modifications, and enabling compiler optimizations. |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India