List of Constants in Java17 Mar 2025 | 6 min read Like other programming language, Java also has some constants. In the previous section, we have discussed, Java constants, how to declare constants. So, in this section, we will discuss the only types of constants in Java and how to use it. ![]() ConstantsIt is the value that cannot be changed once assigned. In Java, the constant values are defined by using the final keyword. The final keyword represents that the value of the variable cannot be changed. Note that the identifier name must be in capital letters. We can also define constants as static. Syntax: For example: Points to Remember
Types of ConstantsThere are the following types if constants in Java:
Let's discuss each in detail. Numeric ConstantsNumeric constants are the constants that contains numerals. It may also have a leading sign and decimal point. Rule to Define Numeric Constants
There are the following two types of numeric contestants: Integer ConstantsA constant that contains digits (0-9) and does not have decimal point is called integer constants. By default, it is type of int. There are the following three types of integer constants:
Real ConstantsNumeric constants that have a decimal point are called real or floating-point constants. By default, the real constants are of double type. We can explicitly mention the type of a floating-point constant as a float by appending the letter f or F at the end of the constant. For example, 45f, -0.14f, 5.6F. The real constants can be written in the following two forms:
Fractional Form Rules to Define Fractional Form
For example, 3.14, -9.1, 0.67. Exponential Form It is used to represent a real constant when a number is too small or too large. For example, 0.00000149 can be represented as 1.49e-6. The part of the number before e is called mantissa i.e 1.49, whereas, the part after e is called the exponent i.e, 6. Rules to Define Exponent Form
For example, 100.34e4, -56E10, 0.233E10, -0.94e15. Non-numeric ConstantsA constant that does not contain digits is called non-numeric constants. There are the following two types of non-numeric constants: Character Constants A Character constant is a single alphabet, digit or any special symbol enclosed using single quotes. For example, 'Y', 'd', '6', '#', '&'. The maximum length of a character constant is 1 character long. It means that we cannot put more than one character inside single quotation marks. As we may already know that inside computer memory everything is stored in binary form. But how character constants are stored in the memory? It turns out that Every character constant has a unique integer associated with it. An ASCII table represents the decimal number used to represent every known character in the English Language. String Constants String constants consist of zero or more characters enclosed in double quotes (""). At the end of the string, the null character i.e '\0' is automatically placed by the compiler. For example, "hello", " " (denotes blank space), "111". Note: Although not officially part of Primary constants, string constants are given here for the sake of completeness. The data type for string is String, they are stored as an array of characters.Backslash Character Constants Java also supports backslash character constants. These are used in output methods. It is also known as escape sequence. For Example, \n, \t, \a, etc.
The following table denotes the backslash character constants used in Java.
Let's use these constants in a Java program. ConstnatExample.java Output: value of var1 : 23 value of var2 : -5 value of var3 : 9 value of var4 : -12 value of var5 : 120 value of var6 : -212 value of var7 : 90000 value of var8 : -12345 value of var9 : 14.78 value of var10 : -117.34 value of var11 : 70000.1234 value of var12 : -12345.111 value of var13 : false value of var14 : true value of var15 : a value of var16 : p javatpoint 80 Hexadecimal: 801, 2812 21300.0 Next TopicMOOD Factors to Assess a Java Program |
Lead Number in Java
In this section, we will learn what is a lead number and also create Java programs to check if the given number is a lead number or not. The lead number program frequently asked in Java coding tests and academics. Lead Number In a given number if the...
3 min read
ToIntFunction Interface in Java with Examples
The java.util.function package, which was introduced with Java 8, includes the ToIntFunction Interface, which is used to implement functional programming in the language. It is a representation of a function that accepts a type T parameter and outputs an integer value. There is only one generic...
3 min read
Copy Constructor in Java
Like C++, Java also supports the copy constructor. But in C++, it is created by default. In Java, we define copy constructors ourselves. Constructor In Java, a constructor is the same as a method, but the only difference is that the constructor has the same name as...
10 min read
Half Diamond Pattern in Java
Programming is not just about solving complex problems or creating functional software; it is also an art form. One way to explore the artistic side of programming is by creating beautiful patterns and designs using code. In this section, we will delve into the fascinating world...
5 min read
Number Guessing Game in Java
In Java, a number guessing game is a basic game in which the computer creates a random number and the player attempts to guess it within a specific range. Here's a quick rundown of how it works: The game begins with the computer creating a random number...
5 min read
Java UUID
What is UUID? UUID stands for Universally Unique Identifier. UUID are standardized by the Open Software Foundation (OSF). It is a part of Distributive Computing Environment (DCE). A UUID is 36 characters long unique number. It is also known as a Globally Unique Identifier (GUID). Class A UUID...
4 min read
Binary to Gray Code Using Recursion in Java
Named for Frank Grey, Grey Code is a binary numeral system in which there is just a single bit difference between two successive values. It is also known as the "Reflected Binary Code" because the (n-1)-bit form of it may be reflected and appended to itself...
4 min read
Cohesion in Java
In this section, we will discuss about cohesion in Java. Cohesion defines how the classes in Java are designed. is the principle of Object-Oriented programming. Cohesion is closely related to ensuring that the purpose for which a class is getting created in Java is well-focused...
3 min read
Constructor in Inheritance in Java
A class in Java can inherit traits and behaviors from another class thanks to the robust inheritance system. Constructors are essential for initializing objects and maintaining the correct operation of the class hierarchy when dealing with inheritance. In this section, we will examine constructor functionality in...
4 min read
Finding the Differences Between Two Lists in Java
In many programming tasks, you may need to find differences between lists. It is common operation when comparing record sets or analysing data, and Java offers several efficient ways to handle it. Approach 1: Using the List.removeAll() Method Java affords a handy approach known as List.removeAll() that...
3 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India
