You are on page 1of 153

Your performance was as follows:

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:

See sections 2.1.2 and 2.1.3 in the course notes.

2. Which of the following is (are) true regarding the Java API documentation?

I. Programmers can view it on the web.

II. It consists solely of Java classes and methods.


(a) I and II
(b) I only
(c) II only
(d) None
Correct answer is (b)
Your score on this question is: 5.00
Feedback:

See Chapter 3, page 105, in the course textbook.

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:

See section 2.1.4 in the course notes.

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;

III. class serviceElevator{}

(a) I, II, and III


(b) None
(c) I and III only
(d) I only
Correct answer is (d)
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.

8. What is the return value of the following method?

void return_value(String s, int i) {


// code here
}

(a) Its return value is String.


(b) It does not have a return value.
(c) Its return value is int.
(d) Its return values are String and int.
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See sections 2.2.2 through 2.2.4 in the course notes.

9. Which of the following is (are) true regarding instance variables in Java?

I. They are also known as local variables.

II. They are typically used to save state information.


(a) None
(b) I only
(c) II only
(d) I and II
Correct answer is (c)
Your score on this question is: 0.00
Feedback:

See Chapter 4, pages 127 and 129, in the course textbook.

10. Which of the following Java statements assigns the bigger of x and y to the variable
max.

I. if (x > y) max = x; else max = y;


II. if (y - x <= 0) max = x; else max = y;

III. max = x; if (x < y) max = y;

(a) III only


(b) I only
(c) I and II only
(d) I, II and III
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

Segment I chooses x if it is bigger then y, or it chooses y. Segment II chooses x


when y - x < 0 so it is good too. Segment III first picks x, but then changes it
into y if the later is bigger. See section 2.3.4 of the course notes.

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.

II. Java is object-oriented.


(a) II only
(b) I only
(c) I and II
(d) None
Correct answer is (c)
Your score on this question is: 5.00
Feedback:

See section 2.1.1 of the course notes.

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:

See section 2.3.5 in 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)

Computes the sum of the odd integers from 1 through n.

(b)

Computes the sum of the even integers from 1 through n.

(c)

Computes the sum of the odd integers from 1 through n - 1.

(d)

Computes the sum of the even integers from 1 through n - 1.


Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See sections 2.3.2 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) =, ==
(b) =, equals()
(c) :=, =
(d) ==, =
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See sections 2.3.2 and 2.3.3 in the course notes.

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:

See section 2.3.2 of the course notes.

17. Consider the following Boolean expression.

!(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:

See section 2.3.3 in the course notes.

18. The scope of an identifier is the


(a) list of classes that can use the identifier
(b) number of times in the program the identifier was used
(c) list of methods that can use the identifier
(d) area of a program where that identifier can be used
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
The scope may be an entire class, a single method, or a set of braces. See section
2.3.1.3, subsection "Scope" 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) 4
(b) 2
(c) Undefined
(d) 3
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.3.1 in the course notes.

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.

2. Which of the following is (are) true regarding programming in Java?

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.

III. Java does not distinguish between uppercase and lowercase.


(a) I only
(b) I and II only
(c) II and III only
(d) I, II, and III
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See Chapter 1, pages 10–1, in the course textbook.

3. You can call an application a client in a client/server architecture if


(a) your computer provides information to the general public
(b) the application requests information from a computer on the Internet that provides
information to many consumers
(c) you pay to your ISP to get on Internet
(d) you only use a Web browser produced by a single company
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See section 1.1.3 of the course notes.

4. What is the name of the class whose definition is begun by the following line?

public class Hello extends Greeting

(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.

5. Which of the following is a keyword in Java?


(a) println
(b) comment
(c) servlet
(d) import
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.1.2 in the course notes.


6. Which of the statements below correctly constructs an object using the following
constructor?

Plane(int a, int b, int c)


{
// code
}

(a) p = new Plane;


(b) p = Plane;
(c) p = Plane(1, 2, 3);
(d) p = new Plane(1, 2, 3);
Correct answer is (d)
Your score on this question is: 5.00
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.

7. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?

I. int numPeople;
II. int Counter;

III. class serviceElevator{}

(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.

8. Valid method definitions in Java include which of the following?

I. public method myMethod() {}


II. public void myMethod(int i) {}

III. public void myMethod {}


(a) II and III only
(b) None
(c) I only
(d) II only
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See sections 2.2.2 through 2.2.4 in the course notes.

9. Consider the following line of Java code.

public int log() throws Exception

What is the return type in the line of code?


(a) int
(b) throws
(c) public
(d) Exception
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See Chapter 4, page 122, in the course textbook.

10. In Java, non-sequential execution of code is achieved by using _____ statements.


(a) ordering
(b) branching
(c) control
(d) concurrent
Correct answer is (c)
Your score on this question is: 5.00
Feedback:

See sections 2.3.4 and 2.3.5 in the course notes.


11. Which of the following data types is a Java primitive type?
(a) Object
(b) Integer
(c) real
(d) int
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.3.1 in the course notes.

12. Which of the following is (are) true about Java?

I. Java is portable.

II. Java is object-oriented.


(a) None
(b) I only
(c) I and II
(d) II only
Correct answer is (c)
Your score on this question is: 5.00
Feedback:

See section 2.1.1 of the course notes.

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.

14. How many times will the following loop execute?

boolean flag = false;


int count = 0;
while (flag = true) {
if (count <= 10)
count = count + 1;
else
flag = false;
}

(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:

See sections 2.3.2 and 2.3.3 in the course notes.

16. What is output when the following Java statement is executed?

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:

See section 2.3.2 in the course notes.

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?
(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:

See section 2.3.3 in the course notes.

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:

See section 2.3.1.3, subsection "Scope," in the course notes.

19. In Java, which of the following identifiers are correct?

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?

(a) Exactly one


(b) At least one
(c) None
(d) At most one

Correct answer is (b)

Your score on this question is: 0.00

Feedback:

See sections 2.1.2 and 2.1.3 in the course notes.

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

Correct answer is (c)

Your score on this question is: 5.00

Feedback:

See Chapter 1, page 3, in the course textbook.

3.

A certain group of _____ connected together form the Internet.

(a) Internet service providers


(b) search engines
(c) computers
(d) Web users

Correct answer is (c)

Your score on this question is: 5.00

Feedback:

See section 1.1.1 of the course notes.

4.

Valid Java comments include which of the following?

1. /* this is an /* embedded */ comment */


2. /* this is an // embedded // comment */
3. // this is a comment */
(a) I only
(b) II and III only
(c) I and II only
(d) I and III only

Correct answer is (b)

Your score on this question is: 5.00

Feedback:
See section 2.1.3, subsections "The Catfish Class," in the course notes.

5.

In Java, the method HttpRequest.getParameter returns an object of which of the following


classes?

(a) HttpRequest
(b) Parameter
(c) String
(d) PrintWriter

Correct answer is (c)

Your score on this question is: 5.00

Feedback:

See section 2.1.4, subsection "Getting User Input," in the course notes.

6.

Which of the following is true if a Java class is declared public?

(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.

Correct answer is (c)

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?

1. int numPeople;
2. int Counter;
3. class serviceElevator{}

(a) None
(b) I and III only
(c) I, II, and III
(d) I only

Correct answer is (d)

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.

8.

The following line can be the start of

public void paint(Graphics g)

(a) a method definition


(b) a variable declaration
(c) a method call
(d) a class definition

Correct answer is (a)

Your score on this question is: 5.00

Feedback:
See section 2.2.2 through 2.2.4 in the course notes.

9.

In Java, the initial values of method parameters are set by

(a) arguments of the invoking message


(b) initialization statements
(c) accessor methods
(d) access control

Correct answer is (a)

Your score on this question is: 0.00

Feedback:

See Chapter 4, page 150, in the course textbook.

10.

In Java, non-sequential execution of code is achieved by using _____ statements.

(a) ordering
(b) branching
(c) concurrent
(d) control

Correct answer is (d)

Your score on this question is: 5.00

Feedback:

See sections 2.3.4 and 2.3.5 in the course notes.

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

Correct answer is (c)

Your score on this question is: 5.00

Feedback:

See sections 2.3.1 and 2.3.2 in the course notes.

12.

The term Java Virtual Machine refers to

(a) a household appliance operated by Java (usually a smart toaster)


(b) a hardware extension needed to run Java
(c) a compiler of Java source code
(d) an interpreter of Java bytecode

Correct answer is (d)

Your score on this question is: 5.00

Feedback:
See section 2.1.2 of the course notes.

13.

Consider the following code segment.

for (int j = 0; j < 10; j++)


for (int k = 10; k > 0; k--)
System.out.print("Hello");

The code segment shows an example of _____ loops.


(a) opposite
(b) nested
(c) sequential
(d) infinite

Correct answer is (b)

Your score on this question is: 0.00

Feedback:

See section 2.3.5 in the course notes.

14.

How many times will the following be executed?

int i = 0;
while (i > 5 || i < 5) {
System.out.println(i + "1");
}

(a) 5
(b) 6
(c) infinitely many
(d) 4

Correct answer is (c)

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:

See sections 2.3.2 and 2.3.3 in the course notes.

16.

What is output when the following Java statement is executed?

System.out.println(-5%-2);

(a) 2
(b) –1
(c) 0
(d) 1

Correct answer is (b)

Your score on this question is: 5.00

Feedback:

See section 2.3.2 in the course notes.

17.

Consider the following Boolean expression.

!(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: 5.00

Feedback:

See section 2.3.3 in the course notes.

18.

Consider the Java code below.

class MyClass {

int age;

void myMethod() {

int counter = 19;

age = counter;

Which of the following is true concerning the code?

(a) age and counter have the same scope.


(b) age is an instance variable and counter is a local variable.
(c) age and counter will always contain the same value.
(d) myMethod will generate a compile-time error because age cannot be referenced.

Correct answer is (b)

Your score on this question is: 0.00

Feedback:

See section 2.3.1.3, subsection "Scope," in the course notes.


19.

Legal Java statements include which of the following?

1. String greeting = new String();


2. String greeting = String();
3. String greeting = null;

(a) I only
(b) II and III only
(c) I and III 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, Variables, in the course notes.

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

Correct answer is (c)

Your score on this question is: 5.00

Feedback:

See Chapter 9, page 333, in the course textbook.

View Assessment Result: Exam 2 Multiple-Choice

Your performance was as follows:


1. 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.class
(c) MyClass.class, MyClass.java
(d) MyClass.java, MyClass.exe
Correct answer is (b)
Your score on this question is: 5.00
Feedback:

See sections 2.1.2 and 2.1.3 in the course notes.

2. Which of the following is (are) true regarding the Java API documentation?

I. The list of classes can be filtered by package.


II. Typically, only the most important methods of a class are listed.

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:

See Chapter 3, pages 105–8, in the course textbook.

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.

4. The following is a Java program segment:

public void paint (Graphics g)


{
int x = 10;
int y = 20;
paintPicture( g, x, y);
}
public void paintPicture(Graphics g, int a, int b)
{
g.setColor(Color.red);
// more code follows
}

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?

Plane(int a, int b, int c)


{
// code
}

(a) p = new Plane(1, 2, 3);


(b) p = Plane;
(c) p = new Plane;
(d) p = Plane(1, 2, 3);
Correct answer is (a)
Your score on this question is: 5.00
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.

7. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?

I. int numPeople;
II. int Counter;

III. class serviceElevator{}

(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.

8. Consider the following Java code fragment.

public class TrafficLight{


int status;
public void changeStatus(int newStatus) {
status = newStatus;
}

public void turnOn(int newStatus) {


// . . .
}
}

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:

See section 2.2.2 in the course notes.

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:

See Chapter 4, page 150, in the course textbook.

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)

Any value of x would make the condition true.

(b) Only one branch of an if-else-statement can be executed.


(c)

The condition could never be true for any value of x.

(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

II. Range of values


(a) I and II
(b) I only
(c) None
(d) II only
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See section 2.3.1and 2.3.2 in the course notes.

12. Which words in the following line of code are Java keywords?

public void paint(Graphics g)

(a) public, void, paint


(b) public, void
(c) public, Graphics
(d) void, Graphics
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See section 2.1.4 in the course notes.

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:

See section 2.3.5 of the course notes.

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?

I. double x = numbers(); while (x <= 0.5) x = numbers();


II. double x = 0.1; while (x >= 0.5) x = numbers();

III. double x; for (x = numbers(); x >= 0.5; x = numbers());

(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:

See sections 2.3.2 and 2.3.3 in the course notes.

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?

I. The loop counter is not initialized correctly.


II. The loop increments by the wrong amount.

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:

See section 2.3.5 of the course notes.

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))

III. (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.

18. The scope of an identifier is the


(a) area of a program where that identifier can be used
(b) list of classes that can use the identifier
(c) number of times in the program the identifier was used
(d) list of methods that can use the identifier
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
The scope may be an entire class, a single method, or a set of braces. See section
2.3.1.3, subsection "Scope" 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:

See section 2.3.1 in the course notes.

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:

See Chapter 9, page 333, in the course textbook.

Go to top of assessment.
Total score: 80.00
© Copyright 2003 iCarnegie, Inc. All rights reserved.

Your performance was as follows:


1. How many ".class" files will be generated after a successful compilation of any ".java"
file?
(a) At most one
(b) None
(c) Exactly one
(d) At least one
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See sections 2.1.2 and 2.1.3 in the course notes.

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.

3. You can call an application a client in a client/server architecture if


(a) you pay to your ISP to get on Internet
(b) the application requests information from a computer on the Internet that provides
information to many consumers
(c) your computer provides information to the general public
(d) you only use a Web browser produced by a single company
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See section 1.1.3 of the course notes.

4. Valid Java comments include which of the following?

I. /* this is an /* embedded */ comment */


II. /* this is an // embedded // comment */

III. // this is a comment */

(a) I and II only


(b) I only
(c) I and III only
(d) II and III only
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
See section 2.1.3, subsections "The Catfish Class," in the course notes.

5. Valid comments in Java include which of the following?

I. /* Comment 1 */
II. // Comment 2

III. /**
* Comment 3
*/

(a) I, II, and III


(b) I and III only
(c) I and II only
(d) II only
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See section 2.1.2 in the course notes.

6. What operator is used to allocate storage for objects?


(a) =
(b) ==
(c) init
(d) new
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.2.3 in the course notes.

7. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?

I. int numPeople;
II. int Counter;

III. class serviceElevator{}

(a) I, II, and III


(b) I and III only
(c) None
(d) I only
Correct answer is (d)
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.

8. The following line can be the start of

public void paint(Graphics g)

(a) a method call


(b) a class definition
(c) a method definition
(d) a variable declaration
Correct answer is (c)
Your score on this question is: 5.00
Feedback:
See section 2.2.2 through 2.2.4 in the course notes.

9. In Java, methods used to create an object of a class are typically known as


(a) creators
(b) makers
(c) accessors
(d) constructors
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See Chapter 3, page 77, in the course textbook.

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. if (x > y) max = x; else max = y;


II. if (y - x <= 0) max = x; else max = y;

III. max = x; if (x < y) max = y;

(a) I, II, and III


(b) I only
(c) III only
(d) I and II only
Correct answer is (a)
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

II. Range of values


(a) None
(b) II only
(c) I only
(d) I and II
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.3.1and 2.3.2 in the course notes.

12. Which words in the following line of code are Java keywords?

public void paint(Graphics g)

(a) public, void, paint


(b) public, void
(c) public, Graphics
(d) void, Graphics
Correct answer is (b)
Your score on this question is: 5.00
Feedback:

See section 2.1.4 in the course notes.

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:

See sections 2.3.2 and 2.3.3 in the course notes.

16. Consider the following code fragment.

int m = 3;
int n = m / 2;

What is the value of n?


(a) 1.0
(b) 2
(c) 1.5
(d) 1
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
Integer division truncates. See section 2.3.2 in the course notes.
17. Which of the following is not a Boolean operator in Java?
(a) ||
(b) &&
(c) !
(d) %
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.3.3 in the course notes.

18. The scope of an identifier is the


(a) number of times in the program the identifier was used
(b) list of classes that can use the identifier
(c) list of methods that can use the identifier
(d) area of a program where that identifier can be used
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
The scope may be an entire class, a single method, or a set of braces. See section
2.3.1.3, subsection "Scope" in the course notes.

19. Valid Java identifiers include which of the following?

I. _$4dollar
II. $_4dollar

III. 4_dollar

(a) III only


(b) I and II only
(c) None
(d) I, II, and III
Correct answer is (b)
Your score on this question is: 5.00
Feedback:

See section 2.3.1 in the course notes.


20. The value of the largest index of an instance of class java.util.Vector is always
_____ the size of the vector.
(a) half of
(b) equal to
(c) one greater than
(d) one less than
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See Chapter 9, page 333, in the course textbook.

View Assessment Result

Family Name: Shaykamalov


Given Name: Serik
Login: sshaykam
E-mail: 11024@iitu.kz
Status: Enrolled

Assessment Name: Exam 2 Multiple-Choice


Instance: 1

Section: IITU-050602 Computer Science CS-0901


During: Fall/Autumn 2009
Section Status: Active

For course: Introduction to Information Systems


(SSD1)

Corresponding to: SSD1


At: INTERNATIONAL UNIVERSITY OF INFORMATION TECHNOLOGY

Your performance was as follows:

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.

Total score: 95.00


1.
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.

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

Correct answer is (b)

Your score on this question is: 5.00

Feedback:

See Chapter 1, page 3, in the course textbook.

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?

1. (Web servers, Web clients)


2. (FTP servers, FTP users)

(a) I only
(b) I and II
(c) II only
(d) None

Correct answer is (a)

Your score on this question is: 0.00

Feedback:

See sections 1.1.1 and 1.1.3 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.*;


(b) import java.sql.all;
(c) import all java.sql;
(d) import java.sql;

Correct answer is (a)

Your score on this question is: 5.00

Feedback:

See section 2.1.4 in the course notes.

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

Correct answer is (c)

Your score on this question is: 5.00

Feedback:
See section 2.1.4, subsection "The Welcome Servlet," in the course notes.

6.

In Java, which of the following is true about constructors?

(a) Constructors cannot return a value.


(b) Constructors can only accept primitive Java types as parameters.
(c) Constructors must be declared for every class.
(d) Constructors can only return 0 or a negative integer.

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.

7.

Which of the following is (are) consistent with Java naming conventions regarding
capitalization?

1. int numPeople;
2. int Counter;
3. class serviceElevator{}

(a) I, II, and III


(b) None
(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.
8.

Which of the following is not a valid name of a Java method?

(a) fred$wallet
(b) RESET
(c) 3jane
(d) Napoleon_The_First

Correct answer is (c)

Your score on this question is: 5.00

Feedback:

See section 2.2.2 in the course notes.

9.

Which of the following is (are) true regarding object state and behavior in Java?

1. Objects of the same class always share the same state.


2. Objects of the same class always share the same behavior.

(a) None
(b) II only
(c) I only
(d) I and II

Correct answer is (b)

Your score on this question is: 5.00

Feedback:

See Chapter 4, pages 141–2, in the course textbook.

10.

Consider the following program segment.


public String nameOfEmployee (int salary) {

if (salary < 50000) {

if (salary > 45000)

return "Joe";

else if (salary < 60000) return "John";

else return "Jack";

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

Correct answer is (b)

Your score on this question is: 5.00

Feedback:

See section 2.3.4 in the course notes.

11.

Suppose an object p is an instance of the following class

public class IQ
{
public int getIQ(String s)
{
return 50;
}
}

Which of the following lines is a correct Java statement?

(a) IQ x = getIQ("chuck");
(b) int c = p.getIQ("aleks");
(c) getIQ.p("bob");
(d) String s = IQ.getIQ(p);

Correct answer is (b)

Your score on this question is: 5.00

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?

public void draw(Graphics g)

(a) Method draw cannot be called by other classes.


(b) Method draw will not return a value.
(c) Method draw will not draw anything to the screen.
(d) Method draw will not do any computations.

Correct answer is (b)

Your score on this question is: 5.00

Feedback:

See section 2.1.3 in the course notes.

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:

See section 2.3.5 in 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) 6
(c) 3
(d) 0

Correct answer is (b)

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) =, equals()
(d) ==, =

Correct answer is (b)

Your score on this question is: 5.00

Feedback:

See sections 2.3.2 and 2.3.3 in the course notes.

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?

1. The loop counter is not initialized correctly.


2. The loop increments by the wrong amount.
3. The loop guard causes the loop to terminate at the wrong place.

(a) II and III


(b) None
(c) I and III
(d) I only

Correct answer is (c)

Your score on this question is: 5.00

Feedback:

See section 2.3.5 of the course notes.


17.

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

(a) II and III only


(b) III only
(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.3.3 in the course notes.

18.

Which of the following kinds of scope do local variables have in Java?

(a) Local
(b) Method
(c) Block
(d) Class

Correct answer is (c)

Your score on this question is: 5.00

Feedback:

See section 2.3.1.3, subsection "Scope," in the course notes.


19.
In Java, which of the following identifiers are correct?

1. MYCLASS
2. my_Class
3. myclass.1

(a) II and III only


(b) I and II only
(c) I and III only
(d) I, II, and III

Correct answer is (b)

Your score on this question is: 5.00

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

Correct answer is (d)

Your score on this question is: 5.00

Feedback:

See Chapter 9, page 332, in the course textbook.

Go to top of assessment.

Total score: 95.00

© Copyright 2003 iCarnegie, Inc. All rights reserved.


View Assessment Result: Exam 2 Multiple-Choice

Your performance was as follows:


1. When compiling a Java program that contains syntax errors, the compiler will always
(b) fail to complete the compilation and report a guess of what and where the errors are
Correct answer is (b)
2. Model elements in Java programs that share a common behavior can be grouped into
categories called
(d) classes
Correct answer is (d)
3. Which of the following is not a valid URL?
(d) http:/www.cmu.edu
Correct answer is (d)
4. Which of the following is a Java statement that imports classes in the package java.sql?
(d) import java.sql.*;
Correct answer is (d)
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?
(c) request.getParameter("Foo");
Correct answer is (c)
6. Which of the following can be a valid definition for a Java class?
(d) public class Welcome extends HttpServlet {}
Correct answer is (d)
7. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?

I. int numPeople;
II. int Counter;

III. class serviceElevator{}

(b) I only
Correct answer is (b)
8. Valid method definitions in Java include which of the following?

I. public method myMethod() {}


II. public void myMethod(int i) {}

III. public void myMethod {}

(c) II only

Correct answer is (c)


9. Which of the following is (are) true regarding objects in Java?

I. Every object is an instance of a class.

II. Objects of the same class share a common set of behaviors.


(b) I and II
Correct answer is (b)
10. In Java, non-sequential execution of code is achieved by using _____ statements.
(c) control
Correct answer is (c)
11. Which of the following are valid Java statements?

I. i = i;
II. // y = 5;

III. x = 10

(a) I only

Correct answer is (a)


12. The SDK compiler is _____, and the SDK interpreter is _____.
(c) javac, java
Correct answer is (c)
13. How many times will this loop execute?

int y = 1;
int i;
for (i = 10; i < 0; i = i - 1)
y = i + 2;

(c) 0 The loop test is false because i is not less than 0


Correct answer is (c)
14. int i = 1, sum = 0;
while (i < 3){
int j = 0;
while ( j < 2){
sum = sum + j;
j = j + 1;
}
i = i + 1;
}

What is the value of sum after the loop?

(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);

(b) I and II only


Correct answer is (b)
20. The value of the largest index of an instance of class java.util.Vector is always
_____ the size of the vector.
(a) one less than
Correct answer is (a)

View Assessment Result: Exam 2 Multiple-Choice

Your performance was as follows:


1. 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) bytecode, source code

(d) HTML, bytecode


Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See section 2.1.2 and 2.1.3 in the course notes.

2. Which of the following is (are) true regarding the Java API documentation?

I. The list of classes can be filtered by package.


II. Typically, only the most important methods of a class are listed.

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: 5.00
Feedback:

See Chapter 3, pages 105–8, in the course textbook.

3. Which of the following is (are) true about client-server architecture?

I. Web clients can only be executed on a powerful computer.

II. Web servers can support only one client at a time.

(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:

See section 1.1.3 of the course notes.

4. What is the name of the class whose definition is begun by the following line?

public class Hello extends Greeting

(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.

5. Which of the following is a keyword in Java?

(a) comment

(b) servlet

(c) println

(d) import
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.1.2 in the course notes.

6. What operator is used to allocate storage for objects?

(a) ==

(b) new

(c) =

(d) init
Correct answer is (b)
Your score on this question is: 5.00
Feedback:

See section 2.2.3 in the course notes.

7. Which of the following variable names conforms to Java naming conventions?

(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.

9. Which of the following is (are) true regarding instance variables in Java?

I. They are also known as local variables.

II. They are typically used to save state information.

(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:

See Chapter 4, pages 127 and 129, in the course textbook.

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)

Any value of x would make the condition true.

(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.

(d) Only one branch of an if-else-statement can be executed.


Correct answer is (b)
Your score on this question is: 5.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, which of the following values can be assigned to a boolean variable?

I. -1
II. 0

III. 2

(a) I and II only

(b) I only

(c) II and III only

(d) None
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.3.1 in the course notes.

12. The SDK compiler is _____, and the SDK interpreter is _____.

(a) javac, java

(b) jcc, java

(c) jcc, javai

(d) javac, javai


Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See section 2.1.2 in the course notes.

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)

Computes the sum of the even integers from 1 through n.

(b)

Computes the sum of the even integers from 1 through n - 1.

(c)

Computes the sum of the odd integers from 1 through n - 1.

(d)

Computes the sum of the odd integers from 1 through n.


Correct answer is (a)
Your score on this question is: 5.00
Feedback:
See sections 2.3.2 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) =, ==

(b) =, equals()
(c) ==, =

(d) :=, =
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See sections 2.3.2 and 2.3.3 in the course notes.

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?

I. The loop counter is not initialized correctly.


II. The loop increments by the wrong amount.

III. The loop guard causes the loop to terminate at the wrong place.

(a) I and III

(b) I only

(c) None

(d) II and III


Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See section 2.3.5 of the course notes.

17. Which of the following is not a Boolean operator in Java?

(a) ||

(b) !

(c) &&

(d) %
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.3.3 in the course notes.


18. In Java, the scope of a parameter of a method contains the scope of which of the following?

(a) Class variables of the method

(b) Local variables of the method

(c) Instance variables of the method

(d) Global variables of the method


Correct answer is (b)
Your score on this question is: 5.00
Feedback:

See section 2.3.1 in the course notes.

19. Consider the following Java code fragment.

public class BigBox {

public int xHeight;

public int yHeight;

// . . .

The variables xHeight and yHeight are _____ variables.

(a) instance

(b) local

(c) global

(d) parameter
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See section 2.3.1 in the course notes.

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) half of

(c) equal to

(d) one less than


Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See Chapter 9, page 333, in the course textbook.

Go to top of assessment.
Total score: 100.00
© Copyright 2003 iCarnegie, Inc. All rights reserved.

View Assessment Result: Exam 2 Multiple-Choice

Your performance was as follows:


1. 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.java
(b) MyClass.java, MyClass.class
(c) MyClass.class, MyClass.exe
(d) MyClass.java, MyClass.exe
Correct answer is (b)
Your score on this question is: 5.00
Feedback:

See sections 2.1.2 and 2.1.3 in the course notes.

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:

See Chapter 1, page 3, in the course textbook.

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:

See section 1.1.1 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;
(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 in the course notes.

5. 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) target
(b) action
(c) method
(d) name
Correct answer is (c)
Your score on this question is: 5.00
Feedback:

See section 2.1.4, subsection "The Welcome Servlet," in the course notes.

6. In a Java class Hello, a method declared to be public can be called by


(a) only the class Hello
(b) any class
(c) only the classes in the same package as Hello
(d) only the class Hello and the subclasses of Hello
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 variable names conforms to Java naming conventions?


(a) AmountOfFuelRemainingInTheTank
(b) fuel_remaining
(c) fuelRemaining
(d) FuelRemaining
Correct answer is (c)
Your score on this question is: 5.00
Feedback:

See section 2.2.2 in the course notes.

8. Which of the following statements is true about methods in Java?

I. Every method must be declared public.


II. Every method must accept at least one parameter.

III. Every method must return a value.


(a) II and III only
(b) none of them
(c) III only
(d) I, II, and III
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See sections 2.2.2 through 2.2.4 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:

See Chapter 3, page 78, in the course textbook.

10. Consider the following program segment.

public String nameOfEmployee (int salary) {

if (salary < 50000) {

if (salary > 45000)

return "Joe";

else if (salary < 60000) return "John";

else return "Jack";

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:

See section 2.3.4 in the course notes.

11. The type of the number 2.0 in Java can be


(a) boolean
(b) double
(c) Panel
(d) int
Correct answer is (b)
Your score on this question is: 5.00
Feedback:
See section 2.3.1 in the course notes.

12. A Java Virtual Machine (JVM) is


(a) a compiler that generates Java bytecode
(b) hardware that interprets Java bytecode
(c) a decompiler that creates Java source code from Java bytecode
(d) software that interprets Java bytecode
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.1.2 in the course notes.

13. Consider a Java for-loop with the following form.

for (initialization; loopGuard; update)


loopBody

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:

See section 2.3.5 the course notes.

14. How many times will the following be executed?

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:

See sections 2.3.2 and 2.3.3 in the course notes.

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:

See section 2.3.2 in the course notes.

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

III. x == true || x == false

(a) II and III only


(b) I and III only
(c) I, II, and III
(d) III only
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See section 2.3.3 in the course notes.

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:

See section 2.3.1 in the course notes.

19. The amount of memory used to store a variable depends on


(a) the type of the variable
(b) the number of times the variable is accessed
(c) the scope of the variable
(d) whether the variable is declared in a class that extends class Applet
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 2.3.1 in the course notes.

20. In Java, the class java.util.Vector models an


(a) unordered collection of individual elements
(b) ordered collection of name-value pairs
(c) unordered collection of name-value pairs
(d) ordered collection of individual elements
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See Chapter 9, page 333, in the course textbook.

Go to top of assessment.
Total score: 90.00
© Copyright 2003 iCarnegie, Inc. All rights reserved.

View Assessment Result: Exam 2 Multiple-Choice

Your performance was as follows:


1. How many ".class" files will be generated after a successful compilation of any ".java"
file?
(a) None
(b) Exactly one
(c) At most one
(d) At least one
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See sections 2.1.2 and 2.1.3 in the course notes.

2. Which of the following is (are) true regarding the Java API documentation?

I. Programmers can view it on the web.


II. It consists solely of Java classes and methods.
(a) I and II
(b) I only
(c) II only
(d) None
Correct answer is (b)
Your score on this question is: 5.00
Feedback:

See Chapter 3, page 105, in the course textbook.

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:

See section 1.1.3 of the course notes.

4. What is the name of the class whose definition is begun by the following line?

public class Hello extends Greeting

(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.

6. What operator is used to allocate storage for objects?


(a) init
(b) ==
(c) =
(d) new
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.2.3 in the course notes.

7. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?

I. int numPeople;
II. int Counter;

III. class serviceElevator{}

(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.

8. The following line can be the start of

public void paint(Graphics g)

(a) a class definition


(b) a variable declaration
(c) a method definition
(d) a method call
Correct answer is (c)
Your score on this question is: 5.00
Feedback:
See section 2.2.2 through 2.2.4 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:

See Chapter 4, page 122, in the course textbook.

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. if (x > y) max = x; else max = y;


II. if (y - x <= 0) max = x; else max = y;

III. max = x; if (x < y) max = y;

(a) I, II, and III


(b) III only
(c) I only
(d) I and II only
Correct answer is (a)
Your score on this question is: 5.00
Feedback:
See section 2.3.4 of the course notes.

11. Which of the following are primitive Java types?

I. int
II. Integer

III. Double

(a) I and II only


(b) I, II and III only
(c) II and III only
(d) I only
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 2.3.1in the course notes.

12. Which words in the following line of code are Java keywords?

public void paint(Graphics g)

(a) public, Graphics


(b) void, Graphics
(c) public, void
(d) public, void, paint
Correct answer is (c)
Your score on this question is: 5.00
Feedback:

See section 2.1.4 in the course notes.

13. Consider the following code segment.

for (int j = 0; j < 10; j++)


for (int k = 10; k > 0; k--)
System.out.print("Hello");

The code segment shows an example of _____ loops.


(a) infinite
(b) nested
(c) sequential
(d) opposite
Correct answer is (b)
Your score on this question is: 5.00
Feedback:

See section 2.3.5 in the course notes.

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:

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 (d)
Your score on this question is: 5.00
Feedback:

See sections 2.3.2 and 2.3.3 in the course notes.


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?

I. The loop counter is not initialized correctly.


II. The loop increments by the wrong amount.

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:

See section 2.3.5 of the course notes.

17. Consider the following Boolean expression.

!(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:

See section 2.3.3 in the course notes.


18. Consider the Java code below.

class MyClass {

int age;

void myMethod() {

int counter = 19;

age = counter;

Which of the following is true concerning the code?


(a) age and counter will always contain the same value.
(b) myMethod will generate a compile-time error because age cannot be referenced.
(c) age and counter have the same scope.
(d) age is an instance variable and counter is a local variable.
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.3.1.3, subsection "Scope," in the course notes.

19. In the class defined below

class MyClass {
int age = 19;
void myMethod()
{
int counter;
}
}

(a)

both age and counter are instance variables

(b) age

is an instance variable and counter is a local variable

(c)
both age and counter are local variables

(d) age

is a local variable and counter is an instance variable


Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 2.3.1 of the course notes.

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:

See Chapter 9, page 332, in the course textbook.

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.

II. It consists solely of Java classes and methods.


(a) None
(b) I and II
(c) I only
(d) II only
Correct answer is (c)
Your score on this question is: 0.00
Feedback:

See Chapter 3, page 105, in the course textbook.

3. Which of the following statements about the Internet is (are) true?

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.

III. The primary business of an ISP is to sell advertising on the Internet.


(a) II and III only
(b) II only
(c) I only
(d) I and II only
Correct answer is (b)
Your score on this question is: 5.00
Feedback:

See section 1.1.5 of the course notes.

4. The following is a Java program segment:

public void paint (Graphics g)


{
int x = 10;
int y = 20;
paintPicture( g, x, y);
}
public void paintPicture(Graphics g, int a, int b)
{
g.setColor(Color.red);
// more code follows
}

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.

5. Valid comments in Java include which of the following?

I. /* Comment 1 */
II. // Comment 2

III. /**
* Comment 3
*/

(a) I and III only


(b) II only
(c) I and II only
(d) I, II, and III
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.1.2 in the course notes.

6. What operator is used to allocate storage for objects?


(a) new
(b) ==
(c) =
(d) init
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See section 2.2.3 in the course notes.

7. Which of the following variable names conforms to Java naming conventions?


(a) fuel_remaining
(b) FuelRemaining
(c) AmountOfFuelRemainingInTheTank
(d) fuelRemaining
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See section 2.2.2 in the course notes.

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.

9. Consider the following line of Java code.

public int log() throws Exception

What is the return type in the line of code?


(a) public
(b) throws
(c) Exception
(d) int
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See Chapter 4, page 122, in the course textbook.

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. if (x > y) max = x; else max = y;


II. if (y - x <= 0) max = x; else max = y;

III. max = x; if (x < y) max = y;

(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

II. Range of values


(a) I and II
(b) I only
(c) None
(d) II only
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See section 2.3.1and 2.3.2 in the course notes.

12. Which of the following statements best describes objects in Java?


(a) An object is everything included into the program with the import command.
(b) An object is a data-structure equipped with methods for manipulating that data.
(c) An object is a set of classes that share a common structure and a common behavior.
(d) An object is a collection of methods that produce graphical elements in the applet or
application window, or compute and return values.
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 2.2.1 of the course notes.

13. How many times will the following loop execute?

int i;
for (i = 0; i < 9; i = i + 1)
i = 8;

(a) infinitely many


(b) 9
(c) 2
(d) 1
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)

Computes the sum of the odd integers from 1 through n - 1.

(b)

Computes the sum of the even integers from 1 through n - 1.

(c)

Computes the sum of the odd integers from 1 through n.


(d)

Computes the sum of the even integers from 1 through n.


Correct answer is (d)
Your score on this question is: 5.00
Feedback:
See sections 2.3.2 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:

See sections 2.3.2 and 2.3.3 in the course notes.

16. In Java, the operator "+" can be used for which of the following purposes?

I. Addition of two integers


II. Concatenation of two strings

III. Addition of two floating point variables


(a) I, II, and III
(b) I only
(c) I and III only
(d) II and III only
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See section 2.3.2 in the course notes.

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:

See section 2.3.3 of the course notes.

18. The scope of an identifier is the


(a) number of times in the program the identifier was used
(b) list of methods that can use the identifier
(c) list of classes that can use the identifier
(d) area of a program where that identifier can be used
Correct answer is (d)
Your score on this question is: 5.00
Feedback:
The scope may be an entire class, a single method, or a set of braces. See section
2.3.1.3, subsection "Scope" in the course notes.

19. In Java, which of the following identifiers are correct?

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.

20. In Java, the class java.util.Vector models an


(a) unordered collection of individual elements
(b) ordered collection of individual elements
(c) unordered collection of name-value pairs
(d) ordered collection of name-value pairs
Correct answer is (b)
Your score on this question is: 5.00

Your performance was as follows:


1. Consider the following program segment.

public String assignString(int x) {

String s=null;

if (x<5) s = "less than 5";

if (x<10) s = "less than 10";

else s = "greater than 10";

return s;

If the method assignString is called with the value 4 as its argument, what String value
will be returned?

(c) "less than 10"

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)

The condition could never be true for any value of x.


3. In Java, the data type of a variable determines which of the following?

I. Valid operators

II. Range of values

(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?

public class Hello extends Applet { . . . }

(b) Three
6. The term Java Virtual Machine refers to

(a) an interpreter of Java bytecode


7. 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 1 2 0 2 4 0 3 6
8. Consider a Java for-loop with the following form.

for (initialization; loopGuard; update)


loopBody

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

10. int i = 1, sum = 0;


while (i < 3){
int j = 0;
while ( j < 2){
sum = sum + j;
j = j + 1;
}
i = i + 1;
}

What is the value of sum after the loop?

(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

III. x == true || x == false

(b) II and III only


15. In Java, the scope of a parameter of a method contains the scope of which of the following?

(b) Local variables of the method


16. In which of the following Java statements are the variables a, b, c, and d declared?

(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?

(c) Vector v = new Vector();

1. In Java, non-sequential execution of code is achieved by using _____ statements.

(d) control
2. Consider the following program segment.

public String nameOfEmployee (int salary) {

if (salary < 50000) {

if (salary > 45000)

return "Joe";

else if (salary < 60000) return "John";

else return "Jack";

return null;

If the method nameOfEmployee is called with the value 55000 as its argument, what
String value will be returned?

(b) "John"

3. Which of the following data types is a Java primitive type?

(c) boolean
4. Suppose an object p is an instance of the following class

public class IQ
{
public int getIQ(String s)
{
return 50;
}
}

Which of the following lines is a correct Java statement?

(a) int c = p.getIQ("aleks");

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?

(a) import java.awt.*;

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;

(d) four times


9. How many times will the following loop execute?

boolean flag = false;


int count = 0;
while (flag = true) {
if (count <= 10)
count = count + 1;
else
flag = false;
}

(c) infinitely many

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?

I. double x = numbers(); while (x <= 0.5) x = numbers();


II. double x = 0.1; while (x >= 0.5) x = numbers();

III. double x; for (x = numbers(); x >= 0.5; x = numbers());

(a) III only


12. In Java, the expression –7 % 3 evaluates to

(a) –1
13. What does the following expression evaluate to?
2 * 4 - 3 + 5 / 2.0

(a) 7.5

14. Which of the following is not a Boolean operator in Java?

(c) %

15. The scope of an identifier is the

(a) area of a program where that identifier can be used

(b) number of times in the program the identifier was used

(c) list of methods that can use the identifier

(d) list of classes that can use the identifier


Correct answer is (a)
Your score on this question is: 0.00
Feedback:
The scope may be an entire class, a single method, or a set of braces. See section
2.3.1.3, subsection "Scope" in the course notes.

16. In which of the following Java statements are the variables a, b, c, and d declared?

(a) int a-d;

(b) int a, int b, int c, int d;

(c) int a..d;

(d) int a, b, c, d;
Correct answer is (d)
Your score on this question is: 5.56
Feedback:

See section 2.3.1 in the course notes.

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:

See Chapter 9, page 335, in the course textbook.


18. Which of the following is the term used for the action of informing the system of the true
nature of an object reference in Java?

(a) Instantiating

(b) Casting

(c) Declaring

(d) Initializing
Correct answer is (b)
Your score on this question is: 0.00

Your performance was as follows:


1. Consider the following program segment.

public String assignString(int x) {

String s=null;

if (x<5) s = "less than 5";

if (x<10) s = "less than 10";

else s = "greater than 10";

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.

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?

I. if (x > y) max = x; else max = y;


II. if (y - x <= 0) max = x; else max = y;

III. max = x; if (x < y) max = y;

(a) I and II only

(b) III only

(c) I only

(d) I, II, and III


Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 2.3.4 of the course notes.

3. Which of the following data types is a Java primitive type?

(a) Integer

(b) real

(c) Object

(d) int
Correct answer is (d)
Your score on this question is: 0.00
Feedback:

See section 2.3.1 in the course notes.

4. Suppose an object p is an instance of the following class

public class IQ
{
public int getIQ(String s)
{
return 50;
}
}

Which of the following lines is a correct Java statement?

(a) String s = IQ.getIQ(p);

(b) getIQ.p("bob");

(c) IQ x = getIQ("chuck");

(d) int c = p.getIQ("aleks");


Correct answer is (d)
Your score on this question is: 5.56
Feedback:
See sections 2.3.1 in the course notes.

5. The purpose of the interpreter called java in the JDK is to

(a) edit Java source code

(b) compile Java source code

(c) produce Java .class files

(d) execute Java .class files


Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 2.1.2 in the course notes.

6. The behavior components of a Java class are called

(a) data

(b) objects

(c) methods

(d) keywords
Correct answer is (c)
Your score on this question is: 5.56
Feedback:

See section 2.2.1 in the course notes.

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;

(a) three times

(b) four times

(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;

What does the above loop do?

(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;

III. while (!false) i = 0;

(a) I, II, and III

(b) I and III only

(c) III only

(d) I only
Correct answer is (b)
Your score on this question is: 0.00
Feedback:

See sections 2.3.5 in the course notes.

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.

12. What does the following expression evaluate to?

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:

2 * 4 - 3 + 5 / 2.0 (2 * 4) - 3 + (5 / 2.0) ( 8 ) - 3 + ( 2.5 ) (


8 - 3 ) + ( 2.5 ) ( 5 + 2.5 ) 7.5

13. In Java, the operator "+" can be used for which of the following purposes?

I. Addition of two integers


II. Concatenation of two strings

III. Addition of two floating point variables

(a) I and III only

(b) II and III only

(c) I only

(d) I, II, and III


Correct answer is (d)
Your score on this question is: 5.56
Feedback:

See section 2.3.2 in the course notes.

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

(b) The expression cannot be evaluated based on the information presented.

(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:

! ( ( T || F ) && !F ) ! ( ( T ) && T ) ! ( T && T ) ! ( T ) F

See section 2.3.3 in the course notes.

15. The region of a program where a variable can be referenced is known as the _____ of the
variable.

(a) storage space

(b) conventional space

(c) scope

(d) type
Correct answer is (c)
Your score on this question is: 0.00
Feedback:

See section 2.3.1.3, subsection "Scope," in the course notes.

16. Valid Java identifiers include which of the following?

I. _$4dollar
II. $_4dollar

III. 4_dollar

(a) None

(b) I and II only

(c) III only

(d) I, II, and III


Correct answer is (b)
Your score on this question is: 0.00
Feedback:

See section 2.3.1 in the course notes.


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) elementAt(1)

(c) read(1)

(d) read(0)
Correct answer is (a)
Your score on this question is: 5.56
Feedback:

See Chapter 9, page 335, in the course textbook.

18. In the Java class java.util.Vector, the method add adds a new element at the

(a) index specified when the Vector was instantiated

(b) middle of the Vector

(c) end of the Vector

(d) Vector index specified in an add parameter


Correct answer is (c)
Your score on this question is: 0.00
Feedback:

See Chapter 9, page 333, in the course textbook.

View Assessment Result

Family Zhiyenta Given Azama Login azhiyen E- 11432@iitu. Status Enrolle


Name: y Name: t :t mail: kz :d
Multiple-Choice Quiz 4 1
Assessment Name: Instance:
IITU-050602 Computer Science Fall/Autumn Active
Section: During: Section Status:
CS-0901 2009
For course: Introduction to Information Systems (SSD1)
SSD1 INTERNATIONAL UNIVERSITY OF INFORMATION
Corresponding to: At:
TECHNOLOGY
Your performance was as follows:
You took 9 minutes on this assessment from Thu Oct 22 2009 23:37:09 GMT+0600 to Thu
Oct 22 2009 23:45:50 GMT+0600.
Total score: 76.47
1. Consider the following class.
public class AppletClass extends java.applet.Applet {

public void paint(java.awt.Graphics g)

g.drawString("Welcome to Java!", 30, 30);

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:

See sections 2.1.2 and 2.1.3 in the course notes.

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:

See sections 2.1.2 and 2.1.3 in the course notes.

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:

See section 2.1.2 and 2.1.3 in the course notes.

6. Redefining a problem is often done so the programmer can


(a) rewrite the problem using fewer words
(b) understand the problem better
(c) write better comments in the program solution
(d) reduce syntax errors in the program solution
Correct answer is (b)
Your score on this question is: 5.88
Feedback:
Programmers usually restate the program in terms that they are more
comfortable with. This allows them to understand the problem better. This
restatement is a redefinition of the problem. This restatement or redefinition is
usually done in a manner that breaks the original problem down into smaller sub-
problems that may be easier to solve. See section 2.1.6 in the course notes.

7. Which of the following is not true of the process of programming?


(a) The overall model of programming is a step-by-step, linear process.
(b) A large amount of time is usually spent in evaluation and testing.
(c) It is sometimes necessary to redefine parts of a problem, even after coding has been
done.
(d) It is important to plan solutions to problems before actually coding them.
Correct answer is (a)
Your score on this question is: 0.00
Feedback:

See section 2.1.6 in the course notes.

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:

See section 2.1.6 in the course notes.

9. Which of the following statements is true of the process of programming?


(a) The best way to program is to begin coding immediately, and then to follow up by
testing.
(b) Most of the time spent in programming is usually spent planning the solution to a
problem.
(c) Programming is synonymous with coding.
(d) Programming can be made easier by dividing a larger problem into smaller pieces.
Correct answer is (d)
Your score on this question is: 5.88
Feedback:
See section 2.1.6 in the course notes.

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:

See section 2.1.4 in the course notes.

11. What is the name of the class whose definition is begun by the following line?

public class Hello extends Greeting

(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.

12. Valid Java comments include which of the following?

I. /* this is an /* embedded */ comment */


II. /* this is an // embedded // comment */

III. // this is a comment */

(a) I and II only


(b) I only
(c) I and III only
(d) II and III only
Correct answer is (d)
Your score on this question is: 5.88
Feedback:
See section 2.1.3, subsections "The Catfish Class," in the course notes.

13. The following is a Java program segment:

public void paint (Graphics g)


{
int x = 10;
int y = 20;
paintPicture( g, x, y);
}
public void paintPicture(Graphics g, int a, int b)
{
g.setColor(Color.red);
// more code follows
}

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?

I. The content of a program is called code.


II. Executing code means erasing the 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:

See Chapter 1, page 1, in the course textbook.

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?

I. Programmers can view it on the web.

II. It consists solely of Java classes and methods.

(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
*/

(a) I and III only

(b) I, II, and III

(c) II only

(d) I and II only


Correct answer is (b)
Your score on this question is: 0.00
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.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

1. Consider the following class.

public class AppletClass extends java.applet.Applet {

public void paint(java.awt.Graphics g)

g.drawString("Welcome to Java!", 30, 30);

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:

See sections 2.1.2 and 2.1.3 in the course notes.

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:

See section 2.1.6 in the course notes.

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:

See section 2.1.6 of the course notes.

8. When a Java class is designed, which of the following is a part (are parts) of the planning
stage?

I. Deciding how to display the results


II. Writing a problem definition

III. Identifying the data needed to solve the problem


(a) II and III
(b) I and II
(c) I and III
(d) II only
Correct answer is (a)
Your score on this question is: 5.88
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. In addition to coding, the process of programming model involves which of the


following?

I. Evaluation and testing


II. Defining and redefining a problem

III. Planning a solution to a problem


(a) I, II, and III
(b) II and III only
(c) None
(d) I only
Correct answer is (a)
Your score on this question is: 5.88
Feedback:

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?

public class Hello extends Greeting

(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:

See section 2.1.4 in the course notes.

12. Valid Java comments include which of the following?

I. /* this is an /* embedded */ comment */


II. /* this is an // embedded // comment */

III. // this is a comment */

(a) I and III only


(b) II and III only
(c) I and II only
(d) I only
Correct answer is (b)
Your score on this question is: 5.88
Feedback:
See section 2.1.3, subsections "The Catfish Class," in the course notes.

13. The following is a Java program segment:

public void paint (Graphics g)


{
int x = 10;
int y = 20;
paintPicture( g, x, y);
}
public void paintPicture(Graphics g, int a, int b)
{
g.setColor(Color.red);
// more code follows
}

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.

15. Which of the following is a keyword in Java?


(a) comment
(b) import
(c) servlet
(d) println
Correct answer is (b)
Your score on this question is: 0.00
Feedback:

See section 2.1.2 in the course notes.


16. Valid comments in Java include which of the following?

I. /* Comment 1 */
II. // Comment 2

III. /**
* Comment 3
*/

(a) I and III only


(b) I and II only
(c) I, II, and III
(d) II only
Correct answer is (c)
Your score on this question is: 5.88
Feedback:

See section 2.1.2 in the course notes.

17. Which of the following is (are) true regarding programming in Java?

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.

III. Java does not distinguish between uppercase and lowercase.


(a) I and II only
(b) I, II, and III
(c) I only
(d) II and III only
Correct answer is (c)
1. How many ".class" files will be generated after a successful compilation of any
".java" file?

(a) At most one

(b) None

(c) Exactly one

(d) At least one


Correct answer is (d)

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) 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:

See sections 2.1.2 and 2.1.3 in the course notes.

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.

(a) HTML, bytecode

(b) bytecode, source code

(c) source code, bytecode

(d) source code, HTML


Correct answer is (c)

Feedback:

See section 2.1.2 and 2.1.3 in the course notes.

5. In Java programming, a programmer creates _____ files, and then a compiler translates them
to _____ files.

(a) source, byte code

(b) byte code, source


(c) HTML, byte code

(d) source, HTML


Correct answer is (a)

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) Defining the problem

(b) Planning a solution to the problem

(c) Coding

(d) Testing and evaluation


Correct answer is (d)

Feedback:

See section 2.1.6 in the course notes.

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.

(b) defining/redefining --> planning --> implementing/coding --> testing/analyzing

(c) planning --> redefining--> coding--> testing

(d) planning --> coding --> testing --> analyzing


Correct answer is (a)

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?

(a) Planning the method for obtaining the input

(b) Coding

(c) Planning a solution to the problem

(d) Defining the problem


Correct answer is (d)

Feedback:
See section 2.1.6 of the course notes.

9. Which of the following statements is true of the process of programming?

(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.

(c) Programming is synonymous with coding.

(d) The best way to program is to begin coding immediately, and then to follow up by testing.
Correct answer is (a)

Feedback:

See section 2.1.6 in the course notes.

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)

Feedback:

See section 2.1.4 in the course notes.

11. Valid Java comments include which of the following?

I. /* this is an /* embedded */ comment */


II. /* this is an // embedded // comment */

III. // this is a comment */

(a) II and III only

(b) I and III only

(c) I only

(d) I and II only


Correct answer is (a)

Feedback:
See section 2.1.3, subsections "The Catfish Class," in the course notes.
12. The following is a Java program segment:

public void paint (Graphics g)


{
int x = 10;
int y = 20;
paintPicture( g, x, y);
}
public void paintPicture(Graphics g, int a, int b)
{
g.setColor(Color.red);
// more code follows
}

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?

public class Hello extends Greeting

(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.

16. Valid comments in Java include which of the following?

I. /* Comment 1 */
II. // Comment 2

III. /**
* Comment 3
*/

(a) I, II, and III

(b) II only

(c) I and III only

(d) I and II only


Correct answer is (a)

Feedback:

See section 2.1.2 in the course notes.

17. Which of the following is (are) true regarding computer programs and code?

I. The content of a program is called code.


II. Executing code means erasing the code.

III. Programs consist of text that can cause a computer to perform a task.
(a) II and III only

(b) I, II, and III

(c) I and II only

(d) I and III only


Correct answer is (d)

Feedback:

See Chapter 1, page 1, in the course textbook.

Your performance was as follows:

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.

Total score: 100.00

1.
In Java programming, a programmer creates _____ files, and then a compiler translates them to
_____ files.

(a) source, byte code


(b) source, HTML
(c) byte code, source
(d) HTML, byte code

Correct answer is (a)

Your score on this question is: 5.88

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 _____.

(a) MyClass.java, MyClass.class


(b) MyClass.class, MyClass.java
(c) MyClass.java, MyClass.exe
(d) MyClass.class, MyClass.exe

Correct answer is (a)

Your score on this question is: 5.88

Feedback:

See sections 2.1.2 and 2.1.3 in the course notes.


3.
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 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

Correct answer is (d)

Your score on this question is: 5.88

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

Correct answer is (c)

Your score on this question is: 5.88

Feedback:

See sections 2.1.2 and 2.1.3 in 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, 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.

6.

Which of the following is not true of the process of programming?

(a) The overall model of programming is a step-by-step, linear process.


(b) It is sometimes necessary to redefine parts of a problem, even after coding has been done.
(c) A large amount of time is usually spent in evaluation and testing.
(d) It is important to plan solutions to problems before actually coding them.

Correct answer is (a)

Your score on this question is: 5.88

Feedback:

See section 2.1.6 in the course notes.

7.

Which of the following must be the first phase of the programming process?

(a) Planning a solution to the problem


(b) Defining the problem
(c) Planning the method for obtaining the input
(d) Coding

Correct answer is (b)

Your score on this question is: 5.88

Feedback:

See section 2.1.6 of the course notes.

8.

When a Java class is designed, which of the following is a part (are parts) of the planning stage?

1. Deciding how to display the results


2. Writing a problem definition
3. Identifying the data needed to solve the problem

(a) II only
(b) I and III
(c) I and II
(d) II and III

Correct answer is (d)

Your score on this question is: 5.88

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.

Which of the following statements is true of the process of programming?


(a) Most of the time spent in programming is usually spent planning the solution to a problem.
(b) Programming is synonymous with coding.
(c) The best way to program is to begin coding immediately, and then to follow up by testing.
(d) Programming can be made easier by dividing a larger problem into smaller pieces.

Correct answer is (d)

Your score on this question is: 5.88

Feedback:

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?

public class Hello extends Greeting

(a) Greeting
(b) Hello
(c) Greeting.Hello
(d) Hello.Greeting

Correct answer is (b)

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:

See section 2.1.4 in the course notes.

12.

Valid Java comments include which of the following?

1. /* this is an /* embedded */ comment */


2. /* this is an // embedded // comment */
3. // this is a comment */

(a) I and II only


(b) I and III only
(c) I only
(d) II and III only

Correct answer is (d)

Your score on this question is: 5.88

Feedback:
See section 2.1.3, subsections "The Catfish Class," in the course notes.

13.

The following is a Java program segment:

public void paint (Graphics g)


{
int x = 10;
int y = 20;
paintPicture( g, x, y);
}
public void paintPicture(Graphics g, int a, int b)
{
g.setColor(Color.red);
// more code follows
}

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

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.

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.88

Feedback:

See section 2.1.5, subsection "Coding the Servlet," in the course notes.

15.

In Java, it is possible to define a _____ within a _____.

(a) method, class


(b) class, method
(c) method, method
(d) method, variable

Correct answer is (a)

Your score on this question is: 5.88

Feedback:

See section 2.1.3 in the course notes.

16.

In Java, the method HttpRequest.getParameter returns an object of which of the following classes?

(a) PrintWriter
(b) String
(c) HttpRequest
(d) Parameter

Correct answer is (b)

Your score on this question is: 5.88

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?

1. The list of classes can be filtered by package.


2. Typically, only the most important methods of a class are listed.
3. The documentation for one class often refers to other classes.

(a) I and II only


(b) I and III only
(c) II and III only
(d) I, II, and III
Correct answer is (b)

Your score on this question is: 5.88

Feedback:

See Chapter 3, pages 105-8, in the course textbook.

View Assessment Result: Multiple-Choice Quiz 5

View Assessment Result: Multiple-Choice Quiz 5

Your performance was as follows:


1. Which of the following can be a valid definition for a Java class?
(a) Welcome extends HttpServlet {}
(b) public Welcome class extends HttpServlet {}
(c) public class Welcome extends HttpServlet {}
(d) public void class Welcome extends HttpServlet {}
Correct answer is (c)
Your score on this question is: 8.33
Feedback:

See sections 2.2.2 and 2.1.2 in the course notes.

2. Which of the statements below correctly constructs an object using the following
constructor?

Plane(int a, int b, int c)


{
// code
}

(a) p = new Plane(1, 2, 3);


(b) p = Plane(1, 2, 3);
(c) p = new Plane;
(d) p = Plane;
Correct answer is (a)
Your score on this question is: 0.00
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 variable names conforms to Java naming conventions?
(a) fuel_remaining
(b) FuelRemaining
(c) fuelRemaining
(d) AmountOfFuelRemainingInTheTank
Correct answer is (c)
Your score on this question is: 8.33
Feedback:

See section 2.2.2 in the course notes.

4. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?

I. int numPeople;
II. int Counter;

III. class serviceElevator{}

(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.

5. Consider the following Java code segment.

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:

See sections 2.2.2 through 2.2.4 in the course notes.

6. What is the return value of the following method?

void return_value(String s, int i) {


// code here
}

(a) Its return value is int.


(b) It does not have a return value.
(c) Its return value is String.
(d) Its return values are String and int.
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See sections 2.2.2 through 2.2.4 in the course notes.

7. If variable br references an instance of the class java.io.BufferedReader, which of


the following statements is a legal call to the method readLine of the class?
(a) br(readLine);
(b) br.readLine();
(c) readLine(br);
(d) br.readLine;
Correct answer is (b)
Your score on this question is: 8.33
Feedback:

See section 2.2.2 through 2.2.4 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) 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.

9. Consider the following Java code fragment.

public class TrafficLight{


int status;
public void changeStatus(int newStatus) {
status = newStatus;
}

public void turnOn(int newStatus) {


// . . .
}
}

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:

See section 2.2.2 in the course notes.

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:

See Chapter 4, page 122, in the course textbook.

12. Consider the following line of Java code.

public void log() throws Exception

The line of code is a method


(a) prototype
(b) body
(c) delimiter
(d) definition
Correct answer is (a)
Your score on this question is: 8.33
Feedback:

See Chapter 4, page 121, in the course textbook.

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)

Your performance was as follows:


1. In Java, which of the following is true about constructors?
(a) Constructors cannot return a value.
(b) Constructors can only accept primitive Java types as parameters.
(c) Constructors can only return 0 or a negative integer.
(d) Constructors must be declared for every class.
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 2.2.2, subsection "Mapping English Terms to Java Terms," in the
course notes.

2. Which of the statements below correctly constructs an object using the following
constructor?

Plane(int a, int b, int c)


{
// code
}

(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;

III. class serviceElevator{}

(a) I and III only


(b) I, II, and III
(c) I only
(d) None
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.

4. Which of the following variable names conforms to Java naming conventions?


(a) fuelRemaining
(b) AmountOfFuelRemainingInTheTank
(c) FuelRemaining
(d) fuel_remaining
Correct answer is (a)
Your score on this question is: 8.33
Feedback:

See section 2.2.2 in the course notes.

5. If variable br references an instance of the class java.io.BufferedReader, which of


the following statements is a legal call to the method readLine of the class?
(a) br.readLine();
(b) readLine(br);
(c) br(readLine);
(d) br.readLine;
Correct answer is (a)
Your score on this question is: 8.33
Feedback:

See section 2.2.2 through 2.2.4 in the course notes.

6. Consider the following Java code segment.

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:

See sections 2.2.2 through 2.2.4 in the course notes.

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.

8. Which of the following statements is true about methods in Java?

I. Every method must be declared public.


II. Every method must accept at least one parameter.

III. Every method must return a value.


(a) II and III only
(b) none of them
(c) III only
(d) I, II, and III
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See sections 2.2.2 through 2.2.4 in the course notes.

9. The following line can be the start of


public void paint(Graphics g)

(a) a method call


(b) a method definition
(c) a class definition
(d) a variable declaration
Correct answer is (b)
Your score on this question is: 8.33
Feedback:
See section 2.2.2 through 2.2.4 in the course notes.

10. What is the return value of the following method?

void return_value(String s, int i) {


// code here
}

(a) It does not have a return value.


(b) Its return values are String and int.
(c) Its return value is String.
(d) Its return value is int.
Correct answer is (a)
Your score on this question is: 8.33
Feedback:
See sections 2.2.2 through 2.2.4 in the course notes.

11. Which of the following is (are) true regarding objects in Java?

I. The Java language has some predefined objects.

II. Messages are sent from an object to its class.


(a) II only
(b) None
(c) I only
(d) I and II
Correct answer is (c)
Your score on this question is: 8.33
Feedback:

See Chapter 1, pages 4–6, in the course textbook.

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:

See Chapter 4, page 139, in the course textbook.

Go to top of assessment.
Total score: 75.00
© Copyright 2003 iCarnegie, Inc. All rights reserved.

Which of the following can be a valid definition for a Java class?


(a) Welcome extends HttpServlet {}
(b) public Welcome class extends HttpServlet {}
(c) public void class Welcome extends HttpServlet {}
(d) public class Welcome extends HttpServlet {}
Correct answer is (d)
Your score on this question is: 8.33
Feedback:

See sections 2.2.2 and 2.1.2 in the course notes.

2. Which of the statements below correctly constructs an object using the following
constructor?

Plane(int a, int b, int c)


{
// code
}

(a) p = Plane(1, 2, 3);


(b) p = new Plane;
(c) p = new Plane(1, 2, 3);
(d) p = Plane;
Correct answer is (c)
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 variable names conforms to Java naming conventions?


(a) AmountOfFuelRemainingInTheTank
(b) fuelRemaining
(c) FuelRemaining
(d) fuel_remaining
Correct answer is (b)
Your score on this question is: 8.33
Feedback:

See section 2.2.2 in the course notes.

4. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?

I. int numPeople;
II. int Counter;

III. class serviceElevator{}

(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.

5. Valid method definitions in Java include which of the following?

I. public method myMethod() {}


II. public void myMethod(int i) {}

III. public void myMethod {}

(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:

See sections 2.2.2 through 2.2.4 in the course notes.

6. Which of the following is not a valid name of a Java method?


(a) Napoleon_The_First
(b) RESET
(c) fred$wallet
(d) 3jane
Correct answer is (d)
Your score on this question is: 8.33
Feedback:

See section 2.2.2 in the course notes.

7. Which of the following statements is true about methods in Java?

I. Every method must be declared public.


II. Every method must accept at least one parameter.

III. Every method must return a value.


(a) none of them
(b) II and III only
(c) I, II, and III
(d) III only
Correct answer is (a)
Your score on this question is: 8.33
Feedback:
See sections 2.2.2 through 2.2.4 in the course notes.

8. The following line can be the start of

public void paint(Graphics g)

(a) a class definition


(b) a variable declaration
(c) a method definition
(d) a method call
Correct answer is (c)
Your score on this question is: 8.33
Feedback:
See section 2.2.2 through 2.2.4 in the course notes.

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.

10. Consider the following Java code segment.

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:

See sections 2.2.2 through 2.2.4 in the course notes.

11. Which of the following is (are) true regarding objects in Java?


I. The Java language has some predefined objects.

II. Messages are sent from an object to its class.


(a) I and II
(b) None
(c) I only
(d) II only
Correct answer is (c)
Your score on this question is: 8.33
Feedback:

See Chapter 1, pages 4–6, in the course textbook.

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.

View Assessment Result: Multiple-Choice Quiz 5

Your performance was as follows:


1. Which of the statements below correctly constructs an object using the following
constructor?

Plane(int a, int b, int c)


{
// code
}

(a) p = new Plane;


(b) p = Plane(1, 2, 3);
(c) p = Plane;
(d) p = new Plane(1, 2, 3);
Correct answer is (d)
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.

2. In a Java class Hello, a method declared to be public can be called by


(a) only the class Hello
(b) only the class Hello and the subclasses of Hello
(c) any class
(d) only the classes in the same package as Hello
Correct answer is (c)
Your score on this question is: 0.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.

3. Which of the following is (are) consistent with Java naming conventions regarding
capitalization?

I. int numPeople;
II. int Counter;

III. class serviceElevator{}

(a) I and III only


(b) I only
(c) None
(d) I, II, and III
Correct answer is (b)
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.

4. Which of the following variable names conforms to Java naming conventions?


(a) fuel_remaining
(b) fuelRemaining
(c) FuelRemaining
(d) AmountOfFuelRemainingInTheTank
Correct answer is (b)
Your score on this question is: 8.33
Feedback:

See section 2.2.2 in the course notes.

5. Which of the following is not a valid name of a Java method?


(a) 3jane
(b) fred$wallet
(c) RESET
(d) Napoleon_The_First
Correct answer is (a)
Your score on this question is: 8.33
Feedback:

See section 2.2.2 in the course notes.

6. If variable br references an instance of the class java.io.BufferedReader, which of


the following statements is a legal call to the method readLine of the class?
(a) br(readLine);
(b) br.readLine;
(c) readLine(br);
(d) br.readLine();
Correct answer is (d)
Your score on this question is: 0.00
Feedback:

See section 2.2.2 through 2.2.4 in the course notes.

7. What is the return value of the following method?

void return_value(String s, int i) {


// code here
}

(a) Its return value is int.


(b) Its return value is String.
(c) It does not have a return value.
(d) Its return values are String and int.
Correct answer is (c)
Your score on this question is: 8.33
Feedback:
See sections 2.2.2 through 2.2.4 in the course notes.

8. Consider the following Java code fragment.

public class TrafficLight{


int status;
public void changeStatus(int newStatus) {
status = newStatus;
}

public void turnOn(int newStatus) {


// . . .
}
}

In the method turnOn, which of the following statements should be used to call method
changeStatus?

(a) changeStatus(TrafficLight, newStatus);


(b) TrafficLight.changeStatus(newStatus);
(c) changeStatus.newStatus;
(d) changeStatus(newStatus);
Correct answer is (d)
Your score on this question is: 8.33
Feedback:

See section 2.2.2 in the course notes.

9. Valid method definitions in Java include which of the following?

I. public method myMethod() {}


II. public void myMethod(int i) {}

III. public void myMethod {}

(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:

See sections 2.2.2 through 2.2.4 in the course notes.

10. Which of the following statements is true about methods in Java?

I. Every method must be declared public.


II. Every method must accept at least one parameter.

III. Every method must return a value.


(a) none of them
(b) III only
(c) II and III only
(d) I, II, and III
Correct answer is (a)
Your score on this question is: 8.33
Feedback:
See sections 2.2.2 through 2.2.4 in the course notes.

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:

See Chapter 3, page 77, in the course textbook.

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:

See Chapter 4, page 121, in the course textbook.

Go to top of assessment.
Total score: 58.33
© Copyright 2003 iCarnegie, Inc. All rights reserved.

Your performance was as follows:


1. Consider the following program segment.

public String assignString(int x) {

String s=null;

if (x<5) s = "less than 5";

if (x<10) s = "less than 10";

else s = "greater than 10";

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.

2. In Java, non-sequential execution of code is achieved by using _____ statements.


(a) branching
(b) ordering
(c) concurrent
(d) control
Correct answer is (d)
Your score on this question is: 5.56
Feedback:

See sections 2.3.4 and 2.3.5 in the course notes.

3. Which of the following are valid Java statements?

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.

4. Which of the following are primitive Java types?

I. int
II. Integer

III. Double

(a) I and II only


(b) II and III only
(c) I only
(d) I, II and III only
Correct answer is (c)
Your score on this question is: 5.56
Feedback:
See section 2.3.1in the course notes.

5. In Java, identifiers are names used for which of the following?

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:

See section 2.1.4 in the course notes.

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:

See section 2.2.1 in the course notes.

7. How many times will the following loop execute?

int i;
for (i = 0; i < 9; i = i + 1)
i = 8;

(a) infinitely many


(b) 9
(c) 1
(d) 2
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 2.3.5 of the course notes.

8. When the following code segment is executed, how many times will the string "Hello!"
be printed?

for (int i = 0; i < 6; i++)


for (int j = i; j < 6 - i; j++)
System.out.print("Hello!");
(a) 11
(b) 36
(c) 21
(d) 12
Correct answer is (d)
Your score on this question is: 5.56
Feedback:

See section 2.3.5 in the course notes.

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?

I. double x = numbers(); while (x <= 0.5) x = numbers();


II. double x = 0.1; while (x >= 0.5) x = numbers();

III. double x; for (x = numbers(); x >= 0.5; x = numbers());

(a) I, II and III


(b) III only
(c) I only
(d) II and III only
Correct answer is (b)
Your score on this question is: 5.56
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.

10. int i = 1, sum = 0;


while (i < 3){
int j = 0;
while ( j < 2){
sum = sum + j;
j = j + 1;
}
i = i + 1;
}

What is the value of sum after the loop?


(a) 0
(b) 4
(c) 2
(d) 6
Correct answer is (c)
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) :=, =
(c) =, equals()
(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.

12. In Java, the expression –7 % 3 evaluates to


(a) –2
(b) –1
(c) 1
(d) 2
Correct answer is (b)
Your score on this question is: 5.56
Feedback:

See section 2.3.2 in the course notes.

13. What does the following expression evaluate to?

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:

2 * 4 - 3 + 5 / 2.0 (2 * 4) - 3 + (5 / 2.0) ( 8 ) - 3 + ( 2.5 ) (


8 - 3 ) + ( 2.5 ) ( 5 + 2.5 ) 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

III. x == true || x == false

(a) II and III only


(b) I, II, and III
(c) I and III only
(d) III only
Correct answer is (a)
Your score on this question is: 5.56
Feedback:

See section 2.3.3 in the course notes.

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:

See section 2.3.1.3, subsection "Scope," in the course notes.


16. What is the value of x after execution of the following Java code fragment?

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:

See section 2.3.1 in the course notes.

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:

See Chapter 9, page 332, in the course textbook.

18. Consider the following Java program segment.

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?

I. Programmers can view it on the web.

II. It consists solely of Java classes and methods.


(a) None
(b) II only
(c) I and II
(d) I only
Correct answer is (d)
Your score on this question is: 5.00
Feedback:

See Chapter 3, page 105, in the course textbook.

3. A Web site can be navigated using


(a) a Web server
(b) a text editor
(c) a Web browser
(d) an image viewer
Correct answer is (c)
Your score on this question is: 5.00
Feedback:

See section 1.1.1 of the course notes.

4. The following is a Java program segment:

public void paint (Graphics g)


{
int x = 10;
int y = 20;
paintPicture( g, x, y);
}
public void paintPicture(Graphics g, int a, int b)
{
g.setColor(Color.red);
// more code follows
}

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.

6. Which of the following is true if a Java class is declared public?


(a) The source code of the class is freely available for viewing.
(b) The class can be used only by Java applets, not by Java applications.
(c) The class can be accessed by any other class.
(d) The class can be used only by other classes in the same package.
Correct answer is (c)
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 variable names conforms to Java naming conventions?


(a) fuelRemaining
(b) FuelRemaining
(c) fuel_remaining
(d) AmountOfFuelRemainingInTheTank
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See section 2.2.2 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.

9. Consider the following line of Java code.


public int log() throws Exception

What is the return type in the line of code?


(a) int
(b) throws
(c) Exception
(d) public
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See Chapter 4, page 122, in the course textbook.

10. In Java, non-sequential execution of code is achieved by using _____ statements.


(a) control
(b) branching
(c) concurrent
(d) ordering
Correct answer is (a)
Your score on this question is: 5.00
Feedback:

See sections 2.3.4 and 2.3.5 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.

12. A Java Virtual Machine (JVM) is


(a) a decompiler that creates Java source code from Java bytecode
(b) hardware that interprets Java bytecode
(c) software that interprets Java bytecode
(d) a compiler that generates Java bytecode
Correct answer is (c)
Your score on this question is: 5.00
Feedback:

See section 2.1.2 in the course notes.

13. How many asterisks (*) will be output when the following code segment is executed?

for (int k = 30; k <= 5; k--)


System.out.print("*");

(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.

14. How many times will the following loop execute?

boolean flag = false;


int count = 0;
while (flag = true) {
if (count <= 10)
count = count + 1;
else
flag = false;
}

(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:

See sections 2.3.2 and 2.3.3 in the course notes.

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:

See section 2.3.2 in the course notes.

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

(a) I and II only


(b) III only
(c) I, II, and III
(d) I only
Correct answer is (a)
Your score on this question is: 0.00
Feedback:

See section 2.3.3 in the course notes.

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:

See section 2.3.1 in the course notes.

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:

See section 2.3.1 in the course notes.


20. The value of the largest index of an instance of class java.util.Vector is always
_____ the size of the vector.
(a) one less than
(b) one greater than
(c) equal to
(d) half of
Correct answer is (a)
Your score on this question is: 5.00

You might also like