JAVA.
What is constant? What are types of constant? To know the complete details about constant learn the following carefully and completely.
Constant are also known as tokens, unit of instruction in a java program.
CONSTANT.
What is Constant?
Any fixed value which does not change during the execution of a program is known as Constant.
Syntax:
final datatype name = value;
Example:
final double pi=3.142;
Because,of using final keywords, once it declared it can not be reassigned.
Types of Constant.
- Numeric Constants.
- Character Constant.
01. NUMERIC CONSTANT.
This a type of constant which deals completely with number.
Numeric constant are further grouped in two types.
a. Integer constant.
b. Real constant.
a. Integer constant.
The number which represent without deciamal part is known as Integer constant.
There are 3 types of integer constant.
- Decimal integer constant.
- Octal integer constant.
- Hexadecimal integer constant.
Decimal integer constant.
It is a combination of digit from 0 to 9, minus part of the numbers are also considered.
example:
-25, 0, 65 ,5.
Octal integer constant.
It is a combination of digit from 0 to 7. It must be begin with 0.
example:
035, 020, 07.
Hexadecimal integer constant.
It is a combination of digit from 0 to 9 and alphabet from A to H. It must begin with 0x.
example:
0x45, 0xa5, 0xH4.
b. Real constant.
The number which represent fraction part is known as real constant or floating-point constant.
A real number can be represented in exponential form if the value is either too small or too big.
It is represented in 2 part.
0.64 e 4
mantissa exponent
The part appearing before e is called mantissa.
e or E is representation of exponent.
The part appearing after e is called exponent.
example:
0.64e4
12e-2
45.67
02. CHARACTER CONSTANT.
This a type of constant which deals completely with letter, numbers and words.
Character constant are further grouped in two types.
a. Single character constant.
b. String constant.
a. Single character constant.
Single character constant is a single character enclosed with single quotes('A').
example:
'A'
'5'
'+'
b. String constant.
String character constant is a one or more character enclosed with single quotes("A").
example:
"green"
"9741"
"rs.50.00"
BOOLEAN CONSTANT.
It is special type of constant represent as true or false.
example:
true.
false.
SYMBOLIC CONSTANT.
Constants are also known as Symbolic constant.
Syntax:
final datatype NAME= value;
example:
final double PI = 3.142;
Name should be in capital which shows that different between the normal variable and symbolic constant.
BACKLASH CHARACTER CONSTANT.
It is known as Escape sequence character. They are denoted by particular character.
Some Backlash character constant are:
- \a - Alert
- \b - Backspace
- \r - Carriage return.
- \f - for feed.
- \t - Horizontal tab
- \v - Vertical tan.
- \n - New line.
- \0 - Null character.
- \\ - Backlash.
- \? - Question mark.
- \" - Double quote.
- \' - Single quote.

Comments
Post a Comment