1. What is the range of small data types in Java?
a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) none of the mentioned
Answer: B
Explanation: 16 bits permeate small memory. Its range is from -32768 to 32767.
2. What is the range of byte data type in Java?
a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) none of the mentioned
Answer: A
Explanation: The byte occupies 8 bits in memory. Its range is from -128 to 127.
3. Which of the following are the legal lines of Java code?
1. int w = (int) 888.8;
2. byte x = (byte) 100L;
3. long y = (byte) 100;
4. byte z = (byte) 100L;
a) 1 and 2
b) 2 and 3
c) 3 and 4
d) All statements are true
Answer: D
Explanation: Statements (1), (2), (3), and (4) are correct. (1) is correct because when a floating-point number (in this case a double) is inserted into an int, it loses digits after the decimal. (2) and (4) are correct because long bytes can be inserted. If older than 127, it loses its most important (most left) bits. (3) actually works, even if a cast is not necessary, because a byte can store.
4. An expression related to byte, int, and literal numbers is promoted to which of the following?
a) int
B) long
c) byte
D) float
Answer: A
Explanation: An expression consisting of bytes, ints, shorts, literal numbers, the whole expression is promoted before any calculation is completed.
5. Which of these literal floats can be contained in a data type variable?
a) -1.7e + 308
b) -3.4e + 038
c) + 1.7e + 308
d) -3.4e + 050
Answer: B
Explanation: The range of float data type is - (3.4e38) to + (3.4e38)
6. Which data type value is returned by all transit math functions?
a) int
B) float
C) double
D) long
Answer: C
Explanation: None.
7. What will be the output of the following Java code?
Class average {
public static void main (String [] args[])
{
Double number [] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
Double result;
Result = 0;
for (int i = 0; i <6; ++ i)
result = result + number [i];
System.out.print (result / 6);
}
}
a) 16.34
b) 16.566666644
c) 16.46666666666667
d) 16.46666666666666
View answer
Answer: C
Explanation: None.
Output: $ javac average.java $ java average 16.46666666666667
8. What will be the output of the following Java statement?
Class output {
public static void main (String [] args[])
{
Double A, B, C;
a = 3.0 / 0;
B = 0 / 4.0;
c = 0 / 0.0;
Println (one);
Println (b);
Println (c);
}
}
A) Infinity
b) 0.0
c) NaN
D) All of the mentioned \ _
Answer: D
Explanation: For floating point literals, we have either positive or negative to represent a constant (10 / 0.0) infinite and also have NaN (not a number for undefined like 0 / 0.0), but integral type. For, we do not have any constant so we get an arithmetic exception.
9. What will be the output of the following Java code?
Class growth {
public static void main (String [] args[])
{
int g = 3;
System.out.print (++ g * 8);
}
}
a) 25
b) 24
c) 32
d) 33
Answer: C
Explanation: The operator ++ has more precedence than *, thus G becomes 4 and gives 32 when multiplied by 8.
Output: $ javac increment.java $ java increment 32
10. What will be the output of the following Java code?
Square area {
public static void main (String [] args[])
{
Double r, p, a;
R = 9.8;
pi = 3.14;
A = p * r * r;
Println (one);
}
}
a) 301.5656
b) 301
c) 301.56
d) 301.56560000
Answer: A
Explanation: None.
Output: $ javac area.java $ java area 301.5656
11. What is the numeric range of four data types in Java?
a) -128 to 127
b) 0 to 256
c) 0 to 32767
d) 0 to 65535
Answer: D
Explanation: Char occupies 16-bit in memory, so it supports 216 i: e from 0 to 65535.
12. Which coding type is used for data type characters in Java?
a) ASCII
B) ISO-Latin-1
C) UNICODE
d) none of the mentioned
Answer: C
Explanation: Unicode defines a fully international character set that can represent all characters found in all human languages. Its range is from 0 to 65536.
13. Which of these values can a Boolean variable contain?
A) right and wrong
B) 0 and 1
c) any integer value
d) true
Answer: A
Explanation: Boolean variables can have only one of two possible values, true and false.
14. Which of the following occupies the first 0 to 127 in the Unicode character set used for characters in Java?
a) ASCII
B) ISO-Latin-1
c) none of the mentioned
d) ASCII and ISO-LATIN1
Answer: D
Explanation: The first 0 to 12 127 character sets in Unicode are similar to ISO-LATIN-1 and ASCII.
15. Which is a valid Boolean declaration?) Boolean b1 = 1;
B) boolean b2 = ool wrong ';
C) boolean b3 = false;
d) Boolean b4 = 'true'
Answer: C
Explanation: Booleans can only be assigned true or false literals.