OCJP Preparation - IO and Serialization - BEHIND JAVA

OCJP Preparation - IO and Serialization

Share This

1. Given the program

What is the result?
  • A. Compilation fails.
  • B. An exception is thrown at runtime.
  • C. An instance of Forest is serialized.
  • D. An instance of Forest and an instance of Tree are both serialized.

2. Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:

What is the result?

  • A. restore 400
  • B. restore 403
  • C. restore 453
  • D. Compilation fails.
  • E. An exception is thrown at runtime.

3. Which three statements concerning the use of the java.io.Serializable interface are true? (Choose three.)

  • A. Objects from classes that use aggregation cannot be serialized.
  • B. An object serialized on one JVM can be successfully deserialized on a different JVM.
  • C. The values in fields with the volatile modifier will NOT survive serialization and deserialization.
  • D. The values in fields with the transient modifier will NOT survive serialization and deserialization.
  • E. It is legal to serialize an object of a type that has a supertype that does NOT implement java.io.Serializable.

4. Assuming that the serializeBanana2() and the deserializeBanana2() methods will correctly use Java serialization and given:

What is the result?

  • A. Compilation fails.
  • B. 1 restored 42
  • C. 12 restored 42
  • D. 121 restored 42
  • E. 1212 restored 42
  • F. An exception is thrown at runtime.

5. When comparing java.io.BufferedWriter to java.io.FileWriter, which capability exists as a method in only one of the two?

  • A. closing the stream
  • B. flushing the stream
  • C. writing to the stream
  • D. marking a location in the stream
  • E. writing a line separator to the stream

6. Given the program

The current directory does NOT contain a directory named "d." Which three are true? (Choose three.)

  • A. Line 16 is never executed.
  • B. An exception is thrown at runtime.
  • C. Line 13 creates a File object named "d."
  • D. Line 14 creates a File object named "f."
  • E. Line 13 creates a directory named "d" in the file system.
  • F. Line 16 creates a directory named "d" and a file 'f' within it in the file system.
  • G. Line 14 creates a file named 'f' inside of the directory named “d” in the file system.

7. Given the program

Which code fragment, inserted at line 15, will allow Foo objects to be correctly serialized and deserialized?

  • A. s.writeInt(x);
  • B. s.serialize(x);
  • C. s.writeObject(x);
  • D. s.defaultWriteObject();

8. Given:

//bw is a reference to a valid BufferedWriter And the snippet:
15. BufferedWriter b1 = new BufferedWriter(new File("f"));
16. BufferedWriter b2 = new BufferedWriter(new FileWriter("f1"));
17. BufferedWriter b3 = new BufferedWriter(new PrintWriter("f2"));
18. BufferedWriter b4 = new BufferedWriter(new BufferedWriter(bw));

What is the result?

  • A. Compilation succeeds.
  • B. Compilation fails due only to an error on line 15.
  • C. Compilation fails due only to an error on line 16.
  • D. Compilation fails due only to an error on line 17.
  • E. Compilation fails due only to an error on line 18.
  • F. Compilation fails due to errors on multiple lines.

9. Given the program

What is the result? (Choose all that apply.)

  • A. exc
  • B. done
  • C. Compilation fails.
  • D. Exactly one object is serialized.
  • E. Exactly two objects are serialized.

10. Given the program

and that the invocation java IOTest file2.txt is issued from a directory that has two subdirectories, "dir1" and "dir1", and that "dir1" has a file "file1.txt" and "dir2" has a file "file2.txt", and the output is "false true", which set(s) of code fragments must be inserted? (Choose all that apply.)

  • A. String path = d;
    System.out.print(file.exists() + " ");
  • B. String path = d;
    System.out.print(file.isFile() + " ");
  • C. String path = File.separator + d;
    System.out.print(file.exists() + " ");
  • D. String path = File.separator + d;
    System.out.print(file.isFile() + " ");

11. Given the program

Which are true? (Choose all that apply.)

  • A. Compilation fails.
  • B. The output is 10 0 9
  • C. The output is 10 0 10
  • D. The output is 10 7 9
  • E. The output is 10 7 10
  • F. In order to alter the standard deserialization process you would override the readObject() method in SpecialSerial.
  • G. In order to alter the standard deserialization process you would override the defaultReadObject() method in SpecialSerial.

No comments:

Post a Comment

Pages