Java Programmer Certification Mock Exam

Please Help Save a Tree!

The pages of this web site are not formatted to conserve paper, but my new book (ISBN: 0-9745862-0-X) is formatted to save paper, save your printer toner, and save money. If you prefer to work my exams from printed pages, then you can save a tree, save your printer toner, and save money if you buy my new book instead of attempting to print the pages of my web site.

Today, you can find my book on the retail web site of the company that prints it and distributes it.


Question 1

class SRC120 {
  static String m1(int i) {return "I";}
  static String m1(long i) {return "L";}
  static String m1(float i) {return "F";}
  static String m1(double i) {return "D";}
  public static void main (String[] args) {
    System.out.print(m1(Math.abs(1.0f)) + m1(Math.abs(1.0d)));
    System.out.print(m1(Math.sqrt(1.0f)) + m1(Math.sqrt(1.0d)));
}}

What is the result of attempting to compile and run the program?

a. Prints: IIII
b. Prints: ILIL
c. Prints: LLLL
d. Prints: FDFD
e. Prints: FDDD
f. Prints: DDFD
g. Prints: DDDD
h. None of the above

Question 2

class SRC121 {
  static String m1(byte i) {return "B";}
  static String m1(char i) {return "C";}
  static String m1(int i) {return "I";}
  static String m1(long i) {return "L";}
  static String m1(float i) {return "F";}
  static String m1(double i) {return "D";}
  public static void main (String[] args) {
    System.out.print(m1(Math.min((byte)1,(byte)2)));
    System.out.print(m1(Math.min('A','B')));
    System.out.print(m1(Math.min(1,2)));
    System.out.print(m1(Math.min((long)1,2)));
    System.out.print(m1(Math.min(1.0f,1)));
    System.out.print(m1(Math.min(1.0,1)));
}}

What is the result of attempting to compile and run the program?

a. Prints: DDDDDD
b. Prints: FFFFFD
c. Prints: FFFDFD
d. Prints: IIILFD
e. Prints: IILLDD
f. Prints: IIILDD
g. Prints: BCILFD
h. Prints: CCILFD
i. None of the above

Question 3

class SRC122 {
  static String m1(int i) {return "I";}
  static String m1(long i) {return "L";}
  static String m1(float i) {return "F";}
  static String m1(double i) {return "D";}
  public static void main (String[] args) {
    System.out.print(m1(Math.abs(1.0f)) + m1(Math.abs(1.0)));
    System.out.print(m1(Math.round(1.0f)) + m1(Math.round(1.0)));
}}

What is the result of attempting to compile and run the program?

a. Prints: IIII
b. Prints: LLLL
c. Prints: FFFF
d. Prints: DDDD
e. Prints: FDFD
f. Prints: ILIL
g. Prints: FDIL
h. Prints: ILFD
i. None of the above

Question 4

Which of the following methods of the java.lang.Math class accepts an argument of type float or double, but has a return type of type int or long respectively.

a. abs
b. ceil
c. floor
d. max
e. min
f. random
g. round
h. sin
i. cos
j. tan
k. sqrt
l. None of the above

Question 5

Which of the following methods of the java.lang.Math class declares a non-primitive argument type?

a. abs
b. ceil
c. floor
d. max
e. min
f. random
g. round
h. sin
i. cos
j. tan
k. sqrt
l. None of the above

Question 6

Which of the following methods of the java.lang.Math class declares a non-primitive return type?

a. abs
b. ceil
c. floor
d. max
e. min
f. random
g. round
h. sin
i. cos
j. tan
k. sqrt
l. None of the above

Question 7

Which of the following statements is true in terms of the java.lang.Math.round method?

a. The returned value is of a floating-point primitive type.
b. The returned value is always of type int.
c. The returned value is always of type long.
d. The returned value is of type long only if the argument is of type long.
e. The returned value is of type long only if the argument is of type double.
f. None of the above

Question 8

Which of the following statements is true in terms of the value returned by the java.lang.Math.round method?

a. Rounds the argument to the nearest whole number. If the result is equally close to two whole numbers, then the even one is returned.
b. Rounds the argument to the nearest whole number. If the result is equally close to two whole numbers, then the odd one is returned.
c. Adds 0.5 to the argument and takes the floor of the result.
d. Adds 0.5 to the argument and takes the ceil of the result.
e. None of the above

Question 9

Suppose that the java.lang.Math.round method is invoked with an argument of type float, and the result exceeds the range of type int. Which of the following occurs?

a. The result is implicitly widened to type long.
b. The returned value is Float.NaN.
c. A run-time exception is thrown.
d. The bits that overflow are ignored and no exception is thrown.
e. The returned value is zero but no exception is thrown.
f. None of the above

Question 10

Which of the following statements is true in terms of the java.lang.Math.sqrt method?

a. It is not overloaded.
b. Returns a float if the argument type is float.
c. If the argument is negative, then the returned value is the square root of the absolute value of the argument.
d. Throws an ArithmeticException if the argument is negative.
e. None of the above

Question 11

Which of the following statements are true in terms of the java.lang.Math.sin method?

a. It is not overloaded.
b. Returns a float if the argument type is float.
c. The argument is an angle measured in radians.
d. The argument is an angle measured in degrees.
e. Throws an ArithmeticException if the argument is greater than 360.

Question 12

Which of the following statements is true in terms of the java.lang.Math.random method?

a. The random method name is overloaded.
b. The argument type is a double that represents a seed value.
c. Throws an ArithmeticException if the seed value is negative.
d. The returned value is always greater than zero and less than or equal to one.
e. None of the above

Question 13

Which of the following statements is true in terms of the java.lang.Math.floor method?

a. Four overloaded versions of floor exist.
b. An ArithmeticException is declared in the throws clause.
c. The type of the return value depends on the argument type.
d. The returned value is always of an integral primitive type.
e. Returns the largest whole number that is less than or equal to the argument value.
f. Returns the smallest whole number that is greater than or equal to the argument value.
g. None of the above

Question 14

Which of the following statements is true in terms of the java.lang.Math.ceil method?

a. Four overloaded versions of ceil exist.
b. An ArithmeticException is declared in the throws clause.
c. The type of the return value depends on the argument type.
d. The returned value is always of an integral primitive type.
e. Returns the largest whole number that is less than or equal to the argument value.
f. Returns the smallest whole number that is greater than or equal to the argument value.
g. None of the above

Question 15

Which of the following statements are true in terms of the java.lang.Math.abs method?

a. Four overloaded versions of abs exist.
b. An ArithmeticException is declared in the throws clause.
c. The type of the return value depends on the argument type.
d. The returned value is always of a floating-point primitive type.
e. If the argument is a negative integral value, then the returned value is always positive.
f. If the argument is positive, then the argument is returned.

Question 16

The java.lang.Math.abs method can return which of the following?

a. Negative infinity
b. Positive infinity
c. NaN
d. Short.MIN_VALUE
e. Integer.MIN_VALUE
f. Long.MIN_VALUE
g. Negative zero
h. Positive zero

Question 17

class SRC123 {
  public static void main (String[] args) {
    System.out.print(Math.floor(-3.6) + "," + Math.ceil(-3.6)+ ",");
    System.out.print(Math.floor(3.6) + "," + Math.ceil(3.6));
}}

What is the result of attempting to compile and run the program?

a. Prints: -3.0,-4.0,3.0,4.0
b. Prints: -3.0,-4.0,4.0,3.0
c. Prints: -4.0,-3.0,3.0,4.0
d. Prints: -4.0,-3.0,4.0,3.0
e. Prints: -4.0,-4.0,3.0,3.0
f. Compile-time error
g. Run-time error
h. None of the above

Question 18

class SRC124 {
  public static void main (String[] args) {
    System.out.print(Math.round(-3.6) + "," + Math.round(-3.4)+ ",");
    System.out.print(Math.round(3.4) + "," + Math.round(3.6));
}}

What is the result of attempting to compile and run the program?

a. Prints: -3.0,-4.0,3.0,4.0
b. Prints: -3.0,-4.0,4.0,3.0
c. Prints: -4.0,-3.0,3.0,4.0
d. Prints: -4.0,-3.0,4.0,3.0
e. Prints: -4.0,-4.0,3.0,3.0
f. Compile-time error
g. Run-time error
h. None of the above

Question 19

class SRC125 {
  public static void main (String[] args) {
    System.out.print(Math.round(-3.6) + Math.round(3.6) + ",");
    System.out.print(Math.round(-3.4) + Math.round(3.4));
}}

What is the result of attempting to compile and run the program?

a. Prints: 0,0
b. Prints: 0,-1
c. Prints: -1,0
d. Prints: -1,-1
e. Prints: 0,1
f. Prints: 1,0
g. Prints: 1,1
h. Compile-time error
i. Run-time error
j. None of the above


Copyright © 2002-2004, Dan Chisholm
All rights reserved.