.111 15-20 Flashcards

1
Q

What does the volatile type do?

A

stops usual memory optimisation by telling it to not cache the variable value but to retrieve from memory as it may change

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

Define composition -

A

classes may hold attributes of class type

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

How does referencing work in java?

A

100% pass by value

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

What is a primitive type?

A

aka value types
= data itself is being accessed/modified/passed into a function
e.g. int, char, float, etc.

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

What is a reference type?

A

use object references to objects, reference is being accessed/modified
e.g. ObjectName

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

What does the this keyword do?

A

returns an object reference to the object instance which the current method is executing in

can be used to differentiate between object attributes and parameter’s w/ same name

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

What happens to java objects when they have no references?

A

get deleted

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

What is API documentation?

A

documentation of classes so other programmers can learn how to use them
JavaDoc = java standard

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

What are some standards in javaDoc?

A

begins w/ /** and ends **/ with * on each line between
@param/@return <varname> followed by explanation</varname>

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

How to automatically generate written documentation?

A

use javadoc -d doc name.java to generate web pages that can be found in index.html

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

What is swing?

A

standard java package for GUIs
- very large + flexible
- heavily OO
- platform independent!

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

How do components work in swing?

A

graphical components implemented as java classes
classes reside in javax.swing package (need to import)

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

What is a JFrame?

A

represents window in host OS (matches the style), inc. title bar + icons for minimise, resize, close, etc.
can be initialised w/ or w/o a title

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

What is JFrame automatically instantiated as?

A

JFrame.HIDE_ON_CLOSE + invisible

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

What is a static variable/method?

A

called on a whole class (all the objects, not just an instance)

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

What is a final variable?

A

cannot have its value changed after it has been initialised - like a constant

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

What holds a component in swing?

A

JPanel = holds a list of components
add new components via componentName.setContentPane(panelName);

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

What are some common components in swing?

A

JLabel, JButton + JTextField

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

What is a layout manager?
(Give examples)

A

provided by Swing to dynamically layout GUI components for you
e.g. FlowLayout, GridLayout + BorderLayout

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

What are pros + cons of layout managers?

A

efficient and help keep application flexible + platform independent
but limits control

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

What does FlowLayout do?

A

arranges components to best fit panel size (left-right, top-bottom)

  • dynamically changes so simple to use
  • lack of control other than specifying left/right/centre centring
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How do you set a layout manager?

A

instantiate a manager - e.g. FlowLayout layout = new FlowLayout;
then panel.setLayout(layout);

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

What does GridLayout do?

A

fits components in a fixed size matrix (specify rows + column as param. in layout instantiation)

  • good for repeating sets of components
  • little control
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What does BorderLayout do?

A

provide relative positioning of up to 5 components in north, south, east, west, center positions

  • a little more control
  • but only 1 component per region
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the best way to use layout managers while maintaining control?
give each panel its own layout manager (can specify positions manually but timely + not flexible)
26
Define event-based programming:
application registers interest in certain events where the environment informs the the application when they occur
27
What are listeners?
set to specific components to notify you when an event occurs and call the actionPerformed(ActionEvent e) function
28
How does it work if setting a listener to multiple components?
all components must match the type of listener (e.g. only buttons for an ActionListener) can use e.getSource() to see which component triggered the event
29
What is a merge conflict?
when someone else has updated the file on the git server as you have edited locally when this occurs, any files in conflict are updated w/ BOTH copies of lines of code that differ
30
What does git pull do?
receive updates from others + merge them into your local repo if the server version is more recent than your local version, will force you to pull before you can push
31
What does git status do?
shows untracked files + changes in tracked files to help figure out what needs to be committed
32
What does git push origin branch do?
shares commits back to the server so changes are visible to others origin = where you cloned repo from branch = what to push
33
What does git commit do?
saves changes to your copy of the repo (get copy via clone command) can add -m to label the update w/ a message
34
What is a personal access token?
used in place of a password for private github projects limits access to resources, selects a limited role + provides an expiry date - more secure
35
What is issue tracking (git)?
allows you to manage a list of requests of changes to your software useful for tracking bugs, synchronising workflow + feature requests
36
What is a repository branch?
like a named sub-copy of the repo that diverges at a given commit may merge back to main later
37
What is the main branch?
definitive true ver of your project code
38
Why use a separate branch?
developers normally create a branch to hold their changes when adding a new feature then merge once feature is complete + approved
39
What are some git commands for branches?
git branch - lists branches in repo git branch branch-name - creates new branch git checkout branch-name - switches to that branch git push origin branch-name - pushes branch to server git merge branch-name - merges branch into current branxh
40
What is repository fork?
deep copy of a repository - independent clone of the repo can be merged into the repo using merge requests
41
What are the benefits of forks?
- allows developers to experiment w/ changes w/o affecting original project - fork created on developer’s own account/organisation + can host new branches, commits, etc. like a normal repo
42
What is a merge request?
code is from a non-collaborator so needs review + control before it is merged into repo so request used typically helpful in open-source projects
43
What is the process of a merge request?
- anyone w/ a fork can request a fork branch to be merged - repo collaborators can then review the changes + communicate w/ the person - collaborators accept/reject request
44
What is continuous integration?
software development practice where developers regularly integrate their code changes into a central repository and each integration is verified by an automated build + automated tests
45
Benefits of CI:
- detect + fix integration issues early - ensures code quality + readability
46
What is continuous development?
next step in CI/CD pipeline - automates deployment process + reduce manual intervention for faster + more reliable software delivery
47
What are the CI workflow steps?
- developer pushes changes to version control system - CI server detects changes + triggers automated build and test process - results reported back to developer
48
What is inheritance?
provides mechanism to promote reuse + extensibility code written by 1 programmer + delivered as a class can then be extended by another to suit the needs of the task at hand
49
What are the inheritance relationships?
base/super/parent class = class being extended subclass = new class typically allowed multiple subclasses for 1 super class but can have multiple super classes for 1 subclass in multiple inheritance languages (C++ & Python)
50
Benefits of inheritance:
- allows class attributes + methods to be accessed/invoked on the new class w/o explicitly defining them - new class can also have further capabilities added w/o affecting original class (specialise for reuse)
51
How do you write inheritance in java vs C++?
java = public class Subclass extends SuperClass C++ = class Subclass : public SuperClass (public accessor makes all public methods/attributes public in new subclass too)
52
What does super() do in java?
calls constructor of that subclass' super class needs to be 1st line of subclass constructor w/ param
53
How is inheritance transitive?
subclasses can become super classes of other classes and they will inherit from the subclasses’ super class too
54
What is an inheritance hierarchy?
tree structure used to map out inheritance relationships as you go up the hierarchy, we get more generalist + abstract, e.g. mammal as you go down, we get more specialist + specific, e.g. humpback whale
55
What is an abstract class?
class designed to be extended (inherited) not actually used for objects e.g. public abstract class ClassName
56
What happens if you try create an instance of an abstract class?
compile time error
57
What is an abstract method?
placeholder method only allowed within an abstract class that subclasses override to use
58
Why use abstract methods?
ensures all subclasses have an implementation of that method when it's unnecessary to write an implementation for that high a level of abstraction
59
What is the difference between polymorphism + method overriding?
polymorphism is a subclass assigned its parent class as a reference but acting differently method overriding is just a subclass acting different to its parent
60
What is constructor chaining?
when subclass uses super() but so does its parent
61
What is the C++ equivalent of super()?
adding : ParentName (param) to constructor declaration
62
Define polymorphism:
to take many forms e.g. that a subclass has all behaviour of their superclass and thus can be treat as a type of their superclass!
63
What is special with parent class object references?
can refer to subclasses as they at least have same methods + variables full backwards compatability!!
64
How does casting apply in inheritance?
can cast between types of object references IF the underlying object is the same class/subclass you're casting to only object reference changes NOT instance!!
65
What is an interface?
named specification of 0 or more methods but only contains desc. of method not actual implementation/functionality
66
What do interfaces help bypass?
classes can implement multiple interfaces so bypasses limitations of single inheritance languages' inheritance based polymorphism
67
What is an example of an interface?
ActionListener containing the actionPerformed() method
68
Can polymorphism apply to interfaces?
YES, class will have capabilities defined in interface so can treat class as a type of the interface/s it implements
69
How to create your own interface?
public interface Name { } where rest follows class procedure so methods go inside braces + name must match filename
70
How does a class declare its using an interface?
class ClassName implements InterfaceName { }
71
Why are custom interfaces helpful?
allow you to define what other programmers must do in order to interface w/ your code so your code can support working w/ objects that haven’t even been written yet
72
How does casting relate to the inheritance hierarchy?
java implicitly casts object references as necessary going up the hierarchy (to parent) can only cast down explicitly though this is dangerous!
73
What is method overriding?
used to change behaviour by replacing a method in the superclass by redefining within subclass
74
How does method overriding apply w/ reference casting?
method called will always be the most specific (lowest in the hierarchy) applicable to that object instance regardless of reference casting
75
What is method overloading?
defining multiple methods w/ the same name but diff. parameter lists to create diff. functionalities
76
How is a method identified in java?
by class, name + param list where name + param list = method signature
77
How do you write a foreach loop in java?
for(type varName : arrName) - iterate foreach var of type in array more readable + don't need counter
78
What do diff. type java arrays initialise to at each index?
string + object arrays = null NOTE - object arrays hold a reference to the object not the actual object int array = 0
79
How do you write a 2D array in java?
int[][] arr = { {1, 2, 3, 4}, {5, 6, 7, 8}}; OR int[][] arr = new int [2][4];