Programming Interview Questions Flashcards

1
Q

What is Object Oriented Programming?

A

A computer programming model

Organises software design around data and objects, rather than functions and logic

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

What are the benefits of OO Programming?

A

Beneficial for collaborative development

Code reusability, scalability and efficiency

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

What is a class?

A

User-defined data types

Act as the “blueprint” for objects, attributes and methods

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

What is an object?

A

Instances of a class, with specifically designed data

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

What are the main principles of OOP?

A

Encapsulation

Abstraction

Inheritance

Polymorphism

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

What is Encapsulation?

A

All important info is privately contained inside of an object

Each object is held privately within a defined class

Provides greater program security and avoids unintended data corruption

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

What is Abstraction?

A

Objects only reveal internal mechanisms that are relevant for the use of other objects - focuses on what an object does rather than how it does it

Simplifies complex systems by modelling them at a higher level of detail while hiding unnecessary implementation details

Helps developers easily make additional changes over time

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

What is Inheritance?

A

Classes can reuse code from other classes.

Allows developers to reuse common logic while maintaining a unique hierarchy

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

What is Polymorphism?

A

The ability to present the same interface for different data types (e.g. 1 method “Draw” for multiple children Square, Circle of a “Shape” class).

Reduces need for duplicate code

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

Examples of mainly OOP languages?

A

Java, Python, C++

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

Examples of pure OOP languages?

A

Ruby

JADE

Emerald

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

Downsides of OOP?

A

Overemphasises data component of software development

Can be complicated to write or take longer to compile

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

Alternative to OOP?

A

Functional programming e.g. Erlang

Many advanced programming languages allow users to combine models, e.g. JavaScript allows the combination of OOP and functional programming

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

What are design patterns?

A

Common and reusable solutions to problems given a certain context

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

What are anti-patterns?

A

“Bad” design patterns

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

Benefits & risks of design patterns?

A

Proven solution

Reusable

Expressive and Elegant

Prevent need for refactoring code

Lower size of codebase

Risk: might fall back on design pattern when there’s a better way to solve this particular problem

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

How many design patterns are there?

A

23

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

Types of software design patterns?

A

Creational

Behavioural

Structural

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

What are Creational Design Patterns?

A

Used for class instantiation

They can be Class creation or object-creational patterns

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

What are Structural Design Patterns?

A

Used for communication between objects

Designed to increase functionality of the classes involved

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

What are Behavioural Design Patterns?

A

Design Patterns that focus on how objects communicate and interact with each other

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

What are the architectural design patterns?

A

MVC Model View Controller

MVP Model View Presenter

MVVM Model View View Model

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

Describe MVC

A

Model = backend logic and data

View = interface components to display data

Controller = Input is directed here first

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

Benefits & risks of MVC

A

Provides separation of concern, separating front-end and back-end code

Makes it easier to update the application without interruption

Exposing the model to view can introduce security and performance concerns

Common for web apps

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

Describe MVP

A

Model = backend logic and data

View = input begins here

Presenter = processes request through the model and passes it back to the view

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

Benefits & risks of MVP

A

Common for Android apps, websites

Suited to make views reusable

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

Describe MVVM

A

Model = backend logic and data

View = input begins here

View-Model = only purpose is maintain the state of view and manipulate the model

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

Benefits & risks of MVVM

A

Used for mobile apps

Suited to help improve performance

Allows view-specific subsets of a model to be created, with the state and logic bound to the view.

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

What is a constructor?

A

A method used to initialise the state of an object

Method is called whenever an object is created

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

What is a destructor?

A

A method called when the object is destroyed

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

What is a virtual function?

A

A member function of a class

Its functionality can be overridden in its derived class

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

What is function overloading?

A

allows you to define multiple methods in a class with the same name but with different parameter lists.

Each overloaded method provides a different implementation of the same functionality

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

What is an abstract class?

A

A class that cannot be instantiated

Serves as a blueprint for other classes to inherit from

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

What is a ternary operator?

A

Equivalent to an if/else statement

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

What is the finalize method?

A

Performs cleanup on resources not being used

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

What are the argument types?

A

Call by Value - value passed only modified inside function

Call by Reference - value passed modified both inside and outside

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

What is method overriding?

A

Where a subclass’s method overrides the main class’s method. Uses same method name, parameter and type.

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

What is the difference between overloading and overriding?

A

Overloading is the same method with different arguments, overriding is a different method with the same argument in a child class

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

What are the access modifiers?

A

Private

Protected

Public

Friend

Protected Friend

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

What is a “sealed” class?

A

Access modifier which prevents other classes from inheriting from it.

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

How to call the base method without creating an instance?

A

Use static method

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

What is the difference between a structure and a class?

A

Structures are public by default and only stores data, classes are private and can store data and methods.

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

What is a pure virtual function?

A

A function which must be overridden in the derived class, but need not be defined.

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

What is the default access modifier in a class?

A

Private

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

What is coupling?

A

The degree of dependency of one class on another class; the ‘strength of relationship’ between modules.

Loose coupling is usually better than tight coupling

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

What is Loose Coupling?

A

Loose coupling = less interdependency, less coordination, less information flow.

Classes A and B are said to be ‘loosely coupled’ if the only knowledge that class A has about class B is what class B has exposed through its interface.

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

What is cohesion?

A

A measure of strength of relationship between the methods and data of a class

High cohesion is usually better than low cohesion

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

What are extension methods?

A

Allow you to add methods to existing types without creating new derived types, modifying the original code or using inheritance.

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

What is a static method?

A

A static method is a method that belongs to a class rather than an instance of a class, meaning you can call a static method without creating an object of the class.

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

What are some example of what you’d use Static methods for?

A

Mathematical operations, string manipulation methods, helper functions.

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

What are the programs in javascript called, and what is special about them?

A

They are called scripts

They are provided and executed as plain text, and don’t need special preparation or compilation to run.

52
Q

What are browser engines, and how do they work?

A

Browsers have embedded engines, sometimes called a “Javascript Virtual Machine”, that:
1. Reads (parses) the script
2. Converts (compiles) the script to machine code
3. Runs the machine code.

53
Q

What is Node.js?

A

A Javascript runtime environment

54
Q

What is a runtime environment?

A

A software platform (e.g. operating system, web browser) that provides an environment for running code

55
Q

Explain the difference between tuples, arrays and lists in C#

A

An array is an ordered data structure that can store multiple variables of the same type.

A tuple is an ordered data structure that contains a sequence of elements of different data types, and can only contain 8 elements.

A list is an ordered data structure that represents a strongly typed list of objects.

56
Q

How to include more than 8 elements in a tuple C#?

A

Use nested tuples

57
Q

What is a jagged array?

A

An array of arrays

58
Q

What is the difference between a strongly typed and weakly typed programming language?

A

A strongly typed programming language, for example C#/python, is one in which the specification of data types is demanded.

Strongly typed languages are more likely to require explicit conversion

A weakly typed programming language, for example Javascript, does not require the explicit specification of different types of objects and variables, and can execute implicit type conversions at runtime.

59
Q

Give an example of a difference between weakly and strongly typed programming languages.

A

Imagine comparing a string and number value. In C#, this will not compile as there’s a type mismatch. In Javascript, this code will compile and implicit conversion from the integer to a string will occur.

60
Q

Benefits and weaknesses of strongly and weakly typed programming languages?

A

Strong typing enforces a rigid set of rules, increasing consistency

Leads to faster development through detecting errors earlier and better optimised code from the compiler

However, using strong typing means that a programmer may lose flexibility

61
Q

What is a compiler?

A

A special program that translates a programming language’s source code into machine code (or another programming language).

62
Q

Implicit vs Explicit conversion?

A

explicit type conversion is when the programmer intentionally changes the data type of a value. Explicit conversions have a risk of losing data, e.g. when converting a double to an int.

implicit type conversion is when the compiler automatically changes the data type of a value

63
Q

explain what an Enum is in c#

A

An enum is a value type that represents a group of constants. Enums can be used to define options for config settings, etc.

64
Q

What are the differences between reference types and value types?

A

Value types represent actual data values and are stored directly in memory where they are declared

Reference types store ‘addresses’ to where the actual data is located in memory. When you create a variable of a reference type, the variable stores a reference to the data, not the data itself.

65
Q

Where are reference and value types typically stored?

A

Reference types are typically stored on the heap in memory, whereas value types are stored on the stack

66
Q

What’s the difference between copying a value type and copying a reference type?

A

Copying a value type gives a copy of the actual data. Copying a reference type gives you a copy of the reference to the same data.

67
Q

What’s the difference between a generic repository and normal repository in C#?

A

A normal repository implements its own specific methods for each entity type it deals with, whereas a generic repository provides a generic interface for CRUD operations that can be used with any entity type.

68
Q

What does PostGIS do?

A

Extends capabilities of PostgreSQL relational database by adding support for storing, indexing and querying geographic data

69
Q

In database design, what is a table?

A

A table is a structure that contains data

70
Q

In database design, what is a view?

A

You can think of a view as a saved ‘SELECT’ statement that you can repeat. A view can join data from several tables.

71
Q

What is the point of design patterns?

A

All patterns provide a way to let some part of a system vary independently of other parts

72
Q

What are the SOLID principles?

A

The SOLID priniciples are:

Single Responsibility Principle

Open/Closed Principle

Liskov Substitution Principle

Interface Segregation Principle

Dependency Inversion Principle

73
Q

Explain the Single Responsibility Principle

A

Each class should do one thing only and have only one reason to change.

74
Q

Explain the Open/Closed Principle

A

Open for extension, closed for modification

Open: designing components in a way that allows them to be extended or enhanced without modifying their existing code

Closed: Once an entity is defined and implemented, its behavious should remain stable and not be altered

Watch out for switch statements!

75
Q

Explain the Liskov Substitution Principle

A

Objects of a superclass must be replaceable with objects of its subclasses

76
Q

Explain the Interface Segregation Principle

A

Code should not be forced to depend upon methods it does not use

Watch out for large interfaces!

77
Q

Explain the Dependency Inversion Principle

A

High-level modules should not depend on low-level modules, both should depend on abstractions.

78
Q

What is the difference between inheritance and composition

A

Composition is a “has a” relationship, Inheritance is an “is a” relationship

Composition is achieved by instantiating variables of other objects, whereas Inheritance is achieved by extended classes

79
Q

Benefits of composition

A

Composition is loosely coupled

Composition has access control

composition is easier to unit test

80
Q

Downsides of inheritance

A

inheritance is tightly coupled

the structure of the parent is forced upon the child

81
Q

What is the difference between compile time and runtime?

A

Compile time: the period where the programming code (e.g. C#) is being converted to machine code (e.g. binary), where syntax and semantics of the code are checked

Runtime: the period where a program is running (and generally occurs after compile time)

82
Q

Explain the repository pattern

A

The repository pattern is a design pattern.

It provides an abstraction layer between the business logic of an application and the data storage mechanisms.

83
Q

What does the repository pattern interface specify?

A

What operations (methods) are supported by the repository

What data (parameters) are required for each operation

The repository interface contains what it CAN do, but not HOW to do it.

The implementation details are in the respective repository class that implements the repository interface.

84
Q

Explain the unit of work pattern

A

The Unit of Work pattern is a design pattern.

It helps to maintain consistency and integrity of data operations by managing transactions and coordinating multiple database operations within a single unit of work.

In the unit, either all operations succeed and are committed, or none of them are applied and they are rolled back.

85
Q

Explain the difference between “scoped”, “singleton” and “transient”

A

In the context of dependency injection containers, these refer to different lifetimes of the services that the container manages

Transient: these services are created each time they are requested; a new instance of the service is created each time it’s resolved from the Dependency Injection container. Transient objects are always different, a new instance is provided to every controller and every service.

Scoped: these services are created once per request or usage scope; this means that a single instance of the service is created and shared within the scope of a single HTTP request (in the case of web applications). Scoped objects are the same within a request, but different across different requests.

Singleton: these services are created once and shared across the entire application lifetime. This means that a single instance of the service is created when it’s first created, and that same instance is reused for all subsequent requests. Singleton objects are the same for every object and every request.

86
Q

What are scoped services used for

A

For components that need to maintain state across multiple operations within the same scope, such as database contexts in web applications.

87
Q

What are transient services used for

A

For scenarios where a new instance is needed for each use

88
Q

What are singleton services used for

A

For stateless (no internal data that changes over time) and thread-safe components that be can shared safely across the application, such as configuration settings

89
Q

What are the benefits of the repository pattern?

A

Code cleaner and easier to maintain

Enables creation of loosely coupled systems

When unit testing, easy to replace a real repository with a fake implementation for testing

90
Q

What is LINQ?

A

LINQ is a set of technologies based on the integration of query capabilities directly into the C# language.

91
Q

What is SQL?

A

SQL stands for ‘structured query language’. SQL is used to query and manipulate the underlying relational databases, e.g. PostgreSQL

92
Q

What is PostgreSQL?

A

An open-source object-relational database system based on POSTGRES

93
Q

Explain what an inner join is

A

An inner join is a type of join operation used in relational databases to combine rows from two or more tables based on a related column between them. The inner join selects only the rows from both tables that have matching values in the specified column(s), excluding rows where there is no match.

94
Q

Explain what a left outer join is

A

Returns all records from the left table, and matching records in the right table

95
Q

Explain what a full outer join is

A

Combines the result of left and right outer join

96
Q

Explain what a cross join is

A

Produces the cartesian product of rows between 2+ tables

97
Q

What is a primary key?

A

A primary key is a special relational database table column (or set of columns) that uniquely identifies each row in the table. It allows for efficient data retrieval, indexing and referencing between tables

98
Q

What are the key characteristics of a primary key?

A

Uniqueness

Non-nullability

Immutable (should not change once assigned to a record)

Indexed (typically indexed by database management system for faster lookup and retrieval operations)

Foreign key references

99
Q

What is a foreign key?

A

A foreign key is a column (or set of columns) that establishes a link between data in two tables

100
Q

What is dependency injection?

A

Dependency injection is a design pattern in which the dependencies of a component are provided from the outside rather than created internally. It is a technique for achieving inversion of control.

101
Q

What is inversion of control?

A

In traditional programming, components control the flow of execution by instantiating and invoking the methods of other components or services they depend on.

Inversion of control is where the control of object creation and management is shifted from the components themselves to an external entity, typically a container or framework.

102
Q

What is meant by a container with respect to dependency injection?

A

A container is a software component or framework that is responsible for managing the lifecycle, configuration and resolution of dependencies within an application.

103
Q

What is SQL Injection?

A

SQL injection is a code injection technique. It is the placement of malicious code in SQL statements.

104
Q

How to prevent SQL injection?

A

You can prevent SQL injection through the use of SQL parameters.

105
Q

What are SQL parameters?

A

SQL parameters are values that are added to an SQL query at execution time

106
Q

How are SQL parameters represented?

A

SQL parameters are represented in the SQL statement by an ‘@’ marker

107
Q

What is meant by a framework?

A

A framework is a pre-built, reusable set of libraries, tools and components that provides a foundation for developing software applications.

108
Q

What is a Linked List?

A

A linked list is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next.

In its most basic form, each node contains data and a reference

109
Q

What are the pros and cons of linked lists?

A

Pros:

Efficient memory utilisation - size decreases or increases as per requirement

Ease of insertion/deletion - no elements need to be shifted after insertion/deletion

Cons:

Many basic operations (such as obtaining the last node of the list) may require iterating through most or all of the list elements.

110
Q

Give some applications of linked lists

A

Can help implement data structures such as stack, queue, hash maps and graphs

Can be used for navigation in web browsers

111
Q

Benefits and Disadvantages of Linked Lists vs Arrays

A

Arrays are of fixed size while Linked Lists are of dynamic size.

Linked lists use more memory

Arrays have easier access to elements

Insertion and Deletion is faster for linked lists.

112
Q

Explain the singleton pattern

A

The singleton pattern is a design pattern that ensures a class has only one instance and provides a global access point to that instance. It is a creational design pattern.

113
Q

When is the singleton pattern used?

A

The singleton pattern is used when exactly one instance of a class is needed throughout the lifetime of an application

114
Q

Give some examples of when you might use the singleton pattern?

A

You might need to implement the singleton pattern when managing shared resources or global configurations

115
Q

How is the singleton pattern achieved?

A

The singleton pattern provides a way to restrict the instantiation of a class to a single object and provides a global access point to that instance.

This is achieved by:

Defining a private constructor to prevent external instantiation

Defining a static method or property to provide access to the single instance

116
Q

What are some benefits of the singleton pattern?

A

Memory efficiency: only one instance of a class can be created

Lazy initialisation: allows instance to be created only when needed, improving performance and reducing startup time

117
Q

What are some drawbacks of the singleton pattern?

A

Testing: Singleton classes can be difficult to test in isolation due to their global state and tight coupling with other parts of the application

Overuse: overusing the singleton pattern can lead to code complexity and dependencies on hidden global state, making the application harder to understand and maintain.

118
Q

Explain how you might set up the Singleton Pattern in C#

A

Set up a private static instance variable e.g.
private static readonly Singleton instance = new Singleton();

Set up a private constructor to prevent external instantiation
private Singleton() { }

Set up a public static property to provide access to the single instance
public static Singleton Instance
{
get { return instance; }
}

119
Q

Explain the strategy pattern

A

The Strategy Pattern is a behavioral design pattern that allows you to define a family of algorithms, encapsulate each one of them, and make them interchangeable. It lets the algorithm vary independently from clients that use it.

120
Q

Give an example of when you might use the strategy pattern

A

If you have a sorting algorithm that needs to be flexible enough to switch between different sorting strategies (bubble sort, quick sort, mergesort) based on different user input or user preferences

121
Q

What are the benefits of the Strategy Pattern?

A

Flexibility: Strategies can be easily added, removed or replaced without modifying the client’s code

Encapsulation: each algorithm is encapsulated into its own class

Testability: Strategies can be tested independently

Reusability: Strategies can be reused across different contexts or applications

122
Q

Explain the components of the strategy pattern

A

Strategy Interface: This is an interface or abstract class that defines a common interface for all supported algorithms.

Concrete Strategies: These are the concrete implementations of the strategy interface

Context: This is a class that uses the strategy interface to perform its operations. The context maintains a reference to a strategy object and delegates the algorithm’s execution to the strategy.

123
Q

What is the observer pattern?

A

The observer pattern is design pattern where multiple observer objects (subscribers) are notified automatically when the state of a subject object (publisher) changes

124
Q

How to implement the observer pattern

A

Define the Subject Interface: This interface defines the methods for attaching, detaching, and notifying observers.

Define the Observer Interface: This interface defines the method that subjects will use to notify observers of state changes.

Create Concrete Subject Class(es): These classes implement the subject interface and maintain a list of observers. They provide methods to attach, detach, and notify observers.

Create Concrete Observer Class(es): These classes implement the observer interface and define the behavior to be executed in response to notifications from subjects.

125
Q

What are the advantages and disadvantages of the observer pattern

A

Advantages:

Loose coupling (between publishers and subscribers)

Disadvantages:

Performance overhead: can be performance issue if a lot of observers etc.
Ordering of notifications: the order in which observers are notified of state changes is not deterministic, which can lead to unexpected behaviour.

126
Q

What is thread safety?

A

Thread safety refers to the ability of a program, module, or system to perform correctly and maintain consistent behavior when accessed or manipulated by multiple threads simultaneously