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
String Creation Heap Usage
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
26
valueOf
static method converts primitives to new String objects
27
trim
String method that removes leading and trailing whitespaces
28
JVM
Abstract description of an architecture (virtual hardware, memory layout, registers, ...) for implementing Java
29
Class Loader | JVM
Locates .class files. Verifies that they are well-formed classes. Loads them into Method Area, links and initialises class (static) variables
30
JVM Shared Memory
Contains 1 heap and 1 Method Area
31
JVM Non-shared Memory
Each thread has a Java Stack and Program Counter (no registers)
32
Java Stack | JVM
Holds state information for thread (e.g. called methods, storing local variables, parameters and doing calculations)
33
Execution Engine | JVM
Describes how bytecode is executed, and what should happen, in terms of the JVM instruction set. Separate instances for each thread
34
Method Area | JVM
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.
35
Method Area Structure | JVM
Often use method tables, each class has a table of pointers to methods that can be called on it, including from superclasses
36
Constant Pool | JVM
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)
37
Heap | JVM
Stores object, along with their (non-static) variables, including inherited ones. Each object has a pointer to it's class in the method area
38
Non-Shared Memory | JVM
Contains a program counter and a stack for each thread
39
JVM Program Counter
Points to instruction being executed in Method Area.
40
JVM Stack
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
41
Stack Frame local Variable (and parameters) Storage | JVM
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)
42
Operand Stack | JVM Stack Frame
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
43
Stack Frame Pointers | JVM
1. To its constant pool 2. To the code to go back to after it is done 3. To the exception table
44
Exception Table | JVM
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
45
Tail Recursion | JVM
If the last line of code is the recursive call then the same stack frame could be used. Java does NOT do this
46
Checked Exceptions
Exceptions that the compiler forces you to catch or defer
47
Unchecked Exceptions
Don't need to catch/defer exception as unchecked exceptions should not happen if the code is written properly. Includes runtime exceptions
48
Error
subclass of throwable indicating serious problem, unchecked
49
Finally | In try catch block
Final clause, always run
50
Static Variables
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.
51
Static Methods
Invoked in the class, not the object. Can only use static variables and methods
52
Final Variables
Can only be changed once when initialised if non-static, or only when declared if static
53
Extending Thread Class | to do threading
Overwrite the run method and call object.start.
54
Implementing Runnable Interface | to do threading
Write run method and then objects can be used in thread constructor. The thread can the be started.
55
Benefits of Runnable | for threading
Allows for a different class to be extended. Data is shared more easily as can call start on same thread multiple times
56
sleep | thread method
Thread sleeps for given milliseconds
57
thread priorities
Can use getter and setters to set priority, from 1-10
58
yield | thread method
Skips next slot of execution
59
interrupt | thread method
Wakes up sleeping thread, causing interruption
60
Java Thread States
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
isAlive | threads
Checks if thread is in the runnable state
62
join | thread
Waits for a specific thread to die before continuing
63
daemon thread
low-priority threads. JVM terminates if only daemon threads left. Can only produce other daemon threads
64
User Thread
High-priority, will be allowed to fully execute
65
@deprecated methods | threads
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
deadlock
Situation where multiple threads are stuck forever
67
Race Condition | threads
When mutliple threads race to access a shared resource, can lead to unintended ordering of data access
68
Synchronization | threads
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
Mutual Exclusion | Threads
The idea that only 1 thread can access a bit of code at a time
70
Mutex Lock
The lock needed in order to access synchronized code
71
atomic execution | threads
The order of threads does not affect the execution of instructions
72
monitor
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
Build Tool
Programs that automate the process of creating an executable application from code. Maven is a Java build tool
74
Archetype | Maven
Template of a project used to make initial structure. Specifies the structure, dependencies and configuration of the project.
75
POM
Project Object Model - XML file that contains the details about the project and configurations, dependencies and build settings
76
POM plugins
set up plugin with version in < pluginManagmement> and configure settings in < plugins>. Represent add-ons to software tool, used in creation of software
77
POM dependencies
Done in < dependencies> tags. External libraries used when compiling or running the software
78
Uber jar | Maven
contains dependencies and source code, in 1 jar file. Uses Shade plugin
79
JavaFX
Software platform for creating desktop application
80
Stage | JavaFX
Top level container. Primary Stage automatically produced. Visually a window. Contains 1 active scene at a time
81
Scene | JavaFX
Holds contents of a window. Contains 1 root node.
82
Scene Graph | JavaFX
A tree made up of a scene and all of its contents
83
Root Node | JavaFX
Parent of all other nodes in a scene
84
Container | JavaFX
A non leaf node
85
Widget/control | JavaFX
Leaf node
86
# | JavaFX CSS file
Used when referring to ID of component, only used for 1 instance. ID of component set with component.setID("ID")
87
. | JavaFX CSS file
Used when referring to class of component, which is applied to any instances of the class.
88
FXML files
Contain visual representation of what is wanted on the screen. Special language for designing the GUI
89
Lambda Expression | Java
object.condition((parameters) -> { code });
90
Method Reference | Java
A Lambda expression which only calls another function. object.condition(class::method); where class is the class that the method is in
91
var | Java
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
Event Handler | java
an interface that specifies how an event is handled. node.setOnEvent(EventHandler) where the event handler is implemented as an anonymous class
93
Observer Pattern | Java
An object that can choose to get updates from other objects
94
Listener | Java
An implementation of an observer pattern (gains updates from other objects). An interface with one method
95
Properties | Listeners
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
Binding | Properties
Can link together some properties so when one is changed the other reflects the change
97
Scheduler
Runs given code every so many milliseconds on a seperate thread
98
Event | JavaFX
Something happening in the GUI, e.g. button press
99
Animations | JavaFX
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
Timeline | JavaFX
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
Animation Timer | JavaFX
Abstract class with 1 method so can implement with lambda expression. The method is called every frame. Can be started and stopped
102
Verification | Testing
Ensuring software implements a function correctly (is the thing done right)
103
Validation | Testing
Ensuring software satisfies customer requirements (Is the right thing being done)
104
White-Box Testing
Used to determine if methods/data structures work. The tester needs to know the internal structure.
105
Black-Box Testing
Testing done without knowledge of internal structure. Tests outputs for given inputs.
106
Unit Testing
White-box testing done on small isolated pieces. Done by developers
107
Integration Testing
White/Black-Box testing done on a combination of larger and larger sections of code. Done by testers
108
System Testing
Black-box testing for the entirety of the system. Done by all
109
Unit Testing benefits
* Early bug detection * Allows better decision making * Faster and safer
110
seam | testing
Boundry between what is being tested and other classes being interacted with
111
Stub | testing
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
Mock | testing
A fake object attempting to mimic the bahaviour of the real object. Used for verifying expected behavior
113
Stub/Mock benefits | testing
* 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
Dependancy Injection | testing
The passing of an external fake object to a class being tested. The fake object and the real one implement the same interface
115
Dependancy Injection Types
* 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
JUnit | testing
Testing framework for Java
117
Exception testing | JUnit
assetThrows(expectedException.class, () -> testedMethod) where the tested method is the method being tested
118
Driver | Testing
A fake class that simulates behaviour of upper level modules.
119
Using mock objects steps | Testing
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
Top Down Integration | Integration Testing
Starts with testing high-level classes with stubs for the needed classes. The adds in these called classes and tests them together.
121
Top Down Integration pros/cons | Integration Testing
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
Bottom Up Integration | Integration Testing
Tests lowest level modules in isolation. Add in modules that call the previous modules and test them together
123
Bottom Up Integration Pros/Cons | Integration Testing
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
Sandwich Integration | Integration Testing
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
Big Bang Integration | Integration Testing
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
scanf | C
scanf("%type", &variable). Stores the input of the given type in the given address
127
Numbers viewed as boolean | C
Statements viewed as true if the value is non-zero
128
sizeof | C
sizeof(variable) gives the number of bytes the variable takes up
129
& | C
&variable gives the memory address of the variable
130
Pointer | C
A variable that holds a memory address. When declared started with an \* and the type determines what type the memory address is of.
131
Pointer Value | C
Value stores at address in pointer is gotten with *pointer.
132
* | C
Dereference Operator
133
Moving Pointers | C
Changing a pointer increases its memory address by a factor of the number of bytes of the type it is storing.
134
\*pointer++ | C
returns *pointer then increments *pointer by 1
135
++\*pointer | C
Increments the value of \*pointer then returns the value
136
malloc | C
malloc(bytes) - Returns a pointer at the beginning of some allocated memory of the given size
137
failed allocation | malloc
May have NULL returned if memory is unable to be allocated
138
free | malloc
free(pointer) - Frees up memory at the given pointer, otherwise will be locked, even after program finishes
139
calloc | C
calloc(numberOfBlocks, sizeOfBlock) - Same as malloc but sets all bytes to 0
140
Passing arrays to functions | C
Arrays are passed by reference.
141
Ordering Functions | C
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
Passing by reference for variables | C
Using a pointer to the variable can effectively accomplish this.
143
Structure | C
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
Structure Definition | C
struct name { type member1; type member2; . . }
145
Initialise members | C Structure
varName.member = value;
146
typedef | C
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
typedef for structures | C
Additional alternative definition: typedef struct { type member1; . . } newName