Programming 2 Flashcards
Serialization
The flattening of an object structure to allow for storage in a file
Deserialization
The reading of an object stored in a file to allow for it to be used
Where does the relative path start from?
The project folder
Input and Output Streams
An abstract class that holds a stream of bytes. (Often representing a file, can be some other I/O)
How to add bytes to an OutputStream
write(int integer) or write(byte[] array)
Reader and Writer
An abstract class that holds a stream of characters
FileWriter/FileOutputStream constructor
Class(file, ifModifyingFile) (if not modifying will wipe existing data).
FileInputStream read
stream.read(array) reads all the bytes from the stream to a given array
FileReader read
reader.read() - reads one character, or -1 if end of stream
ByteArrayStream
Does reading and writing directly into memory, ususally used for generating temporary data
Pipeline Stream
Used for communication between two threads
Print Stream
Output only. Allows for outputting data in text form. Is a wrapper of an output stream
Tagging Interface
Has no methods
Serializing Requirement
The class must implement the Serializable tagging interface. All fields primitives/String/Serializable
What serializes/deserializes objects
ObjectStreams
Serializing/desializing steps
Create an output/input stream to place/recieve data. Pass this to a objectStream. Call write/readObject on the object stream passing the object to serialize if writing
Serial Version UID
serialisation
64 bit secure hash of the class saved with a serialized object. When deserializing can be compared to current class and if it does not match serialization fails. May still work with minor changes
Externalizable
Interface that allows for choosing of what to serialize. Contains writeExternal and readExternal. Requires an empty constructor
Default Deserialization
From the class type from the stream, go the the highest serializable superclass and call the no argument constructor of its superclass.This sets up initial variables and the object. Work down the heirarchy creating and assigning additional varibles from the stream, until the final class is reached
transient
Keyword for variables that prevents it from being serialized
Ways to make a String
- Direct assignment
- String constructor with array of bytes/chars
- String constructor with a String
compareTo
method in the String class that compares the unicode representation (character by character, so gives which is alphabetically first) of the String and the String parameter. output = First String - parameter string
Anonymous Object
Created object with no name, so will be deleted after used
Immutable
Contents of object cannot be changed. Property of a String.