SWE Interview - Set 1 Flashcards

1
Q

Explain OOP and functional programming paradigms:

A

Functional programming (FP) promotes immutability and pure functions, which can offer concurrency benefits. It simplifies reasoning and testing but may have a steeper learning curve and performance trade-offs (in some scenarios). OOP excels in modeling real-world objects, promoting structure, and reusability (through encapsulation and inheritance), but can lead to complex hierarchies and mutable state.

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

What are the pros and cons of Functional Programming?

A

Functional Programming:Pros: Immutable data, pure functions, concurrency, readability, debugging. Cons: Learning curve, potential performance issues, limited industry adoption, complexity in Real-world scenarios.

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

In the context of cons of Functional Programming:What is meant by potential performance issues?

A

Functional programming can introduce potential performance issues: - Memory Overhead- Garbage Collection Overhead- Looping and Recursion

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

What does memory overhead in functional programming refer to, and what are some factors that contribute to it

A

Memory overhead in functional programming refers to the extra memory consumed by the creation of new data structures and function call stacks due to immutability, recursion, and closures, which can impact performance and memory usage.Modern functional languages often use optimization techniques to minimize this impact.

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

How can immutability in functional programming affect the garbage collector and, consequently, the application’s runtime performance?

A

Functional programming’s immutability can result in more objects being created and discarded, which can increase the workload of the garbage collector. Frequent garbage collection can impact the application’s runtime performance.

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

How can recursion in functional programming potentially impact efficiency and lead to issues?

A

Functional programming often encourages recursion over traditional iterative loops. While elegant, recursive functions can be less efficient due to the overhead of function calls and the potential for stack overflow issues in deeply nested recursion.

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

In the context of cons in Functional Programming:What is meant by Complexity in Real-World Scenarios?

A

Functional programming paradigms can sometimes result in complex code structures for tasks that are naturally imperative, potentially making code harder to understand and maintain in real-world scenarios.Looping Through DataImperative Way: int sum = 0; for (int i = 0; i < 10; i++) { sum += i; }Functional Way: int sum = IntStream.range(0, 10) .reduce(0, (x, y) -> x + y);

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

In the context of pros in Functional Programming:What is meant by pure functions?

A

In Functional Programming these are functions that consistently produce the same output for a given input, without side effects or reliance on external state. They enhance predictability, and testability.

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

In the context of pros in Functional Programming:What is meant by concurrency?

A

Concurrency in Functional Programming means running multiple tasks at the same time. Functional programming’s focus on immutability and pure functions makes managing these tasks safer and more predictable, often leading to better performance.

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

What are the pros and cons of OOP?

A

Object-Oriented Programming (OOP): Pros: Modular, abstraction, inheritance, polymorphism, encapsulation. Cons: Complexity, performance overhead, overuse of inheritance, state management challenges.

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

In the context of pros in OOP:What is meant by encapsulation?

A

Encapsulation in OOP bundles data and methods within a class, safeguarding data, promoting modularity, hiding complexities, and enhancing reusability. It fosters maintainable, flexible, and well-organized code. OR:A class that acts as a protective wrapper, encapsulating the internal details and interactions of the data and methods.

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

In the context of cons in OOP:What is meant by state management challenges?Cue: Elves working on a toy workshop in Programville

A

State management challenges in OOP involve controlling and synchronizing data within objects and classes, addressing complexities related to interactions, concurrency, transitions, and inheritance while ensuring consistent and valid data states, leading to potential bugs, maintenance problems, and behavioral inconsistencies.State management challenges in OOP refer to difficulties in maintaining and controlling the data and behavior of objects within a program, such as ensuring data integrity, synchronization, and handling complex state transitions.Effective synchronization, design patterns, and testing are essential for addressing these complexities.Transition: the process of moving an object from one state to another (door = “open” :transition: door = “closed”)

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

In the context of cons in OOP:What is meant by performance overhead?Cue: extra decorations that slow down your toy car a little

A

Performance overhead in OOP refers to the extra time, memory, or processing resources used due to features like abstraction, method calls, memory management, inheritance, and dynamic behavior. These aspects can impact program speed and efficiency.

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

What is a stack and what is a good implementation?

A

A stack is a data structure where elements are organized using the Last-In-First-Out (LIFO) principle, similar to stacking plates. It supports operations like push (adding an element), pop (removing the top element), and peek (viewing the top element). A good implementation involves using arrays or linked lists. Arrays are efficient for smaller stacks, while linked lists are more flexible for larger stacks. The choice of implementation depends on memory constraints and resizing needs.

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

compile-time polymorphism is also known as:

A

static polymorphism

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

runtime polymorphism is also known as:

A

dynamic polymorphism

17
Q

Runtime polymorphism

A

Runtime polymorphism, on the other hand, involves using a single method name in different classes with a common ancestor. The actual method executed is determined by the type of the object, not just the reference type, during program execution. This is achieved through inheritance and method overriding, enabling objects of different classes to invoke their own implementations of the method at runtime.

18
Q

Compile-Time Polymorphism

A

Compile-time polymorphism, or static polymorphism, involves function or operator overloading. Function overloading occurs during compile-time and involves defining multiple functions with the same name in a class, but with different parameter lists. The appropriate function is selected based on the arguments provided when the function is called, with the compiler determining the right function to execute based on the parameter types. It promotes customization and clarity.

19
Q

What is an example in Java that implements IoC ?

A

The Spring Framework is built around the IoC principle.

20
Q

What does Spring’s IoC container handles?

A

It handles object creation, configuration, and injection.

21
Q

What is the difference between Static & Dynamically typed languages?

A

Static type: Types set at compile-time, ensures type safety but can be verbose. Dynamic type: Types set at runtime, offers flexibility but may lead to runtime errors.