Programming Flashcards

1
Q

What happens when a variable is declared?

A
  1. The compiler is told the data type for the values being stored (so that it knows how much space to reserve)
  2. The compiler is being told the identifier that you will be using to refer to that space in memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are constants and how do they work?

A

Constants are named references to literal values. When the program is complied, any references to the constants are replaced by actual values in machine code.

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

What are the benefits of using constants?

A
  • The code becomes easier to understand as descriptive labels are used instead of values
  • The code is easier to maintain as a constant’s value can be changed in one place
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a global scope?

A

It can be referred to anywhere in the program

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

What are features of local variables?

A
  • Their value cannot be accessed or modified from outside the subroutine
  • Their identifier can be reused in other subroutines
  • only stored in memory when the subroutine is being executed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a parameter in a subroutine?

A

Part of the subroutine’s interface that allows values to be passed into the subroutine when it is called

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

What is an argument in a subroutine?

A

Value passed to a subroutine via a parameter

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

What is passing by value?

A

A literal value or copy of a data structure is given to the subroutine. A change made to this copy does not have any effect on the original.

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

What is passing by reference?

A

The subroutine is given a pointer to the address of the value/object in memory. If changes are made to the referenced value or data structure, they change the original so the change persists after the subroutine has finished.

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

What is exception handling?

A

Allows programmers to decide how a program should respond to the occurrence of an error that would otherwise lead to the program terminating abruptly.

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

What is a programming paradigm?

A

An approach to programming

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

What is procedural programming?

A

Type of imperative programming where programs are made up of “imperatives” what are run step-by-step

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

What does the structural approach to programming involve?

A
  • Organising into subroutines and modules
  • Using hierarchy charts to break programs down
  • Storing data in variables and constants that have meaningful identifiers
  • Programming to the interface
  • Using local variables instead of global ones
  • Using indentations, spacing and comments to make code easier to follow
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the advantages to the structured approach?

A
  • Subroutines and modules can be individually tested
  • Modules contains code for related subroutines helping developers find and identify the code they need
  • Indented code is easier to read
  • Comments explain how the program works
  • Meaningful identifiers make the code easier to understand
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a hierarchy chart?

A
  • A diagram showing the structure of a program using a top-down approach
  • Breaks system down layer-by-layer into components and processes
  • Each box contains a label / description for each process
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the advantages of subroutines?

A
  • Each subroutine can be tested separately
  • Meaningful identifiers make the code easier to understand
  • Code easily reused
  • Easier to maintain as code only needs to be changed once within the subroutine
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a class?

A

The definition of an object. Classes define the attributes and methods that an object of the class will have.

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

What is an object?

A

A specific instance of a class resident in memory

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

What is instantiation?

A

The process of creating an instance of an object, belonging to a class, by invoking a constructor method

20
Q

What is encapsulation?

A

Combing data with the procedures and functions that manipulate it to form a new data type

21
Q

What are the properties of OOP?

A
  • Entirely modular approach
  • Everything implemented as objects composed of attributes/properties and methods
  • Data and code that acts on the data are kept together and controlled via methods that comprise the interface
22
Q

What is information hiding?

A

Protects an object’s implementation and internal state from being accessed by other objects

23
Q

What are the uses of information hiding?

A

Allows programmers to implement restrictions on how values are accessed and set. This is done through the use of access modifiers.

24
Q

What are the access modifiers and their descriptions?

A
  • Public: accessed by objects of any other class (+)
  • Private: accessed only by objects of that class (-)
  • Protected: accessed by other objects of the class or subclass (#)
25
What is a getter method?
A method that returns the requested attribute value
26
What is a setter method?
A method that can modify the attribute’s value
27
Why do we use getters and setters?
They allow developers to implement additional checks before accepting or providing data.
28
What is inheritance?
Describes the relationship between classes where a derived “child” class gains the attributes and methods from a “parent” class
29
What is polymorphism?
When objects of different classes respond differently to the use of a common interface
30
What is the interface?
The collection of a classes public methods, attributes and its identifier
31
What is overriding?
- When a method is defined in a derived class with the same identifier as a method from the base class but is given a different implementation/ performs a different function - Redefined method will be used instead of the base’s method when called
32
What are methods that can be overridden by a derived class called?
Virtual methods
33
What does an abstract method define?
The interface: - identifier - return type - list of parameters
34
What are the differences between a virtual and abstract class?
- Virtual can be overridden but abstract must be overridden - Virtual have an implementation but abstract do not - Virtual can be declared in any class but abstract can only be defined in abstract classes
35
What is object association?
Occurs when an object contains or has a reference to another object within it. Often described as a “has a” relationship.
36
What are the two forms of association?
- Composition - “strong” - Aggregation - “weak”
37
What is composition?
It is a restricted form of association where one object contains another. If the container object is deleted, the contained object/s are also deleted.
38
How is composition shown on a UML class diagram?
A line with a solid black diamond on the container
39
What is aggregation?
Type of relationship where one class contains another class. However the aggregated objects independently of the aggregating object and will not be deleted if the aggregating object is.
40
How do you represent aggregation in UML class diagrams?
A line with a hollow diamond on the aggregating
41
How do you represent inheritance in a UML class diagram?
A filled arrow going from the derived class to the base class
42
What are the 3 OOP design principles?
1. Encapsulate what varies 2. Favour composition over inheritance 3. Program to the interface, not implementation
43
What does the design principle “encapsulate what varies” mean?
- Encapsulate parts of our program that frequently changed or updated into classes - Ensures modules are loosely-coupled - Modifications can be tested within the class itself and has minimal impact on the rest of the program
44
What does the design principle “favour composition over inheritance” mean?
- Composition isn more flexible and allows for complex functionalities by combining component objects - If class A requires functionality of class B, it is best to give class A an instance of class B rather than inheriting from it
45
What does the design principle “program to the interface, not implementation” mean?
- To write loosely-coupled code our objects should be designed to only interact with other objects via their interface - This allows for implementation to be changed without affecting the rest of the program
46
What is a static method?
A class method that can be called / invoked without the need to instantiate and object of that class
47
What are the uses of static methods?
- Provide functionality that is related to a class but doesn’t rely on the internal state of an instance of a class - Used for creating “Utility Classes” that creates lots of utility classes