Download Ser321 Review Questions for: Serialization and Json

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Ser321 Review Questions for: Serialization and Json
References:
http://en.wikipedia.org/wiki/JSON-RPC
http://en.wikipedia.org/wiki/JSON
java API documentation for the interface java.io.Serializable
ClassNotes section on Serialization (only the Java sections)
Section 4.5 of “Java Network Programming and Distributed Computing” text by Reilly&Reilly
(available via the internet by searching for the pdf version of the book)
Oracle Java tutorial on jndi covers serialization. See:
https://docs.oracle.com/javase/tutorial/jndi/objects/serial.html
Which of the following are categories of Json Values?
a. String
b. Number
c. Boolean
c. Object
d. List
e. Array
f. Hashtable
g. Vector
h. Stack
i. null
Identify which of the above Json categories the following literal values represent:
“George Shumaker”
125.7
150
true
[ 12, 155.3, 13 ]
{ “twelve”:12, “two”:2, “ten”:10, “name”:”George Shumaker” }
[ true, false, true, true ]
Consider the following Java code that uses org.json.JSONObject:
public User(JSONObject jsonObj){
try{
userNum = jsonObj.getDouble("userNum");
userId = jsonObj.getString("userId");
userPwd = jsonObj.getString("userPwd");
}catch(Exception ex){
System.out.println("Exception constructing user from JSON: "+ex.getMessage());
}
}
a. What does this constructor for the User class do?
b. Give an example of a Json value that would be appropriate input to this constructor (the
string equivalent of the argument jsonObj.
c. Change the constructor so that it creates a Waypoint object whose fields (members) are lat,
lon, elevation (all three are doubles), and name (a string).
d. Show the implementation of the method:
public JSONObject toJsonObject( );
that could be defined in the Waypoint class.
True or False: Serialization can be described as placing an object graph into a stream that can be
written to a file or sent via a socket connection to another running program. A replica of the object can
subsequently be re-constructed by reading the stream, file, or socket.
Suppose I create a java.util.Vector of Waypoint objects. That is, I add several waypoints to the
vector:
java.util.Vector<Waypoint> myVectorOfWaypoints;
Also suppose that I define my Waypoint class to implement the java.io.Serializable interface. Since
java.util.Vector is serializable, I can serialize the vector with Java statements such as:
File outFile = new File("waypoints.ser");
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(outFile));
os.writeObject(myVectorOfWaypoints);
os.flush();
System.out.println("Done exporting the vector of Waypoints");
Explain how this demonstrates that serialization places an object graph into a stream.
True or False. When using Java's built-in serialization facilities, the stream produced
(the waypoints.ser file in the example above) is text as opposed to binary.
True or False? If you create a class that implements Serializable, your class must contain bodies (implementations) for the readObject and writeObject methods that are defined in the Serializable interface.
Explain the use of the java development kit tool: serialver in maintaining a serializable Java class.
Explain how its possible to make changes to a class in such a way that the new version is compatible
with objects serialized from an older version of the class.