Constant means fixed value which is not change at the time of execution of program. In Java, there are two types of constant as follows:
- Numeric Constants
- Character Constants
1. Integer Constants-
An Integer constant refers to a series of digits. There are three types of integer as follows:
a. Decimal integer
Embedded spaces, commas and characters are not allowed in between digits.
For example:- 23 411
b. Octal integer
It allows us any sequence of numbers or digits from 0 to 7 with leading 0 and it is called as Octal integer.
For example:- 011
c. Hexadecimal integer
It allows the sequence which is preceded by 0X or 0x and it also allows alphabets from ‘A’ to ‘F’ or ‘a’ to ‘f’
(‘A’ to ‘F’ stands for the numbers ‘10’ to ‘15’) it is called as Hexadecimal integer.
For example:- 0x7
2. Real Constants-
It allows us fractional data and it is also called as folating point constant. It is used for percentage, height and so on.
For example:- 0.0234
1. Character Constants-
It allows us the series of characters within pair of single quotes.
For example:- 'A'
2. String Constants-
It allows us the series of characters within pair of double quotes. It is used for percentage, height and so on.
For example:- "WELCOME"
"end of program"