1.
What
class is Mark for
the Review
split() (1) Points
method
a
member
of?
Parse
StringBuilder
Array
String (*)
Correct
2. 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 the String.split() method to parse a string. (*)
It is a way of dividing a string into a set of sub-strings. (*)
It is possible to use a for loop to parse a string. (*)
It is not possible to parse a string using regular expressions.
Correct
3. What is the result from the following code?
Mark for Review
public class Test { (1) Points
public static void main(String[] args) {
String str = "91204";
str += 23;
System.out.print(str);
}
}
91227
9120423 (*)
Compile fails.
23
91204
Correct
4. 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)
You don't use a FOR loop with Strings
Search for a specific character or String inside of the String. (*)
Read the String backwards (from last element to first element). (*)
Parse the String. (*)
Correct
5. Which of the following correctly defines a StringBuilder?
Mark for Review
(1) Points
There is no such thing as a StringBuilder in Java.
A class inside the java.util.regex package.
A class that represents a string-like object. (*)
A method that adds characters to a string.
Correct
Section 3
(Answer all questions in this section)
6. 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
7. Which statement added at line one allows the code to compile and run?
Mark for Review
//line one (1) Points
public class Test (
public static void main (String[] args) {
java.io.PrintWriter out = new java.io.PrintWriter
(new java.io.OutputStreamWriter (System.out), true);
System.out.println("Java");
}
}
No statement is needed. (*)
include java.io.*;
import java.io.PrintWriter;
import java.io.OutputStreamWriter
import java.io.*;
Correct
8. In what order do multiple catch statements execute?
Mark for Review
(1) Points
The order they are declared in ( most specific first). (*)
They all execute at the same time.
The order they are declared in (most general first).
None of them execute since you cannot have multiple catch statements.
Correct
9. Multiple exceptions can be caught in one catch statement.
True or false? Mark for Review
(1) Points
True (*)
False
Correct
10. Assertions are boolean statements to test and debug your programs.
True or false? Mark for Review
(1) Points
True (*)
False
Correct
Section 3
(Answer all questions in this section)
11. What is one step you must do to create your own exception?
Mark for Review
(1) Points
Create a new class that implements Exception.
Create a new class that extends Exception. (*)
Exceptions cannot be created. They are only built in to Java.
Declare the primitive data type Exception.
Correct
12. What is exception handling?
Mark for Review
(1) Points
When a file fails to open.
An error that occurs against the flow of your program.
If your program exits before you expect it to.
A consistent way of handling various errors. (*)
Incorrect. Refer to Section 3 Lesson 6.
13. Methods can not throw exceptions.
True or false? Mark for Review
(1) Points
True
False (*)
Correct
14. This is correct syntax for catching an exception:
try(inputStream = "missingfile.txt"); Mark for Review
catch(exception e); (1) Points
True or false?
True
False (*)
Correct
15. When will a finally statement be executed?
Mark for Review
(1) Points
Only if multiple exceptions are caught and thrown.
Never; it is there for visual purposes.
Only if an exception is not thrown.
Always; no matter if an exception is thrown or not. (*)
Only if an exception is thrown.
Correct
Section 3
(Answer all questions in this section)
16. What is the output from the following code?
public class Foo{ Mark for Review
public static void main(String[] args){ (1) Points
try {return;}
finally{System.out.println("you are in Finally");}
}
}
The code will not compile.
The code compiles and print nothing
The code compiles, but an exception is thrown.
The code compiles and prints out モ you are in Finally" (*)
Incorrect. Refer to Section 3 Lesson 6.
17. When are control flow invariants used?
Mark for Review
(1) Points
To test the correct flow of your code. (*)
To test specific variable values of your code.
To test compilation errors in your code.
To test run time errors in code.
Correct
18. What is the definition of a logic error?
Mark for Review
(1) Points
Wrong syntax that will be caught at compile time.
Bugs in code that make your program run different than expected (*)
Computer malfunction that makes your code run incorrectly.
Something that causes your computer to crash.
Correct
19. The following code correctly initializes a pattern with the regular expression "[0-9]
{2}/[0-9]{2}/[0-9]{2}". Mark for Review
(1) Points
Pattern dateP = Pattern.compile("[0-9]{2}/[0-9]{2}/[0-9]{2}");
True or false?
True (*)
False
Correct
20. 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.
Correct
Section 3
(Answer all questions in this section)
21. 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
matches(String regex) (*)
compareTo(String regex)
equalsIgnoreCase(String regex)
equals(String regex)
Correct
22. 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 Mark for Review
exactly five letters long. (1) Points
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?
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
23. 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 = p.matcher(str); (*)
Matcher m = str.matcher(p);
Matcher m = new Matcher();
Correct
24. 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
25. 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. Mark for Review
True or false? (1) Points
True (*)
False
Correct
Section 3
(Answer all questions in this section)
26. 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.
Correct
27. The normalize() method removes redundant name elements from a qualified path.
True or false? Mark for
Review
(1) Points
True (*)
False
Correct
28. An absolute path always starts from the drive letter or mount point.
Mark for
Review
(1) Points
True (*)
False
Correct
29. Java 7 requires you create an instance of java.nio.file.File class.
True or false? Mark for
Review
(1) Points
True
False (*)
Correct
30. 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
Section 3
(Answer all questions in this section)
31. The java.nio.file package has improved exception handling.
True or false? Mark for Review
(1) Points
True (*)
False
Correct
32. The java.io package has problems with no support for symbolic links.
True or false? Mark for Review
(1) Points
True (*)
False
Correct
33. The BufferedOutputStream is a direct subclass of what other class?
Mark for Review
(1) Points
FilterOutputStream (*)
ObjectOutputStream
DigestOutputStream
PrintStream
OutputStream
Correct
34. The System.in is what type of stream?
Mark for Review
(1) Points
An InputStream (*)
A PrintStream
A Reader stream
A BufferedWriter stream
A BufferedReader stream
Correct
35. Which statement determine that "java" is a directory?
Mark for Review
(1) Points
Boolean isDir=Directory.exists ("java");
Boolean isDir=(new Directory("java")).exists(); (*)
Boolean isDir=(new File("java")).isDir();
Boolean isDir=(new File("java")).isDirectory();
Correct
Section 3
(Answer all questions in this section)
36. 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
37. The Files class provides a instance method that creates a new BufferedReader.
True or false? Mark for Review
(1) Points
True (*)
False
Correct
38. You can read input by character or line.
True or false? Mark for Review
(1) Points
True (*)
False
Correct
39. A non-linear recursive method can call how many copies of itself?
Mark for Review
(1) Points
1
2 or more (*)
None
Correct
40. A base case can handle nested conditions.
True or false? Mark for Review
(1) Points
True (*)
False
Correct
Section 3
(Answer all questions in this section)
41. Which case handles the last recursive call?
Mark for Review
(1) Points
The convergence case
The base case (*)
The secondary case
The recursive case
The primary case
Correct
42. 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
43. Forward thinking helps when creating linear recursive methods.
True or false? Mark for Review
(1) Points
True
False (*)
Correct
44. Which two statements can create an instance of an array? (Choose Two)
Mark for Review
(1) Points
(Choose all correct answers)
double da = new double [5];
char[] ca = "java";
int[] ia = new int [5]; (*)
Object oa = new double[5]; (*)
int ia[][] = (1,2,3) (4,5,6);
Incorrect. Refer to Section 3 Lesson 3.
Section 4
(Answer all questions in this section)
45. 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
Switch Workspace
Export (*)
Import
Properties
Correct
Section 4
(Answer all questions in this section)
46. To deploy java applications you may use Java Web Start.
True or false? Mark for Review
(1) Points
True (*)
False
Correct
47. The method for connecting a java application to a database is JNLP.
True or false? Mark for Review
(1) Points
True
False (*)
Correct
48. Java Web Start is used to deploy Java applications.
True or false? Mark for Review
(1) Points
True (*)
False
Correct
49. 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
50. Which of the following files are not required to be uploaded to a web server to deploy
a JWS java application/applet? Mark for Review
(1) Points
jar files
JNLP files
html files
.java files (*)
None of the above
Correct