Programming Flashcards
What happens when a variable is declared?
- The compiler is told the data type for the values being stored (so that it knows how much space to reserve)
- The compiler is being told the identifier that you will be using to refer to that space in memory
What are constants and how do they work?
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.
What are the benefits of using constants?
- 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
What is a global scope?
It can be referred to anywhere in the program
What are features of local variables?
- 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
What is a parameter in a subroutine?
Part of the subroutine’s interface that allows values to be passed into the subroutine when it is called
What is an argument in a subroutine?
Value passed to a subroutine via a parameter
What is passing by value?
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.
What is passing by reference?
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.
What is exception handling?
Allows programmers to decide how a program should respond to the occurrence of an error that would otherwise lead to the program terminating abruptly.
What is a programming paradigm?
An approach to programming
What is procedural programming?
Type of imperative programming where programs are made up of “imperatives” what are run step-by-step
What does the structural approach to programming involve?
- 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
What are the advantages to the structured approach?
- 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
What is a hierarchy chart?
- 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
What are the advantages of subroutines?
- 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
What is a class?
The definition of an object. Classes define the attributes and methods that an object of the class will have.
What is an object?
A specific instance of a class resident in memory
What is instantiation?
The process of creating an instance of an object, belonging to a class, by invoking a constructor method
What is encapsulation?
Combing data with the procedures and functions that manipulate it to form a new data type
What are the properties of OOP?
- 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
What is information hiding?
Protects an object’s implementation and internal state from being accessed by other objects
What are the uses of information hiding?
Allows programmers to implement restrictions on how values are accessed and set. This is done through the use of access modifiers.
What are the access modifiers and their descriptions?
- 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 (#)
What is a getter method?
A method that returns the requested attribute value
What is a setter method?
A method that can modify the attribute’s value
Why do we use getters and setters?
They allow developers to implement additional checks before accepting or providing data.
What is inheritance?
Describes the relationship between classes where a derived “child” class gains the attributes and methods from a “parent” class
What is polymorphism?
When objects of different classes respond differently to the use of a common interface
What is the interface?
The collection of a classes public methods, attributes and its identifier
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
What are methods that can be overridden by a derived class called?
Virtual methods
What does an abstract method define?
The interface:
- identifier
- return type
- list of parameters
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