Monday, December 15, 2025
HomeLanguagesJavaJava – symbolic constants

Java – symbolic constants

In Java, a symbolic constant is a named constant value defined once and used throughout a program. Symbolic constants are declared using the final keyword.

  •  Which indicates that the value cannot be changed once it is initialized.
  • The naming convention for symbolic constants is to use all capital letters with underscores separating words.

Syntax of Symbolic Constants

final data_type CONSTANT_NAME = value;
  • final: The final keyword indicates that the value of the constant cannot be changed once it is initialized.
  • data_type: The data type of the constant such as int, double, boolean, or String.
  • CONSTANT_NAME: The name of the constant which should be written in all capital letters with underscores separating words. 
  • value: The initial value of the constant must be of the same data type as the constant.

Initializing a symbolic constant:

final double PI = 3.14159;

Example:

Java




// Java Program to print an Array
import java.io.*;
public class Example {
    public static final int MAX_SIZE = 10;
  
    public static void main(String[] args)
    {
        int[] array = new int[MAX_SIZE];
  
        for (int i = 0; i < MAX_SIZE; i++) {
            array[i] = i * 2;
        }
  
        System.out.print("Array: ");
        for (int i = 0; i < MAX_SIZE; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }
}


Output

Array: 0 2 4 6 8 10 12 14 16 18 
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32448 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6817 POSTS0 COMMENTS
Nicole Veronica
11954 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12031 POSTS0 COMMENTS
Shaida Kate Naidoo
6955 POSTS0 COMMENTS
Ted Musemwa
7202 POSTS0 COMMENTS
Thapelo Manthata
6899 POSTS0 COMMENTS
Umr Jansen
6884 POSTS0 COMMENTS