C# Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is using?

A

List of directives, specifies namespaces in which the classes/interfaces are located that the code is using, allows one namespace to use another namespace

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

What are partial classes?

A

Allows for one class to be spread across several definitions (often in separate files) which increases readability of the code. All parts must use partial keyword and be in the same namespace, each can inherit from different type and all inherit from it.

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

What are sealed classes?

A

Sealed classes cannot be inherited from, so can’t be extended but they can inherit from other classes. Static classes can’t inherit and can’t be inherited from.

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

What is abstract class?

A

Abstract class is similar to an interface, it provides a blueprint for inheriting classes - defines fields and methods and can implement them but doesn’t have to.. All methods are abstract. The class can’t be instantiated and can only be derived from.

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

What is string builder and what is different to string?

A

String builder is a class that helps with string modification. Strings can’t be modified, each time we add something or transform a string a new string is created, while string builder allows for string modification through modification of each character.

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

Different between as and is?

A

As is used for casting an object type to another, is is used to check the underlying type of an object.

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

Heap and Stack

A

Reference values are stored on heap, values on stack. Stack also stores local variables and method calls. Heap is dynamic but slower.

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

Can C# classes inherit from multiple classes?

A

No, they can inherit from one class but multiple interfaces.

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

Const and readonly

A

Const has to be assigned to and has the same value during lifetime of the application. Readonly can change value at runtime - doesn’t need to be assigned.

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

What is everything in C#?

A

Everything is a class.

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

What is delegation?

A

Evaluating one object in the context of another.

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

What is open recursion?

A

Allowed by delegation -> we can use open recursion by using this keyword to access the inheriting chain.

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

What is abstraction?

A

By using abstract classes or interfaces, we should express the intent of an class without providing implementation. One class shouldn’t know the implementation of another - we can give it a blueprint and tell it what to call without it having to know what exactly happens. Extension of encapsulation in order to maintain code - if too many classes know about each other’s behaviours, it will become impossible to change or maintain code.

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

What is encapsulation?

A

Hiding specific implementation by restricting access to it. Objects hide their internal state only expose themselves to others by methods through which they can communicate, for example by using an interface.

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

What is inheritance?

A

Objects can have things in common .e.g. share logic, instead of copying code, we can reuse the code by making classes inherit from other classes. Types: single (one base class), hierarchical (one base class, multiple derived classes), multilevel (derived class of derived class), multiple (several base classes, several derived classes).

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

What is destructor?

A

Method that destructs an object after it is done being used. Opposite of constructor. It gets called by garbage collector when object is destroyed - frees up resources and memory.

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

Advantage of using getters & setters

A

Encapsulation. Internal state is not exposed as if we used a public property. We have control over who has access to what within an object. Allow for extra validation, allows inheritors to override setters and getters.

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

What are inline functions?

A

Technique used by compilers that instructs to insert complete body function wherever the function is called in the source code.

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

What is virtual function?

A

Function that can be overridden by a derived class.

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

What is friend function?

A

Friend of a class that can access field that are private or protected. Must be declared within the class.

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

What is method overloading?

A

A function that can complete different tasks depending on the parameters we pass in. The signature must be exactly the same except for the parameters. The implementation can be the same/similar except we use the same params to get to the result.

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

What is method overriding?

A

Using inheritance, we can override the behaviour of a method in the parent class The signature must be identical but the implementation can be different.

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

Difference between overriding and overloading methods

A

Overriding uses inheritance to allow child classes to have different implementations. Overloading is defining several methods whose implementation differs based on the parameters we send.

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

What is operator overloading?

A

Providing special meaning/implementation to operators.

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

What is virtual pure function?

A

It is a virtual method that must be overridden in the child class - doesn’t have any implementation in the parent class -> abstract class and an abstract method.

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

What is the finalize function?

A

Called by garbage collector to used to cleanup unmanaged resources before the object is destroyed.

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

What are two types of arguments?

A

Passed by value and passed by reference. Reference type arguments are mutable. Value type arguments are destroyed when the method is done executing.

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

DATA STRUCTURE: What is heap?

A

Complete binary tree. Either minimum or maximum tree, root will be smallest or largest node in the tree.

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

Which data structures use pointers?

A

Linked lists, stack, queu, binary trees.

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

Full vs complete binary tree

A

Full - each node other than leaves have two children.

Complete - every level except the last one is completely filled - all nodes are left as possible.

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

What is infix?

A

It’s an operator position - between elements - A*(B+C).)

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

What is prefix?

A

It’s an operator position - before operator - /*A+B.

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

What is postfix?

A

It’s an operator position - follows after each operator - ABC+*D/.

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

How to implement LRU cache?

A

Last recently used. The least recent should be removed first -> browser keeps track about last visited pages in a queue, double-linked list, hash.

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

Call stack

A

Stack saves the information about the last function called and pushes it to the bottom, once it’s done performing, the highest possible function it goes through the function stack.

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

Void vs NULL

A

Technically, null is a value since it points to a location in memory. Void does not point at anything - data type identifier that means nothing.

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

Most common searching algorithms

A

Binary search, linear search.

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

What are most common sorting algorithms?

A

Selection sort, bubble sort, merge sort, radix sort, heap sort, quick sort.

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

What are fibonacci numbers?

A

It is a series of numbers starting with 0 ad 1 with the following number being a addition of the two previous numbers. 0 1 1 2 3 5

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

What is linear search?

A

Search in sequence, each element is searched and compared against the searched key.

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

How does binary search in binary tree?

A

If tree is empty - the search ends. If the tree not empty, check if root element is it, if not check left of root, then check left of that node, then left until there is none, then go right.

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

What is merge sort?

A

Divide and conquer. Divides an array in half and first sorts each half by more halving until we have just two elements. Adjacent elements of sequence sorted first and merged. O(nlogn)

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

What is bubble sort?

A

Compares adjacent elements and exchanges their values, if they are out of order - largest items sink to the bottom of the list. The smallest value bubbles up to the start. O(n^2)

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

What is quick sort?

A

Pick random element and partition array such that all numbers are less than the element that comes before all elements that are greater than it. Forms subarrays to do it. It’s not great since the random element can be in bad position.

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

What is selection sort?

A

Smallest number is first located and switched with the element at 0 index. Then the second smallest position is put at the second position but that can mean it goes through each element at lesat once. O(n^2)

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

What is radix sort?

A

Sorts ints, first looks at first digits, the same ones are grouped together, that continues until all sorted

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

JIT vs AOT

A

JIT - compiles IL to machine code, AOT - ahead of time delivers fast startup in large apps but needs more disk space and memory

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

Methods vs functions

A

Methods are functions belonging to a class - can operate on the data of the object. Functions need all arguments passed in.

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

What are mixins?

A

Contains methods used by other classes without it being parent class of the other classes, it’s more included than inherited from.

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

What is a monad?

A

Abstracting boilerplate code by passing in their own data type e.g. generics -> List where T is monad

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

What is roslyn?

A

Compiles C# into Intermediary language.

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

What is RUYJIT?

A

Compiles IL into machine ode.

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

Do you modify access to interface?

A

No, can include public identifier but it’s public by default.

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

Stack vs Heap Memory

A

Stack stores value types, function arguments, keeps stack call of methods. Heap - where reference types are stored, keeps track of objects.

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

What is .Net web service?

A

Reusable piece of code that allows for publishing things over the internet and interacting with other resources over HTTP, XML, SOAP. ASP.Net provides simple way of implementing them.

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

Why should we prefer MVC over Web Forms?

A

Web forms are outdated and not well maintained plus MVC allows for separation of concerns.

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

What is Json in relation to .Net?

A

JavaScript object notation. A way to depict data through api calls, easy to read and organise data. Libraries to parse json strings for storage etc.

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

What is Laravel?

A

PHP version of .NET, open source framework based on MVC.

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

.Net vs .Net Core

A

.Net Core is the open source, cross-platform, NUGGET based subset of .Net. They have shared common libraries.

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

What is included in .Net core?

A

.Net runtime, type system, assembly loading, garbage collector, set of framework libraries, SDK tools & language compiler, dotnet app host.

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

Does .NET Core have the same libraries?

A

It shares some base libraries with .Net, except they are shipped as smaller libraries via nugget.

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

What is Core CLR?

A

Common language runtime execution engine that takes care of compilation and garbage collection.

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

What is Mono and how does it differ to Core?

A

Mono is a 3rd party library, implementation of .Net Core for other platforms before Microsoft created Core.

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

Characteristics of Core

A

Cross-platform, open source, can be shipped over nugget, flexible deployment, command line tools, compatible with .Net, developed by Microsoft.

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

What is CTS?

A

Common type system. System for data types shared by most Microsoft languages/frameworks, to ensure smooth communicate between all .Net languages. All types inherit from System.Object

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

How to sort array?

A

Sort(), Reverse()

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

What is circular reference?

A

Trying to reference a project from a project that is referenced by that project. Resources are dependent on each other and create lock condition and the resources can’t be used.

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

What are generics?

A

Placeholders for type of fields, methods, parameters, gets specific type at compile time. Why - reusable code, type safe.

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

What is object pool?

A

The pool of objects currently being used in code, reduces overhead of creating and recreating objects.

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

What are delegates?

A

Instead of using a specific method, we can pass in a blueprint of the method (the signature) without having to define or name the method yet.

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

What is constructor chaining?

A

Calling constructor from another constructor - e.g. child constructor calling parent.

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

What is enum?

A

Value type. Predefined list of possible values = named constants.

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

What are nullable types?

A

Value types can’t normally be null unless we add the null operator which allows it to be nullable.

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

What is null coalescing operator?

A

If first operand is null, the second one will be assigned. var i = null ?? this;

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

What is static constructor?

A

Static constructor gets called to initialize static data before the first instance is created.

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

What are attributes?

A

Reusable code blocks that assign some sort of behaviour to class which is evaluated at runtime, method, property etc. [Route], [DataContract],[HttpGet]

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

What is a thread?

A

It’s a flow of control - set of instructions to be executed, tasks are executed in the thread - by default, C# only has one but more can be created - multi-threading -> could cause deadlock or circular reference.

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

How to hide method of pareint in child?

A

By using the new keyword and implementing the parent method with new implementation but same signature.

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

Abstract vs virtual

A

Abstract classes cannot be implemented by parent, must be implemented by child classes, in abstract classes, virtual by default. Virtual methods must have implementation in parent, don’t have to be implemented in child.

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

What is System.IO?

A

Library namespace that contains functionality for reading, writing to the file system - StreamWriter, StreamReader.

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

What are regular expressions?

A

Patterns that we can use to abstract what we expect e.g. a string to look like - template to match a set of input.

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

Async vs Sync

A

Program can be executed async or sync. Sync execution follows chronologically line by line and waits for all code to complete before it returns (only one thread can access resource), while async returns immediately so that program can perform other operations while the code executes.

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

Do we have to declare private fields?

A

No, they are private by default, unless we defined getters and setters?

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

What is serialization?

A

Process of converting data to the expected data format. Most common: JSON, XML, binary.

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

What is reflection?

A

Able to access metadata of objects - e.g. assembly information during runtime and informs user or modifiers behaviour.

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

What is IEnumerable?

A

Interface for collections that contains GetAwaiter() which allows to iterate through the collection. Base class for collections, IQueryable implements it too.

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

IEnumerable vs IQueryable?

A

IQ derives from IE. IE keeps in memory the object while it is filtered. IQ filters through the collection without saving it in memory. IE is better for LINQ to objects, while IQ is better LINQ to anything else.

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

What are static classes?

A

Classes that can’t be instantiated, can’t be inherited from. If class static, all members are static. Static members are on heap. It’s members can be accessed anywhere. All members also static, no this since there is no instance.

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

Exception handling in C#

A

try, catch, finally - only one catch per exception type.

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

What is finally?

A

It is a statement after the try and catch code block. It is always executed. It’s great to use for closing db connections or getting rid of resources.

91
Q

When to use params keyword?

A

When I don’t now how many parameters will be passed in. Must be last in the list and only one per method. Must be a single-dimensional array.

92
Q

What are two types of errors?

A

Compilation (syntax), runtime errors (exception thrown due to bad data etc. - stack overflow exception or null reference).

93
Q

What is var?

A

Implicitly typed variable used to define a new variable without specifying the type - the variable must be however initialized which sets the type. Only for local variables.

94
Q

What is value type?

A

Data structure that is directly stored in memory - the variable directly contains the value in memory, instead of pointing to chunk of memory. Stored on the heap. When value passed as argument, a copy is passed in and the original variable is not changed.

95
Q

Name value types in C#

A

Struct, int, double, decimal, long, char, , float, bool, byte, enum etc.

96
Q

What is reference type?

A

Variable that is stored on the heap, usually, contains the address in memory of the value rather than the value itself. Passing by reference - passes in the memory location and mutates the object.

97
Q

What is anonymous type?

A

Type that doesn’t have a name - it is subset of reference type and all its properties are read-only. Defined with new keyword.

98
Q

What is casting?

A

Explicitly converting one type as another type if it’s possible.

99
Q

What is bad OOP design?

A

Duplicate code, implementation that is not abstracted, rigidity - hard to change if code is unpredictable, fragility - breaks every change, importability 0 module works only in specific situation, can’t be reused.

100
Q

What is the different between array, array list, jagged array?

A

Array is one-dimensional & fixed length, jagged array is multi-dimensional - array of arrays, array list - no fixed length, stores different data types.

101
Q

What is polymorphism>

A

One name, many forms. Related to inheritance. Parent implements a method while children implement their own version of that method. Static - overloading, dynamic - overridding.

102
Q

What are namespaces?

A

Containers for classes. Include classes, interfaces, enums etc. Organize large chunks of data of code. E.g. System

103
Q

Finalize vs Dispose

A

Dispose from IDisposable - can be called to remove object from memory, Finalize used to clean up resources when objects are no longer used - cannot be called directly.

104
Q

What is boxing and unboxing?

A

Converting value type to reference type and vice versa. Boxing - to object, Unboxing - to reference.

105
Q

What is garbage collection?

A

Process that gets rid of unused objects in memory. Automatic memory manager.

106
Q

What is intermediary language?

A

C# is compiled into it, it is then compiled into machine code. CPU independent, partially compiled C# code.

107
Q

What is common intermediary language?

A

.Net Intermediary language.

108
Q

Advantages of LINQ

A

Easier and simpler syntax than SQL, many extension methods, can be used on many data sources - bridges the gap between objects and data.

109
Q

What is global cache?

A

Machine wide cache. .Net applicatoins share libraries through GC.

110
Q

What is BinaryFormatter?

A

Formatter for binary serialization.

111
Q

What are the types/contents of assembly?

A

Manifest, type metadata, IL, resources (images, assets)

112
Q

What does manifest of assembly contain?

A

Data about the assembly such as assembly version or key, security demands.

113
Q

What is an assembly?

A

Versioned and deployed unit. Collection of types and resources which together form a unit of function. Can be designed as executable (exe) or reusable (dll). Assembly is compiled output.

114
Q

How to disallow a class to be inherited from?

A

Seal it.

115
Q

What are extender classes?

A

Extend functionality of some other class - e.g. static extension methods.

116
Q

What is base class library?

A

Library that all .Net framework inherit from. Contains base functionality. E.g. System.IO

117
Q

What is ASP.Net?

A

The .Net framework meant for web development - make developing web applications easier. Has subsets - Web API, MVC, Web Forms

118
Q

What is .Net or .Net Core?

A

Frameworks for building applications, both developed by Microsoft. One is single platform, the other is cross-platform.

119
Q

What is expression tree?

A

Data structure that contains expressions represents structured queries -> this then ran over a data set. C# compiles queries into language appropriate for data source.

120
Q

Take(1) vs First() vs FirstOrDefault()

A

Use first when we never expect the collection to be empty, if it can be empty use FirstOrDefault. Take(1) returns sequence with the specified number of elements.

121
Q

Why is LINQ better than SQL?

A

LINQ is type safe, debugging of LINQ possible, errors can be discovered during compilation, LINQ compiled into IL, SQL would require another step.

122
Q

What is Data Context?

A

Class that bridges LINQ and SQL. Allowing access to the db and updating data in db. Does 3 things: creates connection to db, submits and retrieves data converts to SLQ and vice versa.

123
Q

What is association?

A

Way of linking objects, two objects are instances of unrelated classes, they collaborate to achieve their goals. No clear owner - both parent and child - but they can interact.

124
Q

What is aggregation?

A

Specialized type of association, way of linking objects. One object belongs to the other object but they’re still independent, don’t control each other life cycles, there is owner and ownee, ownee can’t belong to anyone else.

125
Q

What is composition?

A

Specialized form of aggregation - one object completely controls the other which doesn’t have independent life cycle. Death relationship - if parent dead, child dead.

126
Q

What are 3 ways of linking objects?

A

Association, aggregation, composition.

127
Q

What is an object?

A

Instance of a class.

128
Q

Deferred vs Immediate execution

A

Query is not executed until it is needed, saves performance. Immediate - immediately executes e.g. ToList() or Count()

129
Q

What are query operators?

A

Operators that take in a sequence and transform it based on conditions specified.

130
Q

What is LINQ?

A

Can filter and manipulate data more easily than other queries. Allows to write queries over set of data. Can write LINQ query on any collection implementing IE.

131
Q

When are graphs used?

A

Maps, LAN networks, transportation (finding shortest path)

132
Q

git -d

A

delete the branch

133
Q

git clone

A

copy a repo

134
Q

git stash drop

A

deletes stash

135
Q

git stash pop

A

apply + drop stash

136
Q

What is staging area in GIT?

A

Intermediate area before completing commits, can format, review files.

137
Q

git repo

A

Contains metadata, source code for repo in .git

138
Q

GIT

A

code versioning program and source code management system

139
Q

git stash apply

A

apply stash and don’t delete it

140
Q

git rm

A

Removes file from staging area

141
Q

commit message

A

Adds message to commit

142
Q

C# design patterns

A

Observer (view updates if model changes), abstract method (extends factory method by introducing an abstract class), factory method, singleton

143
Q

JS design pattern

A

Modules - encapsulation, clsses. Prototype - JS inheritance. Observer - observe object. Singleton - Angular services.

144
Q

What is singleton?

A

Only one version of an object exists, client can’t create another instance, C# - making constructor private - all methods defined as static, BAD - cause application to be too rigidly coupled

145
Q

What is factory method?

A

Creating an instance of several derived classes. Centralized creation of objects. Interface or abstract class based. Client shouldn’t know implementation.

146
Q

2 most common design patterns

A

Factory method, singleton

147
Q

What are design patterns?

A

Documented, tried tested solutions to recurring problems in a given context - way to initialize objects etc.

148
Q

What is scrum?

A

15 minute daily meetings, group working together, defining goals, 2 weeks - 1 month sprints, define stories

149
Q

Stack vs Array

A

Array can delete any element based on indices, not just last one.

150
Q

Use of stack

A

Stack call, recursion, execution context

151
Q

How is stack different to linked list

A

Can remove any element of linked list, order is important in stack.

152
Q

How can stack be implemented?

A

Using two queues, linked lists, arrays (array not dynamic so we have to worry about stack overflow)

153
Q

What are hash tables?

A

Can be implemented using linked lists or array of linked lists. Hash function that maps value to a key (index location). Can’t avoid collisions where one value is computed to the same index - need load factor.

154
Q

Wat is binary search tree?

A

Binary trees that are low values on left side of root and larger values on right of root. Left & right nodes also must be binary search trees. No duplicates. To check if binary tree is BST - traverse, if sorted, it is BST.

155
Q

Types of linked lists

A

Single, doubly (pointers go both ways - previous and next), circular linked

156
Q

What are linked lists?

A

Linear, dynamic. Can’t access random elements, must traverse through the whole thing. Pointers are stored instead of data. Each element is separate object pointing to the next node.

157
Q

What are graphs?

A

Set of ordered pairs - edges connect all nodes. Represent objects and relationships - vertices and edges. can be cyclic or not, connected or not. Weighted edges, labelled v or c. Each graph can be represented in adjacent linked list arrays or array lists.

158
Q

Graph traversal techniques

A

DFS - depth-first search goes deep first through each node. BFS - breadth-first - goes through all nodes of the one level than next level.

159
Q

What is binary tree?

A

Types of graph, similar to linked lists but each node points to number of nodes - non-linear data structure. Each node only has two children - left and right. Min nodes = 0, max nodes = 2. To insert new item -> check if item in tree already -> is the tree empty (yes, insert as root), if not -> not empty - is node bigger or lower tan root - right, not left.

160
Q

Use of hash tables

A

db indexing, cache

161
Q

What is data structure?

A

Way of organizing data to manipulate the data efficiently. Relationship between data matters and is represented by the data structure composition. Some are highly specialized to specific tasks.

162
Q

What is array?

A

Static size, all elements referenced by index. Stores same data types. Can access al elements randomly using the index. Can delete any element.

163
Q

Data abstraction

A

Tool to consider complex data in manageable chunk. Mostly focus on data objects involved and what operations will be done on them.

164
Q

Examples of data structures examples

A

Numerical analysis, operating system, AI, compiler design, database management, graphics, statistical analysis.

165
Q

Linear vs Non-Linear

A

Linear - elements follow in sequence - linked lists. Non-linear - no sequence - trees, graphs.

166
Q

What are dynamic data structures?

A

Expand and contract depending on data.

167
Q

What is QUEUE?

A

First in, first out. Ordered list, dynamic memory. FIFO - enqueue, dequeue. Implemented through linked lists or arrays or 2 stacks. List of computer jobs.

168
Q

Operations of abstract data

A

Inserting, removing, sorting, searching (looks for specific node, then stops), traversing (goes through each node once)

169
Q

What is ordered list

A

Sequence of pointers, each node’s position determined by the value of its key component. Values form increasing sequence.

170
Q

Multi-dimensional arrays

A

Multiple indices to store data. Data represents = table with more than one column.

171
Q

Priority queue

A

Order matters, priority defined by key for each element. Two queues - 1 for storing keys, 1 for storing data.

172
Q

What is stack?

A

Insertion order important - first in, last out. Dynamic memory. Can store elements of similar data types while arrays can only hold data of one type. Ideal for recursion.

173
Q

How do I call a method of a class without instantiating it?

A

Making that class or method static.

174
Q

What are token in compiler?

A

Smallest element of program meaningful to the compiler, something that can’t be broke down more - keyword, identifier, constant, operator.

175
Q

What is exception handling?

A

Event that occurs during execution, unexpected behaviour to be handled through throw, try, catch, finally.

176
Q

Interface vs abstract class

A

Both are blueprints for inheriting classes, define methods and properties. Interface cannot contain any implementation while abstract class can. All members of interface are public - can’t contain private, static members. A class can inherit from multiple interfaces but only one class.

177
Q

What is super keyword used for?

A

Used to invoke overridden method that overrides one of the superclass methods. Forwards constructor call to the constructor of the base/super class.

178
Q

What are constructor?

A

Constructor methods initialize objects they belong to - can set state. Default is parameter less constructor. Can be overloaded.

179
Q

What is interface of protocol?

A

Class that sets out structure but never implementation.

180
Q

What is black box?

A

Concept for hiding away code. We need to know the inputs and outputs, not the implementation.

181
Q

Object vs class

A

Class is the blueprint, says what fields, methods it contains. Object is instance of the class with its own state. and behaviour.

182
Q

When to use a struct?

A

When we want to store primitive, value types. Smaller than 16 bytes, immutable.

183
Q

What is a struct?

A

It’s a value type object. Contains value type data. Can contain data and methods, default access is public. Can’t inherit from other classes. Best used for small classes. Stored on stack. Members cannot be null.

184
Q

What is abstract class?

A

Cannot be instantiated, sets out blueprint for inheriting classes, always base class. At least one abstract member but can have non-abstract members with implementation.

185
Q

What is a class?

A

Model, blueprint, template without a state or actual data. Describes features, behaviour of object. Default access modifier is private. Supports inheritance.

186
Q

What happens when we call function in OOP?

A

Tries to find the function with that signature starting in child class and then goes up the chain if none found. It’s runtime’s job.

187
Q

Dynamic dispatch C#

A

Dynamic dispatch becomes possible when each object carries data about its generating type. Type is able to keep track of using virtual functions table. Allows object to override some functions which have been inherited.

188
Q

this pointer in OOP

A

This is part of every instance. Manages state within a data structure. Pointer passed with a call to instance level function which than operates on object. With dynamic dispatch, it is possible to substitute function specifications.

189
Q

What is OOP?

A

Object oriented programming is a programming paradigm based around data or objects rather than logic or functions. It’s a way to organise code. It’s built on this pointer and dynamic dispatch.

190
Q

Library vs Framework

A

Framework is a more complex robust standalone environment that provides everything for building apps. It defines the programming language, the runtime, types. Library in comparison provides a limited piece of functionality within a framework.

191
Q

git log

A

To find specific commit in project, history by author, date or content

192
Q

git checkout

A

checkout branch, updates files based on the branch we want to checkout without merging

193
Q

three laws of TDD

A
  1. Not allowed to write production code unless it is to make a failing test pass
  2. don’t write more than is sufficient to fail
  3. no more production code than is sufficient for failing code to pass
194
Q

fix broken commit

A

git command –amend, can fix commit message but better to create a new one

195
Q

git status vs git diff

A

diff shows differences between various commits and also between working directory and index

196
Q

git add

A

adds files from existing directory to indesx

197
Q

git reset

A

resets index and working directory to the state of your last commit

198
Q

Benefits of TDD

A

Less time debugging, prevents feature creep by defining the tests first, helps define requirements, adding functionality is safer and easier

199
Q

git diff

A

Difference between commits, commit and working tree.

200
Q

git merge

A

Merges with master.

201
Q

rebasing

A

Type of merging the new branch is added to the master.

202
Q

git init

A

Creates new repo in selected project.

203
Q

What does commit contain?

A

Set of files representing state of object at given time, message, timestamp, author, reference to parent commit objects, SHA name string identifying commit.

204
Q

git config

A

Sets up config for git installation.

205
Q

git status

A

Shoes difference between working directory and the index (staging).

206
Q

What is compiler?

A

Translates code into machine code saves it in local file. Once compiled, source code is disregarded - if errors -> stops compiling - C#.

207
Q

What is interpreter?

A

Source code needed all the time. Executes program one statement at a time. Less time to analyze source bode overall execution is slower, doesn’t translate into machine code. Stops executing if there is a syntax error.

208
Q

What are lambda expressions?

A

Expressions that create functions. Way of defining anonymous functions that can be passed around as parameter to a method call. Data type inferred from context. Kinda like fat arrows in JS but lambda expressions can be named.

209
Q

What is managed code?

A

Code that is executed using runtime that has garbage collector that managements memory and disposes of objects that are not used, type checking and exception handling.

210
Q

What is unmanaged code?

A

Directly compiled to native machine code, depends on architecture of target machine, executed directly by operating system. Developer must deal with memory leaks, type checking and exception handling.

211
Q

What are traversal techniques?

A

Pre-order - Root, L, R
In-order - L, Root, R
Post-order - L, R, Root

212
Q

What is binary search?

A

If data already sorted, starts in the middle and looks if element is bigger or smaller than the middle point, then goes either left or right, can’t apply to linked list - can’t sort or find middle element

213
Q

What is heap sort?

A

Based on priority.

214
Q

What are execution steps?

A
  1. source compiled to CIL
  2. CIL is assembled into bytecode and CLI assembly is created
  3. CLI is passed through JIT to generate machine code
  4. CPU executes native code
215
Q

SDK vs runtime

A

SDK - all the stuff that makes developing an app easier,

runtime - virtual machine that hosts and runs the application & abstracts all interaction with operating system

216
Q

What is CLI?

A

Common language infrastructure - compiled code library for deployment versioning and security.

217
Q

What is restful?

A

Representational state transfer. Architectural standard. Set of constraints on data transfer.

218
Q

Composition over Inheritance

A

Composition - takes what it wants, flexible/easy to modify.

Inheritance - more rigid, must implement everything.

219
Q

What is mutzing?

A

Don’t bloat code, remove unnecessary code.

220
Q

What is dependency inversion?

A

High level classes shouldn’t depend on low level classes. Abstraction shouldn’t depend on details, details should depend on abstraction.

221
Q

What is interface segregation principle?

A

Shouldn’t implement interface if we won’t use all the properties, shouldn’t depend on methods, it doesn’t need.

222
Q

What is listov substitute principle?

A

Child should be substitutable for parent, child should extend all functionality not reduce it.

223
Q

What is open/closed principle?

A

Classes should be easily extended but not modified.

224
Q

Higher-order functions

A

Can be used as arguments and be returned by other functions.