OSU CSE 2221 ACTUAL EXAMINATION TEST
2026 QUESTIONS WITH FULL ANSWERS
⩥ c. Answer: The Java compiler does the following:
*a.* checks a bytecode program in a ".class" file for run-time errors and
if there are none, it generates source code for that program in a ".java"
file
*b.* checks a source code program in a ".java" file for run-time errors
and if there are none, it generates bytecode for that program in a ".class"
file
*c.* checks a source code program in a ".java" file for compile-time
errors and, if there are none, it generates bytecode for that program in a
".class" file
*d.* checks a bytecode program in a ".class" file for compile-time errors
and if there are none, it generates source code for that program in a
".java" file
*e.* none of the above
⩥ d. Answer: Which statement correctly defines a java constant?
*a.* const SPECIAL = 1234;
*b.* int SPECIAL = 1234;
*c.* int final SPECIAL = 1234;
,*d.* final int SPECIAL = 1234;
*e.* const int SPECIAL = 1234;
⩥ d. Answer: What is the value of s after the following statement:
String s = (!true) + " : " + (10 + 4) + " is 104";
*a.* "!true : 104 is 104"
*b.* "false : 104 is 104"
*c.* "!true : 14 is 104"
*d.* "false : 14 is 104"
*e.* This is a compile-time error
⩥ b. Answer: The Checkstyle plugin for Eclipse is useful because:
*a.* it warns you of potential compile-time errors
*b.* it helps you make your code understandable for yourself and other
programmers
*c.* it prevents your code from making errors caught by assert
statements
*d.* it tells you when code you have written does not obey its contract
*e.* none of the above
,⩥ d. Answer: If x is an int variable, when does the boolean expression
evaluate to true?
((x % 5 != 0) && (x % 2 != 0))
*a.* when x is divisible by 5 or by 2 but not by both
*b.* when x is divisible by 10
*c.* when x is not divisible by 10
*d.* when x is neither divisible by 5 nor by 2
*e.* when x is either divisible by 5 or by 2
⩥ b. Answer: The nextDouble( ) method of r, a variable of type Random,
returns a double in a range of [0,1). Which of these expressions would
you use to create a random number in the range of [-3,3)?
*a.* r.nextDouble( ) * 3.0 - 3.0
*b.* (r.nextDouble( ) - 0.5) * 6.0
*c.* r.nextDouble( ) * 6.0 + 3.0
*d.* r.nextDouble( ) * 6.0 + 0.5
*e.* (r.nextDouble( ) - 3.0) * 6.0
⩥ a. Answer: Consider the following code fragment:
, int x = 8;
while ((x / 3) != 2) { x = x - 1; }
How many times will the body of the loop execute?
*a.* 0
*b.* 1
*c.* 2
*d.* 3
*e.* the loop will never terminate
⩥ c. Answer: Consider the following method signature:
private static int examScore(int studentNum) {...}
Here, studentNum is called:
*a.* distinguished variable
*b.* an argument
*c.* a formal parameter
*d.* an index
2026 QUESTIONS WITH FULL ANSWERS
⩥ c. Answer: The Java compiler does the following:
*a.* checks a bytecode program in a ".class" file for run-time errors and
if there are none, it generates source code for that program in a ".java"
file
*b.* checks a source code program in a ".java" file for run-time errors
and if there are none, it generates bytecode for that program in a ".class"
file
*c.* checks a source code program in a ".java" file for compile-time
errors and, if there are none, it generates bytecode for that program in a
".class" file
*d.* checks a bytecode program in a ".class" file for compile-time errors
and if there are none, it generates source code for that program in a
".java" file
*e.* none of the above
⩥ d. Answer: Which statement correctly defines a java constant?
*a.* const SPECIAL = 1234;
*b.* int SPECIAL = 1234;
*c.* int final SPECIAL = 1234;
,*d.* final int SPECIAL = 1234;
*e.* const int SPECIAL = 1234;
⩥ d. Answer: What is the value of s after the following statement:
String s = (!true) + " : " + (10 + 4) + " is 104";
*a.* "!true : 104 is 104"
*b.* "false : 104 is 104"
*c.* "!true : 14 is 104"
*d.* "false : 14 is 104"
*e.* This is a compile-time error
⩥ b. Answer: The Checkstyle plugin for Eclipse is useful because:
*a.* it warns you of potential compile-time errors
*b.* it helps you make your code understandable for yourself and other
programmers
*c.* it prevents your code from making errors caught by assert
statements
*d.* it tells you when code you have written does not obey its contract
*e.* none of the above
,⩥ d. Answer: If x is an int variable, when does the boolean expression
evaluate to true?
((x % 5 != 0) && (x % 2 != 0))
*a.* when x is divisible by 5 or by 2 but not by both
*b.* when x is divisible by 10
*c.* when x is not divisible by 10
*d.* when x is neither divisible by 5 nor by 2
*e.* when x is either divisible by 5 or by 2
⩥ b. Answer: The nextDouble( ) method of r, a variable of type Random,
returns a double in a range of [0,1). Which of these expressions would
you use to create a random number in the range of [-3,3)?
*a.* r.nextDouble( ) * 3.0 - 3.0
*b.* (r.nextDouble( ) - 0.5) * 6.0
*c.* r.nextDouble( ) * 6.0 + 3.0
*d.* r.nextDouble( ) * 6.0 + 0.5
*e.* (r.nextDouble( ) - 3.0) * 6.0
⩥ a. Answer: Consider the following code fragment:
, int x = 8;
while ((x / 3) != 2) { x = x - 1; }
How many times will the body of the loop execute?
*a.* 0
*b.* 1
*c.* 2
*d.* 3
*e.* the loop will never terminate
⩥ c. Answer: Consider the following method signature:
private static int examScore(int studentNum) {...}
Here, studentNum is called:
*a.* distinguished variable
*b.* an argument
*c.* a formal parameter
*d.* an index