Core java tutorial for beginners
A tutorial blog which explains different core concepts related to Java along with programming examples

December 1, 2014 Categories: Core Java Basics. No Comments on final Keyword

The final keyword in Java has various uses. In this article, we are going to look at only one of its uses. Other two uses of the final keyword are related to inheritance. So final keyword will be again revisited in the inheritance concept.

Primary use of the final keyword is to declare constants in Java programs. A constant is like a variable but, whose value cannot be changed once initialized. Syntax for declaring a constant using final keyword is shown below:

final data-type identifier = value;

You should remember that a constant should be initialized at the time of declaration itself. Once a constant has been initialized, it cannot be modified later. For example you can declare a PI constant as shown below:

final float PI = 3.14;

Java’s convention for constant names is that they should be written in uppercase. Below code segment ┬ádemonstrates the use of constants (created using final keyword) in a Java program:

There are two more uses of final keyword which will be discussed in inheritance section.

Related Links:

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll Up
Thank you for visiting startertutorials.com! If you like this website do share with your friends by clicking on the social icons available on the left hand side.

As the domain name is quite large to remember, use this short domain to visit this site. Short domain: stuts.me