In: Computer Science
1. Assume you are writing code to serialize a group of Student objects to an XML document. What Java API method will you call to execute the serialization process? NOTE: You must use the XML serialization/deserialization method/concepts presented in this course.
2. Assume that the list of exception types below may occur within the scope of a method. In order to properly handle these exceptions, each type must be handled individually and separately. Arrange the exception types in the order in which your code must address them to insure that no type "falls through" to be processed along with any other type. (HINT: These are all Java API exception types.)
5 points
IOException
Exception
FileSystemException
NoSuchFileException
1. To Serialize an object to XML we need to Create an XMLEncoder Class Object which is available in "java.beans" package. After Creating the Object we can use writeObject() to encode the Object.
To Better Understand the Concept Lets consider the following Student Class:
Student.java
import java.io.*; public class Student { public Student(String name, String Hno,float gpa)
{ |
We Use the Following SerializeToXML class that use the XMLEncoder to Encode Objects to XML files
import java.io.*; } } |
Output:
After Execution the XML file is Generated in the Present Working Directory.
The Created XML file is:
2. The relationship between The four Exceptions is in the following Hierarchy.
So the Correct order to Handel the Four exceptions is First NoSuchFileException, then FileSystemException, then IOException and finally Exception