:grey_question:Full-stack developer interview questions and answers
Rule | Description |
---|---|
Single responsibility principle | A module should be responsible to one, and only one, actor. |
Open/closed principle | A software artifact should be open for extension but closed for modification. |
Liskov substitution principle | It should be possible to substitute base class with derived class. |
Interface segregation principle | Many client-specific interfaces are better than one general-purpose interface. |
Dependency inversion principle | Depend upon Abstractions but not on concretions. This means that each module should be separated from other using an abstract layer which binds them together. Source code dependency points in the opposite direction compared to the flow of control. |
What is deadlock, livelock? (Deadlock is a situation in which two or more competing actions are each waiting for the other to finish, and thus neither ever does. A livelock is similar to a deadlock, except that the states of the processes involved in the livelock constantly change with regard to one another, none progressing.)
Deadlock Prevention. (prevention, detection, avoidance (Mutex hierarchy), and recovery)
Deadlock Avoidance. (Deadlock is a situation that occurs in Operating System when any Process enters a waiting state because another waiting process is holding the demanded resource.)
What is starvation? (a problem encountered in concurrent computing where a process is perpetually denied necessary resources to process its work)
What is race condition? (Behavior of software system where the output is dependent on the sequence or timing of other uncontrollable events)
What is happens-before relation?
What is thread contention? (Contention is simply when two threads try to access either the same resource or related resources in such a way that at least one of the contending threads runs more slowly than it would if the other thread(s) were not running). Contention occurs when multiple threads try to acquire a lock at the same time
What is a thread-safe function? (Can be safely invoked by multiple threads at the same time)
Publish/Subscribe pattern
What is 2-phase locking? (Growing phase, shrinking phase. Guarantees serializablity for transactions, doesn't prevent deadlock).
What is the difference between thread and process? (Threads (of the same process) run in a shared memory space, while processes run in separate memory spaces)
What is false sharing, cache pollution, cache miss, thread affinity, ABA-problem, speculative execution?
What is a
algorithm?
What is sequential consistency? (The result of any execution is the same as if the operations of all the processors were executed in some sequential order, and the operations of each individual processor appear in this sequence in the order specified by its program).
What is a memory barrier? (A memory barrier, also known as a membar, memory fence or fence instruction, is a type of barrier instruction that causes a CPU or compiler to enforce an ordering constraint on memory operations issued before and after the barrier instruction)
Synchonization aids in Java
What is data race? (When a program contains two conflicting accesses that are not ordered by a happens-before relationship, it is said to contain a data race. Two accesses to (reads of or writes to) the same variable are said to be conflicting if at least one of the accesses is a write. But see this)
Java memory model
What is monitor in Java? (Each object in Java is associated with a monitor, which a thread can lock or unlock)
What is safe publication?
What is wait/notify?
Amdahl's law? (Speedup = 1 / (1 - p + p / n))
Dining philosophers problem (Resource hierarchy (first take lower-indexed fork), arbitrator, communication (dirty/clean forks)).
Produces/consumer problem.
Readers/writers problem.
Isolation_level\Anomaly | Lost_update (because of rollback) | Dirty_read | Non_repeatable_reads second_lost_update | Phantoms | Write_skew |
---|---|---|---|---|---|
Read Uncommitted | - | may occur | may occur | may occur | may occur |
Read Committed | - | - | may occur | may occur | may occur |
Repeatable Read | - | - | - | may occur | may occur |
Snapshot | - | - | - | - | may occur |
Serializable | - | - | - | - | - |
1 Read-write registers
2 Test-and-set, swap, fetch-and-add, queue, stack
⋮ ⋮
∞ Augmented queue, compare-and-swap, sticky byte
Data race. When an evaluation of an expression writes to a memory location and another evaluation reads or modifies the same memory location, the expressions are said to conflict. A program that has two conflicting evaluations has a data race unless
If a data race occurs, the behavior of the program is undefined.
int binarySearch(int[] a, int fromInclusive, int toExclusive, int key) {
int low = fromInclusive;
int high = toExclusive - 1;
while (low <= high) {
int mid = (low + high) >>> 1;
int midVal = a[mid];
if (midVal < key)
low = mid + 1;
else if (midVal > key)
high = mid - 1;
else
return mid; // key found
}
return -(low + 1); // key not found
}
void qSort(int[] a, int fromInclusive, int toInclusive) {
int i = fromInclusive;
int j = toInclusive;
if (i >= j) return;
int separator = a[i + random.nextInt(j - i + 1)];
do {
while (a[i] < separator) ++i;
while (a[j] > separator) --j;
if (i > j) break;
int t = a[i];
a[i] = a[j];
a[j] = t;
++i;
--j;
} while (i <= j);
qSort(a, fromInclusive, j);
qSort(a, i, toInclusive);
}
select 2 primes: p,q
n = p*q
phi(n) = (p-1)*(q-1)
select 1<e<phi(n), gcd(e,phi(n))=1
d=e^-1 mod phi(n)
(e,n) - public key
(d,n) - private key
c = m^e mod n
m = c^d mod n = m^(e*d) mod n = m^(e*d mod phi(n)) mod n = m