Professional Documents
Culture Documents
1. How many ".class" files will be generated after a successful compilation of any ".java"
file?
(a) At least one
(b) At most one
(c) None
(d) Exactly one
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
2. Which of the following is (are) true regarding the Java API documentation?
3. A program that finds Web pages based on user input is typically referred to as a
(a) Uniform Resource Locator
(b) search engine
(c) help server
(d) search client
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See sections 1.1.1 and 1.1.4 of the course notes.
4. Which of the following is a Java statement that imports classes in the package java.sql?
(a) import java.sql.all;
(b) import java.sql.*;
(c) import java.sql;
(d) import all java.sql;
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
5. Consider a Java servlet that is invoked upon the submission of a form. If the form
contains a radio button control with the name Foo, which of the following lines of code in
the servlet can retrieve the value of this radio button?
(a) request.getParameter("Foo", radio);
(b) request.getParameter("Foo");
(c) request.getFoo();
(d) request.getRadio("Foo");
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See section 2.1.5, subsection "Coding the Servlet," in the course notes.
6. If p1 is an object of a class Point and p1.drawCircle can be called from any Java class,
which of the following statements about the method drawCircle in class Point must be
true?
(a) The method returns three values.
(b) The keyword public was used in the method's definition.
(c) The method has no arguments.
(d) The method has three arguments.
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See section 2.1.3, subsection "Behavior of Catfish Class," and section 2.2.1,
subsection "Object state and the Object's Interface," in the course notes.
7. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?
I. int numPeople;
II. int Counter;
See section 2.2.2, subsection "Mapping English Terms to Java Terms," in the
course notes.
10. Which of the following Java statements assigns the bigger of x and y to the variable
max.
11. Java provides eight types for storing and using simple data: byte, short, int, long, float,
double, char, and boolean. Which of these types are used to store the logical values true
and false?
(a) boolean
(b) byte
(c) char
(d) short
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
Variables of type boolean are used to store the values true or false. See section
2.3.3 in the course notes.
12. Which of the following is (are) true about Java?
I. Java is portable.
13. Consider the following outline of a code segment that includes a for-loop with a blank.
int total = 0;
for (int i = 10 ; _____ ; i--)
total = total + i;
System.out.print(total);
Which of the following expressions should be used to fill in the blank so that the value
49 will be output when the resulting code segment is executed?
(a) i < 3
(b) i == 3
(c) i > 3
(d) i >= 3
Correct answer is (c)
Your score on this question is: 5.00
Feedback:
14. What does the following loop compute, assuming n is a positive even integer?
int i = 1;
int sum = 0;
while (i <= n) {
if (i % 2 == 0)
sum = sum + i;
i = i + 1;
}
(a)
(b)
(c)
(d)
15. In Java, for primitives, the assignment operator is the symbol _____ and the equality
operator is the symbol _____.
(a) =, ==
(b) =, equals()
(c) :=, =
(d) ==, =
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
16. What is the value of x at the end of execution of the following line of Java code?
int x = 2 + 3 * (8 % 3);
(a) 1
(b) 8
(c) 10
(d) 2
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
!(a&&b)
For any given values of a and b, which of the following must have the same value as the
expression above?
(a) (!a)||(!b)
(b) (!a)&&(!b)
(c) !(a||b)
(d) (a||b)
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
19. What is the value of x after execution of the following Java code fragment?
int x = 4;
x = 3;
(a) 4
(b) 2
(c) Undefined
(d) 3
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
20. Reusable collection classes are included in which of the following Java packages?
(a) java.text
(b) java.io
(c) java.util
(d) java.net
Correct answer is (c)
Your score on this question is: 5.00
When compiling a Java program that contains syntax errors, the Java compiler will always
(a) report syntax errors at the exact locations and will not successfully compile
(b) ignore the syntax errors and will generate a program that produces correct results
(c) ignore the syntax errors and will generate a program that produces approximate
results
(d) report syntax errors at some approximate locations and will not successfully compile
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
See section 2.1.2 and 2.1.3 of the course notes.
I. Java has a set of rules that govern what an acceptable program is.
II. Java has a set of keywords whose meanings can be customized by the
programmer.
4. What is the name of the class whose definition is begun by the following line?
(a) Greeting
(b) Hello
(c) Greeting.Hello
(d) Hello.Greeting
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See section 2.1.4, subsection "The Welcome Servlet" in the course notes.
7. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?
I. int numPeople;
II. int Counter;
(a) I only
(b) I and III only
(c) I, II, and III
(d) None
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
See section 2.2.2, subsection "Mapping English Terms to Java Terms," in the
course notes.
I. Java is portable.
13. What is the output of the following loop? Assume the method print prints its argument
on the screen.
int i, j;
for (i = 1; i <= 3; i = i + 1)
for (j = 0; j < 3; j = j + 1)
System.out.print(i * j + " ");
(a) 0 0 0 1 2 3 2 4 9
(b) 0 1 1 0 2 4 0 3 9
(c) 0 1 2 0 2 4 0 3 6
(d) 1 2 3 2 4 6 3 6 9
Correct answer is (c)
Your score on this question is: 5.00
Feedback:
See section 2.3.5 of the course notes.
(a) 10
(b) 0
(c) infinitely many
(d) 9
Correct answer is (c)
Your score on this question is: 5.00
Feedback:
See section 2.3.5 of the course notes. The loop condition contains an assignment,
not an equality.
15. In Java, for primitives, the assignment operator is the symbol _____ and the equality
operator is the symbol _____.
(a) =, equals()
(b) =, ==
(c) :=, =
(d) ==, =
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
System.out.println(-5%-2);
(a) 1
(b) 0
(c) –1
(d) 2
Correct answer is (c)
Your score on this question is: 5.00
Feedback:
!(!(a&&b))
For which of the following values of a and b, respectively, will the expression evaluate
to true?
(a) false, true
(b) true, true
(c) true, false
(d) false, false
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
18. The region of a program where a variable can be referenced is known as the _____ of
the variable.
(a) scope
(b) storage space
(c) type
(d) conventional space
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
I. MYCLASS
II. my_Class
III. myclass.1
(a) II and III only
(b) I and III only
(c) I and II only
(d) I, II, and III
Correct answer is (c)
Your score on this question is: 5.00
Feedback:
See section 2.3.1.2. in the course notes.
20. Which of the following is a method invocation that retrieves the first element from an
instance of class java.util.Vector?
(a) elementAt(1)
(b) read(1)
(c) elementAt(0)
(d) read(0)
Correct answer is (c)
1.
How many ".class" files will be generated after a successful compilation of any ".java" file?
Feedback:
2.
Model elements in Java programs that share a common behavior can be grouped into categories
called
(a) objects
(b) codes
(c) classes
(d) programs
Feedback:
3.
Feedback:
4.
Feedback:
See section 2.1.3, subsections "The Catfish Class," in the course notes.
5.
(a) HttpRequest
(b) Parameter
(c) String
(d) PrintWriter
Feedback:
See section 2.1.4, subsection "Getting User Input," in the course notes.
6.
(a) The class can be used only by Java applets, not by Java applications.
(b) The class can be used only by other classes in the same package.
(c) The class can be accessed by any other class.
(d) The source code of the class is freely available for viewing.
7.
Which of the following is (are) consistent with Java naming conventions regarding
capitalization?
1. int numPeople;
2. int Counter;
3. class serviceElevator{}
(a) None
(b) I and III only
(c) I, II, and III
(d) I only
Feedback:
See section 2.2.2, subsection "Mapping English Terms to Java Terms," in the course notes.
8.
Feedback:
See section 2.2.2 through 2.2.4 in the course notes.
9.
Feedback:
10.
(a) ordering
(b) branching
(c) concurrent
(d) control
Feedback:
11.
In the following Java code fragment, what must be the type of the variable x in order to make the
assignment valid?
int y = 2;
x = (double) y;
(a) int
(b) Integer
(c) double
(d) Undefined
Feedback:
12.
Feedback:
See section 2.1.2 of the course notes.
13.
Feedback:
14.
int i = 0;
while (i > 5 || i < 5) {
System.out.println(i + "1");
}
(a) 5
(b) 6
(c) infinitely many
(d) 4
Feedback:
See sections 2.3.3 and 2.3.5 of the course notes.
15.
In Java, for primitives, the assignment operator is the symbol _____ and the equality operator is
the symbol _____.
(a) =, equals()
(b) ==, =
(c) :=, =
(d) =, ==
Feedback:
16.
System.out.println(-5%-2);
(a) 2
(b) –1
(c) 0
(d) 1
Feedback:
17.
!(a&&b)
For any given values of a and b, which of the following must have the same value as the
expression above?
(a) (!a)||(!b)
(b) (a||b)
(c) (!a)&&(!b)
(d) !(a||b)
Feedback:
18.
class MyClass {
int age;
void myMethod() {
age = counter;
Feedback:
(a) I only
(b) II and III only
(c) I and III only
(d) I, II, and III
Feedback:
20.
Which of the following methods can be used to determine the number of elements contained in
an instance of class java.util.Vector?
(a) add
(b) contains
(c) size
(d) capacity
Feedback:
2. Which of the following is (are) true regarding the Java API documentation?
III. The documentation for one class often refers to other classes.
(a) I and II only
(b) II and III only
(c) I, II, and III
(d) I and III only
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
3. Which of the following is ethical to do without the permission of the owner of a Web
site?
(a) Use small amounts of text from that site in your Web page, without attributing the
text to its source
(b) Use a picture from that site in your Web page
(c) Use large amounts of text from that site in your Web page
(d) Place a link to that site in your Web page
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
See section 1.1.6 in the course notes.
What will be the value of the parameter "a", in the method paintPicture when this code is
executed?
(a) 20
(b) 10
(c) This will not compile. This is an error because the parameter "a" was never declared
and never given a value.
(d) 0
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
The first argument of the call is the graphics object, "g" This value is transferred
to the first formal argument (parameter) which is also called "g". The value of the
second argument (parameter) in the call, "x" is transferred to the second formal
argument (parameter), "a" so the formal argument (parameter), "a" will have a
value of 10. The names do not have to be the same - just the types. The same is
true for the third argument (parameter) in the call, "y". It s value is transferred to
the third formal argument, "b" which will have a value of 20.
5. In a Java servlet, which of the following lines can cause data that was input by a user into
an HTML form to be retrieved?
(a) request.getParameter("Name");
(b) out.println("Form value");
(c) response.setContentType("text/html");
(d) response.getWriter();
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
See section 2.1.5, subsection "Coding the Servlet," in the course notes.
6. Which of the statements below correctly constructs an object using the following
constructor?
7. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?
I. int numPeople;
II. int Counter;
(a) None
(b) I, II, and III
(c) I only
(d) I and III only
Correct answer is (c)
Your score on this question is: 5.00
Feedback:
See section 2.2.2, subsection "Mapping English Terms to Java Terms," in the
course notes.
In the method turnOn, which of the following statements should be used to call method
changeStatus?
(a) TrafficLight.changeStatus(newStatus);
(b) changeStatus.newStatus;
(c) changeStatus(TrafficLight, newStatus);
(d) changeStatus(newStatus);
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
9. In Java, methods that change or return the values of instance variables are known as
_____ methods.
(a) class
(b) parameter
(c) instance
(d) accessor
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
10. A programmer claims that, in the following code fragment, task A will never be
performed. Which of the following supports the programmer's claim?
double x = 19.9999;
if (x >= 20.0 && x <= 0.0)
perform task A
else
perform task B
(a)
(d)
The value of x is close enough to 20.0 that they could be considered equal.
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
The Boolean expression requires that x be both less or equal 0 AND greater or
equal 20 at the same time - that is not possible.
11. In Java, the data type of a variable determines which of the following?
I. Valid operators
12. Which words in the following line of code are Java keywords?
13. Assume that variable n has been declared to be of type int, assume that n has a positive
value, and consider the following Java program segment.
int s = 0;
for (int i = n; i > 0; i = i - 1)
s = s + i;
The value of s at the end of any execution of the program segment is the sum of the
(a) integers from 1 through n
(b) odd integers from 1 through n
(c) integers from 1 through n – 1
(d) even integers from 1 through n
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
14. Assume you are given a method with a specification double numbers(); that supplies
you with numbers from the user's input. You need to find the first input number from
user input that is smaller than 0.5 and put it in the variable x. Which of the following
can be used for that purpose?
(a) I only
(b) I, II and III
(c) III only
(d) II and III only
Correct answer is (c)
Your score on this question is: 5.00
Feedback:
The first item sets x to the first number greater than 0.5; the second item never
gets user input. See section 2.3.5 of the course notes.
15. In Java, for primitives, the assignment operator is the symbol _____ and the equality
operator is the symbol _____.
(a) =, ==
(b) :=, =
(c) =, equals()
(d) ==, =
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
16. The following code segment is intended to sum together all of the even numbers in the
range 1 through 40 and to store the final result in the variable sum.
int sum = 0;
for (int j = 1; j < 40; j+=2)
sum = sum + j;
Which of the following is an error (are errors) in the code segment that will prevent the
intended result?
III. The loop guard causes the loop to terminate at the wrong place.
(a) None
(b) I and III
(c) II and III
(d) I only
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
17. Which of the following Boolean expressions involving the int variable i will always
evaluate to true, regardless of the value of i?
I. (i < 10) != (i >= 10)
II. (i == 0) == (!(i != 0))
(a) II only
(b) I only
(c) I and II only
(d) I, II, and III
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 2.3.3 in the course notes.
19. What is the value of x after execution of the following Java code fragment?
int x = 4;
x = 3;
(a) 3
(b) Undefined
(c) 4
(d) 2
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
20. The value of the largest index of an instance of class java.util.Vector is always
_____ the size of the vector.
(a) one greater than
(b) one less than
(c) equal to
(d) half of
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
Go to top of assessment.
Total score: 80.00
© Copyright 2003 iCarnegie, Inc. All rights reserved.
2. Model elements in Java programs that share a common behavior can be grouped into
categories called
(a) programs
(b) classes
(c) objects
(d) codes
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See Chapter 1, page 3, in the course textbook.
I. /* Comment 1 */
II. // Comment 2
III. /**
* Comment 3
*/
7. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?
I. int numPeople;
II. int Counter;
See section 2.2.2, subsection "Mapping English Terms to Java Terms," in the
course notes.
10. Assume that max, x, and y are Java variables of type int and assume that x and y have
different values. Execution of which of the following Java program segments will result
in the larger of x and y being assigned to max?
11. In Java, the data type of a variable determines which of the following?
I. Valid operators
12. Which words in the following line of code are Java keywords?
13. What is the output of the following loop? Assume the method print prints its argument
on the screen.
int i, j;
for (i = 1; i <= 3; i = i + 1)
for (j = 0; j < 3; j = j + 1)
System.out.print(i * j + " ");
(a) 0 0 0 1 2 3 2 4 9
(b) 0 1 1 0 2 4 0 3 9
(c) 1 2 3 2 4 6 3 6 9
(d) 0 1 2 0 2 4 0 3 6
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
See section 2.3.5 of the course notes.
14. What is the value of product when the following loop completes?
int i = 3;
int product = 1;
while (i != 0) {
product = product * i;
i = i - 1;
}
(a) 1
(b) 3
(c) 0
(d) 6
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
See section 2.3.5 of the course notes.
15. In Java, for primitives, the assignment operator is the symbol _____ and the equality
operator is the symbol _____.
(a) :=, =
(b) =, ==
(c) ==, =
(d) =, equals()
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
int m = 3;
int n = m / 2;
I. _$4dollar
II. $_4dollar
III. 4_dollar
You took 31 minutes on this assessment from Thu Nov 12 2009 10:45:12 GMT+0600 to
Thu Nov 12 2009 11:15:29 GMT+0600.
(a) report syntax errors at the exact locations and will not successfully compile
(b) ignore the syntax errors and will generate a program that produces correct results
(c) ignore the syntax errors and will generate a program that produces approximate results
(d) report syntax errors at some approximate locations and will not successfully compile
Feedback:
See section 2.1.2 and 2.1.3 of the course notes.
2.
Model elements in Java programs that share a common behavior can be grouped into categories
called
(a) objects
(b) classes
(c) codes
(d) programs
Feedback:
3.
Which of the following pairs (A, B) use HTTP as a means for A to communicate with B and B to
communicate with A?
(a) I only
(b) I and II
(c) II only
(d) None
Feedback:
4.
Which of the following is a Java statement that imports classes in the package java.sql?
Feedback:
5.
A Java servlet can be declared with the type of content it will produce, such as image/gif
or text/html, by using a call to which of the following methods of HttpServletResponse?
(a) resetBuffer
(b) encodeURL
(c) setContentType
(d) addCookie
Feedback:
See section 2.1.4, subsection "The Welcome Servlet," in the course notes.
6.
Feedback:
See section 2.2.2, subsection "Mapping English Terms to Java Terms," in the course notes.
7.
Which of the following is (are) consistent with Java naming conventions regarding
capitalization?
1. int numPeople;
2. int Counter;
3. class serviceElevator{}
Feedback:
See section 2.2.2, subsection "Mapping English Terms to Java Terms," in the course notes.
8.
(a) fred$wallet
(b) RESET
(c) 3jane
(d) Napoleon_The_First
Feedback:
9.
Which of the following is (are) true regarding object state and behavior in Java?
(a) None
(b) II only
(c) I only
(d) I and II
Feedback:
10.
return "Joe";
return null;
If the method nameOfEmployee is called with the value 55000 as its argument, what String
value will be returned?
(a) "Jack"
(b) "John"
(c) "Joe"
(d) null
Feedback:
11.
public class IQ
{
public int getIQ(String s)
{
return 50;
}
}
(a) IQ x = getIQ("chuck");
(b) int c = p.getIQ("aleks");
(c) getIQ.p("bob");
(d) String s = IQ.getIQ(p);
Feedback:
See sections 2.3.1 in the course notes.
12.
In the following code fragment, what does the use of the keyword void imply?
Feedback:
13.
Consider the following outline of a code segment that includes a for-loop with a blank.
int total = 0;
for (int i = 10 ; _____ ; i--)
total = total + i;
System.out.print(total);
Which of the following expressions should be used to fill in the blank so that the value 49 will be
output when the resulting code segment is executed?
(a) i == 3
(b) i >= 3
(c) i > 3
(d) i < 3
Feedback:
14.
int i = 3;
int product = 1;
while (i != 0) {
product = product * i;
i = i - 1;
}
(a) 1
(b) 6
(c) 3
(d) 0
Feedback:
See section 2.3.5 of the course notes.
15.
In Java, for primitives, the assignment operator is the symbol _____ and the equality operator is
the symbol _____.
(a) :=, =
(b) =, ==
(c) =, equals()
(d) ==, =
Feedback:
16.
The following code segment is intended to sum together all of the even numbers in the range 1
through 40 and to store the final result in the variable sum.
int sum = 0;
for (int j = 1; j < 40; j+=2)
sum = sum + j;
Which of the following is an error (are errors) in the code segment that will prevent the intended
result?
Feedback:
Which of the following Boolean expressions in Java must evaluate to true, regardless of the
value of the Boolean variable x?
1. !x && x
2. x || !x
3. x == true || x == false
Feedback:
18.
(a) Local
(b) Method
(c) Block
(d) Class
Feedback:
1. MYCLASS
2. my_Class
3. myclass.1
Feedback:
See section 2.3.1.2. in the course notes.
20.
Reusable collection classes are included in which of the following Java packages?
(a) java.text
(b) java.net
(c) java.io
(d) java.util
Feedback:
Go to top of assessment.
I. int numPeople;
II. int Counter;
(b) I only
Correct answer is (b)
8. Valid method definitions in Java include which of the following?
(c) II only
I. i = i;
II. // y = 5;
III. x = 10
(a) I only
int y = 1;
int i;
for (i = 10; i < 0; i = i - 1)
y = i + 2;
(b) 2
Correct answer is (b)
15. In Java, for primitives, the assignment operator is the symbol _____ and the equality
operator is the symbol _____.
(d) =, ==
Correct answer is (d)
16. What is output when the following Java statement is executed?
System.out.println(-5%-2);
(b) –1
Correct answer is (b)
17. Consider the following Boolean expression.
!(!(a&&b))
For which of the following values of a and b, respectively, will the expression evaluate
to true?
(c) true, true
Correct answer is (c)
18. Which of the following kinds of scope do local variables have in Java?
(d) Block
Correct answer is (d)
19. Consider a Java method printDouble that takes one parameter of type double. If x is a
variable of type int, correct ways of calling printDouble include which of the
following?
I. printDouble(x);
II. printDouble( (double) x);
III. printDouble(x.double);
2. Which of the following is (are) true regarding the Java API documentation?
III. The documentation for one class often refers to other classes.
(a) I and II
(b) None
(c) I only
(d) II only
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
4. What is the name of the class whose definition is begun by the following line?
(a) Greeting
(b) Hello.Greeting
(c) Greeting.Hello
(d) Hello
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
See section 2.1.4, subsection "The Welcome Servlet" in the course notes.
(a) comment
(b) servlet
(c) println
(d) import
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
(a) ==
(b) new
(c) =
(d) init
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
(a) AmountOfFuelRemainingInTheTank
(b) fuelRemaining
(c) FuelRemaining
(d) fuel_remaining
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See section 2.2.2 in the course notes.
8. Suppose you are given a class called List which has print as one of its methods and a
correctly instantiated object called myList. Which of the following could be a valid call to the
print method?
(a) myList.print;
(b) myList.print();
(c) print(List);
(d) print.myList();
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See section 2.2.4 in the course notes.
(a) I and II
(b) II only
(c) I only
(d) None
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
10. A programmer claims that, in the following code fragment, task A will never be performed.
Which of the following supports the programmer's claim?
double x = 19.9999;
if (x >= 20.0 && x <= 0.0)
perform task A
else
perform task B
(a)
(b)
The condition could never be true for any value of x.
(c)
The value of x is close enough to 20.0 that they could be considered equal.
11. In Java, which of the following values can be assigned to a boolean variable?
I. -1
II. 0
III. 2
(b) I only
(d) None
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
12. The SDK compiler is _____, and the SDK interpreter is _____.
13. What is the output of the following loop? Assume the method print prints its argument on
the screen.
int i, j;
for (i = 1; i <= 3; i = i + 1)
for (j = 0; j < 3; j = j + 1)
System.out.print(i * j + " ");
(a) 0 0 0 1 2 3 2 4 9
(b) 1 2 3 2 4 6 3 6 9
(c) 0 1 1 0 2 4 0 3 9
(d) 0 1 2 0 2 4 0 3 6
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
See section 2.3.5 of the course notes.
14. What does the following loop compute, assuming n is a positive even integer?
int i = 1;
int sum = 0;
while (i <= n) {
if (i % 2 == 0)
sum = sum + i;
i = i + 1;
}
(a)
(b)
(c)
(d)
15. In Java, for primitives, the assignment operator is the symbol _____ and the equality
operator is the symbol _____.
(a) =, ==
(b) =, equals()
(c) ==, =
(d) :=, =
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
16. The following code segment is intended to sum together all of the even numbers in the range
1 through 40 and to store the final result in the variable sum.
int sum = 0;
for (int j = 1; j < 40; j+=2)
sum = sum + j;
Which of the following is an error (are errors) in the code segment that will prevent the
intended result?
III. The loop guard causes the loop to terminate at the wrong place.
(b) I only
(c) None
(a) ||
(b) !
(c) &&
(d) %
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
// . . .
(a) instance
(b) local
(c) global
(d) parameter
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
20. The value of the largest index of an instance of class java.util.Vector is always _____
the size of the vector.
(b) half of
(c) equal to
Go to top of assessment.
Total score: 100.00
© Copyright 2003 iCarnegie, Inc. All rights reserved.
2. Model elements in Java programs that share a common behavior can be grouped into
categories called
(a) classes
(b) programs
(c) objects
(d) codes
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
3. Of the following, which is the most accurate characterization of the World Wide Web?
(a) A collection of commercial sites that sell products and services
(b) A collection of commercial sites that offer free disk space but sell advertising space
(c) The portion of computers on the Internet that communicate via FTP
(d) The portion of computers on the Internet that communicate via HTTP
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
4. Which of the following is a Java statement that imports classes in the package java.sql?
(a) import java.sql;
(b) import java.sql.*;
(c) import all java.sql;
(d) import java.sql.all;
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See section 2.1.4, subsection "The Welcome Servlet," in the course notes.
9. Which of the following is a Java keyword that is used to create object instances?
(a) create
(b) new
(c) construct
(d) public
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
return "Joe";
return null;
If the method nameOfEmployee is called with the value 55000 as its argument, what
String value will be returned?
(a) "John"
(b) "Joe"
(c) "Jack"
(d) null
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
Among the three placeholders, initialization, loopGuard, and update, which are
optional in a legal Java for-loop?
(a) None
(b) initialization
(c) update
(d) All
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
int i = 0;
while (i > 5 || i < 5) {
System.out.println(i + "1");
}
(a) 6
(b) 5
(c) 4
(d) infinitely many
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
See sections 2.3.3 and 2.3.5 of the course notes.
15. In Java, for primitives, the assignment operator is the symbol _____ and the equality
operator is the symbol _____.
(a) =, equals()
(b) :=, =
(c) ==, =
(d) =, ==
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
16. What is the value of variable x at the end of the execution of the following Java
statement?
int x = 1 + 5%2/2;
(a) 0
(b) 1
(c) 3
(d) 2
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
17. Which of the following Boolean expressions in Java must evaluate to true, regardless
of the value of the Boolean variable x?
I. !x && x
II. x || !x
18. In Java, the scope of a parameter of a method contains the scope of which of the
following?
(a) Global variables of the method
(b) Class variables of the method
(c) Local variables of the method
(d) Instance variables of the method
Correct answer is (c)
Your score on this question is: 5.00
Feedback:
Go to top of assessment.
Total score: 90.00
© Copyright 2003 iCarnegie, Inc. All rights reserved.
2. Which of the following is (are) true regarding the Java API documentation?
3. In the context of the World Wide Web, which of the following is true about a Uniform
Resource Locator?
(a) It describes how text in a Web page is to be formatted.
(b) It specifies the location of a Web page.
(c) It sells customers connections to the Internet.
(d) It allows Web sites to trace the geographical location of a client.
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
4. What is the name of the class whose definition is begun by the following line?
(a) Hello
(b) Hello.Greeting
(c) Greeting.Hello
(d) Greeting
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
See section 2.1.4, subsection "The Welcome Servlet" in the course notes.
5. In a Java servlet, which of the following lines can cause data that was input by a user into
an HTML form to be retrieved?
(a) response.setContentType("text/html");
(b) response.getWriter();
(c) request.getParameter("Name");
(d) out.println("Form value");
Correct answer is (c)
Your score on this question is: 5.00
Feedback:
See section 2.1.5, subsection "Coding the Servlet," in the course notes.
7. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?
I. int numPeople;
II. int Counter;
(a) I only
(b) None
(c) I and III only
(d) I, II, and III
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
See section 2.2.2, subsection "Mapping English Terms to Java Terms," in the
course notes.
9. In Java, variables declared in the body of a method are known as _____ variables.
(a) public
(b) class
(c) local
(d) instance
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
10. Assume that max, x, and y are Java variables of type int and assume that x and y have
different values. Execution of which of the following Java program segments will result
in the larger of x and y being assigned to max?
I. int
II. Integer
III. Double
12. Which words in the following line of code are Java keywords?
14. What is the value of the variable i at the end of execution of the following Java
program segment?
int i = 1;
while (i < 3) {
i = i * 2;
(a) 2
(b) 3
(c) 1
(d) 4
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
15. In Java, for primitives, the assignment operator is the symbol _____ and the equality
operator is the symbol _____.
(a) :=, =
(b) ==, =
(c) =, equals()
(d) =, ==
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
int sum = 0;
for (int j = 1; j < 40; j+=2)
sum = sum + j;
Which of the following is an error (are errors) in the code segment that will prevent the
intended result?
III. The loop guard causes the loop to terminate at the wrong place.
(a) II and III
(b) I only
(c) None
(d) I and III
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
!(a&&b)
For any given values of a and b, which of the following must have the same value as the
expression above?
(a) !(a||b)
(b) (!a)&&(!b)
(c) (a||b)
(d) (!a)||(!b)
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
class MyClass {
int age;
void myMethod() {
age = counter;
class MyClass {
int age = 19;
void myMethod()
{
int counter;
}
}
(a)
(b) age
(c)
both age and counter are local variables
(d) age
20. Reusable collection classes are included in which of the following Java packages?
(a) java.net
(b) java.text
(c) java.util
(d) java.io
Correct answer is (c)
Your score on this question is: 5.00
Feedback:
Go to top of assessment.
Total score: 75.00
© Copyright 2003 iCarnegie, Inc. All rights reserved.
1. When compiling a Java program that contains syntax errors, the Java compiler will
always
(a) report syntax errors at some approximate locations and will not successfully compile
(b) report syntax errors at the exact locations and will not successfully compile
(c) ignore the syntax errors and will generate a program that produces correct results
(d) ignore the syntax errors and will generate a program that produces approximate
results
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
See section 2.1.2 and 2.1.3 of the course notes.
2. Which of the following is (are) true regarding the Java API documentation?
I. Programmers can view it on the web.
I. The Internet connection provided by an ISP can only be used to search and
browse the Web.
II. ISP is an acronym for Internet Service Provider.
What will be the value of the parameter "a", in the method paintPicture when this code is
executed?
(a) 10
(b) This will not compile. This is an error because the parameter "a" was never declared
and never given a value.
(c) 0
(d) 20
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
The first argument of the call is the graphics object, "g" This value is transferred
to the first formal argument (parameter) which is also called "g". The value of the
second argument (parameter) in the call, "x" is transferred to the second formal
argument (parameter), "a" so the formal argument (parameter), "a" will have a
value of 10. The names do not have to be the same - just the types. The same is
true for the third argument (parameter) in the call, "y". It s value is transferred to
the third formal argument, "b" which will have a value of 20.
I. /* Comment 1 */
II. // Comment 2
III. /**
* Comment 3
*/
8. Which of the following method names adheres to the Java naming convention standards?
(a) IsEmpty
(b) isEmpty
(c) is_empty
(d) is-empty
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See section 2.2.2 in the course notes.
10. Assume that max, x, and y are Java variables of type int and assume that x and y have
different values. Execution of which of the following Java program segments will result
in the larger of x and y being assigned to max?
(a) I only
(b) I, II, and III
(c) I and II only
(d) III only
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See section 2.3.4 of the course notes.
11. In Java, the data type of a variable determines which of the following?
I. Valid operators
int i;
for (i = 0; i < 9; i = i + 1)
i = 8;
14. What does the following loop compute, assuming n is a positive even integer?
int i = 1;
int sum = 0;
while (i <= n) {
if (i % 2 == 0)
sum = sum + i;
i = i + 1;
}
(a)
(b)
(c)
15. In Java, for primitives, the assignment operator is the symbol _____ and the equality
operator is the symbol _____.
(a) =, equals()
(b) ==, =
(c) :=, =
(d) =, ==
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
16. In Java, the operator "+" can be used for which of the following purposes?
17. Assume that isRaining, haveUmbrella, haveCoat, and shortTrip have been declared
as type boolean and consider the following Java program segment.
isRaining = true;
haveUmbrella = false;
boolean takeBus = isRaining && !((haveUmbrella && haveCoat) ||
shortTrip);
At the end of execution of the program segment, the value of variable takeBus is
(a) dependent on the value of shortTrip
(b) dependent on the value of haveCoat
(c) false
(d) true
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
I. MYCLASS
II. my_Class
III. myclass.1
(a) I, II, and III
(b) II and III only
(c) I and III only
(d) I and II only
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
See section 2.3.1.2. in the course notes.
String s=null;
return s;
If the method assignString is called with the value 4 as its argument, what String value
will be returned?
2. A programmer claims that, in the following code fragment, task A will never be performed.
Which of the following supports the programmer's claim?
double x = 19.9999;
if (x >= 20.0 && x <= 0.0)
perform task A
else
perform task B
(a)
I. Valid operators
(a) I and II
4. The type of the number 2.0 in Java can be
(b) double
5. The following code fragment contains how many Java keywords?
(b) Three
6. The term Java Virtual Machine refers to
int i, j;
for (i = 1; i <= 3; i = i + 1)
for (j = 0; j < 3; j = j + 1)
System.out.print(i * j + " ");
(a) 0 1 2 0 2 4 0 3 6
8. Consider a Java for-loop with the following form.
Among the three placeholders, initialization, loopGuard, and update, which are
optional in a legal Java for-loop?
(b) All
9. What is the value of product when the following loop completes?
int i = 3;
int product = 1;
while (i != 0) {
product = product * i;
i = i - 1;
}
(b) 6
(c) 2
11. In Java, for primitives, the assignment operator is the symbol _____ and the equality
operator is the symbol _____.
(b) =, ==
12. In Java, the expression –7 % 3 evaluates to
(b) –1
13. What does the following expression evaluate to?
2 * 4 - 3 + 5 / 2.0
(a) 7.5
14. Which of the following Boolean expressions in Java must evaluate to true, regardless of the
value of the Boolean variable x?
I. !x && x
II. x || !x
(a) int a, b, c, d;
17. Which of the following methods can be used to determine the number of elements contained
in an instance of class java.util.Vector?
(d) size
18. Which of the following Java statements correctly declares and instantiates a Vector v?
(d) control
2. Consider the following program segment.
return "Joe";
return null;
If the method nameOfEmployee is called with the value 55000 as its argument, what
String value will be returned?
(b) "John"
(c) boolean
4. Suppose an object p is an instance of the following class
public class IQ
{
public int getIQ(String s)
{
return 50;
}
}
5. An object is an instance of a
(c) class
6. Which of the following is a code statement that allows a Java program to use methods of a
pre-built library class?
8. How many times will the body of the following loop be executed?
int sum = 0;
int n;
for (n = 9; n > 0; n = n / 2)
sum = sum + n;
10. Assume you are given a method with a specification double numbers(); that supplies you
with numbers from the user's input. You need to find the first input number from user input
that is smaller than 0.5 and put it in the variable x. Which of the following can be used for
that purpose?
(a) –1
13. What does the following expression evaluate to?
2 * 4 - 3 + 5 / 2.0
(a) 7.5
(c) %
16. In which of the following Java statements are the variables a, b, c, and d declared?
(d) int a, b, c, d;
Correct answer is (d)
Your score on this question is: 5.56
Feedback:
17. Which of the following is a method invocation that retrieves the first element from an
instance of class java.util.Vector?
(a) elementAt(0)
(b) read(0)
(c) read(1)
(d) elementAt(1)
Correct answer is (a)
Your score on this question is: 5.56
Feedback:
(a) Instantiating
(b) Casting
(c) Declaring
(d) Initializing
Correct answer is (b)
Your score on this question is: 0.00
String s=null;
return s;
If the method assignString is called with the value 4 as its argument, what String value
will be returned?
(a) null
2. Assume that max, x, and y are Java variables of type int and assume that x and y have
different values. Execution of which of the following Java program segments will result in the
larger of x and y being assigned to max?
(c) I only
(a) Integer
(b) real
(c) Object
(d) int
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
public class IQ
{
public int getIQ(String s)
{
return 50;
}
}
(b) getIQ.p("bob");
(c) IQ x = getIQ("chuck");
(a) data
(b) objects
(c) methods
(d) keywords
Correct answer is (c)
Your score on this question is: 5.56
Feedback:
7. How many times will the body of the following loop be executed?
int sum = 0;
int n;
for (n = 9; n > 0; n = n / 2)
sum = sum + n;
(c) once
(d) twice
Correct answer is (b)
Your score on this question is: 5.56
Feedback:
See section 2.3.5 of the course notes.
8. int sum = 0;
int count = 18;
int i = 1;
for (i = 0; i < count; i = i + 2)
sum = sum + i;
(a) It computes the sum of the even numbers from 0 through count - 1
(b) It computes the sum of the odd numbers from 0 through count
(c) It computes the sum of the even numbers from 0 through count
(d) It computes the sum of the odd numbers from 0 through count - 1
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 2.3.5 of the course notes.
9. Which of the following Java while-loops is (are) infinite?
I. while (true) i = 0;
II. while (false) i = 1;
(d) I only
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
10. What is the value of product when the following loop completes?
int i = 3;
int product = 1;
while (i != 0) {
product = product * i;
i = i - 1;
}
(a) 6
(b) 1
(c) 3
(d) 0
Correct answer is (a)
Your score on this question is: 5.56
Feedback:
See section 2.3.5 of the course notes.
11. In Java, for primitives, the assignment operator is the symbol _____ and the equality
operator is the symbol _____.
(a) =, ==
(b) =, equals()
(c) :=, =
(d) ==, =
Correct answer is (a)
Your score on this question is: 5.56
Feedback:
See sections 2.3.2 and 2.3.3 in the course notes.
2 * 4 - 3 + 5 / 2.0
(a) 5
(b) 7
(c) 7.5
(d) 5.0
Correct answer is (c)
Your score on this question is: 5.56
Feedback:
See section 2.3.2 in the course notes. Following the precedence of the operators, the
expression evaluates like this:
13. In Java, the operator "+" can be used for which of the following purposes?
(c) I only
14. If T represents the value true and F represents the value false, what does the following
expression evaluate to?
! ( ( T || F ) && !F )
(a) false
(c) There is an error in the expression so the program containing this expression cannot be
compiled.
(d) true
Correct answer is (a)
Your score on this question is: 5.56
Feedback:
Using the precedence of the operators and the parentheses in the expression, it can be
evaluated like this:
15. The region of a program where a variable can be referenced is known as the _____ of the
variable.
(c) scope
(d) type
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
I. _$4dollar
II. $_4dollar
III. 4_dollar
(a) None
(a) elementAt(0)
(b) elementAt(1)
(c) read(1)
(d) read(0)
Correct answer is (a)
Your score on this question is: 5.56
Feedback:
18. In the Java class java.util.Vector, the method add adds a new element at the
Before compiling this class, the Java compiler requires that it be stored with which of the
following names?
(a) AppletClass.applet
(b) AppletClass.java
(c) Applet.java
(d) Any filename with the extension ".java"
Correct answer is (b)
Your score on this question is: 5.88
Feedback:
See sections 2.1.2 and 2.1.3 in the course notes.
2. When compiling a Java program that contains syntax errors, the compiler will always
(a) fix the syntax errors and complete the compilation
(b) ignore the syntax errors and create a compiled program without the lines containing
errors
(c) fail to complete the compilation and report a guess of what and where the errors are
(d) fail to complete the compilation and report the exact location of each error
Correct answer is (c)
Your score on this question is: 5.88
Feedback:
3. Upon compilation, the source code of a Java class MyClass will be stored in the file
_____, and the corresponding byte code will be stored in the file _____.
(a) MyClass.java, MyClass.class
(b) MyClass.java, MyClass.exe
(c) MyClass.class, MyClass.java
(d) MyClass.class, MyClass.exe
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
4. When compiling a Java program that contains syntax errors, the Java compiler will
always
(a) report syntax errors at some approximate locations and will not successfully compile
(b) ignore the syntax errors and will generate a program that produces approximate
results
(c) report syntax errors at the exact locations and will not successfully compile
(d) ignore the syntax errors and will generate a program that produces correct results
Correct answer is (a)
Your score on this question is: 5.88
Feedback:
See section 2.1.2 and 2.1.3 of the course notes.
5. When programming a Java applet, a programmer creates a(n) _____ file, which a Java
compiler translates into a(n) _____ file.
(a) source code, HTML
(b) bytecode, source code
(c) HTML, bytecode
(d) source code, bytecode
Correct answer is (d)
Your score on this question is: 5.88
Feedback:
8. Of the following phases of programming, which is generally the phase on which most
time is spent?
(a) Defining the problem
(b) Testing and evaluation
(c) Coding
(d) Planning a solution to the problem
Correct answer is (b)
Your score on this question is: 5.88
Feedback:
10. Which of the following is a Java statement that imports classes in the package java.sql?
(a) import java.sql;
(b) import java.sql.*;
(c) import java.sql.all;
(d) import all java.sql;
Correct answer is (b)
Your score on this question is: 5.88
Feedback:
11. What is the name of the class whose definition is begun by the following line?
(a) Hello.Greeting
(b) Greeting.Hello
(c) Hello
(d) Greeting
Correct answer is (c)
Your score on this question is: 5.88
Feedback:
See section 2.1.4, subsection "The Welcome Servlet" in the course notes.
What will be the value of the parameter "a", in the method paintPicture when this code
is executed?
(a) This will not compile. This is an error because the parameter "a" was never declared
and never given a value.
(b) 0
(c) 10
(d) 20
Correct answer is (c)
Your score on this question is: 5.88
Feedback:
The first argument of the call is the graphics object, "g" This value is transferred
to the first formal argument (parameter) which is also called "g". The value of the
second argument (parameter) in the call, "x" is transferred to the second formal
argument (parameter), "a" so the formal argument (parameter), "a" will have a
value of 10. The names do not have to be the same - just the types. The same is
true for the third argument (parameter) in the call, "y". It s value is transferred to
the third formal argument, "b" which will have a value of 20.
14. A Java servlet can obtain an object for sending data to the client of the servlet by calling
which of the following methods of HttpServletResponse?
(a) getCharacterEncoding
(b) encodeURL
(c) getWriter
(d) setContentType
Correct answer is (c)
Your score on this question is: 5.88
Feedback:
See section 2.1.4, subsection "The Welcome Servlet," in the course notes.
15. In Java, the method HttpRequest.getParameter returns an object of which of the
following classes?
(a) String
(b) PrintWriter
(c) Parameter
(d) HttpRequest
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 2.1.4, subsection "Getting User Input," in the course notes.
16. Consider a Java source file that begins with the following line.
import javax.servlet.http.*;
In this file, which of the following lines of code can introduce a valid definition for a
Java servlet class named Welcome?
(a) new Welcome extends HttpServlet
(b) public class Welcome extends HttpServlet
(c) public servlet Welcome extends HttpServlet
(d) servlet class Welcome
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 2.1.4, subsection "The Welcome Servlet," in the course notes.
17. Which of the following is (are) true regarding computer programs and code?
III. Programs consist of text that can cause a computer to perform a task.
(a) II and III only
(b) I and III only
(c) I and II only
(d) I, II, and III
Correct answer is (b)
Your score on this question is: 5.88
Feedback:
Go to top of assessment.
Total score: 76.47
© Copyright 2003 iCarnegie, Inc. All rights reserved.
Which of the following is (are) true regarding the Java API documentation?
(a) I only
(b) II only
(c) I and II
(d) None
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
Valid comments in Java include which of the following?
I. /* Comment 1 */
II. // Comment 2
III. /**
* Comment 3
*/
(c) II only
(a) request.getFoo();
(b) request.getRadio("Foo");
(c) request.getParameter("Foo");
(d) request.getParameter("Foo", radio);
Correct answer is (c)
Your score on this question is: 5.88
Which of the following attributes of an HTML FORM element determines whether a submission of the
form will be processed by the servlet method doPost or the servlet method doGet?
(a) name
(b) target
(c) action
(d) method
Correct answer is (d)
Your score on this question is: 5.88
Before compiling this class, the Java compiler requires that it be stored with which of the
following names?
(a) AppletClass.applet
(b) AppletClass.java
(c) Applet.java
(d) Any filename with the extension ".java"
Correct answer is (b)
Your score on this question is: 5.88
Feedback:
See sections 2.1.2 and 2.1.3 in the course notes.
2. When programming a Java applet, a programmer creates a(n) _____ file, which a Java
compiler translates into a(n) _____ file.
(a) source code, bytecode
(b) source code, HTML
(c) HTML, bytecode
(d) bytecode, source code
Correct answer is (a)
Your score on this question is: 5.88
Feedback:
See section 2.1.2 and 2.1.3 in the course notes.
3. When compiling a Java program that contains syntax errors, the compiler will always
(a) fail to complete the compilation and report a guess of what and where the errors are
(b) ignore the syntax errors and create a compiled program without the lines containing
errors
(c) fix the syntax errors and complete the compilation
(d) fail to complete the compilation and report the exact location of each error
Correct answer is (a)
Your score on this question is: 5.88
Feedback:
4. When compiling a Java program that contains syntax errors, the Java compiler will
always
(a) ignore the syntax errors and will generate a program that produces correct results
(b) report syntax errors at the exact locations and will not successfully compile
(c) report syntax errors at some approximate locations and will not successfully compile
(d) ignore the syntax errors and will generate a program that produces approximate
results
Correct answer is (c)
Your score on this question is: 5.88
Feedback:
See section 2.1.2 and 2.1.3 of the course notes.
5. Upon compilation, the source code of a Java class MyClass will be stored in the file
_____, and the corresponding byte code will be stored in the file _____.
(a) MyClass.class, MyClass.exe
(b) MyClass.java, MyClass.exe
(c) MyClass.class, MyClass.java
(d) MyClass.java, MyClass.class
Correct answer is (d)
Your score on this question is: 5.88
Feedback:
See sections 2.1.2 and 2.1.3 in the course notes.
6. Of the following phases of programming, which is generally the phase on which most
time is spent?
(a) Testing and evaluation
(b) Planning a solution to the problem
(c) Coding
(d) Defining the problem
Correct answer is (a)
Your score on this question is: 5.88
Feedback:
7. Which of the following must be the first phase of the programming process?
(a) Defining the problem
(b) Planning the method for obtaining the input
(c) Planning a solution to the problem
(d) Coding
Correct answer is (a)
Your score on this question is: 5.88
Feedback:
8. When a Java class is designed, which of the following is a part (are parts) of the planning
stage?
All of these are part of the programming process. See section 2.1.6 in the course
notes.
10. What is the name of the class whose definition is begun by the following line?
(a) Greeting
(b) Greeting.Hello
(c) Hello
(d) Hello.Greeting
Correct answer is (c)
Your score on this question is: 5.88
Feedback:
See section 2.1.4, subsection "The Welcome Servlet" in the course notes.
11. Which of the following is a Java statement that imports classes in the package java.sql?
(a) import java.sql.all;
(b) import java.sql;
(c) import all java.sql;
(d) import java.sql.*;
Correct answer is (d)
Your score on this question is: 5.88
Feedback:
What will be the value of the parameter "a", in the method paintPicture when this code
is executed?
(a) 10
(b) This will not compile. This is an error because the parameter "a" was never declared
and never given a value.
(c) 0
(d) 20
Correct answer is (a)
Your score on this question is: 5.88
Feedback:
The first argument of the call is the graphics object, "g" This value is transferred
to the first formal argument (parameter) which is also called "g". The value of the
second argument (parameter) in the call, "x" is transferred to the second formal
argument (parameter), "a" so the formal argument (parameter), "a" will have a
value of 10. The names do not have to be the same - just the types. The same is
true for the third argument (parameter) in the call, "y". It s value is transferred to
the third formal argument, "b" which will have a value of 20.
14. Consider a Java source file that begins with the following line.
import javax.servlet.http.*;
In this file, which of the following lines of code can introduce a valid definition for a
Java servlet class named Welcome?
(a) public servlet Welcome extends HttpServlet
(b) servlet class Welcome
(c) public class Welcome extends HttpServlet
(d) new Welcome extends HttpServlet
Correct answer is (c)
Your score on this question is: 5.88
Feedback:
See section 2.1.4, subsection "The Welcome Servlet," in the course notes.
I. /* Comment 1 */
II. // Comment 2
III. /**
* Comment 3
*/
I. Java has a set of rules that govern what an acceptable program is.
II. Java has a set of keywords whose meanings can be customized by the
programmer.
(b) None
Feedback:
See sections 2.1.2 and 2.1.3 in the course notes.
2. When compiling a Java program that contains syntax errors, the compiler will always
(b) fail to complete the compilation and report the exact location of each error
(c) ignore the syntax errors and create a compiled program without the lines containing errors
(d) fail to complete the compilation and report a guess of what and where the errors are
Correct answer is (d)
Feedback:
3. When compiling a Java program that contains syntax errors, the Java compiler will always
(a) ignore the syntax errors and will generate a program that produces correct results
(b) ignore the syntax errors and will generate a program that produces approximate results
(c) report syntax errors at the exact locations and will not successfully compile
(d) report syntax errors at some approximate locations and will not successfully compile
Correct answer is (d)
Feedback:
See section 2.1.2 and 2.1.3 of the course notes.
4. When programming a Java applet, a programmer creates a(n) _____ file, which a Java
compiler translates into a(n) _____ file.
Feedback:
5. In Java programming, a programmer creates _____ files, and then a compiler translates them
to _____ files.
Feedback:
See sections 2.1.2 and 2.1.3 in the course notes.
6. Of the following phases of programming, which is generally the phase on which most time is
spent?
(c) Coding
Feedback:
7. Programming involves four general phases that the programmer moves into and out of during
the development of a program. The order in which the programmer moves through these
phases is generally which of the following?
(a) There is no defined order. The programmer moves into and out of one of the various four
phases as dictated by circumstance and situation while writing the program.
Feedback:
Programmers move into and out of the four phases in varying patterns. The
programming process is not a linear or straight-line process. See section 2.1.6 in the
course notes.
8. Which of the following must be the first phase of the programming process?
(b) Coding
Feedback:
See section 2.1.6 of the course notes.
(a) Programming can be made easier by dividing a larger problem into smaller pieces.
(b) Most of the time spent in programming is usually spent planning the solution to a
problem.
(d) The best way to program is to begin coding immediately, and then to follow up by testing.
Correct answer is (a)
Feedback:
10. Which of the following is a Java statement that imports classes in the package java.sql?
(a) import java.sql;
Feedback:
(c) I only
Feedback:
See section 2.1.3, subsections "The Catfish Class," in the course notes.
12. The following is a Java program segment:
What will be the value of the parameter "a", in the method paintPicture when this code is
executed?
(a) 10
(b) This will not compile. This is an error because the parameter "a" was never declared and
never given a value.
(c) 0
(d) 20
Correct answer is (a)
Feedback:
The first argument of the call is the graphics object, "g" This value is transferred to
the first formal argument (parameter) which is also called "g". The value of the second
argument (parameter) in the call, "x" is transferred to the second formal argument
(parameter), "a" so the formal argument (parameter), "a" will have a value of 10. The
names do not have to be the same - just the types. The same is true for the third
argument (parameter) in the call, "y". It s value is transferred to the third formal
argument, "b" which will have a value of 20.
13. What is the name of the class whose definition is begun by the following line?
(a) Greeting
(b) Greeting.Hello
(c) Hello
(d) Hello.Greeting
Correct answer is (c)
Feedback:
See section 2.1.4, subsection "The Welcome Servlet" in the course notes.
14. A Java servlet can obtain an object for sending data to the client of the servlet by calling
which of the following methods of HttpServletResponse?
(a) encodeURL
(b) getWriter
(c) setContentType
(d) getCharacterEncoding
Correct answer is (b)
Feedback:
See section 2.1.4, subsection "The Welcome Servlet," in the course notes.
15. Which of the following attributes of an HTML FORM element determines whether a submission
of the form will be processed by the servlet method doPost or the servlet method doGet?
(a) action
(b) name
(c) target
(d) method
Correct answer is (d)
Feedback:
See section 2.1.4, subsection "The Welcome Servlet," in the course notes.
I. /* Comment 1 */
II. // Comment 2
III. /**
* Comment 3
*/
(b) II only
Feedback:
17. Which of the following is (are) true regarding computer programs and code?
III. Programs consist of text that can cause a computer to perform a task.
(a) II and III only
Feedback:
You took 9 minutes on this assessment from Thu Oct 22 2009 17:39:17 GMT+0600 to Thu Oct
22 2009 17:47:37 GMT+0600.
1.
In Java programming, a programmer creates _____ files, and then a compiler translates them to
_____ files.
Feedback:
See sections 2.1.2 and 2.1.3 in the course notes.
2.
Upon compilation, the source code of a Java class MyClass will be stored in the file _____, and the
corresponding byte code will be stored in the file _____.
Feedback:
(a) report syntax errors at the exact locations and will not successfully compile
(b) ignore the syntax errors and will generate a program that produces approximate results
(c) ignore the syntax errors and will generate a program that produces correct results
(d) report syntax errors at some approximate locations and will not successfully compile
Feedback:
See section 2.1.2 and 2.1.3 of the course notes.
4.
When compiling a Java program that contains syntax errors, the compiler will always
(a) fail to complete the compilation and report the exact location of each error
(b) fix the syntax errors and complete the compilation
(c) fail to complete the compilation and report a guess of what and where the errors are
(d) ignore the syntax errors and create a compiled program without the lines containing errors
Feedback:
5.
When programming a Java applet, a programmer creates a(n) _____ file, which a Java compiler
translates into a(n) _____ file.
Feedback:
6.
Feedback:
7.
Which of the following must be the first phase of the programming process?
Feedback:
8.
When a Java class is designed, which of the following is a part (are parts) of the planning stage?
(a) II only
(b) I and III
(c) I and II
(d) II and III
Feedback:
Deciding how to do things is part of implementation. The planning stage of a class consists of
designing the skeleton of the class-problem statement-as well as of deciding what data and methods
the class will need. See section 2.1.6 in the course notes.
9.
Feedback:
10.
What is the name of the class whose definition is begun by the following line?
(a) Greeting
(b) Hello
(c) Greeting.Hello
(d) Hello.Greeting
Feedback:
See section 2.1.4, subsection "The Welcome Servlet" in the course notes.
11.
Which of the following is a Java statement that imports classes in the package java.sql?
Feedback:
12.
Feedback:
See section 2.1.3, subsections "The Catfish Class," in the course notes.
13.
What will be the value of the parameter "a", in the method paintPicture when this code is executed?
(a) 10
(b) 0
(c) This will not compile. This is an error because the parameter "a" was never declared and never
given a value.
(d) 20
Feedback:
The first argument of the call is the graphics object, "g" This value is transferred to the first formal
argument (parameter) which is also called "g". The value of the second argument (parameter) in the
call, "x" is transferred to the second formal argument (parameter), "a" so the formal argument
(parameter), "a" will have a value of 10. The names do not have to be the same - just the types. The
same is true for the third argument (parameter) in the call, "y". It s value is transferred to the third
formal argument, "b" which will have a value of 20.
14.
In a Java servlet, which of the following lines can cause data that was input by a user into an HTML
form to be retrieved?
(a) response.setContentType("text/html");
(b) response.getWriter();
(c) request.getParameter("Name");
(d) out.println("Form value");
Feedback:
See section 2.1.5, subsection "Coding the Servlet," in the course notes.
15.
Feedback:
16.
In Java, the method HttpRequest.getParameter returns an object of which of the following classes?
(a) PrintWriter
(b) String
(c) HttpRequest
(d) Parameter
Feedback:
See section 2.1.4, subsection "Getting User Input," in the course notes.
17.
Which of the following is (are) true regarding the Java API documentation?
Feedback:
2. Which of the statements below correctly constructs an object using the following
constructor?
4. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?
I. int numPeople;
II. int Counter;
(a) None
(b) I and III only
(c) I only
(d) I, II, and III
Correct answer is (c)
Your score on this question is: 8.33
Feedback:
See section 2.2.2, subsection "Mapping English Terms to Java Terms," in the
course notes.
public class IQ
{
public int getIQ(String s)
{
return 50;
}
}
If object p is an instance of class IQ, which of the following is a Java statements that will
not generate a compilation error?
(a) String s = IQ.getIQ(p);
(b) int c = p.getIQ("alex");
(c) getIQ.p("bob");
(d) IQ x = getIQ("chuck");
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
8. Suppose you are given a class called List which has print as one of its methods and a
correctly instantiated object called myList. Which of the following could be a valid call
to the print method?
(a) myList.print;
(b) print(List);
(c) myList.print();
(d) print.myList();
Correct answer is (c)
Your score on this question is: 8.33
Feedback:
See section 2.2.4 in the course notes.
In the method turnOn, which of the following statements should be used to call method
changeStatus?
(a) TrafficLight.changeStatus(newStatus);
(b) changeStatus.newStatus;
(c) changeStatus(newStatus);
(d) changeStatus(TrafficLight, newStatus);
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
10. Which of the following method names adheres to the Java naming convention
standards?
(a) is_empty
(b) IsEmpty
(c) isEmpty
(d) is-empty
Correct answer is (c)
Your score on this question is: 8.33
Feedback:
See section 2.2.2 in the course notes.
11. In Java, variables declared in the body of a method are known as _____ variables.
(a) instance
(b) public
(c) class
(d) local
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
Go to top of assessment.
Total score: 58.33
© Copyright 2003 iCarnegie, Inc. All rights reserved.
Suppose you are given a class called List which has print as one of its methods and a
correctly instantiated object called myList. Which of the following could be a valid call to the
print method?
(a) print.myList();
(b) print(List);
(c) myList.print;
(d) myList.print();
Correct answer is (d)
2. Which of the statements below correctly constructs an object using the following
constructor?
(a) p = Plane;
(b) p = new Plane(1, 2, 3);
(c) p = Plane(1, 2, 3);
(d) p = new Plane;
Correct answer is (b)
Your score on this question is: 8.33
Feedback:
See sections 2.2.4 and 2.2.6 in the course notes. Refer to the manner in which the
constructors for the HtmlPage and AlgaeColony classes are implemented.
3. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?
I. int numPeople;
II. int Counter;
See section 2.2.2, subsection "Mapping English Terms to Java Terms," in the
course notes.
public class IQ
{
public int getIQ(String s)
{
return 50;
}
}
If object p is an instance of class IQ, which of the following is a Java statements that will
not generate a compilation error?
(a) int c = p.getIQ("alex");
(b) getIQ.p("bob");
(c) String s = IQ.getIQ(p);
(d) IQ x = getIQ("chuck");
Correct answer is (a)
Your score on this question is: 8.33
Feedback:
7. Which of the following method names adheres to the Java naming convention standards?
(a) is-empty
(b) IsEmpty
(c) isEmpty
(d) is_empty
Correct answer is (c)
Your score on this question is: 8.33
Feedback:
See section 2.2.2 in the course notes.
12. Variables that are declared in the prototype of a Java method are called
(a) return-types
(b) instance variables
(c) static variables
(d) parameters
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
Go to top of assessment.
Total score: 75.00
© Copyright 2003 iCarnegie, Inc. All rights reserved.
2. Which of the statements below correctly constructs an object using the following
constructor?
4. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?
I. int numPeople;
II. int Counter;
(a) None
(b) I, II, and III
(c) I only
(d) I and III only
Correct answer is (c)
Your score on this question is: 8.33
Feedback:
See section 2.2.2, subsection "Mapping English Terms to Java Terms," in the
course notes.
(a) None
(b) I only
(c) II and III only
(d) II only
Correct answer is (d)
Your score on this question is: 8.33
Feedback:
9. Which of the following method names adheres to the Java naming convention standards?
(a) IsEmpty
(b) is_empty
(c) isEmpty
(d) is-empty
Correct answer is (c)
Your score on this question is: 8.33
Feedback:
See section 2.2.2 in the course notes.
public class IQ
{
public int getIQ(String s)
{
return 50;
}
}
If object p is an instance of class IQ, which of the following is a Java statements that
will not generate a compilation error?
(a) int c = p.getIQ("alex");
(b) getIQ.p("bob");
(c) IQ x = getIQ("chuck");
(d) String s = IQ.getIQ(p);
Correct answer is (a)
Your score on this question is: 8.33
Feedback:
12. Which Java keyword specifies a method so that the method can be called by other
classes?
(a) external
(b) public
(c) global
(d) void
Correct answer is (b)
Your score on this question is: 8.33
Feedback:
See section 2.2.1, subsection "Object State and the Object's Interface," in the
course notes.
3. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?
I. int numPeople;
II. int Counter;
See section 2.2.2, subsection "Mapping English Terms to Java Terms," in the
course notes.
In the method turnOn, which of the following statements should be used to call method
changeStatus?
(a) I only
(b) II and III only
(c) None
(d) II only
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
11. In Java, methods used to create an object of a class are typically known as
(a) makers
(b) constructors
(c) creators
(d) accessors
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
12. The brackets "{" and "}" that mark the beginning and end of a Java class definition are
(a) operators
(b) delimiters
(c) prototypes
(d) terminators
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
Go to top of assessment.
Total score: 58.33
© Copyright 2003 iCarnegie, Inc. All rights reserved.
String s=null;
return s;
If the method assignString is called with the value 4 as its argument, what String
value will be returned?
(a) null
(b) "greater than 10"
(c) "less than 10"
(d) "less than 5"
Correct answer is (c)
Your score on this question is: 5.56
Feedback:
See section 2.3.4 the course notes.
I. i = i;
II. // y = 5;
III. x = 10
(a) I only
(b) III only
(c) I and II only
(d) II and III only
Correct answer is (a)
Your score on this question is: 5.56
Feedback:
See section 2.3.1 in the course notes.
I. int
II. Integer
III. Double
I. Classes
II. Methods
III. Parameters
(a) I and III only
(b) I, II, and III
(c) II and III only
(d) I and II only
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
6. An object is an instance of a
(a) package
(b) method
(c) function
(d) class
Correct answer is (d)
Your score on this question is: 5.56
Feedback:
int i;
for (i = 0; i < 9; i = i + 1)
i = 8;
8. When the following code segment is executed, how many times will the string "Hello!"
be printed?
9. Assume you are given a method with a specification double numbers(); that supplies
you with numbers from the user's input. You need to find the first input number from
user input that is smaller than 0.5 and put it in the variable x. Which of the following can
be used for that purpose?
The first item sets x to the first number greater than 0.5; the second item never
gets user input. See section 2.3.5 of the course notes.
11. In Java, for primitives, the assignment operator is the symbol _____ and the equality
operator is the symbol _____.
(a) =, ==
(b) :=, =
(c) =, equals()
(d) ==, =
Correct answer is (a)
Your score on this question is: 5.56
Feedback:
2 * 4 - 3 + 5 / 2.0
(a) 5.0
(b) 7
(c) 7.5
(d) 5
Correct answer is (c)
Your score on this question is: 5.56
Feedback:
See section 2.3.2 in the course notes. Following the precedence of the operators,
the expression evaluates like this:
14. Which of the following Boolean expressions in Java must evaluate to true, regardless
of the value of the Boolean variable x?
I. !x && x
II. x || !x
15. Which of the following kinds of scope do local variables have in Java?
(a) Block
(b) Local
(c) Method
(d) Class
Correct answer is (a)
Your score on this question is: 5.56
Feedback:
int x = 4;
x = 3;
(a) 2
(b) 4
(c) Undefined
(d) 3
Correct answer is (d)
Your score on this question is: 5.56
Feedback:
17. Reusable collection classes are included in which of the following Java packages?
(a) java.util
(b) java.text
(c) java.io
(d) java.net
Correct answer is (a)
Your score on this question is: 5.56
Feedback:
String a = "A";
String b = "B";
String c = "C";
String d = "D";
Vector v = new Vector();
v.add(a);
v.add(b);
v.add(c);
v.add(d);
At the end of execution of the program segment, what value will be returned by
v.size()?
(a) 10
(b) 5
(c) 4
(d) 3
Correct answer is (c)
Your score on this question is: 5.56
Feedback:
1. When compiling a Java program that contains syntax errors, the Java compiler will
always
(a) ignore the syntax errors and will generate a program that produces correct results
(b) report syntax errors at some approximate locations and will not successfully compile
(c) ignore the syntax errors and will generate a program that produces approximate
results
(d) report syntax errors at the exact locations and will not successfully compile
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See section 2.1.2 and 2.1.3 of the course notes.
2. Which of the following is (are) true regarding the Java API documentation?
What will be the value of the parameter "a", in the method paintPicture when this code is
executed?
(a) 10
(b) 0
(c) 20
(d) This will not compile. This is an error because the parameter "a" was never declared
and never given a value.
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
The first argument of the call is the graphics object, "g" This value is transferred
to the first formal argument (parameter) which is also called "g". The value of the
second argument (parameter) in the call, "x" is transferred to the second formal
argument (parameter), "a" so the formal argument (parameter), "a" will have a
value of 10. The names do not have to be the same - just the types. The same is
true for the third argument (parameter) in the call, "y". It s value is transferred to
the third formal argument, "b" which will have a value of 20.
5. A Java servlet can obtain an object for sending data to the client of the servlet by calling
which of the following methods of HttpServletResponse?
(a) getWriter
(b) encodeURL
(c) setContentType
(d) getCharacterEncoding
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
See section 2.1.4, subsection "The Welcome Servlet," in the course notes.
8. Which of the following method names adheres to the Java naming convention standards?
(a) IsEmpty
(b) is_empty
(c) is-empty
(d) isEmpty
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
See section 2.2.2 in the course notes.
11. In Java, which of the following values can be assigned to a boolean variable?
I. -1
II. 0
III. 2
(a) None
(b) I and II only
(c) II and III only
(d) I only
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
See section 2.3.1 in the course notes.
13. How many asterisks (*) will be output when the following code segment is executed?
(a) 1
(b) 25
(c) 0
(d) 26
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
Boundary testing on this loop will show that the initial value of the loop counter
makes the loop guard expression false. See section 2.3.5 in the course notes.
(a) 9
(b) 0
(c) infinitely many
(d) 10
Correct answer is (c)
Your score on this question is: 5.00
Feedback:
See section 2.3.5 of the course notes. The loop condition contains an assignment,
not an equality.
15. In Java, for primitives, the assignment operator is the symbol _____ and the equality
operator is the symbol _____.
(a) :=, =
(b) =, equals()
(c) ==, =
(d) =, ==
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
16. What is the value of variable x at the end of the execution of the following Java
statement?
int x = 1 + 5%2/2;
(a) 1
(b) 3
(c) 0
(d) 2
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
17. In Java, if x is a Boolean variable with the value true, which of the following
expressions will evaluate to true?
I. !x || x
II. ! (x && !x)
III. x == !x
18. In Java, the scope of a parameter of a method contains the scope of which of the
following?
(a) Local variables of the method
(b) Global variables of the method
(c) Instance variables of the method
(d) Class variables of the method
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
19. In which of the following Java statements are the variables a, b, c, and d declared?
(a) int a..d;
(b) int a-d;
(c) int a, int b, int c, int d;
(d) int a, b, c, d;
Correct answer is (d)
Your score on this question is: 5.00
Feedback: