Java programming
 
Answer the following questions about basic operations in the Java programming language.

1. The type long can be used to store values in the following range:
Ο -231 to 231 - 1
Ο -264 to 264
Ο -232 to 232 - 1
Ο -263 to 263 - 1
-263 to 263 - 1
The type long is a 64-bit two's complement that can be used for long integers.


2. Which of the following is not a hexadecimal number?
(A) 999
(B) (hex)23
(C) 0x556
(D) 0x1F2
Ο (A)
Ο (C)
Ο (A) & (B)
Ο (A), (B) & (C)
(A) & (B)
Hexadecimal numbers start with "0x" in the Java programming language.


3. Select the invalid assignment statements from the following:
(A) float x = 238.88;
(B) double y = 0x443;
Ο (B)
Ο (A) & (C)
Ο (B) & (D)
Ο (A) & (B)
(A) & (C)
238.88 is a double in Java. To assign this value to a float, 238.88f must be used. A variable of type boolean cannot be converted to an integer in Java.


4. If not assigned a value, a variable of type char has the following default value:
Ο '\u0000'
Ο '\uffff'
Ο " " (space)
Ο '\u0001'
'\u0000'
The value of a variable of type char is 16 bits of data formatted as a Unicode character.

5. 15 & 29 = ?
Ο 44
Ο 14
Ο 12
Ο 13
13
When written in binary format, 15 is 1111, and 29 is 11101. 1111 & 11101 is 1101, which is 13 in decimal.

6. 27 | 8 = ?
Ο 8
Ο 19
Ο 27
Ο 35
27
When written in binary format, 27 is 11011, and 8 is 1000. 11011 | 1000 is 11011, which is 27.

7. Identify the statements that are correct:
(A) int a = 13, a>>2 = 3
(B) int b = -8, b>>1 = -4
(C) int a = 13, a>>>2 = 3
(D) int b = -8, b>>>1 = -4
Ο (A), (B), (C) & (D)
Ο (A), (B) & (C)
Ο (A) & (B)
Ο (C) & (D)
(A), (B) & (C)
The shift operation "y1 >>> y2" is identical to "y1 >> y2" for all positive values of y1. It shifts the bits in y1 to the right by y2 positions.

8. Consider the following code: int x, y, z;
y = 1;
z = 5;
x = 0 - (++y) + z++;

After execution of this, what will be the values of x, y and z?
Ο x = 3, y = 2, z = 6
Ο x = 4, y = 1, z = 5
Ο x = -7, y = 1, z = 5
Ο x = 4, y = 2, z = 6
x = 3, y = 2, z = 6
Both y and z get incremented as a result of the last statement, but y gets incremented before and z after the assisgment of the calculated value to x.

9. What will be the result of the expression
a % b
when a and b are of type int and their values are a = 10 and b = 6?
Ο 1.66
Ο 1
Ο None of these
Ο 4
4
The modulus operator (%) may be used with floating-point as well as integer types. It returns the remainder of a division operation. Therefore, 10 % 6 will return 4.

10. What will be the result of the expression
a % b
when a and b are of type int and their values are a = -17 and b = -6?
Ο -5
Ο -23
Ο 5
Ο None of these
5
a % b calculates the remainder when a is divided by b

11. What will be the value of a after execution of the following statements:
int a = 23, b = 34;
a = ((a < b) ? (b + a) : (b - a);

Ο 11
Ο 57
Ο 23
Ο 34
Ο Error. Cannot be executed.
57


12. Choose the operations that can be performed on String objects:
(A) +
(B) + =
(C) -
(D) %
(E) ^

Ο (A) & (B)
Ο (A)
Ο (D)/option>
Ο (D) & (E)
Ο None of these
(A) & (B)
The "+" and "+ =" operators are overlaoded in Java. They join the two operands into one String object.

13. (1 | 4) + (4 & 2) = ?
(in base ten)

Ο 1
Ο 2
Ο 8
Ο 5
Ο 3
5
In binary, 1 | 4 is 1 | 100 = 101, which is 5 in decimal. Similarly, 4 & 2 is 100 & 10 = 0, which is 0 in decimal.

14. Of the following functions from the class java.lang.Math, select those that produce a value of 25, when a = 25.7.
Ο (C)
Ο (D) & (E)
Ο (A), (C) & (E)
Ο (A)
Ο (C) & (E)
(A), (C) & (E)
The funtions ceil, rint and round all return the value 25 in this case. The difference lies in the type of argument returned: ceil and rint return a double, where as round will return an int or a long, depending upon the type of a (float or double, respectively).

15. In the code below, what data types the variable x can have?
byte b1 = 5;
byte b2 = 10;
x = b1 * b2;(A) byte
(B) int
(C) short
(D) long
(E) float
(F) double

Ο (A), (B), (D) & (E)
Ο (B), (D), (E) & (F)
Ο (B), (C) & (D)
Ο (B), (D) & (E)
Ο (D) & (F)
(B), (D), (E) & (F)


16. Given the declarations
int x , m = 2000;
short y;
byte b1 = -40, b2;
long n;
Which of the following assignment statements will evaluate correctly?
(A) x = m * b1;
(B) y = m * b1;
(C) n = m * 3L;
(D) x = m * 3L;

Ο (A) & (C)
Ο (A), (B) & (C)
Ο (A), (C) & (D)
Ο (B) & (C)
Ο (A) & (D)
(A) & (C)


17. Given the declarations
boolean b;
short x1 = 100, x2 = 200, x3 = 300; Which of the following statements are evaluated to true?
(A) b = x1 * 2 == x2;
(B) b = x1 + x2 != 3 * x1;
(C) b = (x3 - 2*x2<0) || ((x3 = 400)<2**x2);
(D) b = (x3 - 2*x2>0) || ((x3 = 400) 2*x2);

Ο (A), (B) & (C)
Ο (A), (C) & (D)
Ο (B) & (C)
Ο (A) & (C)
Ο (A) & (D)
(A) & (C)


18. In which of the following code fragments, is the variable x evaluated to 8?
(A) int x = 32;
x = x>>2;
(B) int x = 33;
x = x>>2;
(C) int x = 35;
x = x>>2;
(D) int x = 16;
x = x>>1;

Ο (A), (B) & (C)
Ο (A), (C) & (D)
Ο (A), (B), (C) & (D)
Ο (B) & (C)
Ο (A) & (D)
(A), (B), (C) & (D)


19. Consider the following code snippet:
.....
.....
try

Ο Error. Won't compile
Ο Catch block
Ο Division by zero
Ο Division by zero
Catch block

Catch block


20. Which of the following represent legal flow control statements?
(A) break;
(B) break();
(C) continue outer;
(D) continue(inner);
(E) return;
(F) exit();

Ο (A), (C) & (E)
Ο (A), (B) & (C)
Ο (A), (C) & (D)
Ο (A) & (E)
Ο (C) & (E)
(A), (C) & (E)




2. Which of the following is not a hexadecimal number?
(A) 999
(B) (hex)23
(C) 0x556
(D) 0x1F2
Ο (A)
Ο (C)
Ο (A) & (B)
Ο (A), (B) & (C)
(A) & (B)
Hexadecimal numbers start with "0x" in the Java programming language.

3. Select the invalid assignment statements from the following:
(A) float x = 238.88;
(B) double y = 0x443;
Ο (B)
Ο (A) & (C)
Ο (B) & (D)
Ο (A) & (B)
(A) & (C)
238.88 is a double in Java. To assign this value to a float, 238.88f must be used. A variable of type boolean cannot be converted to an integer in Java.

4. If not assigned a value, a variable of type char has the following default value:
Ο '\u0000'
Ο '\uffff'
Ο " " (space)
Ο '\u0001'
'\u0000'
The value of a variable of type char is 16 bits of data formatted as a Unicode character.

5. 15 & 29 = ?
Ο 44
Ο 14
Ο 12
Ο 13
13
When written in binary format, 15 is 1111, and 29 is 11101. 1111 & 11101 is 1101, which is 13 in decimal.

6. 27 | 8 = ?
Ο 8
Ο 19
Ο 27
Ο 35
27
When written in binary format, 27 is 11011, and 8 is 1000. 11011 | 1000 is 11011, which is 27.

7. Identify the statements that are correct:
(A) int a = 13, a>>2 = 3
(B) int b = -8, b>>1 = -4
(C) int a = 13, a>>>2 = 3
(D) int b = -8, b>>>1 = -4
Ο (A), (B), (C) & (D)
Ο (A), (B) & (C)
Ο (A) & (B)
Ο (C) & (D)
(A), (B) & (C)
The shift operation "y1 >>> y2" is identical to "y1 >> y2" for all positive values of y1. It shifts the bits in y1 to the right by y2 positions.

8. Consider the following code: int x, y, z;
y = 1;
z = 5;
x = 0 - (++y) + z++;

After execution of this, what will be the values of x, y and z?
Ο x = 3, y = 2, z = 6
Ο x = 4, y = 1, z = 5
Ο x = -7, y = 1, z = 5
Ο x = 4, y = 2, z = 6
x = 3, y = 2, z = 6
Both y and z get incremented as a result of the last statement, but y gets incremented before and z after the assisgment of the calculated value to x.

9. What will be the result of the expression
a % b
when a and b are of type int and their values are a = 10 and b = 6?
Ο 1.66
Ο 1
Ο None of these
Ο 4
4
The modulus operator (%) may be used with floating-point as well as integer types. It returns the remainder of a division operation. Therefore, 10 % 6 will return 4.

10. What will be the result of the expression
a % b
when a and b are of type int and their values are a = -17 and b = -6?
Ο -5
Ο -23
Ο 5
Ο None of these
5
a % b calculates the remainder when a is divided by b

11. What will be the value of a after execution of the following statements:
int a = 23, b = 34;
a = ((a < b) ? (b + a) : (b - a);

Ο 11
Ο 57
Ο 23
Ο 34
Ο Error. Cannot be executed.
57


12. Choose the operations that can be performed on String objects:
(A) +
(B) + =
(C) -
(D) %
(E) ^

Ο (A) & (B)
Ο (A)
Ο (D)/option>
Ο (D) & (E)
Ο None of these
(A) & (B)
The "+" and "+ =" operators are overlaoded in Java. They join the two operands into one String object.

13. (1 | 4) + (4 & 2) = ?
(in base ten)

Ο 1
Ο 2
Ο 8
Ο 5
Ο 3
5
In binary, 1 | 4 is 1 | 100 = 101, which is 5 in decimal. Similarly, 4 & 2 is 100 & 10 = 0, which is 0 in decimal.

14. Of the following functions from the class java.lang.Math, select those that produce a value of 25, when a = 25.7.
Ο (C)
Ο (D) & (E)
Ο (A), (C) & (E)
Ο (A)
Ο (C) & (E)
(A), (C) & (E)
The funtions ceil, rint and round all return the value 25 in this case. The difference lies in the type of argument returned: ceil and rint return a double, where as round will return an int or a long, depending upon the type of a (float or double, respectively).

15. In the code below, what data types the variable x can have?
byte b1 = 5;
byte b2 = 10;
x = b1 * b2;(A) byte
(B) int
(C) short
(D) long
(E) float
(F) double

Ο (A), (B), (D) & (E)
Ο (B), (D), (E) & (F)
Ο (B), (C) & (D)
Ο (B), (D) & (E)
Ο (D) & (F)
(B), (D), (E) & (F)


16. Given the declarations
int x , m = 2000;
short y;
byte b1 = -40, b2;
long n;
Which of the following assignment statements will evaluate correctly?
(A) x = m * b1;
(B) y = m * b1;
(C) n = m * 3L;
(D) x = m * 3L;

Ο (A) & (C)
Ο (A), (B) & (C)
Ο (A), (C) & (D)
Ο (B) & (C)
Ο (A) & (D)
(A) & (C)


17. Given the declarations
boolean b;
short x1 = 100, x2 = 200, x3 = 300; Which of the following statements are evaluated to true?
(A) b = x1 * 2 == x2;
(B) b = x1 + x2 != 3 * x1;
(C) b = (x3 - 2*x2<0) || ((x3 = 400)<2**x2);
(D) b = (x3 - 2*x2>0) || ((x3 = 400) 2*x2);

Ο (A), (B) & (C)
Ο (A), (C) & (D)
Ο (B) & (C)
Ο (A) & (C)
Ο (A) & (D)
(A) & (C)


18. In which of the following code fragments, is the variable x evaluated to 8?
(A) int x = 32;
x = x>>2;
(B) int x = 33;
x = x>>2;
(C) int x = 35;
x = x>>2;
(D) int x = 16;
x = x>>1;

Ο (A), (B) & (C)
Ο (A), (C) & (D)
Ο (A), (B), (C) & (D)
Ο (B) & (C)
Ο (A) & (D)
(A), (B), (C) & (D)


19. Consider the following code snippet:
.....
.....
try

Ο Error. Won't compile
Ο Catch block
Ο Division by zero
Ο Division by zero
Catch block

Catch block


20. Which of the following represent legal flow control statements?
(A) break;
(B) break();
(C) continue outer;
(D) continue(inner);
(E) return;
(F) exit();

Ο (A), (C) & (E)
Ο (A), (B) & (C)
Ο (A), (C) & (D)
Ο (A) & (E)
Ο (C) & (E)
(A), (C) & (E)




3. Select the invalid assignment statements from the following:
(A) float x = 238.88;
(B) double y = 0x443;
Ο (B)
Ο (A) & (C)
Ο (B) & (D)
Ο (A) & (B)
(A) & (C)
238.88 is a double in Java. To assign this value to a float, 238.88f must be used. A variable of type boolean cannot be converted to an integer in Java.

4. If not assigned a value, a variable of type char has the following default value:
Ο '\u0000'
Ο '\uffff'
Ο " " (space)
Ο '\u0001'
'\u0000'
The value of a variable of type char is 16 bits of data formatted as a Unicode character.

5. 15 & 29 = ?
Ο 44
Ο 14
Ο 12
Ο 13
13
When written in binary format, 15 is 1111, and 29 is 11101. 1111 & 11101 is 1101, which is 13 in decimal.

6. 27 | 8 = ?
Ο 8
Ο 19
Ο 27
Ο 35
27
When written in binary format, 27 is 11011, and 8 is 1000. 11011 | 1000 is 11011, which is 27.

7. Identify the statements that are correct:
(A) int a = 13, a>>2 = 3
(B) int b = -8, b>>1 = -4
(C) int a = 13, a>>>2 = 3
(D) int b = -8, b>>>1 = -4
Ο (A), (B), (C) & (D)
Ο (A), (B) & (C)
Ο (A) & (B)
Ο (C) & (D)
(A), (B) & (C)
The shift operation "y1 >>> y2" is identical to "y1 >> y2" for all positive values of y1. It shifts the bits in y1 to the right by y2 positions.

8. Consider the following code: int x, y, z;
y = 1;
z = 5;
x = 0 - (++y) + z++;

After execution of this, what will be the values of x, y and z?
Ο x = 3, y = 2, z = 6
Ο x = 4, y = 1, z = 5
Ο x = -7, y = 1, z = 5
Ο x = 4, y = 2, z = 6
x = 3, y = 2, z = 6
Both y and z get incremented as a result of the last statement, but y gets incremented before and z after the assisgment of the calculated value to x.

9. What will be the result of the expression
a % b
when a and b are of type int and their values are a = 10 and b = 6?
Ο 1.66
Ο 1
Ο None of these
Ο 4
4
The modulus operator (%) may be used with floating-point as well as integer types. It returns the remainder of a division operation. Therefore, 10 % 6 will return 4.

10. What will be the result of the expression
a % b
when a and b are of type int and their values are a = -17 and b = -6?
Ο -5
Ο -23
Ο 5
Ο None of these
5
a % b calculates the remainder when a is divided by b

11. What will be the value of a after execution of the following statements:
int a = 23, b = 34;
a = ((a < b) ? (b + a) : (b - a);

Ο 11
Ο 57
Ο 23
Ο 34
Ο Error. Cannot be executed.
57


12. Choose the operations that can be performed on String objects:
(A) +
(B) + =
(C) -
(D) %
(E) ^

Ο (A) & (B)
Ο (A)
Ο (D)/option>
Ο (D) & (E)
Ο None of these
(A) & (B)
The "+" and "+ =" operators are overlaoded in Java. They join the two operands into one String object.

13. (1 | 4) + (4 & 2) = ?
(in base ten)

Ο 1
Ο 2
Ο 8
Ο 5
Ο 3
5
In binary, 1 | 4 is 1 | 100 = 101, which is 5 in decimal. Similarly, 4 & 2 is 100 & 10 = 0, which is 0 in decimal.

14. Of the following functions from the class java.lang.Math, select those that produce a value of 25, when a = 25.7.
Ο (C)
Ο (D) & (E)
Ο (A), (C) & (E)
Ο (A)
Ο (C) & (E)
(A), (C) & (E)
The funtions ceil, rint and round all return the value 25 in this case. The difference lies in the type of argument returned: ceil and rint return a double, where as round will return an int or a long, depending upon the type of a (float or double, respectively).

15. In the code below, what data types the variable x can have?
byte b1 = 5;
byte b2 = 10;
x = b1 * b2;(A) byte
(B) int
(C) short
(D) long
(E) float
(F) double

Ο (A), (B), (D) & (E)
Ο (B), (D), (E) & (F)
Ο (B), (C) & (D)
Ο (B), (D) & (E)
Ο (D) & (F)
(B), (D), (E) & (F)


16. Given the declarations
int x , m = 2000;
short y;
byte b1 = -40, b2;
long n;
Which of the following assignment statements will evaluate correctly?
(A) x = m * b1;
(B) y = m * b1;
(C) n = m * 3L;
(D) x = m * 3L;

Ο (A) & (C)
Ο (A), (B) & (C)
Ο (A), (C) & (D)
Ο (B) & (C)
Ο (A) & (D)
(A) & (C)


17. Given the declarations
boolean b;
short x1 = 100, x2 = 200, x3 = 300; Which of the following statements are evaluated to true?
(A) b = x1 * 2 == x2;
(B) b = x1 + x2 != 3 * x1;
(C) b = (x3 - 2*x2<0) || ((x3 = 400)<2**x2);
(D) b = (x3 - 2*x2>0) || ((x3 = 400) 2*x2);

Ο (A), (B) & (C)
Ο (A), (C) & (D)
Ο (B) & (C)
Ο (A) & (C)
Ο (A) & (D)