Question

In: Computer Science

5) File I/O A) Compare and contrast InputStream/OutputStream based file I/O to Scanner/Printwriter based file I/O:...

5) File I/O

A) Compare and contrast InputStream/OutputStream based file I/O to Scanner/Printwriter based file I/O:

B) Discuss Serialization, what is it? What are the processes and features? What is the function of the keyword Transient?

Solutions

Expert Solution

A. Compare and contrast InputStream/OutputStream based file I/O to Scanner/Printwriter based file I/O

The objective of InputStream and OutputStream is to extract various approaches to information and yield: regardless of whether the stream is a record, a website page, or the screen shouldn't make any difference. The only thing that is in any way important is that you get data from the stream (or send data into that stream). Stream here is referred to anything having more than one bit of character.

InputStream is utilized for some things that you read from.

OutputStream is utilized for some things that you write to.

While on the other hand, Scanner/Printwriter is normally used when we know input/output is of type string or of primitive types.

A Scanner object developed with System.in filters the standard information stream for gatherings of characters. A portion of its techniques convert a gathering characters to a particular information type. For instance, the nextInt() strategy peruses in a gathering of characters that can be changed over to an int.

PrintWriter is used to send characters to a text file.

B. Discuss Serialization, what is it? What are the processes and features? What is the function of the keyword Transient?

Serialization is a system of changing over the condition of an item into a byte stream. Deserialization is the turn around process where the byte stream is utilized to reproduce the real Java object in memory.

The byte stream created is platform independent. So, the object serialized on one platform can be deserialized on a different platform.

To make a Java object serializable we implement the java.io.Serializable interface.


The ObjectOutputStream class contains writeObject() method for serializing an Object.

public final void writeObject(Object obj)
                       throws IOException

The ObjectInputStream class contains readObject() method for deserializing an object.

public final Object readObject()
                  throws IOException,
               ClassNotFoundException

Advantages of Serialization
1. To save/persist state of an object.
2. To travel an object across a network.

Transient is a Java catchphrase which denotes a a member variable not to be serialized when it is persevered to stream of bytes. At the point when an item is moved through the system, the article should be 'serialized'. Serialization changes over the article state to sequential bytes. Those bytes are sent over the system and the item is reproduced from those bytes. Member variable set apart by the java transient watchword are not moved; they are lost deliberately.


Related Solutions

Important notes: Use Console I/O (Scanner and System.out) for all user I/O in this lab. Do...
Important notes: Use Console I/O (Scanner and System.out) for all user I/O in this lab. Do not hard code data file paths or filenames; always ask the user for them. Complete the Monster Attack project by doing the following: In place of the driver used in homework 2, add a menu with a loop and switch (this is already done, ignore this). The user must be able to add attacks, get a report on existing attacks, save a file, retrieve...
Compare and contrast a minimum of two I/O theories in training and development and determine which...
Compare and contrast a minimum of two I/O theories in training and development and determine which is most appropriate .
Compare and contrast the prokaryotic and eukaryotic genomes by giving 5 similarities and 5 differences. Based...
Compare and contrast the prokaryotic and eukaryotic genomes by giving 5 similarities and 5 differences. Based on what you learned about the endosymbiont theory predict three characteristics about mitochondrial DNA.
Compare and contrast measures based on activity and measures based on strategy
Compare and contrast measures based on activity and measures based on strategy
• Compare and contrast antisocial personality disorder and psychopathy. o How common are each?
• Compare and contrast antisocial personality disorder and psychopathy. o How common are each?
Q # 5: Compare and contrast the metabolism of delta-9-THC based on oral ingestion vs. inhalation...
Q # 5: Compare and contrast the metabolism of delta-9-THC based on oral ingestion vs. inhalation drug exposure. Q # 6: Explain the difference between acute (short-term) and chronic (long-term) fat cell related pharmacokinetics?
5. Compare and contrast the structure and location of a nucleus and ganglion. 6. Compare and...
5. Compare and contrast the structure and location of a nucleus and ganglion. 6. Compare and contrast the structure and location of a tract and nerve.
Compare and contrast hydrogels with other non-hydrogel based biomaterial.
Compare and contrast hydrogels with other non-hydrogel based biomaterial.
Compare and Contrast the decisions of a competitive firm and a platform based firm.  
Compare and Contrast the decisions of a competitive firm and a platform based firm.  
Compare and contrast valuation models based on discounted cash flows and valuation approaches based on the...
Compare and contrast valuation models based on discounted cash flows and valuation approaches based on the relevant multiples of comparable investments.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT