1
h07
CS56 W18
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu section
4pm, 5pm or 6pm
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h07: Serialization (HFJ 14)

ready? assigned due points
true Thu 02/15 11:00AM Tue 02/20 11:00AM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the four lowest scores (if you have zeros, those are the four lowest scores.)


This homework concerns HFJ Chapter 14. Please read that chapter, and then answer these questions.

  1. (10 pts) Please fill in the information at the top of this homework sheet, including your name and umail address. Put the time your discussion section starts (4pm, 5pm or 6pm) in the space indicated (the one you are registered for—even if you usually attend a different one.) If the other two items apply, please fill them in as well. Please do this every single time you submit homework for this class.
  2. (20 pts) Serialization is all about saving the “state” of an object. Obviously, this doesn’t mean “California” vs. “Nevada” or “Arizona”. But explaining what it does mean can be a bit tricky. That makes it a good “job interview question”. Explain what it means to “save the state of an object” in Java. For full credit, your answer should address some of the subtle issues referred to in the text.

  3. (20 pts) What, according to our textbook authors, is “the beauty of buffers”?

    Explain in your own words—don’t just copy text down from the book. The book uses an analogy of a shopping cart, so “in your own words” means, among other things, you must not use that analogy. If you want to use an analogy, come up with your own, different analogy..

  4. The book describes a technique known as “chaining” in the context of talking about Java IO Streams. Give an example of some code from the book that demonstrates this technique, and more importantly explain in your own words what the chaining of the two or kinds kinds of stream accomplishes.

    • (5 pts) for a correct example
    • (10 pts) for a correct explanation of the example
  5. The textbook mentions two options for saving the state of an object in some place external to a running Java program: (1) the built-in Java serialization technique (java.io.Serializable interface) (2) writing to a plain text file.

    In fact, there are many options for serializing an object, including SQL databases such as (MySQL, Postgres, etc.), no-SQL databases (such as MongoDB). A popular serialization format is JSON (JavaScript Object Notation), which despite having “JavaScript” in the name, is actually a format that can be used by many programming languages (including JavaScript, but also Java, Ruby, and Python.) We’ll discuss these in lecture, since they aren’t covered in the book.

    But for now, to establish a basis for discussing these: tell me what the book says about the pros/cons of the two techniques described.

    1. (10 pts) What is an advantage of Java's built-in serialization over writing to plain text files?
    2. (10 pts) What is an advantage of plain text files over Java's built-in serialization—or alteratively, a situation where plain text files would be more appropriate or useful than Java's built-in serialization?
  6. (5 pts) Suppose a certain object implements the Serializable interface. There is some part of the object that should NOT be saved when serializing the object. How do you indicate this in your code?

  7. (10 pts) For this question, consider the reading in HFJ about serialization. Your friend B. C. Dull says: "I don't get why object serialization is such a big deal. You have a pointer to each object, and you know how many bytes it takes up in memory, and you know the objects type. Just write those bytes to a file, along with a few extra bytes indicating the type—problem solved. Then you read those bits back in and restore the objects. What's the big deal". You however, see more deeply into the situation, and say: "Well, B.C., it isn't quite that simple. You are forgetting a few subtle issues—things you should realize from your previous study of how data structures work—things you should have learned in CS16 and CS24. Even though those were C/C++ courses, the same problems are going to arise in Java." B.C. says: "I don't see what you are getting at. Can you explain it to me?" What do you say to B.C. to help him/her realize why Object Serialization is more subtle than just writing out all the bits exactly as they are, and reading them back in exactly as they are? HINT: Think about things like linked lists, pointers, and references, and how they are implemented in both C++ and Java.

http://UCSB-CS56-F16.github.io/hwk/h12