1) What is Literal in Java?
A) Literal is the value that is given or assigned to a variable.
B) Literal is a data type
C) Literal is similar to String
Explanation:
Examples: 123, 45.67f, 'C', "abc", false
2) What are the types of Literals available in Java language?
A) Integer and Float
Explanation:
Literals are Data assigned to Primitive data type variables.
3) What are the types of Integer Literals in Java?
A) Decimal Literals
B) Octal and Hexadecimal Literals
Explanation:
JDK 7 introduced binary literals to easily set individual bits of a number.
4) Choose correct examples of decimal literals in Java.
C)
long a = 987____654_3__21L;
Explanation:
To represent big numbers, simply append letter 'l' or 'L' to the number to make it a long integer. This avoids compiler errors saying "out of range"
5) An Octal number is Java is represented with a leading ____?
A) O (Alphabet)
Explanation:
Eg. int a=0765;
6) Choose correct ranges for Decimal, Octal and Hexadecimal numbers in Java?
A) Decimal: 0 to 9
C) Hexadecimal: 0 to 9 and A to F / a to f
7) Choose the correct example of Octal Literal in Java?
Explanation:
int = 0______11; // 8^1 * 1 + 8^0 * 1 = 9
8) What is the prefix used to represent Hexadecimal numbers in Java?
A) 0x
Explanation:
int a=0xFEB5;
int b=0X9876__45;
9) Choose correct examples of Hexadecimal literals in Java?
A)
long a = 0X987654321L;
C)
byte b = 0X0__________F;
10) Binary literals in Java are introduced with which version of Java?
A) JDK 5
11) Underscore symbols in literal numbers are introduced with which version of Java?
A) JDK 5
12) What is the prefix used to represent Binary literals in Java?
A) b or B
Explanation:
ZERO B or ZERO b
byte a = 0b00001111; //15 in decimal
13) What is the correct representation of using Binary literals in Java?
C)
int a = 0B0______________1;
Explanation:
int a = 0B0______________1; //decimal=1
int b = 0b1010; //decimal=10
14) What is the compiler error for improperly using Underscores ( _ ) in literals in Java?
A) Underscores are out of range
B) IllegalUnderscoresException
C) Underscores have to be located within digits
Explanation:
Underscore symbols cannot be used at the beginning and the end of digits of a number.
15) Choose a correct rule for using Underscores in literals of Java language.
A) Underscores cannot come at the end of a number or next to the last digit of a number.
B) Underscores cannot come at the beginning of a number or before the first digit of a number.
C) Underscores cannot come before or after a decimal point in real numbers like float and double.
Explanation:
Also, there is no limit on the number of underscores between digits.
16) What is the maximum number of Underscore characters that can be used in between the digits of a numeric literal in Java?
A) 8
Explanation:
Theoretically, there is no limit on the number of underscores.
17) Java uses UTF-16 Unicode format to represent characters. What is UTF?
A) Universal Transcript Format
B) Universal Transformation Format
C) Universal Technology Format
Explanation:
Unicode contains 65535 characters.
18) What is the name given to character literals in Java that start with a Back Slash character?
A) Back Slash Sequence
Explanation:
\b = backspace
\n = new line
\\ = backslash
19) What is the literal in Java that can be used to test whether an Object of any type is alive or not?
A) alive
Explanation:
String a;
if(a==null)
System.out.println("Object destroyed");
20) What is the common UTF standard used on the Websites for information exchange?
A) UTF 16
Explanation:
UTF 16 character encoding standard used by Java language is used only by the Windows internal system and JavaScript Library. Unix, Linux and MacOS use UTF-8 encoding standard.