Programming 2 Flashcards
Difference between a byte-based stream and character-based stream.
Byte-based uses InputStream and OutputStream.
Character-based uses a Reader and Writer.
Steps for a Java I/O operation
Get a file ready with the File class
Set up a Stream
Using Read or Write
Close the Stream
Byte-based vs Character-based
Byte-based
Uses InputStream and OutputStream.
Setting up the stream creates a new file if one doesn’t already exist.
New line with \r\n
Best for raw data, e.g. mouse and keyboard.
Character-based
Uses Reader and Writer.
Creates a new file, or overwrites an existing one.
Best for pure text.
ByteArray Stream
Reads and writes directly into memory.
Normally used for generating temporary data.
Pipeline stream
Mainly used for communicating and connecting between threads.
Object serialisation
Used to store objects to the disk so they can be written to a data stream.
Only properties are serialised.
Done with an ObjectOutputStream.
Object deserialisation
Used to unflatten an object when pulling it off the disk.
Done with ObjectInputStream.
Object versioning
A serialised object has a hash of the object’s class written as part of its state when serialised.
During deserialisation, the serial version UID is compared to the existing classes, and if they don’t match the deserialisation fails and it results in an InvalidClassException.
Requirements for serialisation
An object can be serialised if:
All the fields are primitives or Strings.
Any class referenced in variables are also declared as Serializable
.
(Ignoring static properties)
Types of String comparisons
Double equals (==)
Checks if the variables point to the same String in the heap.
.equals()
Checks if the variables have equal values.
Verification vs Validation
Verification: testing software correctly implements a specific function.
Validation: testing software satisfies customer requirements.
White-box vs Black-box testing
White-box: using known inputs and outputs.
Black-box: used to test without knowledge on the internal workings of the software.
Unit testing
Includes:
Identifying the code to be tested in isolation.
Developing a suite of test cases.
Writing a test harness for each case.
White-box testing done by developers.
Integration testing
Repeatedly testing the combination of larger collections of code units.
A mix of white- and black-box testing done by testers.
System testing
Testing the entirety of the system.
Black-box testing done at the end of development.