Programming 2 Flashcards

1
Q

Serialization

A

The flattening of an object structure to allow for storage in a file

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

Deserialization

A

The reading of an object stored in a file to allow for it to be used

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

Where does the relative path start from?

A

The project folder

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

Input and Output Streams

A

An abstract class that holds a stream of bytes. (Often representing a file, can be some other I/O)

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

How to add bytes to an OutputStream

A

write(int integer) or write(byte[] array)

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

Reader and Writer

A

An abstract class that holds a stream of characters

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

FileWriter/FileOutputStream constructor

A

Class(file, ifModifyingFile) (if not modifying will wipe existing data).

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

FileInputStream read

A

stream.read(array) reads all the bytes from the stream to a given array

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

FileReader read

A

reader.read() - reads one character, or -1 if end of stream

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

ByteArrayStream

A

Does reading and writing directly into memory, ususally used for generating temporary data

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

Pipeline Stream

A

Used for communication between two threads

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

Print Stream

A

Output only. Allows for outputting data in text form. Is a wrapper of an output stream

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

Tagging Interface

A

Has no methods

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

Serializing Requirement

A

The class must implement the Serializable tagging interface. All fields primitives/String/Serializable

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

What serializes/deserializes objects

A

ObjectStreams

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

Serializing/desializing steps

A

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

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

Serial Version UID

serialisation

A

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

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

Externalizable

A

Interface that allows for choosing of what to serialize. Contains writeExternal and readExternal. Requires an empty constructor

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

Default Deserialization

A

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

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

transient

A

Keyword for variables that prevents it from being serialized

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

Ways to make a String

A
  1. Direct assignment
  2. String constructor with array of bytes/chars
  3. String constructor with a String
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

compareTo

A

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

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

Anonymous Object

A

Created object with no name, so will be deleted after used

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

Immutable

A

Contents of object cannot be changed. Property of a String.

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

String Creation Heap Usage

A

When using direct assignment all Strings with that same value will be stored in the same heap location. When using the String constructor it will create it’s own unique heap location

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

valueOf

A

static method converts primitives to new String objects

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

trim

A

String method that removes leading and trailing whitespaces

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

JVM

A

Abstract description of an architecture (virtual hardware, memory layout, registers, …) for implementing Java

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

Class Loader

JVM

A

Locates .class files. Verifies that they are well-formed classes. Loads them into Method Area, links and initialises class (static) variables

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

JVM Shared Memory

A

Contains 1 heap and 1 Method Area

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

JVM Non-shared Memory

A

Each thread has a Java Stack and Program Counter (no registers)

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

Java Stack

JVM

A

Holds state information for thread (e.g. called methods, storing local variables, parameters and doing calculations)

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

Execution Engine

JVM

A

Describes how bytecode is executed, and what should happen, in terms of the JVM instruction set. Separate instances for each thread

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

Method Area

JVM

A

Stores class information (e.g. name, modifier(public…), field information), method definitions and class (static) variables. Stores a constant pool for each type of Class.

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

Method Area Structure

JVM

A

Often use method tables, each class has a table of pointers to methods that can be called on it, including from superclasses

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

Constant Pool

JVM

A

Contains ordered list of constants used by the class, i.e. literals (strings, integers) and symbolic references (to methods(ones called by the class methods), classes). If the symbolic reference refers to another loaded class then the reference will be replaced with a pointer to it (constant pool resolution)

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

Heap

JVM

A

Stores object, along with their (non-static) variables, including inherited ones. Each object has a pointer to it’s class in the method area

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

Non-Shared Memory

JVM

A

Contains a program counter and a stack for each thread

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

JVM Program Counter

A

Points to instruction being executed in Method Area.

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

JVM Stack

A

Allows for only push/pop frame. When a thread calls a method, frame (containing state information on thread execution) is pushed onto stack. All local variables, parameters and calculations done on frame. Can call other method, which puts the other method on top on stack

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

Stack Frame local Variable (and parameters) Storage

JVM

A

Stored as array of words. These variables are referenced by index. Will store primitives directly and references to objects in heap. The zero index always references the object that the method is called on (when non-static method)

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

Operand Stack

JVM Stack Frame

A

Storing arguments for any instructions. e.g. in a = 1, 1 would first be stored in the operand stack, then put into the variables array

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

Stack Frame Pointers

JVM

A
  1. To its constant pool
  2. To the code to go back to after it is done
  3. To the exception table
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

Exception Table

JVM

A

Holds a method’s catch clauses. Matching catch clause searched for when exception happens. If found, PC updated to catching code. Else, method terminated and exception rethrown to previous frame

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

Tail Recursion

JVM

A

If the last line of code is the recursive call then the same stack frame could be used. Java does NOT do this

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

Checked Exceptions

A

Exceptions that the compiler forces you to catch or defer

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

Unchecked Exceptions

A

Don’t need to catch/defer exception as unchecked exceptions should not happen if the code is written properly. Includes runtime exceptions

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

Error

A

subclass of throwable indicating serious problem, unchecked

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

Finally

In try catch block

A

Final clause, always run

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

Static Variables

A

The variable is now for the class, all objects of that class share the same value. Can be changed with Class.variable or object.variable.

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

Static Methods

A

Invoked in the class, not the object. Can only use static variables and methods

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

Final Variables

A

Can only be changed once when initialised if non-static, or only when declared if static

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

Extending Thread Class

to do threading

A

Overwrite the run method and call object.start.

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

Implementing Runnable Interface

to do threading

A

Write run method and then objects can be used in thread constructor. The thread can the be started.

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

Benefits of Runnable

for threading

A

Allows for a different class to be extended. Data is shared more easily as can call start on same thread multiple times

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

sleep

thread method

A

Thread sleeps for given milliseconds

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

thread priorities

A

Can use getter and setters to set priority, from 1-10

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

yield

thread method

A

Skips next slot of execution

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

interrupt

thread method

A

Wakes up sleeping thread, causing interruption

60
Q

Java Thread States

A

Exists in exactly 1 states
1. New - not yet started
2. Runnable - executing
3. Blocked - waiting for a lock
4. Waiting - waiting indefinitely for notification
5. Timed Waiting - waiting for notification/time out whichever happen first
6. Terminated

61
Q

isAlive

threads

A

Checks if thread is in the runnable state

62
Q

join

thread

A

Waits for a specific thread to die before continuing

63
Q

daemon thread

A

low-priority threads. JVM terminates if only daemon threads left. Can only produce other daemon threads

64
Q

User Thread

A

High-priority, will be allowed to fully execute

65
Q

@deprecated methods

threads

A

These methods are not recommended as can cause deadlock
suspend
resume
stop - ends thread execution (better if you change a flag to tell method to stop)

66
Q

deadlock

A

Situation where multiple threads are stuck forever

67
Q

Race Condition

threads

A

When mutliple threads race to access a shared resource, can lead to unintended ordering of data access

68
Q

Synchronization

threads

A

To use a sychronised section of code the lock is needed, meaning only 1 thread can access it at a time. defined by synchronized block or keyword

69
Q

Mutual Exclusion

Threads

A

The idea that only 1 thread can access a bit of code at a time

70
Q

Mutex Lock

A

The lock needed in order to access synchronized code

71
Q

atomic execution

threads

A

The order of threads does not affect the execution of instructions

72
Q

monitor

A

Any object that manages the states of threads. Contains:
special room - the only thread that can run sychronized code
wait room - Threads that have chosen to wait and must be notified to leave
Entry Set - threads that are ready to go into the special room

73
Q

Build Tool

A

Programs that automate the process of creating an executable application from code. Maven is a Java build tool

74
Q

Archetype

Maven

A

Template of a project used to make initial structure. Specifies the structure, dependencies and configuration of the project.

75
Q

POM

A

Project Object Model - XML file that contains the details about the project and configurations, dependencies and build settings

76
Q

POM plugins

A

set up plugin with version in < pluginManagmement> and configure settings in < plugins>. Represent add-ons to software tool, used in creation of software

77
Q

POM dependencies

A

Done in < dependencies> tags. External libraries used when compiling or running the software

78
Q

Uber jar

Maven

A

contains dependencies and source code, in 1 jar file. Uses Shade plugin

79
Q

JavaFX

A

Software platform for creating desktop application

80
Q

Stage

JavaFX

A

Top level container. Primary Stage automatically produced. Visually a window. Contains 1 active scene at a time

81
Q

Scene

JavaFX

A

Holds contents of a window. Contains 1 root node.

82
Q

Scene Graph

JavaFX

A

A tree made up of a scene and all of its contents

83
Q

Root Node

JavaFX

A

Parent of all other nodes in a scene

84
Q

Container

JavaFX

A

A non leaf node

85
Q

Widget/control

JavaFX

A

Leaf node

86
Q

#

JavaFX CSS file

A

Used when referring to ID of component, only used for 1 instance. ID of component set with component.setID(“ID”)

87
Q

.

JavaFX CSS file

A

Used when referring to class of component, which is applied to any instances of the class.

88
Q

FXML files

A

Contain visual representation of what is wanted on the screen. Special language for designing the GUI

89
Q

Lambda Expression

Java

A

object.condition((parameters) -> {
code
});

90
Q

Method Reference

Java

A

A Lambda expression which only calls another function. object.condition(class::method); where class is the class that the method is in

91
Q

var

Java

A

Used to simplify defining variables. Use var as the object type and it will still have the same type if it is implicit. This is only used in local variables

92
Q

Event Handler

java

A

an interface that specifies how an event is handled. node.setOnEvent(EventHandler) where the event handler is implemented as an anonymous class

93
Q

Observer Pattern

Java

A

An object that can choose to get updates from other objects

94
Q

Listener

Java

A

An implementation of an observer pattern (gains updates from other objects). An interface with one method

95
Q

Properties

Listeners

A

Allows for attaching listeners to variables. Property wraps the variable so when getter or setter called events can be triggered, and binders can be used

96
Q

Binding

Properties

A

Can link together some properties so when one is changed the other reflects the change

97
Q

Scheduler

A

Runs given code every so many milliseconds on a seperate thread

98
Q

Event

JavaFX

A

Something happening in the GUI, e.g. button press

99
Q

Animations

JavaFX

A

Can be done with transitions which are pre-made classes that extend the Transition class. ParralelTransition and SequentialTransition play a given list of animations. Can also make transition with a TimeLine

100
Q

Timeline

JavaFX

A

A type of animation for allowing customisation. Defined by giving it a set a keyframes which define the values of certain nodes at certains times. timeline.getKeyFrames().add(new KeyFrame(Duration.millis(number), new KeyValue (node.doSomething, byValue));
timeline.play

101
Q

Animation Timer

JavaFX

A

Abstract class with 1 method so can implement with lambda expression. The method is called every frame. Can be started and stopped

102
Q

Verification

Testing

A

Ensuring software implements a function correctly (is the thing done right)

103
Q

Validation

Testing

A

Ensuring software satisfies customer requirements (Is the right thing being done)

104
Q

White-Box Testing

A

Used to determine if methods/data structures work. The tester needs to know the internal structure.

105
Q

Black-Box Testing

A

Testing done without knowledge of internal structure. Tests outputs for given inputs.

106
Q

Unit Testing

A

White-box testing done on small isolated pieces. Done by developers

107
Q

Integration Testing

A

White/Black-Box testing done on a combination of larger and larger sections of code. Done by testers

108
Q

System Testing

A

Black-box testing for the entirety of the system. Done by all

109
Q

Unit Testing benefits

A
  • Early bug detection
  • Allows better decision making
  • Faster and safer
110
Q

seam

testing

A

Boundry between what is being tested and other classes being interacted with

111
Q

Stub

testing

A

A fake object with bare minimum methods. Used for state verification. Passes hard-coded values to a higher up in the program structure class

112
Q

Mock

testing

A

A fake object attempting to mimic the bahaviour of the real object. Used for verifying expected behavior

113
Q

Stub/Mock benefits

testing

A
  • Errors in the external class don’t cause issues
  • The external class doesn’t need to be implmented
  • The test is faster if the external class uses many resources
114
Q

Dependancy Injection

testing

A

The passing of an external fake object to a class being tested. The fake object and the real one implement the same interface

115
Q

Dependancy Injection Types

A
  • Passing the fake object in the constructor
  • Using an extension class to store the current object which can be settered and gettered
  • Create a factory class that returns the fake object
116
Q

JUnit

testing

A

Testing framework for Java

117
Q

Exception testing

JUnit

A

assetThrows(expectedException.class, () -> testedMethod) where the tested method is the method being tested

118
Q

Driver

Testing

A

A fake class that simulates behaviour of upper level modules.

119
Q

Using mock objects steps

Testing

A
  1. Set the method calls in the expected order for the mock object
  2. Set the mock to replay mode to allow execution of test
  3. Set to verify mode to check if the expected methods were called
120
Q

Top Down Integration

Integration Testing

A

Starts with testing high-level classes with stubs for the needed classes. The adds in these called classes and tests them together.

121
Q

Top Down Integration pros/cons

Integration Testing

A

Pros:
* Drivers easy to write as just user simulation
* Encourages early prototypes
Cons:
* Needs many stubs/mocks early
* Modules at bottom of hierarchy not tested in isolation

122
Q

Bottom Up Integration

Integration Testing

A

Tests lowest level modules in isolation. Add in modules that call the previous modules and test them together

123
Q

Bottom Up Integration Pros/Cons

Integration Testing

A

Pros:
* No/few stubs
* reusable low-level modules thoroughly tested
* Testing in parralel with development
Cons:
* Needs drivers, can be difficult to find where to start testing from
* Overall logic tested late

124
Q

Sandwich Integration

Integration Testing

A

Hybrid of bottom up and top down. Tests the top and bottom three layers of the program. More complicated but can mitigate problems of both individual solutions

125
Q

Big Bang Integration

Integration Testing

A

No incremental testing. Tests done in isolation and for the whole system. Good for smaller systems to save time. Issues found late and hard to pinpoint.

126
Q

scanf

C

A

scanf(“%type”, &variable). Stores the input of the given type in the given address

127
Q

Numbers viewed as boolean

C

A

Statements viewed as true if the value is non-zero

128
Q

sizeof

C

A

sizeof(variable) gives the number of bytes the variable takes up

129
Q

&

C

A

&variable gives the memory address of the variable

130
Q

Pointer

C

A

A variable that holds a memory address. When declared started with an * and the type determines what type the memory address is of.

131
Q

Pointer Value

C

A

Value stores at address in pointer is gotten with *pointer.

132
Q

*

C

A

Dereference Operator

133
Q

Moving Pointers

C

A

Changing a pointer increases its memory address by a factor of the number of bytes of the type it is storing.

134
Q

*pointer++

C

A

returns *pointer then increments *pointer by 1

135
Q

++*pointer

C

A

Increments the value of *pointer then returns the value

136
Q

malloc

C

A

malloc(bytes) - Returns a pointer at the beginning of some allocated memory of the given size

137
Q

failed allocation

malloc

A

May have NULL returned if memory is unable to be allocated

138
Q

free

malloc

A

free(pointer) - Frees up memory at the given pointer, otherwise will be locked, even after program finishes

139
Q

calloc

C

A

calloc(numberOfBlocks, sizeOfBlock) - Same as malloc but sets all bytes to 0

140
Q

Passing arrays to functions

C

A

Arrays are passed by reference.

141
Q

Ordering Functions

C

A

If a function is called before it’s defined and the value returned by the function hasn’t been declared than it is assumed to return an int. Functions can be written in reverse order of execution or declared before they are called. i.e. returnType name (parameters);

142
Q

Passing by reference for variables

C

A

Using a pointer to the variable can effectively accomplish this.

143
Q

Structure

C

A

Works like defining a new type that can store a collection of different data types. Can then be used to declare variables of the type i.e. struct structName varName;

144
Q

Structure Definition

C

A

struct name {
type member1;
type member2;
.
.
}

145
Q

Initialise members

C Structure

A

varName.member = value;

146
Q

typedef

C

A

Assigns an alternative name to a data type i.e. typedef oldTypeName newName. Written by replacing name of a declared variable with the new type name. If used on pointers removes the need to use the dereference operator (*) in decleration.

147
Q

typedef for structures

C

A

Additional alternative definition:
typedef struct {
type member1;
.
.
} newName