Section 6
(Answer all questions in this section)
1. FIFO stands for: Mark for Review
(1) Points
First In First Out (*)
Fast Interface Fast Output
First Interface First Output
Fast In Fast Out
Incorrect Incorrect. Refer to Section 6 Lesson 3.
2. Which scenario best describes a stack? Mark for Review
(1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom. (*)
A row of books that you can take out of only the middle of the books first and work your way outward toward either edge.
A line at the grocery store where the first person in the line is the first person to leave.
All of the above describe a stack.
Correct Correct
3. To allow our classes to have a natural order we could implement the Comparable interface.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
4. A LinkedList is a list of elements that is dynamically stored.
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 6 Lesson 3.
5. Selection sort is a sorting algorithm that involves finding the minimum value in the list, swapping it with the value in the first position, and repeating these steps for the remainder of the list.
True or false? Mark for Review
(1) Points
True (*)
False
6. Which of the following is the correct lexicographical order for the conents of the following int array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review
(1) Points
{71, 1, 3, 28,29, 50, 22, 83, 1, 17}
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}
Test: Section 6 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 6
(Answer all questions in this section)
1. Implementing the Comparable interface in your class allows you to define its sort order.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
2. Which statements, inserted it at line 2, will ensure that the code snippet will compile successfully.(Choose Two):
1.public static void main (String[]args) {
2,//insert code here
3. s.put ("StudentID", 123);
4.} Mark for Review
(1) Points
(Choose all correct answers)
SortedMap s= new TreeMap(); (*)
HashMap s= new HashMap(); (*)
ArrayList s= new ArrayList();
Map s= new SortedMap();
Correct Correct
3. Which of the following is a list of elements that have a first in last out ordering. Mark for Review
(1) Points
Stacks (*)
Arrays
HashMaps
Enums
Correct Correct
4. A HashMap can only store String types.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
5. Which of the following correctly adds "Cabbage" to the ArrayList vegetables? Mark for Review
(1) Points
vegetables += "Cabbage";
vegetables[0] = "Cabbage";
vegetables.get("Cabbage");
vegetables.add("Cabbage"); (*)
Correct Correct
Page 1 of 3 Next Summary
Test: Section 6 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 6
(Answer all questions in this section)
6. ArrayList and Arrays both require you to define their size before use.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
7. Choose the best definiton for a collection. Mark for Review
(1) Points
It enables you to create a generic class without specifying a type between angle brackets <>.
It is a special type of class that is associated with one or more non-specified Java type.
It is a subclass of List.
It is an interface in the java.util package that is used to define a group of objects. (*)
Correct Correct
8. The local petting zoo is writing a program to be able to collect group animals according to species to better keep track of what animals they have.
Which of the following correctly defines a collection that may create these types of groupings for each species at the zoo? Mark for Review
(1) Points
public class
animalCollection {ナ} (*)
public class
animalCollection(AnimalType T) {ナ}
public class
animalCollection {ナ}
public class
animalCollection(animalType) {ナ}
None of the these.
Incorrect Incorrect. Refer to Section 6 Lesson 1.
9. The following code will compile.
True or False?
class Node implements Comparable{
public int compareTo(T obj){return 1;}
}
class Test{
public static void main(String[] args){
Node nc=new Node<>();
Comparable com=nc;
}
Mark for Review
(1) Points
True (*)
False
Correct Correct
10. An example of an upper bounded wildcard is. Mark for Review
(1) Points
ArrayList
ArrayList (*)
ArrayList
ArrayList
Incorrect Incorrect. Refer to Section 6 Lesson 1.
Previous Page 2 of 3 Next Summary
Test: Section 6 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 6
(Answer all questions in this section)
11. < ? > is an example of a bounded generic wildcard.
True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
12. Big-O Notation is used in Computer Science to describe the performance of Sorts and Searches on arrays. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
13. Of the options below, what is the fastest run-time? Mark for Review
(1) Points
n*log(n)
n^2
n
log(n) (*)
Correct Correct
14. Which of the following is the correct lexicographical order for the conents of the following int array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review
(1) Points
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}
{71, 1, 3, 28,29, 50, 22, 83, 1, 17}
Correct Correct
15. A sequential search is an iteration through the array that stops at the index where the desired element is found.
True or false? Mark for Review
(1) Points
True (*)
False
(Answer all questions in this section)
1. FIFO stands for: Mark for Review
(1) Points
First In First Out (*)
Fast Interface Fast Output
First Interface First Output
Fast In Fast Out
Incorrect Incorrect. Refer to Section 6 Lesson 3.
2. Which scenario best describes a stack? Mark for Review
(1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom. (*)
A row of books that you can take out of only the middle of the books first and work your way outward toward either edge.
A line at the grocery store where the first person in the line is the first person to leave.
All of the above describe a stack.
Correct Correct
3. To allow our classes to have a natural order we could implement the Comparable interface.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
4. A LinkedList is a list of elements that is dynamically stored.
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 6 Lesson 3.
5. Selection sort is a sorting algorithm that involves finding the minimum value in the list, swapping it with the value in the first position, and repeating these steps for the remainder of the list.
True or false? Mark for Review
(1) Points
True (*)
False
6. Which of the following is the correct lexicographical order for the conents of the following int array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review
(1) Points
{71, 1, 3, 28,29, 50, 22, 83, 1, 17}
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}
Test: Section 6 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 6
(Answer all questions in this section)
1. Implementing the Comparable interface in your class allows you to define its sort order.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
2. Which statements, inserted it at line 2, will ensure that the code snippet will compile successfully.(Choose Two):
1.public static void main (String[]args) {
2,//insert code here
3. s.put ("StudentID", 123);
4.} Mark for Review
(1) Points
(Choose all correct answers)
SortedMap s= new TreeMap(); (*)
HashMap s= new HashMap(); (*)
ArrayList s= new ArrayList();
Map s= new SortedMap();
Correct Correct
3. Which of the following is a list of elements that have a first in last out ordering. Mark for Review
(1) Points
Stacks (*)
Arrays
HashMaps
Enums
Correct Correct
4. A HashMap can only store String types.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
5. Which of the following correctly adds "Cabbage" to the ArrayList vegetables? Mark for Review
(1) Points
vegetables += "Cabbage";
vegetables[0] = "Cabbage";
vegetables.get("Cabbage");
vegetables.add("Cabbage"); (*)
Correct Correct
Page 1 of 3 Next Summary
Test: Section 6 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 6
(Answer all questions in this section)
6. ArrayList and Arrays both require you to define their size before use.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
7. Choose the best definiton for a collection. Mark for Review
(1) Points
It enables you to create a generic class without specifying a type between angle brackets <>.
It is a special type of class that is associated with one or more non-specified Java type.
It is a subclass of List.
It is an interface in the java.util package that is used to define a group of objects. (*)
Correct Correct
8. The local petting zoo is writing a program to be able to collect group animals according to species to better keep track of what animals they have.
Which of the following correctly defines a collection that may create these types of groupings for each species at the zoo? Mark for Review
(1) Points
public class
animalCollection {ナ} (*)
public class
animalCollection(AnimalType T) {ナ}
public class
animalCollection {ナ}
public class
animalCollection(animalType) {ナ}
None of the these.
Incorrect Incorrect. Refer to Section 6 Lesson 1.
9. The following code will compile.
True or False?
class Node implements Comparable{
public int compareTo(T obj){return 1;}
}
class Test{
public static void main(String[] args){
Node nc=new Node<>();
Comparable com=nc;
}
Mark for Review
(1) Points
True (*)
False
Correct Correct
10. An example of an upper bounded wildcard is. Mark for Review
(1) Points
ArrayList
ArrayList (*)
ArrayList
ArrayList
Incorrect Incorrect. Refer to Section 6 Lesson 1.
Previous Page 2 of 3 Next Summary
Test: Section 6 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 6
(Answer all questions in this section)
11. < ? > is an example of a bounded generic wildcard.
True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
12. Big-O Notation is used in Computer Science to describe the performance of Sorts and Searches on arrays. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
13. Of the options below, what is the fastest run-time? Mark for Review
(1) Points
n*log(n)
n^2
n
log(n) (*)
Correct Correct
14. Which of the following is the correct lexicographical order for the conents of the following int array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review
(1) Points
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*)
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}
{71, 1, 3, 28,29, 50, 22, 83, 1, 17}
Correct Correct
15. A sequential search is an iteration through the array that stops at the index where the desired element is found.
True or false? Mark for Review
(1) Points
True (*)
False
7. Of the options below, what is the fastest run-time? Mark for Review
(1) Points
log(n) (*)
n
n*log(n)
n^2
Correct Correct
8. Why might a sequential search be inefficient? Mark for Review
(1) Points
It utilizes the "divide and conquer" method, which makes the algorithm more error prone.
It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)
It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.
It is never inefficient.
Correct Correct
9. Which is the correct way to initialize a HashSet? Mark for Review
(1) Points
HashSet classMates =
new HashSet(); (*)
ClassMates = public class
HashSet();
classMates = new HashSet[String]();
String classMates = new
String();
Incorrect Incorrect. Refer to Section 6 Lesson 2.
10. A collection is an interface in the Java API.
True or false? Mark for Review
(1) Points
True (*)
False
11. Choose the best definiton for a collection. Mark for Review
(1) Points
It is an interface in the java.util package that is used to define a group of objects. (*)
It is a special type of class that is associated with one or more non-specified Java type.
It enables you to create a generic class without specifying a type between angle brackets <>.
It is a subclass of List.
Correct Correct
12. The following code will compile.
True or False?
class Node implements Comparable{
public int compareTo(T obj){return 1;}
}
class Test{
public static void main(String[] args){
Node nc=new Node<>();
Comparable com=nc;
}
Mark for Review
(1) Points
True (*)
False
Correct Correct
13. When would an enum (or enumeration) be used? Mark for Review
(1) Points
When you wish to remove data from memory.
When you want to be able to create any number of objects of that class.
When you already know all the possibilities for objects of that class. (*)
When you wish to initialize a HashSet.
Incorrect Incorrect. Refer to Section 6 Lesson 1.
14. What is the correct definition of Enumeration (or enum)? Mark for Review
(1) Points
A list of elements that is dynamically stored.
Code that initializes an ArrayList
A keyword that specifies a class whose objects are defined inside the class. (*)
A bounded generic class
Incorrect Incorrect. Refer to Section 6 Lesson 1.
15. Enumerations (enums) must be declared in their own class.
True or False? Mark for Review
(1) Points
True
False (*)
1. ArrayList and Arrays both require you to define their size before use.
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 6 Lesson 2.
2. Which line contains an compilation error?
interface Shape {}
class Circle implements Shape{}
public class Test{
public static void main(String[] args) {
List ls = new ArrayList(); // Line 1
List lc = new ArrayList(); // Line 2
Circle c = new Circle();
ls.add(c); // Line 3
lc.add(c); // Line 4
}
} Mark for Review
(1) Points
Line 4
Line 1
Line 2
Line 3 (*)
Correct Correct
3. Which interface forms the root of the collections hierarchy? Mark for Review
(1) Points
java.util.Collections
java.util.List
java.util.Collection (*)
java.util.Map
Incorrect Incorrect. Refer to Section 6 Lesson 2.
4. public static void printArray(T[] array){.
is an example of what? Mark for Review
(1) Points
A generic instance
A generic class
A concreate method.
A generic method (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
5. A generic class is a type of class that associates one or more non-specific Java types with it.
True or False? Mark for Review
(1) Points
True (*)
False
6. Generic methods can only belong to generic classes.
True or False? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
7. Generic methods are required to be declared as static.
True or False? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
8. Which of the following best describes lexicographical order? Mark for Review
(1) Points
An order based on the value of characters. (*)
The order of indicies after an array has been sorted.
A complex sorting algorithm that is efficient on large arrays.
A simple sorting algorithm that is inefficient on large arrays.
Incorrect Incorrect. Refer to Section 6 Lesson 4.
9. A sequential search is an iteration through the array that stops at the index where the desired element is found. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
10. Which sort algorithm was used to sort the char array {'M', 'S', 'A', 'T', 'H'}?
The steps are shown below:
Mark for Review
(1) Points
Merge Sort
Sequential Search
Binary Search
Selection Sort
Bubble Sort (*)
11. Selection sort is efficient for large arrays.
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 6 Lesson 4.
12. To allow our classes to have a natural order we could implement the Comparable interface.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
13. The Comparable interface defines the compareTo method.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
14. A LinkedList is a list of elements that is dynamically stored.
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 6 Lesson 3.
15. Which scenario best describes a stack? Mark for Review
(1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom. (*)
A row of books that you can take out of only the middle of the books first and work your way outward toward either edge.
A line at the grocery store where the first person in the line is the first person to leave.
All of the above describe a stack.
1. Which code inserted into the code below guarantees that the program will output [1,2]?
import java.util.*;
public class Example{
public static void main(String[] args){
//insert code here
set.add(2);
set.add(1);
System.out.println(set);
}
} Mark for Review
(1) Points
Set set = new LinkedHashSet();
Set set = new TreeSet(); (*)
Set set = new SortedSet();
List set = new SortedList();
Set set = new HashSet();
4. Wildcards in generics allows us greater control on the types that can be used.
True or False? Mark for Review
(1) Points
True (*)
False
Correct Correct
5. Examine the code below. Which statement about this code is true?
1.class Shape { }
2.class Circle extends Shape { }
3.class Rectangle extends Shape { }
4.class Node { }
5.public class Test{
6.public static void main(String[] args){
7.Node nc = new Node<>();
8.Node ns = nc;
}
} Mark for Review
(1) Points
The code compiles.
An error at line 7 causes compilation to fail.
An error at line 4 causes compilation to fail.
6. < ? extends Animal > is an example of a bounded generic wildcard.
True or False? Mark for Review
(1) Points
True (*)
False
8. A HashMap can store duplicates.
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 6 Lesson 3.
9. Which of the following describes a deque. Mark for Review
(1) Points
It is pronounced "deck" for short.
It implements a stack.
Allows for insertion or deletion of elements from the first element added or the last one.
All of the above. (*)
11. Which of the following is a list of elements that have a first in last out ordering. Mark for Review
(1) Points
Arrays
Enums
Stacks (*)
HashMaps
An error at line 8 causes compilation to fail. (*)
1. A HashSet is a set that is similar to an ArrayList. A HashSet does not have any specific ordering.
True or false? Mark for Review
(1) Points
True (*)
False
3. What is the output from the following code snippet?
Integer[] ar = {1, 2, 1, 3};
Set set = new TreeSet(Arrays.asList(ar));
set.add(4);
for (Integer element : set) {
System.out.print(element);
} Mark for Review
(1) Points
12134
1234 (*)
1213
11234
6. What is the result from the following code snippet?
public static void main(String[] args) {
List list1 = new ArrayList();
list1.add(new Gum());
List list2 = list1;
list2.add(new Integer(9));
System.out.println(list2.size());
} Mark for Review
(1) Points
The code will not compile.
2 (*)
1
an exception will be thrown at runtime
Incorrect Incorrect. Refer to Section 6 Lesson 1.
7. < ? > is an example of a bounded generic wildcard.
True or False? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 6 Lesson 1.
8. Stacks are identical to Queues.
True or false? Mark for Review
(1) Points
True
False (*)
10. Which of the following methods adds a Key-Value map to a HashMap? Mark for Review
(1) Points
get(Key, Value)
put(Key, Value) (*)
add(Key, Value)
remove(Key, Value)
11. Where you enqueue an element in the list? Mark for Review
(1) Points
adds it to the start of the list
removes it from the front of the list
adds it to the end of the list (*)
removes it from the end of the list
15. Which searching algorithm involves using a low, middle, and high index value to find the location of a value in a sorted set of data (if it exists)? Mark for Review
(1) Points
Sequential Search
Merge Sort
Selection Sort
Binary Search (*)
All of the above
2. A LinkedList is a type of Stack.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
3. A HashMap can store duplicates.
True or false? Mark for Review
(1) Points
True
False (*)
5. < ? extends Animal > would only allow classes or subclasses of Animal to be used.
True or False? Mark for Review
(1) Points
True (*)
False
8. Which of the following would initialize a generic class "Cell" using a String type?
I. Cell cell = new Cell(); .
II. Cell cell = new Cell(); .
III. Cell cell = new String;
Mark for Review
(1) Points
II only
III only
II and III
I and II (*)
I only
10. Which one of the following would initialize a HashSet raffleTickets which will store the class RaffleTicket. Mark for Review
(1) Points
HashSet raffleTickets = new HashSet();
HashSet raffleTickets = new ();
HashSet raffleTickets = new HashSet(); (*)
HashSet raffleTickets = new HashSet();
11. Which of the following correctly adds "Cabbage" to the ArrayList vegetables? Mark for Review
(1) Points
vegetables.get("Cabbage");
vegetables.add("Cabbage"); (*)
vegetables += "Cabbage";
vegetables[0] = "Cabbage";
13. Binary searches can be performed on sorted and unsorted data.
True or false? Mark for Review
(1) Points
True
False (*)
5. What is the output from the following code snippet?
public static void main(String[] args){
List li=new ArrayList();
li.add(1);
li.add(2);
print(li);
}
public static void print(List list) {
for (Number n : list)
System.out.print(n + " ");
} Mark for Review
(1) Points
1 2 (*)
1
2
The code will not compile.
6. Enumerations (enums) are useful for storing data : Mark for Review
(1) Points
When the class is a subclass of Object.
You cannot store data in an enum.
When you know all of the possibilities of the class (*)
When the class is constantly changing
Incorrect Incorrect. Refer to Section 6 Lesson 1.
7. An example of an upper bounded wildcard is. Mark for Review
(1) Points
ArrayList
ArrayList
ArrayList (*)
ArrayList
10. Which one of the following would initialize a HashSet raffleTickets which will store the class RaffleTicket. Mark for Review
(1) Points
HashSet raffleTickets = new HashSet(); (*)
HashSet raffleTickets = new ();
HashSet raffleTickets = new HashSet();
HashSet raffleTickets = new HashSet();
11. What is a set? Mark for Review
(1) Points
A keyword in Java that initializes an ArrayList.
Something that enables you to create a generic class without specifying a type between angle brackets <>.
A collection of elements that contains duplicates.
A collection of elements that does not contain duplicates. (*)
3. Which scenario best describes a queue? Mark for Review
(1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom.
A row of books that you can take out of only the middle of the books first and work your way outward toward either edge.
A line at the grocery store where the first person in the line is the first person to leave. (*)
All of the above describe a queue.
Incorrect Incorrect. Refer to Section 6 Lesson 3.
14. Stacks are identical to Queues.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
15. Implementing the Comparable interface in your class allows you to define its sort order.
True or false? Mark for Review
(1) Points
True (*)
False
Section 7
(Answer all questions in this section)
1. Which of the following correctly defines a StringBuilder? Mark for Review
(1) Points
A class inside the java.util.regex package.
A method that adds characters to a string.
There is no such thing as a StringBuilder in Java.
A class that represents a string-like object. (*)
Correct Correct
2. Which of the following correctly initializes a StringBuilder? Mark for Review
(1) Points
StringBuilder sb = "This is my String Builder";
StringBuilder sb = StringBuilder(500);
StringBuilder sb = new StringBuilder(); (*)
None of the above.
Incorrect Incorrect. Refer to Section 7 Lesson 1.
3. Which of the following methods are StringBuilder methods? Mark for Review
(1) Points
append
delete
insert
replace
All of the above. (*)
Correct Correct
4. Which of the following methods can be used to replace a segment in a string with a new string? Mark for Review
(1) Points
remove(String oldString, String newString)
replaceAll(String oldString, String newString) (*)
replaceAll(String newString)
substring(int start, int end, String newString)
None of the above. There is no replaceAll(String newString) method with one argument.
Incorrect Incorrect. Refer to Section 7 Lesson 1.
5. What class is the split() method a member of? Mark for Review
(1) Points
StringBuilder
Array
String (*)
Parse
6. A linear recursion requires the method to call which direction? Mark for Review
(1) Points
Forward
Backward (*)
Both forward and backward
None of the above
Incorrect Incorrect. Refer to Section 7 Lesson 3.
7. Consider the following recursive method recur(x, y). What is the value of recur(4, 3)?
public static int recur(int x, int y) {
if (x == 0) {
return y;
}
return recur(x - 1, x + y);
} Mark for Review
(1) Points
12
13 (*)
9
10
Correct Correct
8. A base case can handle nested conditions.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
9. Which two statements can create an instance of an array? (Choose Two) Mark for Review
(1) Points
(Choose all correct answers)
int ia[][] = (1,2,3) (4,5,6);
double da = new double [5];
int[] ia = new int [5]; (*)
char[] ca = "java";
Object oa = new double[5]; (*)
Incorrect Incorrect. Refer to Section 7 Lesson 3.
10. A non-linear recursive method is less expensive than a linear recursive method.
True or false? Mark for Review
(1) Points
True
False (*)
11. A regular expression is a character or a sequence of characters that represent a string or multiple strings.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
12. Consider designing a program that organizes your contacts alphabetically by last name, then by first name. Oddly, all of your contacts' first and last names are exactly five letters long.
Which of the following segments of code establishes a Pattern namePattern with a group for the first name and a group for the last name considering that the string contactsName is always in the format lastName_firstName? Mark for Review
(1) Points
Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)
Pattern namePattern = Pattern.compile("first_last");
Pattern namePattern = new Pattern(last{5},first{5});
Pattern namePattern = new Pattern();
None of the above.
1. Which of the following correctly defines a StringBuilder? Mark for Review
(1) Points
There is no such thing as a StringBuilder in Java.
A method that adds characters to a string.
A class inside the java.util.regex package.
A class that represents a string-like object. (*)
Correct Correct
2. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
Read the String backwards (from last element to first element). (*)
You don't use a FOR loop with Strings
Search for a specific character or String inside of the String. (*)
Parse the String. (*)
Correct Correct
3. Which of the following are true about parsing a String?(Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
It is possible to use a for loop to parse a string. (*)
It is a way of dividing a string into a set of sub-strings. (*)
It is possible to use the String.split() method to parse a string. (*)
It is not possible to parse a string using regular expressions.
Correct Correct
4. What is the result from the following code?
public class Test {
public static void main(String[] args) {
String str = "91204";
str += 23;
System.out.print(str);
}
} Mark for Review
(1) Points
9120423 (*)
Compile fails.
91204
23
91227
Correct Correct
5. Which of the following methods can be used to replace a segment in a string with a new string? Mark for Review
(1) Points
remove(String oldString, String newString)
replaceAll(String oldString, String newString) (*)
replaceAll(String newString)
substring(int start, int end, String newString)
None of the above. There is no replaceAll(String newString) method with one argument.
Correct Correct
Page 1 of 3 Next Summary
Test: Section 7 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 7
(Answer all questions in this section)
6. What does the dot (.) represent in regular expressions? Mark for Review
(1) Points
An indication for one or more occurrences of the preceding character.
A match for any character. (*)
A range specified between brackets that allows variability of a character.
Nothing, it is merely a dot.
Correct Correct
7. Consider that you are writing a program for analyzing feedback on the video game you have developed. You have completed everything except the segment of code that checks that the user's input, String userI, is a valid rating. Note that a valid rating is a single digit between 1 and 5 inclusive. Which of the following segments of code returns true if the user's input is a valid rating?(Choose Two) Mark for Review
(1) Points
(Choose all correct answers)
return userI.matches("{1-5}");
return userI.matches("[1-5].*");
return userI.matches("[1-5]"); (*)
return userI.matches("[1-5]{1}"); (*)
Correct Correct
8. Consider designing a program that organizes your contacts alphabetically by last name, then by first name. Oddly, all of your contacts' first and last names are exactly five letters long.
Which of the following segments of code establishes a Pattern namePattern with a group for the first name and a group for the last name considering that the string contactsName is always in the format lastName_firstName? Mark for Review
(1) Points
Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)
Pattern namePattern = Pattern.compile("first_last");
Pattern namePattern = new Pattern(last{5},first{5});
Pattern namePattern = new Pattern();
None of the above.
Correct Correct
9. Which of the following correctly defines Matcher? Mark for Review
(1) Points
A class in the java.util.regex package that stores the format of a regular expression.
A method of dividing a string into a set of sub-strings.
A regular expression symbol that represents any character.
A class in the java.util.regex package that stores the matches between a pattern and a string. (*)
Correct Correct
10. Square brackets are a representation for any character in regular expressions "[ ]".
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 7 Lesson 2.
Previous Page 2 of 3 Next Summary
Test: Section 7 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 7
(Answer all questions in this section)
11. A linear recursive method can call how many copies of itself? Mark for Review
(1) Points
1 (*)
2 or more
None
Correct Correct
12. The base case condition can work with a constant or variable.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
13. A linear recursion requires the method to call which direction? Mark for Review
(1) Points
Forward
Backward (*)
Both forward and backward
None of the above
Correct Correct
14. A non-linear recursive method can call how many copies of itself? Mark for Review
(1) Points
1
2 or more (*)
None
Correct Correct
15. A non-linear recursive method is less expensive than a linear recursive method.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
Previous Page 3 of 3
Incorrect Incorrect. Refer to Section 7 Lesson 2.
13. Which of the following correctly defines a repetition operator? Mark for Review
(1) Points
A symbol that represents any character in regular expressions.
A method that returns the number of occurrences of the specified character.
symbol in regular expressions that indicates the number of occurrences a specified character appears in a matching string. (*)
None of the above.
Incorrect Incorrect. Refer to Section 7 Lesson 2.
14. Consider that you are writing a program for analyzing feedback on the video game you have developed. You have completed everything except the segment of code that checks that the user's input, String userI, is a valid rating. Note that a valid rating is a single digit between 1 and 5 inclusive. Which of the following segments of code returns true if the user's input is a valid rating?(Choose Two) Mark for Review
(1) Points
(Choose all correct answers)
return userI.matches("[1-5]"); (*)
return userI.matches("{1-5}");
return userI.matches("[1-5]{1}"); (*)
return userI.matches("[1-5].*");
Correct Correct
15. One benefit to using groups with regular expressions is that you can segment a matching string and recall the segments (or groups) later in your program.
True or false? Mark for Review
(1) Points
True (*)
False
2. Forward thinking helps when creating linear recursive methods.
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect Incorrect. Refer to Section 7 Lesson 3.
3. A non-linear recursive method can call how many copies of itself? Mark for Review
(1) Points
1
2 or more (*)
None
5. Which case handles the last recursive call? Mark for Review
(1) Points
The convergence case
The base case (*)
The secondary case
The primary case
The recursive case
6. Which of the following does not correctly match the regular expression symbol to its proper function? Mark for Review
(1) Points
"{x}" means there must be x occurrences of the preceding character in the string to be a match.
"?" means there may be zero or one occurrences of the preceding character in the string to be a match.
"+" means there may be zero or more occurrences of the preceding character in the string to be a match. (*)
"{x,}" means there may be x or more occurrences of the preceeding character in the string to be a match.
"{x,y}" means there may be between x and y occurrences of the preceding character in the string to be a match.
Incorrect Incorrect. Refer to Section 7 Lesson 2.
7. What is the correct explanation of when this code will return true?
return str.matches(".*[0-9]{6}.*"); Mark for Review
(1) Points
Any time that str contains two dots.
Any time that str contains a sequence of 6 digits. (*)
Any time that str has between zero and nine characters followed by a 6.
Any time str contains a 6.
Always.
Incorrect Incorrect. Refer to Section 7 Lesson 2.
8. Which of the following correctly defines Pattern? Mark for Review
(1) Points
A class in the java.util.regex package that stores the format of a regular expression. (*)
A class in the java.util.regex package that stores matches.
A method of dividing a string into a set of sub-strings.
A regular expression symbol that represents any character.
9. What does the dot (.) represent in regular expressions? Mark for Review
(1) Points
An indication for one or more occurrences of the preceding character.
A match for any character. (*)
A range specified between brackets that allows variability of a character.
Nothing, it is merely a dot.
Correct Correct
10. Consider that you are making a calendar and decide to write a segment of code that returns true if the string month is April, May, June, or July. Which code segment correctly implements use of regular expressions to complete this task? Mark for Review
(1) Points
return month.compareTo("April, May, June, July");
return month.equals("April, May, June, July");
return month.substring(0,3);
return month.matches("April"|"May"|"June"|"July");
return month.matches("April|May|June|July"); (*)
11. What is the result from the following code?
public class Test {
public static void main(String[] args) {
String str = "91204";
str += 23;
System.out.print(str);
}
} Mark for Review
(1) Points
91227
9120423 (*)
Compile fails.
23
91204
13. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
Search for a specific character or String inside of the String. (*)
You don't use a FOR loop with Strings
Read the String backwards (from last element to first element). (*)
Parse the String. (*)
1. Which case does a recursive method call last? Mark for Review
(1) Points
Recursive Case
Convergence Case
Basic Case
Base Case (*)
None of the above
7. Which of the following correctly initializes a Matcher m for Pattern p and String str? Mark for Review
(1) Points
Matcher m = new Matcher(p,str);
Matcher m = str.matcher(p);
Matcher m = new Matcher();
Matcher m = p.matcher(str); (*)
Correct Correct
8. Your teacher asks you to write a segment of code that returns true if String str contains zero or one character(s) and false otherwise. Which of the following code segments completes this task?(Choose Two) Mark for Review
(1) Points
(Choose all correct answers)
return str.matches(".?"); (*)
return str.contains(".");
if( str.length() == 0 || str.length() == 1)
{ return true;}
return false; (*)
return str.matches("[a-z]*");
10. A regular expression is a character or a sequence of characters that represent a string or multiple strings.
True or false? Mark for Review
(1) Points
True (*)
False
13. Identify the method, of those listed below, that is not available to both StringBuilders and Strings? Mark for Review
(1) Points
indexOf(String str)
charAt(int index)
delete(int start, int end) (*)
length()
15. Which of the following are true about parsing a String?(Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
It is a way of dividing a string into a set of sub-strings. (*)
It is possible to use the String.split() method to parse a string. (*)
It is possible to use a for loop to parse a string. (*)
It is not possible to parse a string using regular expressions.
Section 8
(Answer all questions in this section)
1. An absolute path always starts from the drive letter or mount point. Mark for Review
(1) Points
True (*)
False
Correct Correct
2. The way that you read from a file has changed since the introduction of Java 7.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
Test: Section 8 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 8
(Answer all questions in this section)
1. The method for connecting a java application to a database is JNLP.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
2. To deploy java applications you may use Java Web Start.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
3. Which of the following is an attribute of a three tier architecture application? Mark for Review
(1) Points
an application of that type has a client and server only
a complex application that includes a client, a server and database (*)
an application of that type runs on a single computer
None of the above
All of the above
Correct Correct
4. If a programmer uses the line
import com.test.*,
there is no need to use
import com.test.code.*
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
5. How would you make an instance of Car in a class that didn't import the vehicle package below?
package vehicle;
public class Car{
public Car(){}
} Mark for Review
(1) Points
Car c = new Car();
vehicle.Car c=new Car();
vehicle.Car c=new vehicle.Car(); (*)
vehicle.Car c=new vehicle();
None of the above
Correct Correct
Page 1 of 3 Next Summary
Test: Section 8 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 8
(Answer all questions in this section)
6. The way that you read from a file has changed since the introduction of Java 7.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
7. Prior to Java 7, you write to a file with a call to the BufferedWriter class's write() method.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
8. The Files class can perform which of the following functions? Mark for Review
(1) Points
Navigates the file system
Creates files (*)
Works with absolute paths
Works with relative paths
Works across disk volumes
Incorrect Incorrect. Refer to Section 8 Lesson 1.
9. An absolute path always starts from the drive letter or mount point. Mark for Review
(1) Points
True (*)
False
Correct Correct
10. Which of these construct a DataInputStream instance? Mark for Review
(1) Points
New dataInputStream(new writer("java.txt"));
New dataInputStream(new InputStream("java.txt"));
New dataInputStream(new file("java.txt"));
New dataInputStream(new FileInputStream("java.txt")); (*)
New dataInputStream("java.txt");
Incorrect Incorrect. Refer to Section 8 Lesson 1.
Previous Page 2 of 3 Next Summary
Test: Section 8 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 8
(Answer all questions in this section)
11. The BufferedInputStream is a direct subclass of what other class? Mark for Review
(1) Points
FileInputStream
InputStream
PipedInputStream
FilterInputStream (*)
InputStream
Incorrect Incorrect. Refer to Section 8 Lesson 2.
12. The System.out is what type of stream? Mark for Review
(1) Points
A PrintStream (*)
A BufferedWriter stream
A BufferedReader stream
An OutputStream
A Reader stream
Correct Correct
13. Which of the following static methods is not provided by the Files class to check file properties or duplication? Mark for Review
(1) Points
Files.isHidden(Path p);
Files.isArchived(Path p); (*)
Files.isReadable(Path p);
Files.isWritable(Path p);
Correct Correct
14. The Files class provides a instance method that creates a new BufferedReader.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
15. The BufferedOutputStream is a direct subclass of what other class? Mark for Review
(1) Points
FilterOutputStream (*)
ObjectOutputStream
PrintStream
DigestOutputStream
OutputStream
Correct Correct
Previous Page 3 of 3 Summary
3. Prior to Java 7, you write to a file with a call to the BufferedWriter class's write() method.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
4. Which of the following is an absolute Windows path? Mark for Review
(1) Points
data
\Users\UserName\data
/home/user/username
C:\Users\UserName\data (*)
/
Correct Correct
5. The java.nio.file package has improved exception handling.
True or false? Mark for Review
(1) Points
True (*)
False
6. The import keyword allows you to access classes of the package without package Fully Qualified Name.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
7. The method for connecting a Java application to a database is by using: Mark for Review
(1) Points
jar files
JNLP
JDBC (*)
Java Web Start
None of the above
Correct Correct
8. What option do you choose from the File menu in Eclipse to start the process of creating a runnable JAR file? Mark for Review
(1) Points
Properties
Import
Export (*)
Switch Workspace
Incorrect Incorrect. Refer to Section 8 Lesson 3.
9. To deploy java applications you may use Java Web Start.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
10. If a programmer uses the line
import com.test.*,
there is no need to use
import com.test.code.*
True or false? Mark for Review
(1) Points
True
False (*)
11. You can read input by character or line.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
12. The Files class lets you check for file properties.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
13. The Paths class provides a static get() method to find a valid Path.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
14. The read() method of java.io.Reader class lets you read a character at a time.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
15. Which of the following static methods is not provided by the Files class to check file properties or duplication? Mark for Review
(1) Points
Files.isWritable(Path p);
Files.isHidden(Path p);
Files.isArchived(Path p); (*)
Files.isReadable(Path p);
1. Which the following statements is NOT TRUE about DataSource? Mark for Review
(1) Points
DataSource can be implemented as a pool of connections.
DataSource can participate in the Distributed transaction.
DataSource can manage a set of JDBC Drivers registered in the system. (*)
DataSource will typically be registered with a naming service.
Incorrect Incorrect. Refer to Section 9 Lesson 2.
2. Which of the following can fill in the //INSERT HERE correctly? (Choose Two)
ResultSet rset = stmt.executeQuery(sqlQuery);
if(rs.next()){
//INSERT HERE
}
Mark for Review
(1) Points
(Choose all correct answers)
Object s = rs.getObject(1); (*)
String s = rs.getString(1);
String s = rs.getObject(0);
String s = rs.getString(0);
Incorrect Incorrect. Refer to Section 9 Lesson 2.
3. Which JDBC interface can be used to access information such as database URL, username and table names? Mark for Review
(1) Points
Statement Interface
PreparedStatement Interface
DatabaseMetaData Interface (*)
CallableStatement Interface
Correct Correct
4. Which of the following methods will move the cursor, returning a Boolean value from the ResultSet Object? Mark for Review
(1) Points
(Choose all correct answers)
beforeFirst() (*)
absolute()
afterFirst()
afterLast()
beforeLast()
Incorrect Incorrect. Refer to Section 9 Lesson 2.
5. Which of the following is the correct statement be inserted at //INSERT CODE location that calls the database-stored procedure sayHello?
class Test{
public static void main(String[] args) {
try {
Connection conn = getConnection();
//INSERT CODE
cstat.setString(1, "Hello");
cstat.registerOutParameter(2, Types.NUMERIC);
cstat.setInt(2, 10);
}
catch(SQLException e){}
}
}
Mark for Review
(1) Points
CallableStatement cstat = con.prepareCall("{sayHello(?, ?)}");
CallableStatement cstat = con.prepareCall("{call procedure_sayHello (?, ?)}");
CallableStatement cstat = con.prepareCall("{call sayHello}");
CallableStatement cstat = con.prepareCall("sayHello(?, ?)");
CallableStatement cstat = con.prepareCall("{call sayHello(?, ?)}"); (*)
6. Suppose that you have a table EMPLOYEES with three rows. The first_name in those rows are A, B, and C. What does the following output?
String sql = "select first_name from Employees order by first_name desc";
Statement stmt=conn.createStatement = (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rset= stmt.executeQuery(sql);
rset.absolute(1);
rset.next();
System.out.println(rset.getString(1));
Mark for Review
(1) Points
A
B (*)
C
The code does not compile.
A SQLException is thrown.
Incorrect Incorrect. Refer to Section 9 Lesson 2.
7. From JDBC, how would you execute DML statements (i.e. insert, delete, update) in the database? Mark for Review
(1) Points
By making use of the execute(...) statement from DataStatement Object
By invoking the executeDelete(...), executeUpdate(...) methods of the DataStatement
By invoking the execute(...) or executeUpdate(...) method of a JDBC Statement object or sub-interface object (*)
By invoking the DeleteStatement or UpdateStatement JDBC object
Incorrect Incorrect. Refer to Section 9 Lesson 2.
8. Which symbol is used as a placeholder to pass parameters to a PreparedStatement or CallableStatement? Mark for Review
(1) Points
!
? (*)
@
#
Incorrect Incorrect. Refer to Section 9 Lesson 2.
9. To execute a stored SQL procedure, which JDBC interface should be used? Mark for Review
(1) Points
Statement Interface
PreparedStatement Interface
PrePreparedStatement Interface
CallableStatement Interface (*)
Incorrect Incorrect. Refer to Section 9 Lesson 1.
10. The java.sql.DriverManager class will typically be registered with a naming service based on the Java Naming Directory (JNDI) API. Mark for Review
(1) Points
True
False (*)
11. Given the following code, assume there are rows of data in the table EMP. What is the result?
1 Connection conn - new Connection(URL);
2 Statement stmt = conn.createStatement();
3 ResultSet result - stmt.executeQuery("select count(*) from EMP");
4 if(rs.next()){
5 System.out.println(rs.getInt(1));
6 } Mark for Review
(1) Points
Compiler error on line 2
Runtime error on line 3
2
0
Compiler error on line 1 (*)
Incorrect Incorrect. Refer to Section 9 Lesson 1.
12. Which of the following is NOT a JDBC interface used to execute SLQ statements? Mark for Review
(1) Points
Statement Interface
PreparedStatement Interface
PrePreparedStatement Interface (*)
CallableStatement Interface
Correct Correct
13. What type of JDBC driver will convert the database invocation directly into network protocol? Mark for Review
(1) Points
Type 1 driver
Type 2 driver
Type 3 driver
Type 4 driver (*)
Correct Correct
14. Which of the following is a valid JDBC URL? Mark for Review
(1) Points
oracle:thin:localhostdfot/dfot:1521:xe
jdbc::oracle-thin:dfot/dfotoracle:1521:xe
jdbc:oracle:thin:dfot/dfotlocalhost:1521:xe (*)
oracle:thin:jdbc:dfot/dfotlocalhost:1521:xe
Incorrect Incorrect. Refer to Section 9 Lesson 1.
15. You must explicitly close ResultSet and Statement objects once they are no longer in use. Mark for Review
(1) Points
True (*)
False
Test: Java Programming Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 6
(Answer all questions in this section)
1. Which scenario best describes a queue? Mark for Review
(1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom.
A row of books that you can take out of only the middle of the books first and work your way outward toward either edge.
A line at the grocery store where the first person in the line is the first person to leave. (*)
All of the above describe a queue.
Correct Correct
2. The Comparable interface defines the compareTo method.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
3. Which statements, inserted it at line 2, will ensure that the code snippet will compile successfully.(Choose Two):
1.public static void main (String[]args) {
2,//insert code here
3. s.put ("StudentID", 123);
4.} Mark for Review
(1) Points
(Choose all correct answers)
ArrayList s= new ArrayList();
Map s= new SortedMap();
HashMap s= new HashMap(); (*)
SortedMap s= new TreeMap(); (*)
Correct Correct
4. Which of the following describes a deque. Mark for Review
(1) Points
It is pronounced "deck" for short.
It implements a stack.
Allows for insertion or deletion of elements from the first element added or the last one.
All of the above. (*)
Correct Correct
5. Where you enqueue an element in the list? Mark for Review
(1) Points
adds it to the start of the list
removes it from the front of the list
adds it to the end of the list (*)
removes it from the end of the list
Correct Correct
Page 1 of 10 Next Summary
Test: Java Programming Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 6
(Answer all questions in this section)
6. Stacks are identical to Queues.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
7. What is a set? Mark for Review
(1) Points
A collection of elements that contains duplicates.
Something that enables you to create a generic class without specifying a type between angle brackets <>.
A collection of elements that does not contain duplicates. (*)
A keyword in Java that initializes an ArrayList.
Correct Correct
8. A HashSet is a set that is similar to an ArrayList. A HashSet does not have any specific ordering.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
9. ArrayList and Arrays both require you to define their size before use.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
10. Which class is an ordered collection that may contain duplicates? Mark for Review
(1) Points
set
array
list (*)
enum
Correct Correct
Previous Page 2 of 10 Next Summary
Test: Java Programming Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 6
(Answer all questions in this section)
11. Which is the correct way to initialize a HashSet? Mark for Review
(1) Points
HashSet classMates =
new HashSet(); (*)
String classMates = new
String();
classMates = new HashSet[String]();
ClassMates = public class
HashSet();
Correct Correct
12. A sequential search is an iteration through the array that stops at the index where the desired element is found. True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
13. Bubble Sort is a sorting algorithm that involves swapping the smallest value into the first index, finding the next smallest value and swapping it into the next index and so on until the array is sorted.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
14. Which of the following best describes lexicographical order? Mark for Review
(1) Points
A simple sorting algorithm that is inefficient on large arrays.
A complex sorting algorithm that is efficient on large arrays.
The order of indicies after an array has been sorted.
An order based on the ASCII value of characters. (*)
Correct Correct
15. Big-O Notation is used in Computer Science to describe the performance of Sorts and Searches on arrays. True or false? Mark for Review
(1) Points
True (*)
False
16. Which of the following best describes lexicographical order? Mark for Review
(1) Points
The order of indicies after an array has been sorted.
An order based on the ASCII value of characters. (*)
A complex sorting algorithm that is efficient on large arrays.
A simple sorting algorithm that is inefficient on large arrays.
Correct Correct
17. Why might a sequential search be inefficient? Mark for Review
(1) Points
It utilizes the "divide and conquer" method, which makes the algorithm more error prone.
It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)
It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.
It is never inefficient.
Correct Correct
18. Of the options below, what is the fastest run-time? Mark for Review
(1) Points
n
n*log(n)
log(n) (*)
n^2
Correct Correct
19. public static void printArray(T[] array){ナ.
is an example of what? Mark for Review
(1) Points
A generic class
A concreate method.
A generic instance
A generic method (*)
Correct Correct
20. Examine the code below. Which statement about this code is true?
1.class Shape { }
2.class Circle extends Shape { }
3.class Rectangle extends Shape { }
4.class Node { }
5.public class Test{
6.public static void main(String[] args){
7.Node nc = new Node<>();
8.Node ns = nc;
}
} Mark for Review
(1) Points
An error at line 7 causes compilation to fail.
An error at line 8 causes compilation to fail. (*)
The code compiles.
An error at line 4 causes compilation to fail.
Correct correct
Previous Page 4 of 10 Next Summary
Test: Java Programming Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 6
(Answer all questions in this section)
21. What is the output from the following code snippet?
public static void main(String[] args){
List li=new ArrayList();
li.add(1);
li.add(2);
print(li);
}
public static void print(List list) {
for (Number n : list)
System.out.print(n + " ");
} Mark for Review
(1) Points
1
1 2 (*)
2
The code will not compile.
Correct Correct
22. The local petting zoo is writing a program to be able to collect group animals according to species to better keep track of what animals they have.
Which of the following correctly defines a collection that may create these types of groupings for each species at the zoo? Mark for Review
(1) Points
public class
animalCollection {ナ} (*)
public class
animalCollection(AnimalType T) {ナ}
public class
animalCollection {ナ}
public class
animalCollection(animalType) {ナ}
None of the these.
Correct Correct
23. The following code will compile.
True or False?
class Node implements Comparable{
public int compareTo(T obj){return 1;}
}
class Test{
public static void main(String[] args){
Node nc=new Node<>();
Comparable com=nc;
}
Mark for Review
(1) Points
True (*)
False
Correct Correct
24. A generic class increases the risk of runtime class conversion exceptions.
True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
Section 7
(Answer all questions in this section)
25. Identify the method, of those listed below, that is not available to both StringBuilders and Strings? Mark for Review
(1) Points
length()
delete(int start, int end) (*)
indexOf(String str)
charAt(int index)
Correct Correct
Previous Page 5 of 10 Next Summary
Test: Java Programming Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 7
(Answer all questions in this section)
26. Which of the following methods can be used to replace a segment in a string with a new string? Mark for Review
(1) Points
remove(String oldString, String newString)
replaceAll(String oldString, String newString) (*)
replaceAll(String newString)
substring(int start, int end, String newString)
None of the above. There is no replaceAll(String newString) method with one argument.
Correct Correct
27. What class is the split() method a member of? Mark for Review
(1) Points
Parse
StringBuilder
String (*)
Array
Correct Correct
28. A base case can handle nested conditions.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
29. Forward thinking helps when creating linear recursive methods.
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
30. Which case handles the last recursive call? Mark for Review
(1) Points
The primary case
The convergence case
The base case (*)
The recursive case
The secondary case
Correct Correct
Previous Page 6 of 10 Next Summary
Test: Java Programming Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 7
(Answer all questions in this section)
31. Which case does a recursive method call last? Mark for Review
(1) Points
Recursive Case
Convergence Case
Basic Case
Base Case (*)
None of the above
Correct Correct
32. Which of the following methods for the String class take a regular expression as a parameter and returns true if the string matches the expression? Mark for Review
(1) Points
compareTo(String regex)
equals(String regex)
equalsIgnoreCase(String regex)
matches(String regex) (*)
Correct Correct
33. A regular expression is a character or a sequence of characters that represent a string or multiple strings.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
34. Consider that you are making a calendar and decide to write a segment of code that returns true if the string month is April, May, June, or July. Which code segment correctly implements use of regular expressions to complete this task? Mark for Review
(1) Points
return month.matches("April|May|June|July"); (*)
return month.matches("April"|"May"|"June"|"July");
return month.compareTo("April, May, June, July");
return month.equals("April, May, June, July");
return month.substring(0,3);
Correct Correct
35. Square brackets are a representation for any character in regular expressions "[ ]".
True or false? Mark for Review
(1) Points
True
False (*)
Correct Correct
Previous Page 7 of 10 Next Summary
Test: Java Programming Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 8
(Answer all questions in this section)
36. The java.io package has problems with no support for symbolic links.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
37. The normalize() method removes redundant name elements from a qualified path.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
38. When you import a package, subpackages will not be imported.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
39. Which of the following is not a reason to use a Java package? Mark for Review
(1) Points
It is a way to organize files when a project consists of multiple modules.
It is a way to help resolve naming conflicts when different packages have classes with the same names.
It is a way to protect data from being used by the non-authorized classes.
It is a way to allow programmers to receive packets of information from databases. (*)
None of the above
Correct Correct
40. Java Web Start is used to deploy Java applications.
True or false? Mark for Review
(1) Points
True (*)
False
41. The System.in is what type of stream? Mark for Review
(1) Points
A Reader stream
An InputStream (*)
A PrintStream
A BufferedWriter stream
A BufferedReader stream
Correct Correct
42. The read() method of java.io.Reader class lets you read a character at a time.
True or false? Mark for Review
(1) Points
True (*)
False
Correct Correct
Section 9
(Answer all questions in this section)
43. Given the following code, assume there are rows of data in the table EMP. What is the result?
1 Connection conn - new Connection(URL);
2 Statement stmt = conn.createStatement();
3 ResultSet result - stmt.executeQuery("select count(*) from EMP");
4 if(rs.next()){
5 System.out.println(rs.getInt(1));
6 } Mark for Review
(1) Points
Compiler error on line 2
Runtime error on line 3
2
0
Compiler error on line 1 (*)
Correct Correct
44. The java.sql.DriverManager class will typically be registered with a naming service based on the Java Naming Directory (JNDI) API. Mark for Review
(1) Points
True
False (*)
Correct Correct
45. Which of the following classes or interfaces are included in the database vendor driver library? (Choose two) Mark for Review
(1) Points
(Choose all correct answers)
Statement interface implementation (*)
Java.sql.Connection
Javax.sql.DataSource
Javax.sql.DataSource implementation (*)
Java.sql.DriverManager implementation
Correct Correct
Previous Page 9 of 10 Next Summary
Test: Java Programming Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 9
(Answer all questions in this section)
46. Which of the following is a valid JDBC URL? Mark for Review
(1) Points
oracle:thin:localhost@dfot/dfot:1521:xe
jdbc::oracle-thin:dfot/dfot@oracle:1521:xe
jdbc:oracle:thin:dfot/dfot@localhost:1521:xe (*)
oracle:thin:jdbc:dfot/dfot@localhost:1521:xe
Correct Correct
47. Which the following statements is NOT TRUE about DataSource? Mark for Review
(1) Points
DataSource can be implemented as a pool of connections.
DataSource can participate in the Distributed transaction.
DataSource can manage a set of JDBC Drivers registered in the system. (*)
DataSource will typically be registered with a naming service.
Correct Correct
48. Which symbol is used as a placeholder to pass parameters to a PreparedStatement or CallableStatement? Mark for Review
(1) Points
!
? (*)
@
#
Correct Correct
49. Which of the following can fill in the //INSERT HERE correctly? (Choose Two)
ResultSet rset = stmt.executeQuery(sqlQuery);
if(rs.next()){
//INSERT HERE
}
Mark for Review
(1) Points
(Choose all correct answers)
Object s = rs.getObject(1); (*)
String s = rs.getString(1);
String s = rs.getObject(0);
String s = rs.getString(0);
Correct Correct
50. Which of the following is the correct statement be inserted at //INSERT CODE location that calls the database-stored procedure sayHello?
class Test{
public static void main(String[] args) {
try {
Connection conn = getConnection();
//INSERT CODE
cstat.setString(1, "Hello");
cstat.registerOutParameter(2, Types.NUMERIC);
cstat.setInt(2, 10);
}
catch(SQLException e){}
}
}
Mark for Review
(1) Points
CallableStatement cstat = con.prepareCall("{sayHello(?, ?)}");
CallableStatement cstat = con.prepareCall("{call procedure_sayHello (?, ?)}");
CallableStatement cstat = con.prepareCall("{call sayHello}");
CallableStatement cstat = con.prepareCall("sayHello(?, ?)");
CallableStatement cstat = con.prepareCall("{call sayHello(?, ?)}"); (*)
Correct Correct
Previous Page 10 of 10 Summary
1. Which of the following is the correct order to close the database object? Mark for Review
(1) Points
ResultSet, Statement, Connection (*)
Connection, Statement, ResultSet
Statement, Connection, ResultSet
ResultSet, Connection, Statement
Statement,?ResultSet,?Connection
5. Which of the following classes or interfaces are included in the database vendor driver library? (Choose two) Mark for Review
(1) Points
(Choose all correct answers)
Statement interface implementation (*)
Java.sql.Connection
Javax.sql.DataSource
Java.sql.DataSource implementation (*)
Java.sql.DriverManager implementation
Given the following output from the Minor GC:
ReplyDelete[GC [DefNew: 4032K->64K(4032K), 0.0429742 secs] 9350K->7748K(32704K), 0.0431096 secs]
What estimated percentage of the Java objects will be promoted from Young space to Tenured space?
0.2
0.4
0.6 (*)
0.8
0.9