1. Which of the following are types of loops in Java? Mark for Review
(1) Points
(Choose all correct answers)
while (*)
if/else
do-while (*)
for (*)
Correct Correct
2. What is the function of the word "break" in Java? Mark for Review
(1) Points
It continues onto the next line of code.
It exits the current loop or case statement. (*)
It does not exist in Java.
It stops the program from running.
Correct Correct
3. How many times will the following loop be executed?
What is the value of x after the loop has finished?
What is the value of count after the loop has finished?
int count = 17;
int x = 1;
while(count > x){
x*=3;
count-=3;
} Mark for Review
(1) Points
3; 9; 11
5; 30; 5
4; 8; 27
5; 27; 8
3; 27; 8 (*)
Incorrect Incorrect. Refer to Section 5 Lesson 2.
4. When the for loop condition statement is met the construct is exited. True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 5 Lesson 2.
5. A counter used in a for loop cannot be initialized within the For loop header. True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 5 Lesson 2.
6. A counter used in a for loop cannot be initialized within the For loop statement. True or False? Mark for Review
(1) Points
True
False (*)
7. Which of the following best describes a while loop? Mark for Review
(1) Points
A loop that contains a segment of code that is executed before the conditional statement is tested.
A loop that is executed repeatedly until the conditional statement is false. (*)
A loop that executes the code at least one time even if the conditional statement is false.
A loop that contains a counter in parenthesis with the conditional statement.
Incorrect Incorrect. Refer to Section 5 Lesson 2.
8. The six relational operators in Java are: Mark for Review
(1) Points
>, <, =, !=, <=, >=
>, <, ==, !=, <=, >= (*)
>, <, =, !, <=, >=
>, <, =, !=, =<, =>
9. Determine whether this boolean expression evaluates to true or false:
!(3 < 4 && 5 > 6 || 6 <= 6 && 7 - 1 == 6) Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 5 Lesson 1.
10. Which of the following correctly matches the switch statement keyword to its function? Mark for Review
(1) Points
(Choose all correct answers)
switch: tells the compiler the value to compare the input against
default: signals what code to execute if the input does not match any of the cases (*)
case: signals what code is executed if the user input matches the specified element (*)
switch: identifies what element will be compared to the element of the case statements to find a possible match (*)
if: records the user's input and sends it to the case statements to find a possible match
11. What will print if the following Java code is executed?
Mark for Review
(1) Points
3 (*)
5
0
4
Incorrect Incorrect. Refer to Section 5 Lesson 1.
12. In Java, each case seqment of a switch statement requires the keyword break to avoid "falling through". Mark for Review
(1) Points
True (*)
False
Correct Correct
13. How would you use the ternary operator to rewrite this if statement?
if (gender == "male")
System.out.print("Mr.");
else
System.out.print("Ms."); Mark for Review
(1) Points
(gender == "male") ? "Ms." : "Mr." ;
(gender == "male") ? "Mr." : "Ms." ;
System.out.print( (gender == "male") ? "Mr." : "Ms." ); (*)
System.out.print( (gender == "male") ? "Ms." : "Mr." );
Incorrect Incorrect. Refer to Section 5 Lesson 1.
14. Determine whether this boolean expression evaluates to true or false:
!(3 < 4 && 6 > 6 || 6 <= 6 && 7 - 2 == 6) Mark for Review
(1) Points
True (*)
False
Correct Correct
15. Which of the following expressions will evaluate to true when x and y are boolean variables with opposite values?
I. (x || y) && !(x && y)
II. (x && !y) || (!x && y)
III. (x || y) && (!x ||!y) Mark for Review
(1) Points
I only
II only
I and III
II and III
I, II, and III (*)
switch statements work on all input types including, but not limited to, int, char, and String. True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 5 Lesson 1.
2. The three logic operators in Java are: Mark for Review
(1) Points
!=, =, ==
&&, !=, =
&, |, =
&&, ||, ! (*)
Correct Correct
3. The following code fragment properly implements the switch statement. True or false?
default(input)
switch '+':
answer+=num;
break;
case '-':
answer-=num;
break;
!default
System.out.println("Invalid input"); Mark for Review
(1) Points
True
False (*)
Correct Correct
4. In an if-else construct the condition to be evaluated must end with a semi-colon. True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
5. Which of the following correctly initializes an instance of Scanner, called "in", that reads input from the console screen? Mark for Review
(1) Points
Scanner in = Scanner(System.in);
Scanner in = new Scanner(System.in); (*)
Scanner in = new Scanner("System.in");
System.in in = new Scanner();
Correct Correct
6. Consider that a Scanner has been initialized such that:
Scanner in = new Scanner(System.in);
Which of the following lines of code reads in the user?s input and sets it equal to a new String called input?
Mark for Review
(1) Points
String input = in.close();
String input = in.next(); (*)
String input = in.nextInt();
String input = new String in.next();
Correct Correct
7. Which of the two diagrams below illustrate the correct syntax for variables used in an if-else statement?
Mark for Review
(1) Points
Example A (*)
Example B
Correct Correct
8. Determine whether this boolean expression evaluates to true or false:
!(3 < 4 && 6 > 6 || 6 <= 6 && 7 - 2 == 6) Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 5 Lesson 1.
9. All of the following are essential to initializing a for loop, except which one? Mark for Review
(1) Points
Initializing the iterator(i).
Having a conditional statement.
Updating the counter.
Having an if statement. (*)
Correct Correct
10. When the for loop condition statement is met the construct is exited. True or false? Mark for Review
(1) Points
True
False (*)
11. Why are loops useful? Mark for Review
(1) Points
They save programmers from having to rewrite code.
They allow for repeating code a variable number of times.
They allow for repeating code until a certain argument is met.
All of the above. (*)
Correct Correct
12. For both the if-else construct and the for loop, it is true to say that when the condition statement is met, the construct is exited. True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
13. What is the output of the following code segment?
int num = 7;
while(num >= 0)
{
num -= 3;
}
System.out.println(num); Mark for Review
(1) Points
0
2
-2 (*)
1
Correct Correct
14. In a for loop the counter is not automatically incremented after each loop iteration. Code must be written to increment the counter. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
15. In the code fragment below, the syntax for the for loop's initialization is correct. True or false?
public class ForLoop {
public static void main (String args[])
{
for ((int 1=10) (i<20) (i++))
{
System.out.println ("i: " + i);
}
}
}
Mark for Review
(1) Points
True
False (*)
4
1. When you open more than one file in Eclipse the system will __________________. Mark for Review
(1) Points
Close the previously opened file.
Use tabs to display all files open. (*)
Put the new file opened in a View area only.
None of the above.
Incorrect Incorrect. Refer to Section 4 Lesson 1.
2. When converting gallons to liters its best to put the calculation result into a variable with a _______________ data type. Mark for Review
(1) Points
int
double (*)
boolean
None of the above
1. The following defines a package keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control. (*)
Provides the compiler information that identifies outside classes used within the current class.
Precedes the name of the class.
Correct Correct
2. The following defines a class keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control.
Precedes the name of the class. (*)
Provides the compiler information that identifies outside classes used within the current class.
Correct Correct
3. Which of the following defines a driver class? Mark for Review
(1) Points
Contains a main method and other static methods. (*)
Contains classes that define objects.
Contains a main method, a package, static methods, and classes that define objects.
None of the above.
Correct Correct
4. The following defines a package keyword: Mark for Review
(1) Points
Provides the compiler information that identifies outside classes used within the current class.
Precedes the name of the class.
Defines where this class lives relative to other classes, and provides a level of access control. (*)
Correct Correct
5. What will the method methodA print to the screen?
Mark for Review
(1) Points
6
18 (*)
15
3
Correct Correct
6. Which of the following is the name of a Java primitive data type? Mark for Review
(1) Points
Object
Rectangle
String
int (*)
Correct Correct
7. Which of the following is not correct Java code? Mark for Review
(1) Points
double x=Math.PI*5.0;
double x=Math.sqrt(16);
double x=Math.pow(3,4)*5.0;
double x=Math.pow; (*)
Correct Correct
8. A local variable has precedence over a global variable in a Java method. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
9. Which line of Java code assigns the value of 5 raised to the power of 8 to a? Mark for Review
(1) Points
int a=Math.pow(5,8);
double a=Math.pow(5,8); (*)
double a=pow(8,5);
int a=Math.pow(8,5);
double a=15^8;
Correct Correct
10. Consider the following code snippet. What is printed?
Mark for Review
(1) Points
AtlanticPacificIndianArcticSouthern
The code does not compile.
An ArrayIndexOutofBoundsException is thrown.
55555
87668 (*)
11. Consider the following code snippet. What is printed?
Mark for Review
(1) Points
55555
87658
An ArrayIndexOutofBoundsException is thrown. (*)
AtlanticPacificIndianArcticSouthern
The code does not compile.
Incorrect Incorrect. Refer to Section 4 Lesson 4.
12. Which of the following creates a String named Char? Mark for Review
(1) Points
char string;
String Char; (*)
char Char;
char char;
String char;
Incorrect Incorrect. Refer to Section 4 Lesson 4.
13. When you open more than one file in Eclipse the system will __________________. Mark for Review
(1) Points
Close the previously opened file.
Use tabs to display all files open. (*)
Put the new file opened in a View area only.
None of the above.
Correct Correct
14. Eclipse provides views to help you navigate a hierarchy of information. True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
15. When converting gallons to liters its best to put the calculation result into a variable with a _______________ data type. Mark for Review
(1) Points
int
double (*)
boolean
None of the above
Correct Correct
3. A _______________ is used to organize Java related files. Mark for Review
(1) Points
Workspace
Collection
Project
Package (*)
Incorrect Incorrect. Refer to Section 4 Lesson 1.
4. When importing another package into a class you must import the entire package as well as the package classes that will be called. True or False? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 4 Lesson 2.
5. The following defines a class keyword: Mark for Review
(1) Points
Precedes the name of the class. (*)
Defines where this class lives relative to other classes, and provides a level of access control.
Provides the compiler information that identifies outside classes used within the current class.
6. The following defines an import keyword: Mark for Review
(1) Points
Provides the compiler information that identifies outside classes used within the current class. (*)
Precedes the name of the class.
Defines where this class lives relative to other classes, and provides a level of access control.
Correct Correct
7. The following defines a package keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control. (*)
Precedes the name of the class.
Provides the compiler information that identifies outside classes used within the current class.
Correct Correct
8. Given the code below, which of the following would equate to true?
String s1 = "yes";
String s2 = "yes";
String s3 = new String(s1);
Mark for Review
(1) Points
(Choose all correct answers)
s1 == s2 (*)
s1.equals(s2) (*)
s3.equals(s1) (*)
s3 == s1
s1 = s2
Incorrect Incorrect. Refer to Section 4 Lesson 4.
9. The String methods equals and compareTo perform similar functions and differ in their return type. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
10. The following program prints "Not Equal". True or false?
Mark for Review
(1) Points
True
False (*)
11. Given the following declaration, which line of Java code properly casts one type into another without data loss?
int i=3,j=4; double y=2.54; Mark for Review
(1) Points
double x=i/j;
int x=(double)2.54;
6. What is the purpose of the Eclipse Editor Area and Views? Mark for Review
(1) Points
(Choose all correct answers)
To navigate a hierarchy of information. (*)
To choose the file system location to delete a file.
To modify elements. (*)
Incorrect Incorrect. Refer to Section 4 Lesson 1.
7. In the image below, identify the components.
Mark for Review
(1) Points
A-Main Method, B-Class, C-Package
A-Class, B-MainMethod, C-Package
A-Package, B-Main Method, C-Class (*)
None of the above
Correct Correct
8. Which of the following is the name of a Java primitive data type? Mark for Review
(1) Points
String
Rectangle
double (*)
Object
Incorrect Incorrect. Refer to Section 4 Lesson 3.
9. What is the output of the following lines of code?
int j=7,k=5,m=8,result;
result=j/m*k;
System.out.println(result); Mark for Review
(1) Points
0 (*)
4.375
280
0.175
Correct Correct
10. Which of the following is not a legal name for a variable? Mark for Review
(1) Points
to_be_or_not_to_be
4geeks (*)
R2d2
dgo2sleep
Correct Correct
11. What are Java's primitive types? Mark for Review
(1) Points
boolean, thread, char, double, float, int, long and short
object, byte, string, char, float, int, long and short
boolean, thread, stringbuffer, char, int, float, long and short
boolean, byte, char, double, float, int, long, and short (*)
boolean, byte, string, thread, int, double, long and short
Correct Correct
12. Which line of code does not assign 3.5 to the variable x? Mark for Review
(1) Points
x=3.5;
3.5=x; (*)
double x=3.5
x=7.0/2.0;
Incorrect Incorrect. Refer to Section 4 Lesson 3.
13. Which of the following creates a String reference named s and instantiates it? Mark for Review
(1) Points
(Choose all correct answers)
String s;
s="s";
String s=new String("s"); (*)
String s=""; (*)
Incorrect Incorrect. Refer to Section 4 Lesson 4.
14. The String methods equals and compareTo perform similar functions and differ in their return type. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
15. What will the following code segment output?
Mark for Review
(1) Points
"\\" (*)
"\\\\\"
"\\\"
\"\\\\\"
Incorrect Incorrect. Refer to Section 4 Lesson 4.
double x=(double)i/j; (*)
double x= double i/j;
double x=(double)(i/j);
Incorrect Incorrect. Refer to Section 4 Lesson 3.
12. Which line of Java code will assign the value of the square root of 11 to a variable named a? Mark for Review
(1) Points
int a=Math.sqrt(11);
double a=Math.sqrt*11;
double a=sqrt(11);
double a=Math.sqrt(11); (*)
double a=11^(1/2);
Incorrect Incorrect. Refer to Section 4 Lesson 3.
13. Match each of the following literals ('x', 10, 10.2, 100L, "hello") with its respective data type. Mark for Review
(1) Points
char, int, double, long, String (*)
char, double, int, long, String
char, int, long, float, String
boolean, byte, int, long, Short
char, boolean, float, long, String
Incorrect Incorrect. Refer to Section 4 Lesson 3.
14. Which line of Java code assigns the value of 5 raised to the power of 8 to a? Mark for Review
(1) Points
double a=15^8;
double a=Math.pow(5,8); (*)
int a=Math.pow(5,8);
double a=pow(8,5);
int a=Math.pow(8,5);
Correct Correct
15. A local variable has precedence over a global variable in a Java method. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
1. Which of the following defines a driver class? Mark for Review
(1) Points
Contains a main method and other static methods. (*)
Contains classes that define objects.
Contains a main method, a package, static methods, and classes that define objects.
None of the above.
Incorrect Incorrect. Refer to Section 4 Lesson 2.
2. The following defines a class keyword: Mark for Review
(1) Points
Provides the compiler information that identifies outside classes used within the current class.
Precedes the name of the class. (*)
Defines where this class lives relative to other classes, and provides a level of access control.
Incorrect Incorrect. Refer to Section 4 Lesson 2.
3. Which of the following defines a driver class? Mark for Review
(1) Points
Contains a main method and other static methods. (*)
Contains classes that define objects.
Contains a main method, a package, static methods, and classes that define objects.
None of the above.
Correct Correct
4. The following defines a package keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control. (*)
Provides the compiler information that identifies outside classes used within the current class.
Precedes the name of the class.
Correct Correct
5. Semi-colons at the end of each line are not required to compile successfully. True or False? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 4 Lesson 1.
Page 1 of 3 Next Summary
6. When Eclipse launches, the Welcome page displays. Once this page is closed you cannot return to the resources available on this page. True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
7. In the image below, identify the components.
Mark for Review
(1) Points
A-Main Method, B-Class, C-Package
A-Class, B-MainMethod, C-Package
A-Package, B-Main Method, C-Class (*)
None of the above
Incorrect Incorrect. Refer to Section 4 Lesson 1.
8. Which line of Java code properly calculates the area of a triangle using A=1/2(b)(h) where b and h are Java primitive integers? Mark for Review
(1) Points
double A=(double)1/(double)2*b*h; (*)
double A=(double)(1/2)*b*h;
double A=1/2*b*h;
double A=1/2bh;
Incorrect Incorrect. Refer to Section 4 Lesson 3.
9. Select the declaration and initialization statement that will hold the letter J. Mark for Review
(1) Points
String letter='J';
float letter='J';
int letter='J';
char letter='J'; (*)
Incorrect Incorrect. Refer to Section 4 Lesson 3.
10. Which of the following is a legal identifier? Mark for Review
(1) Points
7up
apple (*)
boolean
grand Total
11. Which of the following is not a legal name for a variable? Mark for Review
(1) Points
dgo2sleep
to_be_or_not_to_be
R2d2
4geeks (*)
Incorrect Incorrect. Refer to Section 4 Lesson 3.
12. What is the output of the following lines of code?
int j=7,k=5,m=8,result;
result=j/m*k;
System.out.println(result); Mark for Review
(1) Points
0 (*)
280
0.175
4.375
Incorrect Incorrect. Refer to Section 4 Lesson 3.
13. What is printed by the following code segment?
Mark for Review
(1) Points
a1
albatross
alligator (*)
albatross alligator
Incorrect Incorrect. Refer to Section 4 Lesson 4.
14. Which of the following creates a String reference named str and instantiates it? Mark for Review
(1) Points
String str;
str="str";
String str=new String("str"); (*)
String s="str";
Incorrect Incorrect. Refer to Section 4 Lesson 4.
15. The following program prints "Not Equal". True or false?
Mark for Review
(1) Points
True
False (*)
1. Match each of the following literals ('x', 10, 10.2, 100L, "hello") with its respective data type. Mark for Review
(1) Points
char, double, int, long, String
char, int, long, float, String
char, boolean, float, long, String
char, int, double, long, String (*)
boolean, byte, int, long, Short
Incorrect Incorrect. Refer to Section 4 Lesson 3.
2. Which of the following is not correct Java code? Mark for Review
(1) Points
double x=Math.PI*5.0;
double x=Math.sqrt(16);
double x=Math.pow; (*)
double x=Math.pow(3,4)*5.0;
Incorrect Incorrect. Refer to Section 4 Lesson 3.
3. What does the following program output?
Mark for Review
(1) Points
total cost: 48
"total cost: " 48
"total cost: " 40
total cost: 40 (*)
total cost: + 40
Incorrect Incorrect. Refer to Section 4 Lesson 3.
4. Which line of Java code properly calculates the area of a triangle using A=1/2(b)(h) where b and h are Java primitive integers? Mark for Review
(1) Points
double A=1/2bh;
double A=(double)(1/2)*b*h;
double A=(double)1/(double)2*b*h; (*)
double A=1/2*b*h;
Incorrect Incorrect. Refer to Section 4 Lesson 3.
5. Which line of Java code will assign the value of the square root of 11 to a variable named a? Mark for Review
(1) Points
double a=Math.sqrt(11); (*)
double a=Math.sqrt*11;
double a=sqrt(11);
int a=Math.sqrt(11);
double a=11^(1/2);
Correct Correct
6. When importing another package into a class you must import the entire package as well as the package classes that will be called. True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
7. Which of the two diagrams below illustrate the general form of a Java program?
Mark for Review
(1) Points
Example A
Example B (*)
Correct Correct
8. The following defines a class keyword: Mark for Review
(1) Points
Provides the compiler information that identifies outside classes used within the current class.
Precedes the name of the class. (*)
Defines where this class lives relative to other classes, and provides a level of access control.
Correct Correct
9. Which of the following defines a driver class? Mark for Review
(1) Points
Contains a main method and other static methods. (*)
Contains classes that define objects.
Contains a main method, a package, static methods, and classes that define objects.
None of the above.
Correct Correct
10. Multiple windows are used when more than one file is open in the edit area. True or False? Mark for Review
(1) Points
True
False (*)
11. In Eclipse, when you run a Java Application, where may the results display? Mark for Review
(1) Points
Editor Window
Console View (*)
Debug View
Task List
None of the above
Correct Correct
12. A _______________ is used to organize Java related files. Mark for Review
(1) Points
Workspace
Collection
Project
Package (*)
Incorrect Incorrect. Refer to Section 4 Lesson 1.
13. Consider the following code snippet. What is printed?
String river = new String("Hudson"); System.out.println(river.length()); Mark for Review
(1) Points
7
river
6 (*)
Hudson
8
Correct Correct
14. Which of the following creates a String reference named s and instantiates it? Mark for Review
(1) Points
(Choose all correct answers)
String s=""; (*)
String s;
s="s";
String s=new String("s"); (*)
Incorrect Incorrect. Refer to Section 4 Lesson 4.
15. Given the code
String s1 = "abcdef";
String s2 = "abcdef";
String s3 = new String(s1);
Which of the following would equate to false?
Mark for Review
(1) Points
s3.equals(s1)
s1 = s2
s1 == s2
s1.equals(s2)
s3 == s1 (*)
Incorrect Incorrect. Refer to Section 4 Lesson 4.
1. Which line of Java code will assign the value of the square root of 11 to a variable named a? Mark for Review
(1) Points
double a=11^(1/2);
double a=Math.sqrt*11;
double a=Math.sqrt(11); (*)
double a=sqrt(11);
int a=Math.sqrt(11);
Correct Correct
2. Which of the following statements correctly assigns "3 times 10 to the 4th power" to the variable number? Mark for Review
(1) Points
double number=3*10^4;
double number=3*10e4;
double number=3(e4);
double number=3e4; (*)
Incorrect Incorrect. Refer to Section 4 Lesson 3.
3. Which of the following is not a legal name for a variable? Mark for Review
(1) Points
2bad (*)
year2000
zero
theLastValueButONe
Incorrect Incorrect. Refer to Section 4 Lesson 3.
4. Which of the following is the name of a Java primitive data type? Mark for Review
(1) Points
int (*)
Rectangle
String
Object
Correct Correct
5. A local variable has precedence over a global variable in a Java method. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
6. The following defines a class keyword: Mark for Review
(1) Points
Precedes the name of the class. (*)
Provides the compiler information that identifies outside classes used within the current class.
Defines where this class lives relative to other classes, and provides a level of access control.
Correct Correct
7. The following defines an import keyword: Mark for Review
(1) Points
Provides the compiler information that identifies outside classes used within the current class. (*)
Precedes the name of the class.
Defines where this class lives relative to other classes, and provides a level of access control.
Correct Correct
8. Which of the two diagrams below illustrate the general form of a Java program?
Mark for Review
(1) Points
Example A
Example B (*)
Incorrect Incorrect. Refer to Section 4 Lesson 2.
9. When importing another package into a class you must import only the package classes that will be called and not the entire package. True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 4 Lesson 2.
10. A workspace can not have more than one stored projects. True or false? Mark for Review
(1) Points
True
False (*)
11. When Eclipse launches, the Welcome page displays. Once this page is closed you cannot return to the resources available on this page. True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
12. In a project, 1 of the classes must contain a main method. True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
13. The == operator can be used to compare two String objects. The result is always true if the two strings are have the exact same characters in each position of the String. True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 4 Lesson 4.
14. Declaring and instantiating a String is much like any other type of variable. However, once instantiated, they are final and cannot be changed. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
15. Consider the following code snippet.
What is printed? Mark for Review
(1) Points
ArrayIndexOutofBoundsException is thrown
1010778
101077810109
88888 (*)
88888888
1. Consider the following code snippet. What is printed?
Mark for Review
(1) Points
ArrayIndexOutofBoundsException is thrown
Polii
PoliiPolii (*)
auaacauaac
auaac
Incorrect Incorrect. Refer to Section 4 Lesson 4.
2. Declaring and instantiating a String is much like any other type of variable. However, once instantiated, they are final and cannot be changed. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
3. The following code prints 5 "a"'s to the screen:
Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 4 Lesson 4.
4. You need to _______________ Java code to generate a .class file Mark for Review
(1) Points
Assemble
Compile (*)
Collect
Package
Incorrect Incorrect. Refer to Section 4 Lesson 1.
5. A workspace is: Mark for Review
(1) Points
The physical location onto which you will store and save your files.
The location where all projects are developed and modified.
The location where you can have one or more stored perspectives.
All of the above. (*)
6. In a project, 1 of the classes must contain a main method. True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
7. What will the method methodA print to the screen?
Mark for Review
(1) Points
6
18 (*)
3
15
Correct Correct
8. Which of the following statements displays 12345?
I. System.out.println( 123 * 100 + 45);
II. System.out.println("123" + 45);
III. System.out.println( 12 + "345"); Mark for Review
(1) Points
All of the above. (*)
I only.
I and II only.
II and III only.
None of the above.
Incorrect Incorrect. Refer to Section 4 Lesson 3.
9. Which of the following examples of Java code is not correct? Mark for Review
(1) Points
char c='r';
boolean b=1; (*)
double d=4.5;
int x=6;
Incorrect Incorrect. Refer to Section 4 Lesson 3.
10. Match each of the following literals ('x', 10, 10.2, 100L, "hello") with its respective data type. Mark for Review
(1) Points
char, boolean, float, long, String
char, double, int, long, String
char, int, long, float, String
char, int, double, long, String (*)
boolean, byte, int, long, Short
Correct Correct
11. What is the result when the following code segment is compiled and executed?
int x = 22, y = 10;
double p = Math.sqrt( ( x + y ) /2);
System.out.println(p); Mark for Review
(1) Points
5.656854249492381 is displayed
2.2 is displayed
Syntax error "sqrt(double) in java.lang.Math cannot be applied to int"
4.0 is displayed (*)
ClassCastException
Incorrect Incorrect. Refer to Section 4 Lesson 3.
12. Which of the two diagrams below illustrate the general form of a Java program?
Mark for Review
(1) Points
Example A
Example B (*)
Correct Correct
13. The following defines a package keyword: Mark for Review
(1) Points
Precedes the name of the class.
Provides the compiler information that identifies outside classes used within the current class.
Defines where this class lives relative to other classes, and provides a level of access control. (*)
Correct Correct
14. The following defines a class keyword: Mark for Review
(1) Points
Precedes the name of the class. (*)
Defines where this class lives relative to other classes, and provides a level of access control.
Provides the compiler information that identifies outside classes used within the current class.
Correct Correct
15. The following defines an import keyword: Mark for Review
(1) Points
Provides the compiler information that identifies outside classes used within the current class. (*)
Precedes the name of the class.
Defines where this class lives relative to other classes, and provides a level of access control.
1. What is the output of the following segment of code?
Mark for Review
(1) Points
2
220
This code does not compile.
0 (*)
222220
Incorrect Incorrect. Refer to Section 6 Lesson 1.
2. Which of the following declares and initializes a one dimensional array named values of size 5 so that all entries contain 1? Mark for Review
(1) Points
int[] values={1,1,1,1,1}; (*)
int[] values={1};
int values[]={1,1,1,1,1,1};
int values={1,1,1,1,1};
Correct Correct
3. What will be the content of the array variable table after executing the following code?
Mark for Review
(1) Points
0 0 1
0 1 0
1 0 0
1 0 0
0 1 0
0 0 1
1 0 0
1 1 0
1 1 1 (*)
1 1 1
0 1 1
0 0 1
Incorrect Incorrect. Refer to Section 6 Lesson 1.
4. What is the output of the following segment of code?
Mark for Review
(1) Points
6
This code does not compile.
753
7531 (*)
7766554433221
Incorrect Incorrect. Refer to Section 6 Lesson 1.
5. The following creates a reference in memory named z that can refer to seven different doubles via an index. True or false?
double z[] = new double[7]; Mark for Review
(1) Points
True (*)
False
6. The following array declaration is valid. True or false?
int k[] = new int[10]; Mark for Review
(1) Points
True (*)
False
Correct Correct
7. The following segment of code initializes a 2 dimensional array of references. True or false?
String[][] array={{"a", "b", "C"},{"a", "b", "c"}}; Mark for Review
(1) Points
True (*)
False
Correct Correct
8. Which of the following declares and initializes a two dimensional array where each element is a reference type? Mark for Review
(1) Points
char[][] words;
String words=new String[10];
String[][] words=new String[10][3]; (*)
char[][] words=new char[10][4];
Incorrect Incorrect. Refer to Section 6 Lesson 1.
9. What is the output of the following segment of code?
Mark for Review
(1) Points
This code doesn't compile.
321111
11 (*)
1111
111
Incorrect Incorrect. Refer to Section 6 Lesson 1.
10. The following array declaration is valid. True or false?
int[] y = new int[5]; Mark for Review
(1) Points
True (*)
False
Correct Correct
11. It is possible to throw and catch a second exception inside a catch block of code. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
12. Choose the best response to this statement: An error can be handled by throwing it and catching it just like an exception. Mark for Review
(1) Points
True. Although errors may be more severe than exceptions they can still be handled in code the same way exceptions are.
True. Errors and exceptions are the same objects and are interchangeable.
False. Exceptions are caused by a mistake in the code and errors occur for no particular reason and therefore cannot be handled or avoided.
False. An error is much more severe than an exception and cannot be dealt with adequately in a program. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
13. If an exception is thrown by a method, where can the catch for the exception be? Mark for Review
(1) Points
The catch must be in the method that threw the exception.
The catch must be immediately after the throw.
There does not need to be a catch in this situation.
The catch can be in the method that threw the exception or in any other method that called the method that threw the exception. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
14. If an exception has already been thrown, what will the interpreter read next in the program? Mark for Review
(1) Points
The end of the program.
The next line of the program even if it is not the catch block of code.
The user input.
Where the program catches the exception. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
15. What does it mean to catch an exception? Mark for Review
(1) Points
It means to throw it.
It means you have fixed the error.
It means to handle it. (*)
It means there was never an exception in your code.
1. After execution of the following statement, which of the following are true?
int number[] = new int[5]; Mark for Review
(1) Points
number[0] is undefined
number.length() is 6
number[4] is null
number[2] is 0 (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
2. The following array declaration is valid. True or false?
int k[] = new int[10]; Mark for Review
(1) Points
True (*)
False
Correct Correct
3. What will be the content of array variable table after executing the following code?
Mark for Review
(1) Points
0 0 0
0 0 0
0 0 0
0 0 1
0 1 0
1 0 0
1 0 0
1 1 0
1 1 1
1 0 0
0 1 0
0 0 1 (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
4. Which of the following declares and initializes a one dimensional array named values of size 5 so that all entries contain 1? Mark for Review
(1) Points
int values[]={1,1,1,1,1,1};
int[] values={1};
int values={1,1,1,1,1};
int[] values={1,1,1,1,1}; (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
5. What is the output of the following segment of code?
Mark for Review
(1) Points
987654
777777 (*)
This code doesn't compile.
555555
456789
6. What will array arr contain after the following code segment has been executed?
int [] arr = {5, 4, 2, 1, 0};
for (int i = 1; i < arr.length; i++)
{
arr[i - 1] += arr[i];
} Mark for Review
(1) Points
None of the above.
9, 6, 3, 1, 0 (*)
10, 6, 3, 1, 0
7, 3, 2, 1, 0
9, 6, 1, 3, 0
Correct Correct
7. The following array declaration is valid:
int[] y = new int[5]; Mark for Review
(1) Points
True (*)
False
Correct Correct
8. Which of the following statements is a valid array declaration? Mark for Review
(1) Points
(Choose all correct answers)
double[] marks; (*)
int number();
counter int[];
float average[]; (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
9. Which of the following statements adds 5 to every element of the one dimensional array prices and then prints it to the screen? Mark for Review
(1) Points
for(int i=0;i<prices.length;i++)
System.out.println(prices[i]+5); (*)
for(int i=1;i<prices.length;i++)
System.out.println(prices[i]+5);
System.out.println(prices[i]+5);
for(int i=0;i<prices.length;i++)
System.out.println(prices[1]+5);
Incorrect Incorrect. Refer to Section 6 Lesson 1.
10. What is the output of the following segment of code?
Mark for Review
(1) Points
642246 (*)
321123
This code doesn't compile.
312213
642
11. What do exceptions indicate in Java? Mark for Review
(1) Points
(Choose all correct answers)
A mistake was made in your code. (*)
There are no errors in your code.
Exceptions do not indicate anything, their only function is to be thrown.
The code has considered and dealt with all possible cases.
The code was not written to handle all possible conditions. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
12. What does it mean to catch an exception? Mark for Review
(1) Points
It means you have fixed the error.
It means there was never an exception in your code.
It means to throw it.
It means to handle it. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
13. What are exceptions used for in Java? Mark for Review
(1) Points
Exceptions have no use, they are just a part of the Java language.
Helping the interpreter compile code quicker and handle user interfaces.
Correcting mistakes made in your code and handling extraordinary cases. (*)
Making the program easier to use for the user and reducing the possibilities of errors occuring.
Incorrect Incorrect. Refer to Section 6 Lesson 2.
14. It is possible to throw and catch a second exception inside a catch block of code. True or false? Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 6 Lesson 2.
15. A computer company has one million dollars to give as a bonus to the employees, and they wish to distribute it evenly amongst them.
The company writes a program to calculate the amount each employee receives, given the number of employees.
Unfortunately, the employees all went on strike before they heard about the bonus. This means that the company has zero employees.
What will happen to the program if the company enters 0 into the employment number? Mark for Review
(1) Points
(Choose all correct answers)
The program will calculate that each employee will receive zero dollars because there are zero employees.
The programmers will have proven their worth in the company because without them the company wrote faulty code.
An unfixable error will occur.
An exception will occur because it is not possible to divide by zero. (*)
questions in this section)
1. Suppose you are writing a program where the user is prompted to the give coordinates where they believe the princess is inside of the castle.
Your program moves the prince to the coordinates that the user specified. If the princess is not found at those coordinates, the user is given a clue that helps them guess coordinates closer to the princess. The user is allowed to enter their new guess of where the princess is.
Assume your program does not take into consideration the possibility that the user may enter coordinates outside of the castle where the princess could not be. What would be the result of the user entering coordinates outside of the castle? How could this be handled in your code? Mark for Review
(1) Points
(Choose all correct answers)
An error would occur. Errors cannot be handled by code.
An exception would occur but could not be handled inside your code. The user would have to restart the program and enter proper coordinates.
An exception would occur. This could be handled by throwing the exception in your code if the user enters invalid coordinates. When the exception is caught, the prince could be moved to the coordinate inside the castle that is closest to those that the user specified. (*)
An exception would occur. This could be handled by throwing an exception in your code if the user enters invalid coordinates. When the exception is caught, the user could be prompted to enter coordinates within the given range of the castle. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
2. If an exception has already been thrown, what will the interpreter read next in the program? Mark for Review
(1) Points
The next line of the program even if it is not the catch block of code.
The end of the program.
The user input.
Where the program catches the exception. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
3. Which of the following correctly matches the symbol with its function? Mark for Review
(1) Points
(Choose all correct answers)
== (two equal signs) compares the memory location of non-primitive objects. (*)
.equals() compares the value of non-primitive objects. (*)
== (two equal signs) compares values of primitive types such as int or char. (*)
= (single equals sign) compares the value of primitive types such as int or char.
== (two equal signs) compares the values of non-primitive objects.
Incorrect Incorrect. Refer to Section 6 Lesson 2.
4. Which of the following would give you an array index out of bounds exception? Mark for Review
(1) Points
Using a single equal symbol to compare the value of two integers.
Unintentionally placing a semicolon directly after initializing a for loop.
Refering to an element of an array that is at an index greater than the length of that array minus one. (*)
Refering to an element of an array that is at an index less than the length of the array minus one.
Misspelling a variable name somewhere in your code.
Incorrect Incorrect. Refer to Section 6 Lesson 2.
5. Which of the following would be a correct way to handle an index out of bounds exception? Mark for Review
(1) Points
(Choose all correct answers)
Throw the exception and catch it. In the catch, set the index to the index of the array closest to the one that was out of bounds. (*)
Rewrite your code to avoid the exception by not permititng the use of an index that is not inside the array. (*)
Throw the exception that prints out an error message. There is no need to have the catch handle the exception if it has already been thrown.
Do nothing, it will fix itself.
6. What is the output of the following segment of code?
Mark for Review
(1) Points
7766554433221
This code does not compile.
6
753
7531 (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
7. Which of the following declares a one dimensional array name scores of type int that can hold 14 values? Mark for Review
(1) Points
int[] scores=new scores int[14];
int score= new int[14];
int scores;
int[] scores=new int[14]; (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
8. Which of the following declares and initializes a two dimensional array named values with 2 rows and 3 columns where each element is a reference to an Object? Mark for Review
(1) Points
String[][] values=new String[2][3]; (*)
String[][] values=new String[3][2];
String[][] values;
String[][] values={"apples","oranges","pears"};
Correct Correct
9. What is the output of the following segment of code?
Mark for Review
(1) Points
642246 (*)
312213
This code doesn't compile.
642
321123
Incorrect Incorrect. Refer to Section 6 Lesson 1.
10. The following creates a reference in memory named q that can refer to six different integers via an index. True or false?
int[] q = new int[8]; Mark for Review
(1) Points
True
False (*)
11. The following creates a reference in memory named y that can refer to five different integers via an index. True or false?
int[] y = new int[5]; Mark for Review
(1) Points
True (*)
False
Correct Correct
12. What is the output of the following segment of code?
int array[][] = {{1,2,3},{3,2,1}};
for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
System.out.print(2*array[1][1]); Mark for Review
(1) Points
444444 (*)
This code doesn't compile.
222222
123321
246642
Incorrect Incorrect. Refer to Section 6 Lesson 1.
13. What is the output of the following segment of code?
Mark for Review
(1) Points
456789
555555
777777 (*)
This code doesn't compile.
987654
Correct Correct
14. After execution of the following statement, which of the following are true?
int number[] = new int[5]; Mark for Review
(1) Points
number.length() is 6
number[2] is 0 (*)
number[0] is undefined
number[4] is null
Correct Correct
15. Which of the following statements print every element of the one dimensional array prices to the screen? Mark for Review
(1) Points
for(int i=0; i <= prices.length; i++){System.out.println(prices[i]);}
for(int i=0; i < prices.length; i++){System.out.println(prices[i]);} (*)
System.out.println(prices.length);
for(int i=1; i <= prices.length; i++){System.out.println(prices[i]);}
(1) Points
(Choose all correct answers)
while (*)
if/else
do-while (*)
for (*)
Correct Correct
2. What is the function of the word "break" in Java? Mark for Review
(1) Points
It continues onto the next line of code.
It exits the current loop or case statement. (*)
It does not exist in Java.
It stops the program from running.
Correct Correct
3. How many times will the following loop be executed?
What is the value of x after the loop has finished?
What is the value of count after the loop has finished?
int count = 17;
int x = 1;
while(count > x){
x*=3;
count-=3;
} Mark for Review
(1) Points
3; 9; 11
5; 30; 5
4; 8; 27
5; 27; 8
3; 27; 8 (*)
Incorrect Incorrect. Refer to Section 5 Lesson 2.
4. When the for loop condition statement is met the construct is exited. True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 5 Lesson 2.
5. A counter used in a for loop cannot be initialized within the For loop header. True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 5 Lesson 2.
6. A counter used in a for loop cannot be initialized within the For loop statement. True or False? Mark for Review
(1) Points
True
False (*)
7. Which of the following best describes a while loop? Mark for Review
(1) Points
A loop that contains a segment of code that is executed before the conditional statement is tested.
A loop that is executed repeatedly until the conditional statement is false. (*)
A loop that executes the code at least one time even if the conditional statement is false.
A loop that contains a counter in parenthesis with the conditional statement.
Incorrect Incorrect. Refer to Section 5 Lesson 2.
8. The six relational operators in Java are: Mark for Review
(1) Points
>, <, =, !=, <=, >=
>, <, ==, !=, <=, >= (*)
>, <, =, !, <=, >=
>, <, =, !=, =<, =>
9. Determine whether this boolean expression evaluates to true or false:
!(3 < 4 && 5 > 6 || 6 <= 6 && 7 - 1 == 6) Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 5 Lesson 1.
10. Which of the following correctly matches the switch statement keyword to its function? Mark for Review
(1) Points
(Choose all correct answers)
switch: tells the compiler the value to compare the input against
default: signals what code to execute if the input does not match any of the cases (*)
case: signals what code is executed if the user input matches the specified element (*)
switch: identifies what element will be compared to the element of the case statements to find a possible match (*)
if: records the user's input and sends it to the case statements to find a possible match
11. What will print if the following Java code is executed?
Mark for Review
(1) Points
3 (*)
5
0
4
Incorrect Incorrect. Refer to Section 5 Lesson 1.
12. In Java, each case seqment of a switch statement requires the keyword break to avoid "falling through". Mark for Review
(1) Points
True (*)
False
Correct Correct
13. How would you use the ternary operator to rewrite this if statement?
if (gender == "male")
System.out.print("Mr.");
else
System.out.print("Ms."); Mark for Review
(1) Points
(gender == "male") ? "Ms." : "Mr." ;
(gender == "male") ? "Mr." : "Ms." ;
System.out.print( (gender == "male") ? "Mr." : "Ms." ); (*)
System.out.print( (gender == "male") ? "Ms." : "Mr." );
Incorrect Incorrect. Refer to Section 5 Lesson 1.
14. Determine whether this boolean expression evaluates to true or false:
!(3 < 4 && 6 > 6 || 6 <= 6 && 7 - 2 == 6) Mark for Review
(1) Points
True (*)
False
Correct Correct
15. Which of the following expressions will evaluate to true when x and y are boolean variables with opposite values?
I. (x || y) && !(x && y)
II. (x && !y) || (!x && y)
III. (x || y) && (!x ||!y) Mark for Review
(1) Points
I only
II only
I and III
II and III
I, II, and III (*)
switch statements work on all input types including, but not limited to, int, char, and String. True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 5 Lesson 1.
2. The three logic operators in Java are: Mark for Review
(1) Points
!=, =, ==
&&, !=, =
&, |, =
&&, ||, ! (*)
Correct Correct
3. The following code fragment properly implements the switch statement. True or false?
default(input)
switch '+':
answer+=num;
break;
case '-':
answer-=num;
break;
!default
System.out.println("Invalid input"); Mark for Review
(1) Points
True
False (*)
Correct Correct
4. In an if-else construct the condition to be evaluated must end with a semi-colon. True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
5. Which of the following correctly initializes an instance of Scanner, called "in", that reads input from the console screen? Mark for Review
(1) Points
Scanner in = Scanner(System.in);
Scanner in = new Scanner(System.in); (*)
Scanner in = new Scanner("System.in");
System.in in = new Scanner();
Correct Correct
6. Consider that a Scanner has been initialized such that:
Scanner in = new Scanner(System.in);
Which of the following lines of code reads in the user?s input and sets it equal to a new String called input?
Mark for Review
(1) Points
String input = in.close();
String input = in.next(); (*)
String input = in.nextInt();
String input = new String in.next();
Correct Correct
7. Which of the two diagrams below illustrate the correct syntax for variables used in an if-else statement?
Mark for Review
(1) Points
Example A (*)
Example B
Correct Correct
8. Determine whether this boolean expression evaluates to true or false:
!(3 < 4 && 6 > 6 || 6 <= 6 && 7 - 2 == 6) Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 5 Lesson 1.
9. All of the following are essential to initializing a for loop, except which one? Mark for Review
(1) Points
Initializing the iterator(i).
Having a conditional statement.
Updating the counter.
Having an if statement. (*)
Correct Correct
10. When the for loop condition statement is met the construct is exited. True or false? Mark for Review
(1) Points
True
False (*)
11. Why are loops useful? Mark for Review
(1) Points
They save programmers from having to rewrite code.
They allow for repeating code a variable number of times.
They allow for repeating code until a certain argument is met.
All of the above. (*)
Correct Correct
12. For both the if-else construct and the for loop, it is true to say that when the condition statement is met, the construct is exited. True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
13. What is the output of the following code segment?
int num = 7;
while(num >= 0)
{
num -= 3;
}
System.out.println(num); Mark for Review
(1) Points
0
2
-2 (*)
1
Correct Correct
14. In a for loop the counter is not automatically incremented after each loop iteration. Code must be written to increment the counter. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
15. In the code fragment below, the syntax for the for loop's initialization is correct. True or false?
public class ForLoop {
public static void main (String args[])
{
for ((int 1=10) (i<20) (i++))
{
System.out.println ("i: " + i);
}
}
}
Mark for Review
(1) Points
True
False (*)
4
1. When you open more than one file in Eclipse the system will __________________. Mark for Review
(1) Points
Close the previously opened file.
Use tabs to display all files open. (*)
Put the new file opened in a View area only.
None of the above.
Incorrect Incorrect. Refer to Section 4 Lesson 1.
2. When converting gallons to liters its best to put the calculation result into a variable with a _______________ data type. Mark for Review
(1) Points
int
double (*)
boolean
None of the above
1. The following defines a package keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control. (*)
Provides the compiler information that identifies outside classes used within the current class.
Precedes the name of the class.
Correct Correct
2. The following defines a class keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control.
Precedes the name of the class. (*)
Provides the compiler information that identifies outside classes used within the current class.
Correct Correct
3. Which of the following defines a driver class? Mark for Review
(1) Points
Contains a main method and other static methods. (*)
Contains classes that define objects.
Contains a main method, a package, static methods, and classes that define objects.
None of the above.
Correct Correct
4. The following defines a package keyword: Mark for Review
(1) Points
Provides the compiler information that identifies outside classes used within the current class.
Precedes the name of the class.
Defines where this class lives relative to other classes, and provides a level of access control. (*)
Correct Correct
5. What will the method methodA print to the screen?
Mark for Review
(1) Points
6
18 (*)
15
3
Correct Correct
6. Which of the following is the name of a Java primitive data type? Mark for Review
(1) Points
Object
Rectangle
String
int (*)
Correct Correct
7. Which of the following is not correct Java code? Mark for Review
(1) Points
double x=Math.PI*5.0;
double x=Math.sqrt(16);
double x=Math.pow(3,4)*5.0;
double x=Math.pow; (*)
Correct Correct
8. A local variable has precedence over a global variable in a Java method. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
9. Which line of Java code assigns the value of 5 raised to the power of 8 to a? Mark for Review
(1) Points
int a=Math.pow(5,8);
double a=Math.pow(5,8); (*)
double a=pow(8,5);
int a=Math.pow(8,5);
double a=15^8;
Correct Correct
10. Consider the following code snippet. What is printed?
Mark for Review
(1) Points
AtlanticPacificIndianArcticSouthern
The code does not compile.
An ArrayIndexOutofBoundsException is thrown.
55555
87668 (*)
11. Consider the following code snippet. What is printed?
Mark for Review
(1) Points
55555
87658
An ArrayIndexOutofBoundsException is thrown. (*)
AtlanticPacificIndianArcticSouthern
The code does not compile.
Incorrect Incorrect. Refer to Section 4 Lesson 4.
12. Which of the following creates a String named Char? Mark for Review
(1) Points
char string;
String Char; (*)
char Char;
char char;
String char;
Incorrect Incorrect. Refer to Section 4 Lesson 4.
13. When you open more than one file in Eclipse the system will __________________. Mark for Review
(1) Points
Close the previously opened file.
Use tabs to display all files open. (*)
Put the new file opened in a View area only.
None of the above.
Correct Correct
14. Eclipse provides views to help you navigate a hierarchy of information. True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
15. When converting gallons to liters its best to put the calculation result into a variable with a _______________ data type. Mark for Review
(1) Points
int
double (*)
boolean
None of the above
Correct Correct
3. A _______________ is used to organize Java related files. Mark for Review
(1) Points
Workspace
Collection
Project
Package (*)
Incorrect Incorrect. Refer to Section 4 Lesson 1.
4. When importing another package into a class you must import the entire package as well as the package classes that will be called. True or False? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 4 Lesson 2.
5. The following defines a class keyword: Mark for Review
(1) Points
Precedes the name of the class. (*)
Defines where this class lives relative to other classes, and provides a level of access control.
Provides the compiler information that identifies outside classes used within the current class.
6. The following defines an import keyword: Mark for Review
(1) Points
Provides the compiler information that identifies outside classes used within the current class. (*)
Precedes the name of the class.
Defines where this class lives relative to other classes, and provides a level of access control.
Correct Correct
7. The following defines a package keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control. (*)
Precedes the name of the class.
Provides the compiler information that identifies outside classes used within the current class.
Correct Correct
8. Given the code below, which of the following would equate to true?
String s1 = "yes";
String s2 = "yes";
String s3 = new String(s1);
Mark for Review
(1) Points
(Choose all correct answers)
s1 == s2 (*)
s1.equals(s2) (*)
s3.equals(s1) (*)
s3 == s1
s1 = s2
Incorrect Incorrect. Refer to Section 4 Lesson 4.
9. The String methods equals and compareTo perform similar functions and differ in their return type. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
10. The following program prints "Not Equal". True or false?
Mark for Review
(1) Points
True
False (*)
11. Given the following declaration, which line of Java code properly casts one type into another without data loss?
int i=3,j=4; double y=2.54; Mark for Review
(1) Points
double x=i/j;
int x=(double)2.54;
6. What is the purpose of the Eclipse Editor Area and Views? Mark for Review
(1) Points
(Choose all correct answers)
To navigate a hierarchy of information. (*)
To choose the file system location to delete a file.
To modify elements. (*)
Incorrect Incorrect. Refer to Section 4 Lesson 1.
7. In the image below, identify the components.
Mark for Review
(1) Points
A-Main Method, B-Class, C-Package
A-Class, B-MainMethod, C-Package
A-Package, B-Main Method, C-Class (*)
None of the above
Correct Correct
8. Which of the following is the name of a Java primitive data type? Mark for Review
(1) Points
String
Rectangle
double (*)
Object
Incorrect Incorrect. Refer to Section 4 Lesson 3.
9. What is the output of the following lines of code?
int j=7,k=5,m=8,result;
result=j/m*k;
System.out.println(result); Mark for Review
(1) Points
0 (*)
4.375
280
0.175
Correct Correct
10. Which of the following is not a legal name for a variable? Mark for Review
(1) Points
to_be_or_not_to_be
4geeks (*)
R2d2
dgo2sleep
Correct Correct
11. What are Java's primitive types? Mark for Review
(1) Points
boolean, thread, char, double, float, int, long and short
object, byte, string, char, float, int, long and short
boolean, thread, stringbuffer, char, int, float, long and short
boolean, byte, char, double, float, int, long, and short (*)
boolean, byte, string, thread, int, double, long and short
Correct Correct
12. Which line of code does not assign 3.5 to the variable x? Mark for Review
(1) Points
x=3.5;
3.5=x; (*)
double x=3.5
x=7.0/2.0;
Incorrect Incorrect. Refer to Section 4 Lesson 3.
13. Which of the following creates a String reference named s and instantiates it? Mark for Review
(1) Points
(Choose all correct answers)
String s;
s="s";
String s=new String("s"); (*)
String s=""; (*)
Incorrect Incorrect. Refer to Section 4 Lesson 4.
14. The String methods equals and compareTo perform similar functions and differ in their return type. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
15. What will the following code segment output?
Mark for Review
(1) Points
"\\" (*)
"\\\\\"
"\\\"
\"\\\\\"
Incorrect Incorrect. Refer to Section 4 Lesson 4.
double x=(double)i/j; (*)
double x= double i/j;
double x=(double)(i/j);
Incorrect Incorrect. Refer to Section 4 Lesson 3.
12. Which line of Java code will assign the value of the square root of 11 to a variable named a? Mark for Review
(1) Points
int a=Math.sqrt(11);
double a=Math.sqrt*11;
double a=sqrt(11);
double a=Math.sqrt(11); (*)
double a=11^(1/2);
Incorrect Incorrect. Refer to Section 4 Lesson 3.
13. Match each of the following literals ('x', 10, 10.2, 100L, "hello") with its respective data type. Mark for Review
(1) Points
char, int, double, long, String (*)
char, double, int, long, String
char, int, long, float, String
boolean, byte, int, long, Short
char, boolean, float, long, String
Incorrect Incorrect. Refer to Section 4 Lesson 3.
14. Which line of Java code assigns the value of 5 raised to the power of 8 to a? Mark for Review
(1) Points
double a=15^8;
double a=Math.pow(5,8); (*)
int a=Math.pow(5,8);
double a=pow(8,5);
int a=Math.pow(8,5);
Correct Correct
15. A local variable has precedence over a global variable in a Java method. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
1. Which of the following defines a driver class? Mark for Review
(1) Points
Contains a main method and other static methods. (*)
Contains classes that define objects.
Contains a main method, a package, static methods, and classes that define objects.
None of the above.
Incorrect Incorrect. Refer to Section 4 Lesson 2.
2. The following defines a class keyword: Mark for Review
(1) Points
Provides the compiler information that identifies outside classes used within the current class.
Precedes the name of the class. (*)
Defines where this class lives relative to other classes, and provides a level of access control.
Incorrect Incorrect. Refer to Section 4 Lesson 2.
3. Which of the following defines a driver class? Mark for Review
(1) Points
Contains a main method and other static methods. (*)
Contains classes that define objects.
Contains a main method, a package, static methods, and classes that define objects.
None of the above.
Correct Correct
4. The following defines a package keyword: Mark for Review
(1) Points
Defines where this class lives relative to other classes, and provides a level of access control. (*)
Provides the compiler information that identifies outside classes used within the current class.
Precedes the name of the class.
Correct Correct
5. Semi-colons at the end of each line are not required to compile successfully. True or False? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 4 Lesson 1.
Page 1 of 3 Next Summary
6. When Eclipse launches, the Welcome page displays. Once this page is closed you cannot return to the resources available on this page. True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
7. In the image below, identify the components.
Mark for Review
(1) Points
A-Main Method, B-Class, C-Package
A-Class, B-MainMethod, C-Package
A-Package, B-Main Method, C-Class (*)
None of the above
Incorrect Incorrect. Refer to Section 4 Lesson 1.
8. Which line of Java code properly calculates the area of a triangle using A=1/2(b)(h) where b and h are Java primitive integers? Mark for Review
(1) Points
double A=(double)1/(double)2*b*h; (*)
double A=(double)(1/2)*b*h;
double A=1/2*b*h;
double A=1/2bh;
Incorrect Incorrect. Refer to Section 4 Lesson 3.
9. Select the declaration and initialization statement that will hold the letter J. Mark for Review
(1) Points
String letter='J';
float letter='J';
int letter='J';
char letter='J'; (*)
Incorrect Incorrect. Refer to Section 4 Lesson 3.
10. Which of the following is a legal identifier? Mark for Review
(1) Points
7up
apple (*)
boolean
grand Total
11. Which of the following is not a legal name for a variable? Mark for Review
(1) Points
dgo2sleep
to_be_or_not_to_be
R2d2
4geeks (*)
Incorrect Incorrect. Refer to Section 4 Lesson 3.
12. What is the output of the following lines of code?
int j=7,k=5,m=8,result;
result=j/m*k;
System.out.println(result); Mark for Review
(1) Points
0 (*)
280
0.175
4.375
Incorrect Incorrect. Refer to Section 4 Lesson 3.
13. What is printed by the following code segment?
Mark for Review
(1) Points
a1
albatross
alligator (*)
albatross alligator
Incorrect Incorrect. Refer to Section 4 Lesson 4.
14. Which of the following creates a String reference named str and instantiates it? Mark for Review
(1) Points
String str;
str="str";
String str=new String("str"); (*)
String s="str";
Incorrect Incorrect. Refer to Section 4 Lesson 4.
15. The following program prints "Not Equal". True or false?
Mark for Review
(1) Points
True
False (*)
1. Match each of the following literals ('x', 10, 10.2, 100L, "hello") with its respective data type. Mark for Review
(1) Points
char, double, int, long, String
char, int, long, float, String
char, boolean, float, long, String
char, int, double, long, String (*)
boolean, byte, int, long, Short
Incorrect Incorrect. Refer to Section 4 Lesson 3.
2. Which of the following is not correct Java code? Mark for Review
(1) Points
double x=Math.PI*5.0;
double x=Math.sqrt(16);
double x=Math.pow; (*)
double x=Math.pow(3,4)*5.0;
Incorrect Incorrect. Refer to Section 4 Lesson 3.
3. What does the following program output?
Mark for Review
(1) Points
total cost: 48
"total cost: " 48
"total cost: " 40
total cost: 40 (*)
total cost: + 40
Incorrect Incorrect. Refer to Section 4 Lesson 3.
4. Which line of Java code properly calculates the area of a triangle using A=1/2(b)(h) where b and h are Java primitive integers? Mark for Review
(1) Points
double A=1/2bh;
double A=(double)(1/2)*b*h;
double A=(double)1/(double)2*b*h; (*)
double A=1/2*b*h;
Incorrect Incorrect. Refer to Section 4 Lesson 3.
5. Which line of Java code will assign the value of the square root of 11 to a variable named a? Mark for Review
(1) Points
double a=Math.sqrt(11); (*)
double a=Math.sqrt*11;
double a=sqrt(11);
int a=Math.sqrt(11);
double a=11^(1/2);
Correct Correct
6. When importing another package into a class you must import the entire package as well as the package classes that will be called. True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
7. Which of the two diagrams below illustrate the general form of a Java program?
Mark for Review
(1) Points
Example A
Example B (*)
Correct Correct
8. The following defines a class keyword: Mark for Review
(1) Points
Provides the compiler information that identifies outside classes used within the current class.
Precedes the name of the class. (*)
Defines where this class lives relative to other classes, and provides a level of access control.
Correct Correct
9. Which of the following defines a driver class? Mark for Review
(1) Points
Contains a main method and other static methods. (*)
Contains classes that define objects.
Contains a main method, a package, static methods, and classes that define objects.
None of the above.
Correct Correct
10. Multiple windows are used when more than one file is open in the edit area. True or False? Mark for Review
(1) Points
True
False (*)
11. In Eclipse, when you run a Java Application, where may the results display? Mark for Review
(1) Points
Editor Window
Console View (*)
Debug View
Task List
None of the above
Correct Correct
12. A _______________ is used to organize Java related files. Mark for Review
(1) Points
Workspace
Collection
Project
Package (*)
Incorrect Incorrect. Refer to Section 4 Lesson 1.
13. Consider the following code snippet. What is printed?
String river = new String("Hudson"); System.out.println(river.length()); Mark for Review
(1) Points
7
river
6 (*)
Hudson
8
Correct Correct
14. Which of the following creates a String reference named s and instantiates it? Mark for Review
(1) Points
(Choose all correct answers)
String s=""; (*)
String s;
s="s";
String s=new String("s"); (*)
Incorrect Incorrect. Refer to Section 4 Lesson 4.
15. Given the code
String s1 = "abcdef";
String s2 = "abcdef";
String s3 = new String(s1);
Which of the following would equate to false?
Mark for Review
(1) Points
s3.equals(s1)
s1 = s2
s1 == s2
s1.equals(s2)
s3 == s1 (*)
Incorrect Incorrect. Refer to Section 4 Lesson 4.
1. Which line of Java code will assign the value of the square root of 11 to a variable named a? Mark for Review
(1) Points
double a=11^(1/2);
double a=Math.sqrt*11;
double a=Math.sqrt(11); (*)
double a=sqrt(11);
int a=Math.sqrt(11);
Correct Correct
2. Which of the following statements correctly assigns "3 times 10 to the 4th power" to the variable number? Mark for Review
(1) Points
double number=3*10^4;
double number=3*10e4;
double number=3(e4);
double number=3e4; (*)
Incorrect Incorrect. Refer to Section 4 Lesson 3.
3. Which of the following is not a legal name for a variable? Mark for Review
(1) Points
2bad (*)
year2000
zero
theLastValueButONe
Incorrect Incorrect. Refer to Section 4 Lesson 3.
4. Which of the following is the name of a Java primitive data type? Mark for Review
(1) Points
int (*)
Rectangle
String
Object
Correct Correct
5. A local variable has precedence over a global variable in a Java method. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
6. The following defines a class keyword: Mark for Review
(1) Points
Precedes the name of the class. (*)
Provides the compiler information that identifies outside classes used within the current class.
Defines where this class lives relative to other classes, and provides a level of access control.
Correct Correct
7. The following defines an import keyword: Mark for Review
(1) Points
Provides the compiler information that identifies outside classes used within the current class. (*)
Precedes the name of the class.
Defines where this class lives relative to other classes, and provides a level of access control.
Correct Correct
8. Which of the two diagrams below illustrate the general form of a Java program?
Mark for Review
(1) Points
Example A
Example B (*)
Incorrect Incorrect. Refer to Section 4 Lesson 2.
9. When importing another package into a class you must import only the package classes that will be called and not the entire package. True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 4 Lesson 2.
10. A workspace can not have more than one stored projects. True or false? Mark for Review
(1) Points
True
False (*)
11. When Eclipse launches, the Welcome page displays. Once this page is closed you cannot return to the resources available on this page. True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
12. In a project, 1 of the classes must contain a main method. True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
13. The == operator can be used to compare two String objects. The result is always true if the two strings are have the exact same characters in each position of the String. True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 4 Lesson 4.
14. Declaring and instantiating a String is much like any other type of variable. However, once instantiated, they are final and cannot be changed. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
15. Consider the following code snippet.
What is printed? Mark for Review
(1) Points
ArrayIndexOutofBoundsException is thrown
1010778
101077810109
88888 (*)
88888888
1. Consider the following code snippet. What is printed?
Mark for Review
(1) Points
ArrayIndexOutofBoundsException is thrown
Polii
PoliiPolii (*)
auaacauaac
auaac
Incorrect Incorrect. Refer to Section 4 Lesson 4.
2. Declaring and instantiating a String is much like any other type of variable. However, once instantiated, they are final and cannot be changed. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
3. The following code prints 5 "a"'s to the screen:
Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 4 Lesson 4.
4. You need to _______________ Java code to generate a .class file Mark for Review
(1) Points
Assemble
Compile (*)
Collect
Package
Incorrect Incorrect. Refer to Section 4 Lesson 1.
5. A workspace is: Mark for Review
(1) Points
The physical location onto which you will store and save your files.
The location where all projects are developed and modified.
The location where you can have one or more stored perspectives.
All of the above. (*)
6. In a project, 1 of the classes must contain a main method. True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
7. What will the method methodA print to the screen?
Mark for Review
(1) Points
6
18 (*)
3
15
Correct Correct
8. Which of the following statements displays 12345?
I. System.out.println( 123 * 100 + 45);
II. System.out.println("123" + 45);
III. System.out.println( 12 + "345"); Mark for Review
(1) Points
All of the above. (*)
I only.
I and II only.
II and III only.
None of the above.
Incorrect Incorrect. Refer to Section 4 Lesson 3.
9. Which of the following examples of Java code is not correct? Mark for Review
(1) Points
char c='r';
boolean b=1; (*)
double d=4.5;
int x=6;
Incorrect Incorrect. Refer to Section 4 Lesson 3.
10. Match each of the following literals ('x', 10, 10.2, 100L, "hello") with its respective data type. Mark for Review
(1) Points
char, boolean, float, long, String
char, double, int, long, String
char, int, long, float, String
char, int, double, long, String (*)
boolean, byte, int, long, Short
Correct Correct
11. What is the result when the following code segment is compiled and executed?
int x = 22, y = 10;
double p = Math.sqrt( ( x + y ) /2);
System.out.println(p); Mark for Review
(1) Points
5.656854249492381 is displayed
2.2 is displayed
Syntax error "sqrt(double) in java.lang.Math cannot be applied to int"
4.0 is displayed (*)
ClassCastException
Incorrect Incorrect. Refer to Section 4 Lesson 3.
12. Which of the two diagrams below illustrate the general form of a Java program?
Mark for Review
(1) Points
Example A
Example B (*)
Correct Correct
13. The following defines a package keyword: Mark for Review
(1) Points
Precedes the name of the class.
Provides the compiler information that identifies outside classes used within the current class.
Defines where this class lives relative to other classes, and provides a level of access control. (*)
Correct Correct
14. The following defines a class keyword: Mark for Review
(1) Points
Precedes the name of the class. (*)
Defines where this class lives relative to other classes, and provides a level of access control.
Provides the compiler information that identifies outside classes used within the current class.
Correct Correct
15. The following defines an import keyword: Mark for Review
(1) Points
Provides the compiler information that identifies outside classes used within the current class. (*)
Precedes the name of the class.
Defines where this class lives relative to other classes, and provides a level of access control.
1. What is the output of the following segment of code?
Mark for Review
(1) Points
2
220
This code does not compile.
0 (*)
222220
Incorrect Incorrect. Refer to Section 6 Lesson 1.
2. Which of the following declares and initializes a one dimensional array named values of size 5 so that all entries contain 1? Mark for Review
(1) Points
int[] values={1,1,1,1,1}; (*)
int[] values={1};
int values[]={1,1,1,1,1,1};
int values={1,1,1,1,1};
Correct Correct
3. What will be the content of the array variable table after executing the following code?
Mark for Review
(1) Points
0 0 1
0 1 0
1 0 0
1 0 0
0 1 0
0 0 1
1 0 0
1 1 0
1 1 1 (*)
1 1 1
0 1 1
0 0 1
Incorrect Incorrect. Refer to Section 6 Lesson 1.
4. What is the output of the following segment of code?
Mark for Review
(1) Points
6
This code does not compile.
753
7531 (*)
7766554433221
Incorrect Incorrect. Refer to Section 6 Lesson 1.
5. The following creates a reference in memory named z that can refer to seven different doubles via an index. True or false?
double z[] = new double[7]; Mark for Review
(1) Points
True (*)
False
6. The following array declaration is valid. True or false?
int k[] = new int[10]; Mark for Review
(1) Points
True (*)
False
Correct Correct
7. The following segment of code initializes a 2 dimensional array of references. True or false?
String[][] array={{"a", "b", "C"},{"a", "b", "c"}}; Mark for Review
(1) Points
True (*)
False
Correct Correct
8. Which of the following declares and initializes a two dimensional array where each element is a reference type? Mark for Review
(1) Points
char[][] words;
String words=new String[10];
String[][] words=new String[10][3]; (*)
char[][] words=new char[10][4];
Incorrect Incorrect. Refer to Section 6 Lesson 1.
9. What is the output of the following segment of code?
Mark for Review
(1) Points
This code doesn't compile.
321111
11 (*)
1111
111
Incorrect Incorrect. Refer to Section 6 Lesson 1.
10. The following array declaration is valid. True or false?
int[] y = new int[5]; Mark for Review
(1) Points
True (*)
False
Correct Correct
11. It is possible to throw and catch a second exception inside a catch block of code. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
12. Choose the best response to this statement: An error can be handled by throwing it and catching it just like an exception. Mark for Review
(1) Points
True. Although errors may be more severe than exceptions they can still be handled in code the same way exceptions are.
True. Errors and exceptions are the same objects and are interchangeable.
False. Exceptions are caused by a mistake in the code and errors occur for no particular reason and therefore cannot be handled or avoided.
False. An error is much more severe than an exception and cannot be dealt with adequately in a program. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
13. If an exception is thrown by a method, where can the catch for the exception be? Mark for Review
(1) Points
The catch must be in the method that threw the exception.
The catch must be immediately after the throw.
There does not need to be a catch in this situation.
The catch can be in the method that threw the exception or in any other method that called the method that threw the exception. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
14. If an exception has already been thrown, what will the interpreter read next in the program? Mark for Review
(1) Points
The end of the program.
The next line of the program even if it is not the catch block of code.
The user input.
Where the program catches the exception. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
15. What does it mean to catch an exception? Mark for Review
(1) Points
It means to throw it.
It means you have fixed the error.
It means to handle it. (*)
It means there was never an exception in your code.
1. After execution of the following statement, which of the following are true?
int number[] = new int[5]; Mark for Review
(1) Points
number[0] is undefined
number.length() is 6
number[4] is null
number[2] is 0 (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
2. The following array declaration is valid. True or false?
int k[] = new int[10]; Mark for Review
(1) Points
True (*)
False
Correct Correct
3. What will be the content of array variable table after executing the following code?
Mark for Review
(1) Points
0 0 0
0 0 0
0 0 0
0 0 1
0 1 0
1 0 0
1 0 0
1 1 0
1 1 1
1 0 0
0 1 0
0 0 1 (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
4. Which of the following declares and initializes a one dimensional array named values of size 5 so that all entries contain 1? Mark for Review
(1) Points
int values[]={1,1,1,1,1,1};
int[] values={1};
int values={1,1,1,1,1};
int[] values={1,1,1,1,1}; (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
5. What is the output of the following segment of code?
Mark for Review
(1) Points
987654
777777 (*)
This code doesn't compile.
555555
456789
6. What will array arr contain after the following code segment has been executed?
int [] arr = {5, 4, 2, 1, 0};
for (int i = 1; i < arr.length; i++)
{
arr[i - 1] += arr[i];
} Mark for Review
(1) Points
None of the above.
9, 6, 3, 1, 0 (*)
10, 6, 3, 1, 0
7, 3, 2, 1, 0
9, 6, 1, 3, 0
Correct Correct
7. The following array declaration is valid:
int[] y = new int[5]; Mark for Review
(1) Points
True (*)
False
Correct Correct
8. Which of the following statements is a valid array declaration? Mark for Review
(1) Points
(Choose all correct answers)
double[] marks; (*)
int number();
counter int[];
float average[]; (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
9. Which of the following statements adds 5 to every element of the one dimensional array prices and then prints it to the screen? Mark for Review
(1) Points
for(int i=0;i<prices.length;i++)
System.out.println(prices[i]+5); (*)
for(int i=1;i<prices.length;i++)
System.out.println(prices[i]+5);
System.out.println(prices[i]+5);
for(int i=0;i<prices.length;i++)
System.out.println(prices[1]+5);
Incorrect Incorrect. Refer to Section 6 Lesson 1.
10. What is the output of the following segment of code?
Mark for Review
(1) Points
642246 (*)
321123
This code doesn't compile.
312213
642
11. What do exceptions indicate in Java? Mark for Review
(1) Points
(Choose all correct answers)
A mistake was made in your code. (*)
There are no errors in your code.
Exceptions do not indicate anything, their only function is to be thrown.
The code has considered and dealt with all possible cases.
The code was not written to handle all possible conditions. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
12. What does it mean to catch an exception? Mark for Review
(1) Points
It means you have fixed the error.
It means there was never an exception in your code.
It means to throw it.
It means to handle it. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
13. What are exceptions used for in Java? Mark for Review
(1) Points
Exceptions have no use, they are just a part of the Java language.
Helping the interpreter compile code quicker and handle user interfaces.
Correcting mistakes made in your code and handling extraordinary cases. (*)
Making the program easier to use for the user and reducing the possibilities of errors occuring.
Incorrect Incorrect. Refer to Section 6 Lesson 2.
14. It is possible to throw and catch a second exception inside a catch block of code. True or false? Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 6 Lesson 2.
15. A computer company has one million dollars to give as a bonus to the employees, and they wish to distribute it evenly amongst them.
The company writes a program to calculate the amount each employee receives, given the number of employees.
Unfortunately, the employees all went on strike before they heard about the bonus. This means that the company has zero employees.
What will happen to the program if the company enters 0 into the employment number? Mark for Review
(1) Points
(Choose all correct answers)
The program will calculate that each employee will receive zero dollars because there are zero employees.
The programmers will have proven their worth in the company because without them the company wrote faulty code.
An unfixable error will occur.
An exception will occur because it is not possible to divide by zero. (*)
questions in this section)
1. Suppose you are writing a program where the user is prompted to the give coordinates where they believe the princess is inside of the castle.
Your program moves the prince to the coordinates that the user specified. If the princess is not found at those coordinates, the user is given a clue that helps them guess coordinates closer to the princess. The user is allowed to enter their new guess of where the princess is.
Assume your program does not take into consideration the possibility that the user may enter coordinates outside of the castle where the princess could not be. What would be the result of the user entering coordinates outside of the castle? How could this be handled in your code? Mark for Review
(1) Points
(Choose all correct answers)
An error would occur. Errors cannot be handled by code.
An exception would occur but could not be handled inside your code. The user would have to restart the program and enter proper coordinates.
An exception would occur. This could be handled by throwing the exception in your code if the user enters invalid coordinates. When the exception is caught, the prince could be moved to the coordinate inside the castle that is closest to those that the user specified. (*)
An exception would occur. This could be handled by throwing an exception in your code if the user enters invalid coordinates. When the exception is caught, the user could be prompted to enter coordinates within the given range of the castle. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
2. If an exception has already been thrown, what will the interpreter read next in the program? Mark for Review
(1) Points
The next line of the program even if it is not the catch block of code.
The end of the program.
The user input.
Where the program catches the exception. (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
3. Which of the following correctly matches the symbol with its function? Mark for Review
(1) Points
(Choose all correct answers)
== (two equal signs) compares the memory location of non-primitive objects. (*)
.equals() compares the value of non-primitive objects. (*)
== (two equal signs) compares values of primitive types such as int or char. (*)
= (single equals sign) compares the value of primitive types such as int or char.
== (two equal signs) compares the values of non-primitive objects.
Incorrect Incorrect. Refer to Section 6 Lesson 2.
4. Which of the following would give you an array index out of bounds exception? Mark for Review
(1) Points
Using a single equal symbol to compare the value of two integers.
Unintentionally placing a semicolon directly after initializing a for loop.
Refering to an element of an array that is at an index greater than the length of that array minus one. (*)
Refering to an element of an array that is at an index less than the length of the array minus one.
Misspelling a variable name somewhere in your code.
Incorrect Incorrect. Refer to Section 6 Lesson 2.
5. Which of the following would be a correct way to handle an index out of bounds exception? Mark for Review
(1) Points
(Choose all correct answers)
Throw the exception and catch it. In the catch, set the index to the index of the array closest to the one that was out of bounds. (*)
Rewrite your code to avoid the exception by not permititng the use of an index that is not inside the array. (*)
Throw the exception that prints out an error message. There is no need to have the catch handle the exception if it has already been thrown.
Do nothing, it will fix itself.
6. What is the output of the following segment of code?
Mark for Review
(1) Points
7766554433221
This code does not compile.
6
753
7531 (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
7. Which of the following declares a one dimensional array name scores of type int that can hold 14 values? Mark for Review
(1) Points
int[] scores=new scores int[14];
int score= new int[14];
int scores;
int[] scores=new int[14]; (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
8. Which of the following declares and initializes a two dimensional array named values with 2 rows and 3 columns where each element is a reference to an Object? Mark for Review
(1) Points
String[][] values=new String[2][3]; (*)
String[][] values=new String[3][2];
String[][] values;
String[][] values={"apples","oranges","pears"};
Correct Correct
9. What is the output of the following segment of code?
Mark for Review
(1) Points
642246 (*)
312213
This code doesn't compile.
642
321123
Incorrect Incorrect. Refer to Section 6 Lesson 1.
10. The following creates a reference in memory named q that can refer to six different integers via an index. True or false?
int[] q = new int[8]; Mark for Review
(1) Points
True
False (*)
11. The following creates a reference in memory named y that can refer to five different integers via an index. True or false?
int[] y = new int[5]; Mark for Review
(1) Points
True (*)
False
Correct Correct
12. What is the output of the following segment of code?
int array[][] = {{1,2,3},{3,2,1}};
for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
System.out.print(2*array[1][1]); Mark for Review
(1) Points
444444 (*)
This code doesn't compile.
222222
123321
246642
Incorrect Incorrect. Refer to Section 6 Lesson 1.
13. What is the output of the following segment of code?
Mark for Review
(1) Points
456789
555555
777777 (*)
This code doesn't compile.
987654
Correct Correct
14. After execution of the following statement, which of the following are true?
int number[] = new int[5]; Mark for Review
(1) Points
number.length() is 6
number[2] is 0 (*)
number[0] is undefined
number[4] is null
Correct Correct
15. Which of the following statements print every element of the one dimensional array prices to the screen? Mark for Review
(1) Points
for(int i=0; i <= prices.length; i++){System.out.println(prices[i]);}
for(int i=0; i < prices.length; i++){System.out.println(prices[i]);} (*)
System.out.println(prices.length);
for(int i=1; i <= prices.length; i++){System.out.println(prices[i]);}
EmoticonEmoticon