1.
Literals :
Literal is a constant assigned to the variable to prepare java
application. Java has provide the following list of Literals
>>int a=10;
>>intàdata
type
>>aàvariable
>>=àoperator
>>10àcontent
[Literals]
>>;àSpecial
Symbol
1.
Integer
group literals / integer literals :
>> byte, short, int, long, à0,20,30………
>>char---------à
‘a’, ‘b’, ‘\t’, ‘\n’, ………….
2.
Floating point literals
>>float à12.22f,
23.234f
>>doubleà22.22,
67.456………………..
3.
Boolean literals
>>Boolean -àtrue,
false.
4.
String literals
>>String --à”abc”,
“xyz”……………….
Note:-
To improve readability over the number JAVA7 has provided a flexibility
like to include ‘_’ symbols in the number.
Ex:-
>>float f=1_23_45_678_2346f;
>>System.out.println(f);
If we provide ‘_’ symbol in the number, compiler will remove all the
provided ‘_’ symbol from number, compiler will reformat that number as original
number, where compiler and JVM will process that number as original number and
JVM will generate output that number without ‘_’ Symbols.
Date :30- july-2016
Number System in Java
To prepare number s in programming’s language’s, we have to use either if
the following Nuber Systems.
1.
Binary Number System (BASE-2)
2.
Octal Number System (BASE-8)
3.
Decimal Number System (BASE-10)
4.
Hexa Decimal Number (BASE-16)
Note:-
All the above number system’s are
allow in java but default number system In java is “decimal number system”.
1.
Binary Number System (BASE-2) :
To prepare number in binary number
system, we have to use symbols like 0’s and 1’s but, the prepared number must
be prefixed with ‘0b’ or ‘0B’.
Ex:-
>>int i=10;àIt
is not binary \, it is decimal
>>int b=0b1010;àValid
>>int c=0B1010;àValid
>>int d=oB1010;àInvalid
>>int e=0b1020;àInvalid
Note:-
Binary number system is not supported by JAVA6 version, binary number system is support by
JAVA7 Version.
2.
Octal Number System(BASE-8) :
Octal Number System to prepare number is octal number system, we have to
use the symbol like 0, 1, 2, 3, 4, 5, 6 and 7. But, the provide number must be
prefixed with ‘0’[zero].
Ex:-
int a=10;àint is not octal, it is
decimal
int b=010234;àValid
int c=o3456;àInvalid
int d=03456;àValid
int e=05678; àInvalid
3.
Decimal Number system (BASE-10) :
To prepare numbers in decimal number system, we have to use the symbols
like 0,1,2,3,4,5,6,7,8,9 and the number not be prefixed with any symbol
4.
Hexa Decimal Number System (BASE-16):
To prepare number in Hexa Decimal Number System, we have to use the
Symbols like 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e and f, but the number must be
prefixed with either ‘0x’ or ‘0X’.
Ex:-
int a=10;àValid,, it is not hexa
decimal, it is decimal
int
b=0X123456;àValid
int
c=0x789abc;àValid
int d=0xdef;àValid
int e=0Xefg;àInvalid
Note:-
If we compile java program the
compiler will recognize the provided number and its number system, compiler will
convert the provide number from the respective number system to decimal number
system, compiler and JVM will process that number as decimal number and JVM
will provide output in decimal number system
No comments:
Post a Comment