GoConqr has a new look! Let us know what you think.

Quiz

Untitled

Daniel Santiago do Carmo Pereira 4 questions

Take the quiz

Questions in this quiz (4)

  1. 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?
    1. Afor(StackTraceElement trace: ex.getStackTrace())
      System.err.println(trace.toString());
    2. BSystem.err.println(ex.getString());
    3. CSystem.err.println(ex.getMessage());
    4. Dfor(Throwable supEx: ex.getSuppressed())
      System.err.println(supEx.toString());
  2. 2Question 2 of 10
    What is the difference between the Executor and ExecutorService interfaces?
    1. AThe Executor interface only supports the submit method.
    2. BThe Executor interface supports both Runnable and Callable objects.
    3. CThe ExecutorService interface provides methods for lifecycle management of both Runnable and Callable objects.
    4. DThe ExecutorService interface does not support the execute method.
  3. 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?
    1. AReplace IllegalArgumentException with FileNotFoundException in the catch statement.
    2. BAdd a throws clause to the method declaration that specifies FileNotFoundException.
    3. CAdd a throws clause to the method declaration that specifies IOException.
    4. DReplace IllegalArgumentException with Exception in the catch statement.
    5. EAdd IOException to the catch statement.
    6. FAdd FileNotFoundException to the catch statement.
  4. 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?
    1. Aclass java.io.IOException
    2. Bclass java.lang.IllegalArgumentException
    3. CCompilation fails due to error on line 2.
    4. DCompilation fails due to error on line 8.
    5. 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
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?