Programming 2 Flashcards

1
Q

Difference between a byte-based stream and character-based stream.

A

Byte-based uses InputStream and OutputStream.
Character-based uses a Reader and Writer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Steps for a Java I/O operation

A

Get a file ready with the File class
Set up a Stream
Using Read or Write
Close the Stream

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Byte-based vs Character-based

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

ByteArray Stream

A

Reads and writes directly into memory.
Normally used for generating temporary data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Pipeline stream

A

Mainly used for communicating and connecting between threads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Object serialisation

A

Used to store objects to the disk so they can be written to a data stream.
Only properties are serialised.
Done with an ObjectOutputStream.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Object deserialisation

A

Used to unflatten an object when pulling it off the disk.
Done with ObjectInputStream.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Object versioning

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Requirements for serialisation

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Types of String comparisons

A

Double equals (==)
Checks if the variables point to the same String in the heap.
.equals()
Checks if the variables have equal values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Verification vs Validation

A

Verification: testing software correctly implements a specific function.
Validation: testing software satisfies customer requirements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

White-box vs Black-box testing

A

White-box: using known inputs and outputs.
Black-box: used to test without knowledge on the internal workings of the software.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Unit testing

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Integration testing

A

Repeatedly testing the combination of larger collections of code units.

A mix of white- and black-box testing done by testers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

System testing

A

Testing the entirety of the system.

Black-box testing done at the end of development.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Testing in isolation

A

If a class depends on another, a ‘fake’ subclass of the required class is made, a mock or stub object.

17
Q

A stub object

A

Passes data to the main program being tested in isolation.
Often uses hard-coded values for simplicity.

18
Q

A driver object

A

A fake main program that accepts test case data and passes it on to the components being tested.
Used to fulfil requirements of missing or incomplete components.

19
Q

Types of integration testing

A

Top-down
Bottom-up
Sandwich
Big Bang

20
Q

Top-down itegration

A

Tests the high-level moules in isolation with stub dependencies.
Adds in the actual modules being called and tests them together.
Repeats until all modules are included.

21
Q

Bottom-up integration

A

Tests the low-level moules in isolation.
Adds in the modules that call this module and tests them together.
Repeats until all modules are included.

22
Q

Sandwich integration

A

Identifies the top, middle, and bottom layers.
The top is tested with Top-down integration, the bottom with Bottom-up integration. Then the middle is included.

23
Q

Big Bang integration

A

Non-incremental, in which each unit is tested thoroughly in isolation.
Then the whole system is integrated and tested together at once.

24
Q

JVM

A

Java Virtual Machine

25
Q

WORA

A

Write Once, Run Anywhere

26
Q

Class loader and Method area

A

The class loader locates .class files, verifies them through their bytecode
Then loads them into the method area in the shared memory.

27
Q

Machine’s memory architecture

A

Comprised of:
Shared memory, one heap and one method area per JVM instance.
Private memory, one java stack and program counter per thread.

28
Q

Program Counter

A

Holds the address of the next bytecode instruction to execute, for each thread.

29
Q

Java stack

A

Holds state information for the thread.
E.g. which methods have been called, local variables, parameters, and used for performing calculations.

30
Q

Execution engine

A

The part of the JVM which describes how bytecode is executed, and what the expected behaviour should be. Done in terms of the JVM instruction set.

31
Q

The Heap

A

Located in the shared memory.
Stores object instances, the values of all non-static fields.
Can be primitives or references/pointers to other instances in the heap.

Non-primitive data are stored as their own object instance.

32
Q

Stack frame

A

When a thread calls a method, a new frame is pushed onto the thread’s Java stack. All local variables, parameters, and temporary calculations are done within this frame.

33
Q

Recursion

A

Defining an entity in terms of itself, e.g. a method calling itself, or a list containing a list.

34
Q

Defining a pointer in C for a primitive or array variable

A

Primitive variable:
*pointer = &var
Array variable:
*pointer = array
*pointer = &array[0]

35
Q

Accessing a pointer in C

A

Access to the memory location: *pointer
Access to the memory address: pointer