define literals in Java . pls help me out !
Answers
Answer:
Literals in Java
Literal : Any constant value which can be assigned to the variable is called as literal/constant.
Integral literals
For Integral data types (byte, short, int, long), we can specify literals in 4 ways:-
Decimal literals (Base 10) : In this form the allowed digits are 0-9.
int x = 101;
Octal literals (Base 8) : In this form the allowed digits are 0-7.
// The octal number should be prefix with 0.
int x = 0146;
Hexa-decimal literals (Base 16) : In this form the allowed digits are 0-9 and characters are a-f. We can use both uppercase and lowercase characters. As we know that java is a case-sensitive programming language but here java is not case-sensitive.
// The hexa-decimal number should be prefix
// with 0X or 0x.
int x = 0X123Face;
Binary literals : From 1.7 onward we can specify literals value even in binary form also, allowed digits are 0 and 1. Literals value should be prefixed with 0b or 0B.
int x = 0b1111;
Example :
// Java program to illustrate the application of Integer literals
public class Test {
public static void main(String[] args)
{
int a = 101; // decimal-form literal
int b = 0100; // octal-form literal
int c = 0xFace; // Hexa-decimal form literal
int d = 0b1111; // Binary literal
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
}
}
101
64
64206
15
I think it may help you :-)
Answer:
OMG how many questions you have ask
it is your answer hope it was helpful to you bye see you again