Quiz
Untitled
Questions in this quiz (4)
1Question 1 of 10
Given the following code fragment:
1. public static void decryptFile(SecretKey key, String fileName) {
2. Cipher calg = null;
3. try (
4. FileReader inputFS = new FileReader(fileName);
5. CipherOutputStream decStream = new CipherOutputStream(System.out, calg);
6. ){
7. calg = Cipher.getInstance("GARBAGE");
8. calg.init(Cipher.DECRYPT_MODE, key);
9. int charByte;
10. while ((charByte = inputFS.read()) != -1)
11. decStream.write((char)charByte);
12. decStream.flush();
13. } catch (Exception ex) {
14 //insert code here
15. }
16. }
Which code fragment, when inserted at line 14, will output exceptions associated with opening and/or closing resources?- Afor(StackTraceElement trace: ex.getStackTrace())
System.err.println(trace.toString()); - BSystem.err.println(ex.getString());
- CSystem.err.println(ex.getMessage());
- Dfor(Throwable supEx: ex.getSuppressed())
System.err.println(supEx.toString());
- Afor(StackTraceElement trace: ex.getStackTrace())
2Question 2 of 10
What is the difference between the Executor and ExecutorService interfaces?- AThe Executor interface only supports the submit method.
- BThe Executor interface supports both Runnable and Callable objects.
- CThe ExecutorService interface provides methods for lifecycle management of both Runnable and Callable objects.
- DThe ExecutorService interface does not support the execute method.
3Question 3 of 10
Given the code fragment:
public static void writeFile(String fileName, String content) {
Path file = Paths.get(fileName);
Charset chars = Charset.defaultCharset();
try (BufferedWriter writer = Files.newBufferedWriter(file, chars)) {
writer.write(content);
} catch (IllegalArgumentException ex) {
System.err.print(ex);
}
}
Which three independent changes should you make to ensure the WriteFile method will compile?- AReplace IllegalArgumentException with FileNotFoundException in the catch statement.
- BAdd a throws clause to the method declaration that specifies FileNotFoundException.
- CAdd a throws clause to the method declaration that specifies IOException.
- DReplace IllegalArgumentException with Exception in the catch statement.
- EAdd IOException to the catch statement.
- FAdd FileNotFoundException to the catch statement.
4Question 4 of 10
Examine the code fragment:
1. public static void readFile() {
2. Path file = Paths.get("test.dat");
3. Charset chars = Charset.defaultCharset();
4. try (BufferedReader reader =
Files.newBufferedReader(file, chars)) { 5. String line = null;
6. while ((line = reader.readLine()) != null)
7. System.out.println(line);
8. } catch (IllegalArgumentException | IOException ex) {
9. System.err.println(ex.getClass());
10. }
11. }
The test.dat file does not exist in the current directory. What is the result?- Aclass java.io.IOException
- Bclass java.lang.IllegalArgumentException
- CCompilation fails due to error on line 2.
- DCompilation fails due to error on line 8.
- Eclass java.nio.file.NoSuchFileException
Information
- Description
- 1Z0-813: Upgrade to Java SE 8 OCP ( Java SE 6 and all prior versions) 1Z0-813: Upgrade to Java SE 8 OCP ( Java SE 6 and all prior versions) Quiz on Untitled, created by Daniel Santiago do Carmo Pereira on 28/04/2017.
- Language
- Português
- Views
- 0
- Tags
- Rating
- No ratings yet Rate this quiz