LITERAL IN JAVA
- A literal is a value that may be
assigned to a primitive or string
variable or passed as an argument to
a method call.
- Literals can be any thing like
number, text or other information
who represents a value.
- Literals are used with addition to
variables.
Below are the different types of literals :-
- Integer literals
- Floating literals
- Character literals
- String literals
- Boolean literals
Integer literals
We can present integer literal in decimal, octal or hexa-decimal. Out of these decimal is default one. To indicate octal, we prefix literal with 0 and for hexadecimal we prefix it with 0x.
eg:-
the value 38 can be expressed as following:-
- 38 in decimal
- 038 in octal
- 0x38 in hexadecimal.
Floating-point literals
A floating point literal expressed a floating point numerical value. Floating point number is just as the real number of mathematics, double or float .
The one which is default type while writing a floating point literal is doubel , but we can also specify it by simply putting D(or d) at the end of it.
If we want to specify a literal as float we can simply put F(or f) as suffix in it.
we can also use E for specifying floating point literal in scientific notation.
eg:-
- 3D in double floating point literal.
- 0F in float floating point literal.
Character literals
We can expressed a character literal by simply putting it into a single quotes, like given below.
eg:- char E='w'
Boolean literals
The only valid literals at boolean type are true and false. In java unlike c we cant thought that 1 is equal to true and 0 is equal to false. We have to use values true and false for doing this.
eg:-
- boolean is Big=true;
- boolean is little=false;
String literals
string literal are always described by double quotes.
eg:-
0 Comment(s)