1 - Fundamentals of Programming Flashcards

1
Q

Describe how the Call Stack grows and shrinks in size during the execution of a program.

A

When a subroutine is called, the Stack grows as a new Stack Frame is added on top for the new activation. When a subroutine call ends, the Stack shrinks as the relevant Stack Frame is popped off the Stack.

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

State three pieces of information that are stored for each active subroutine in the call stack. For each one, explain the purpose of storing them in the call stack.

A

• Parameter values - these are local to the current subroutine call. When the subroutine ends, the values of the parameters are no longer needed.
• Local variable values - same reason as for parameter values.
• Return address - this could be different depending on which line of code the subroutine was called from. Therefore it needs to be stored each time the subroutine is called/activated.

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

Why does the Call Stack follow a stack data structure (only access the item on top)?

A

Nested subroutine/procedure calls work in such a way that the most recent one to be called will be the first one to finish/return. This makes it fit perfectly in a LIFO (Last in First out) data structure.

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

What is a subroutine?

A

A self-contained block of code which has an identifier. It can be called from other parts of the code. They can have parameters, local variables and can return a value. A call to a subroutine is a statement in it’s own right.

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

What is the definition of an array?

A

An array is a fixed-sized collection of data elements, all of the same type, under a single variable name. To access an element, both the array name and that element’s index is required. Indices start at 0.

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

What is meant by the term Global Variable?

A

Global variables are declared outside of any subroutine and are accessible to all subroutines.

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

What is the purpose of the heap?

A

The heap is a pool of unallocated memory used for dynamic memory allocation and storing objects and data with size only known at runtime.

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

Describe how the heap grows and shrinks in size during execution of a program.

A

When an object is created, memory is dynamically allocated for it - the heap grows in size. When all references to an object no longer exist, the memory is freed back to the pool - the heap shrinks.

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

What are the similarities and differences between a primitive variable and an object reference (pointer) variable?

A

Similarities:
• They can both be stored in the Call Stack.
• They both have a fixed size.
• They are both variables.
• They both have identifiers in the code.

Differences:
• Primitive variables store data, whereas object reference variables store memory references to actual data in the heap.

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

What is a variable?

A

Primitive variables have a fixed size and are stored in the stack (in the stack frame for a subroutine). Space in memory for them is allocated before the code is run.

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

How are objects stored?

A

Objects are stored in the heap, and have an object reference which is stored in the stack which “point” to the object’s location in the heap. Objects can vary in size as the program is running so they need memory allocated dynamically.

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

In relation to OOP, what does Protected mean?

A

It is an access modifier. The modified code element can only be accessed within the defining class or a class derived from it.

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

What is an access modifier?

A

Access modifiers are used to restrict code elements from use by other parts of the code. They can be applied to class, variable, and procedure/function definitions.

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

What is a constructor?

A

A constructor is a special procedure which is run when an object is first created.

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

The main concept behind OOP is encapsulation. What does this mean?

A

Encapsulation is the idea of combining properties and methods together and being able to restrict access to an object’s data/functions.

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

What is a programming paradigm?

Give some examples of programming paradigms.

A

A general style of writing code.

• Imperative
• Declarative
• Functional
• Event Driven

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

What is the difference between a class and an object?

A

A class is a template that specifies the data fields and methods. Whereas an object is a specific instance of a class.

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

What is meant by instantiation?

A

Instantiation is where you create an object from a class.

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

Explain what is meant by overriding when writing programs that involve inheritance.

A

An inherited method can be redefined so that it still has the same name but a different implementation. The redefined method will be used instead of the parent’s method.

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

What is polymorphism?

A

When there is a method in a derived class which has the same name, but a different behaviour/implementation.

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

What is an abstract method?

A

A method with a name, parameter list and return type but no implementation. It must be overridden in the first non-abstract derived class. Abstract methods can only exist in abstract classes.

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

What is an abstract class?

A

A class which cannot be instantiated. It usually contains at least one abstract method.

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

Why do many programmers follow the design principle “favour
composition over inheritance”

A

Easier to test each class using unit testing
There can be unintended side-effects for derived classes if a method in
the base class is altered;
Composition is more flexible as if a new class is developed it can easily
be used instead of the class that currently is used in the composition

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

What are the object oriented design principles?

A

• Encapsulate what varies - separate (i.e. put it its own class) the parts that may be subject to change from the parts that will stay the same
• Favour composition over inheritance - favour using aggregation or composition to combine existing objects to make new ones, rather than using inheritance
• Program to interfaces, not implementation - allows programming to an abstraction and not an implementation;

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

What is meant by a base case for a recursive subroutine?

A

The circumstances where a recursive subroutine does not call itself

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

What is a structure?

A

a data structure that consists of a fixed number of variables/ called fields. Every field has an identifier (field name) and a data type.

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

What is another name for a structure?

A

record

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

What is an exception

A

An unexpected event that occurs during runtime

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

What is exception handling

A

refers to how the program deals with and prevents crashes resulting from exceptional circumstances

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

What is a TRY CATCH statement

A

A exception handling statement which allows the program to respond to an exceptional input and instead conduct another method.

31
Q

What is an identifier?

A

The unique name given to a variable/ function/ procedure etc.

32
Q

What is a variable

A

A memory location that contains one or more data values which could change during runtime

33
Q

What is a local Variable

A

A variable that can only be accessed in the subroutine it was declared in and only exists while that subroutine is executing

34
Q

What is a Global Variable

A

A variable that can be accessed and used anywhere in the program

35
Q

What is an Exception

A

An error that causes the program being executed to stop (crash)

36
Q

What is a Constant

A

A memory location that contains a value which does not change during runtime

37
Q

What is a Subroutine

A

A named group of statements/instructions that can be called “out of line”

38
Q

What is a Function

A

A subroutine that returns exactly one value

39
Q

What is a Procedure

A

A subroutine that returns none/ one or more values

40
Q

What is an Interface

A

A programming structure that defines a method that must be implemented/ its parameters and its return values

41
Q

What is A class

A

A template used to create objects

42
Q

What is An Object

A

an instance of a class

43
Q

What is a Inheritance

A

The relationship between two object types in which one is a kind of the other and shares some of its properties or methods

44
Q

What is overriding

A

When a subclass uses its won implementation of a method rather then one defined by a parent class

45
Q

What is a Constructor

A

A method for instantiating an object in a class.

46
Q

Abstract class

A

a class that only exists in a model so subclasses can inherit from it

47
Q

What is a static class

A

a static class cannot be instantiated.

48
Q

What is Private

A

Only code within the class can access this variable or method

49
Q

What is Public

A

Code that can be accessed by any class

50
Q

What is Protected

A

Only code within the class and derived class can access it

51
Q

Virtual Methods

A

a virtual method allows for overrides in child classes

52
Q

Static Method

A

A method without having to be instantiated

53
Q

Abstract Method

A

A method that has no implementation. Only provides the requirement to be written into a child class

54
Q

What is composition

A

The relationship between classes linked with instances of another class inside them. This causes these instances to cease to exist once the superclass is deleted. It is a part of relationship.

55
Q

What is aggregation

A

The relationship between classes where if one class where to be deleted/ the other class would not cease to exist. It is a has a relationship.

56
Q

What is a procedure

A

a named block of code that performs a specific task/ but does not return

57
Q

What is a function

A

a named block of code that has the purpose of returning a value (called the ‘return value’).

58
Q

Parameter

A

It is a placeholder for any value that a subroutine uses when it is called.

59
Q

Interfaces

A

A subroutine interface is the method by which data is passed into and out of a subroutine through parameters and return values.

60
Q

Reference

A

When an argument is passed to a subroutine by reference/ this creates a pointer which contains the memory address of the original variable. Therefore/ any change to the parameter within the subroutine also affects the value of the original variable.

61
Q

By value

A

When an argument is passed to a subroutine by value/ the parameter created for the subroutine is a copy of the original argument.

62
Q

Global Variable

A

A global variable can be accessed anywhere in a program.

63
Q

Advantages subroutines

A

Easy to test/ easier to read/ can be reused easily.

64
Q

4 reasosns why it is bad practice to use global variables

A

Debugging is difficult/ accidental changes are common/ they need to be preserved in memory until the program has stopped running.

65
Q

What is exception handling

A

the way that a program handles exceptional circumstances. Without it the program would crash

66
Q

Types of test data

A

normal boundary erroneous

67
Q

What is normal test data

A

Values that you would except to be entered

68
Q

What is erroneous data?

A

Values that should be rejected when they are entered

69
Q

what is boundary test data

A

values that are just inside the boundary that should be accepted/ and values just outside the boundary that should not be

70
Q

What is a text file

A

All data is stored as strings / ASCII values

71
Q

What is a binary file

A

All data is stored using different data types.

72
Q

What is a recursively defined procedure

A

A procedure that is defined in terms of itself

73
Q

What is a base case

A

The base case is a stopping condition

74
Q

What is a general case

A

General case is the statement in which the subroutine calls itself.