Saturday, 29 June 2024

Angular Interview Questions

  1.  What is the whole goal of Angular ?
  2.  What are directives in Angular and how many types of directives exists?
  3.  Explain data bindings and different types of the same?
  4.  Explain the basic components involved in Angular ?
  5.  Difference between AngularJS vs Angular?
  6.  What are component and modules in Angular?
  7.  What are decorators in Angular ?
  8.  What is metadata or annotations in Angular ?
  9.  What are templates in Angular ?
  10.  What is SPA and how to implement in Angular ?
  11.  Explain the importance of routing in Angular & how to implement?
  12.  What is Lazy loading concept in Angular
  13.  How to implement lazy loading in Angular?
  14.  What is node ?
  15.  What is NPM
  16.  What is the importance of node_modules folder ?
  17.  What is packagejson ?
  18.  What is typescript?
  19.  What is the need of Angular CLI ?
  20.  What are services in Angular ?
  21.  In What scenarios will we use content projection ?
  22.  Explain Content Projection Slots in Angular?
  23.  Why do we need “ViewChild” and “ViewChildren” in Angular?
  24.  What’s Template reference variable
  25.  Explain “ContentChild” and “ContentChildren” ?
  26.  Differentiate between ViewChild , ViewChildren , ContentChild and ContentChildren ?
  27.  What is { static: true } in ViewChild ?
  28.  What’s the importance Angular component hooks / life cycle?
  29.  Explain in detail Angular life cycle hooks?   
  30.  Differentiate between “constructor” and “ngOnInit()” ?   
  31.  How to implement lazy loading in Angular?   
  32.  How to implement HTTP in Angular ?   
  33.  How to pass data between components?   
  34.  What are pipes ?   
  35.  Can you give some examples of inbuilt Angular pipes ?   
  36.  How can we write a custom pipe ?   
  37.  What is RxJs and why do we need it ?   
  38.  What are observables and observers?  
  39.  What is stream in RxJs ?   
  40.  What is the use of subscribe in RxJs ?   
  41.  How to unsubscribe from the stream ?   
  42.  What are operators in RxJs?   
  43.  Where did you use RxJs in Angular ?   
  44.  Differentiate between RxJs and Promises?   
  45.  How to install rxJs ?   
  46.  Why is rxjs called Push/Reactive not pull/imperative ?   
  47.  Name some rxJs Operators ?   
  48.  What are interceptors in Angular?   
  49.  How to implement interceptors?   
  50.  Give some use of Interceptors?   
  51.  Can we provide multi-interceptors?   
  52.  Notes by author for further book expanstion  

Javascript Interview Questions

  1. How can we avoid Global variables?  
  2. What are Closures?  
  3. Why do we need Closures?  
  4. Explain IIFE?  
  5. What is the use of IIFE ?  
  6. What is name collision in global scope ?  
  7. IIFE vs Normal Function
  8. What are design patterns?  
  9. Which is the most used design pattern in JavaScript?  
  10. What is module Pattern and revealing module pattern?  
  11. How many ways are there to create JavaScript objects ?  
  12. How can we do inheritance in JavaScript?  
  13. What is prototype in JavaScript?  
  14. Explain Prototype chaining?  
  15. What is Let Keyword?  
  16. Are Let variables hoisted?  
  17. Explain Temporal Dead Zone?  
  18. Let vs Var  
  19. Tricky Question around Concatenation  
  20. Explain class keyword
  21. So with Class Keyword can we say Javascript is OO ?
  22. What is difference between Class and Normal function?
  23. Explain Arrow function?
  24. When will you use an Arrow function?
  25. Arrow functions vs Normal functions?
  26. Does Arrow function have its own this ?
  27. Explain Synchronous execution?
  28. What is a call Stack in JavaScript ?
  29. What is a blocking call?
  30. How to avoid blocking calls ?
  31. Synch vs Asynch ?
  32. How can we do Asynch calls in Javascript ?
  33. Explain threads ?
  34. Explain Multi-threading ?
  35. Is JavaScript Multi-threaded ?
  36. Then how does Settimeout run
  37. What is a WebAPI/Browser API ?
  38. What is an Event loop and callback queue?
  39. What is the output of the below code (Testing Eventloop and CallBack Queue) ?

C# Interview Questions

  1. Whats the difference between a .NET and C#?
  2. Differentiate between .NET framework vs .NET Core vs .NET 5.0
  3. What is an IL code?
  4. Why IL code is not fully compiled?
  5. Who compiles the IL code and how does it work?
  6. How does JIT compilationwork?
  7. What are different types of JIT?
  8. What is Native Image Generator (Ngen.exe)?
  9. So does it mean that NGEN.EXE will always improve performance?
  10. Is it possible to view the IL code ?
  11. What is a CLR?
  12. What is the difference between managed and unmanaged code?
  13. What is a garbage collector?
  14. What are generations in Garbage collector (Gen 0,  and )?
  15. Garbage collector cleans managed code, howdo we clean unmanaged code?
  16. But when we create a destructor the performance falls down?
  17. So how can we clean unmanaged objects and also maintain performance?
  18. Can we force garbage collector to run?
  19. What is the difference between finalize and dispose?
  20. What is CTS?
  21. What is a CLS (Common Language Specification)?
  22. What is an Assembly?
  23. What are the different types of Assembly?
  24. What is Namespace?
  25. What is Difference between NameSpace and Assembly?
  26. What is ILDASM?
  27. What is Manifest?
  28. Where is the version information stored of an assembly?
  29. Is versioning applicable to private assemblies?
  30. What is the use of strong names?
  31. What is Delay signing?
  32. What is GAC?
  33. How to add and remove an assembly from GAC?
  34. If we have two versions of the same assembly in GAC how to we make a choice?
  35. What is Reflection and why we need it? 5
  36. How do we implement reflection? 5
  37. What are the practical uses of reflection?
  38. What is the use of Dynamic keyword?
  39. What are practical uses of Dynamic keyword?
  40. What is the difference between Reflection and Dynamic?
  41. Figure .:- Reflection
  42. Explain the difference between early binding and late binding?
  43. What is the difference between VAR and Dynamic keyword? 0
  44. Explain term type safety and casting in C#?
  45. Explain casting, implicit conversion and explicit conversion?
  46. What are stack and heap?
  47. What are Value types and Reference types?
  48. What is concept of Boxing and Unboxing?
  49. How performance is affected due to boxing and unboxing?
  50. How can we avoid boxing and unboxing?
  51. If we have a class referencing value type, where is value type stored ?
  52. Are static variables stored on a heap or stack ?
  53. How to prevent my .NET DLL to be decompiled?
  54. What is the difference between Convert.toString and .toString () method?
  55. What is the difference between String vs string? 5
  56. So when both mean the same thing why are they different? 5
  57. So when to use “String” and “string”?
  58. How can we handle exceptions in .NET?
  59. How can I know from which source the exception occurred?
  60. What if we do not catch the exception?
  61. What are system level exceptions and application level exceptions?
  62. Can two catch blocks be executed?
  63. What are different types of collections in .NET?
  64. What is the difference between arraylist and list?
  65. Are Arraylist faster or Arrays?
  66. What are hashtable collections? 0
  67. What are Queues and stack collection? 0
  68. Can you explain generics in .NET? 0
  69. Explain generic constraints and when should we use them?
  70. Can you explain the concept of generic collection?
  71. What is the difference between dictionary and hashtable?
  72. What are the generic equivalent for array list,stack, queues and hashtable?
  73. What is the use of IEnumerable, ICollection, Ilist and IDictionary?
  74. Differentiate IEnumerable vs Iqueryable?
  75. What is code access security (CAS)? 5
  76. So how does CAS actually work?
  77. Is CAS supported in .NET .0?
  78. What is sandboxing?
  79. How can we create a windows service using .NET?
  80. What is serialization and deserialization in .NET?
  81. Can you mention some scenarios where we can use serialization? 0
  82. When should we use binary serialization as compared to XML serialization? 0
  83. What is Regular expression?
  84. What is time out support in regex (regular expression)?
  85. Can you explain the concept of “Short Circuiting”?
  86. What is the difference between “Typeof” and “GetType” ?
  87. Will the following c# code compile?
  88. Explain the use of Icomparable in c#?
  89. What is difference between Icomparable and IComparer ?
  90. Can you explain Lazy Loading?
  91. So how do we implement “LazyLoading” ?
  92. Are there any readymade objects in .NET by which we can implement Lazy loading? 5
  93. What are the advantages / disadvantages of lazy loading?
  94. What is the difference between “IS” and “AS” keyword ?
  95. What is the use of “Yield” keyword?
  96. What is the difference between “==” and .Equals()?
  97. What’s the difference between catch with parameter and catch without parameter?
  98. What are attributes and why do we need it?
  99. How can we create custom Attributes?
  100. How can we mark a method as deprecated?
  101. What is the difference between Build Vs Rebuild Vs Clean solution menu ?
  102. What is the difference between i++ vs ++i ?
  103. When should we use “??”(NULL Coalescing operator)?
  104. Explain need of NULLABLE types ?
  105. In what scenario’s we will use NULLABLE types ?
  106. What is the benefit of coalescing?


Tuesday, 25 June 2024

String Builder Vs String

String v/s String Builder

This Article Provide following details 

  • What is String Builder
  • Strigbuilder vs string
  • What is the need of text modifications in real time application development
  • Stringbuilder inbuilt functions and usage

Prove Following 

  1. Pragmatically Prove string is immutable .
  2. Execution time difference between string and stringbuilder
  3. Memory Usage difference between string and stringbuilder

What is String and string builder ?

In C#, both string and StringBuilder are used to handle text, but they are designed for different scenarios and have distinct characteristics. Here’s a detailed comparison:

The string type is immutable in C#, so we cannot change its content after its creation. This means that if we create a string type object and try to amend it, it will create a new instance of the object in the memory. And if we alter the string a lot of times, it can cause some performance problems.

 

StringBuilder solves this problem, because, unlike string, it can dynamically expand its memory to support any manipulation of its contents




In C#, both string and StringBuilder are used to handle text, they are designed for same purpose, but using it for different scenarios and have distinct characteristics.

Action

String

Stringbuilder

initialization

string name=”ASP4UT”;

Stringbuilder sb=new stringbuilder(“ASP4UT”);

concatenation

name=name+”Tutorial”;

Sb.Append(“Tutorial”);

Format

String.Format(“Name {0} Age {1}”,”Srinivas”,30)

Sb.AppenFormat("Name : {0} Salary {0:C}", Srinivas,157);

Replace

Name.Replace(“oldVal”,”NewVal”)

Sb.Replace(“oldVal”,”NewVal”)


string Characteristics

string objects are immutable, meaning once a string object is created, it cannot be changed.

Any modification to  a string actually creates a new string object, which can lead to performance overhead, especially in loops or repeated concatenations.

Frequent modifications of string objects can lead to high memory usage due to the creation of many temporary objects.


string str = "Hello";
str += " World";                             // Creates a new string object
str += " Welcome";                       // Creates a new string object
str=”Welcome to ASP4UT”;         // Creates a new string object

Note :- here 1 initialization and 3 modifications so to 4 objects are created for str variable.

Console.WriteLine(str);  // Output: Welcome to ASP4UT

StringBuilder Characteristics

StringBuilder objects are mutable, meaning they can be modified without creating new objects. This makes StringBuilder more efficient for repeated modifications, such as loops or concatenating a large number of strings.

StringBuilder reduces memory overhead by minimizing the creation of temporary objects. It maintains an internal buffer to accommodate changes, which can grow as needed.



StringBuilder sb = new StringBuilder("Hello");
sb.Append(" World");                         //modify same object
sb.Append(" Welcome To");               //modify same object
sb.Append(" ASP4UT");                   //modify same object

Note :- here while use new operator 1 object created and for every modification or append same object will get update. 

Console.WriteLine(sb.ToString());      // Output: Hello World Welcome To ASP4UT

Comparison

·  string: Ideal for simple and less frequent string operations.

·  StringBuilder: Ideal for complex and frequent string modifications, especially within loops.


String

·  Thread Safety:

  • Immutable objects like string are inherently thread-safe, as their state cannot be modified after creation.

·  Memory Usage:

  • Frequent modifications of string objects can lead to high memory usage due to the creation of many temporary objects.

·  Ease of Use:

  • string provides a rich set of methods and operators for easy manipulation and comparison of text.


stringbuilder

Capacity Management:

  • StringBuilder has a Capacity property that can be used to pre-allocate memory to avoid frequent resizing.

Thread Safety:

  • StringBuilder is not thread-safe. If a StringBuilder instance is to be used by multiple threads, proper synchronization is required.

Memory Usage:

  • StringBuilder reduces memory overhead by minimizing the creation of temporary objects. It maintains an internal buffer to accommodate changes, which can grow as needed.

Comparison Summary

Feature

string

StringBuilder

Mutability

Immutable

Mutable

Performance

Slower for frequent modifications

Faster for frequent modifications

Memory Usage

Higher due to creation of new objects

Lower due to in-place modifications

Thread Safety

Inherently thread-safe

Not thread-safe

Use Case

Simple, infrequent string manipulations

Complex, frequent string manipulations


Reason why string modification required? 

String value concatenation is a fundamental operation in programming and is needed in nearly every project for various reasons. Here are some key reasons why string concatenation is essential:

  •        Building Dynamic Content:
  •        Generating HTML and XML:
  •        Formatting Output:
  •        Query Construction:
  •        File Paths and URLs:
  •        Data Serialization:
  •        Template Rendering:
  •       Configuration Files:
  •        Command Construction:
  •        User Input Handling:

Concatenating user input with predefined text to form complete messages or commands.

Example: userMessage = "User " + userName + " has logged in".



String builder Inbuilt function to manipulate text.

 

StringBuilder sb = new StringBuilder()

Append()

sb.Append("I hope you learned something.");

Append New string value to existing value.

AppendLine()

sb.AppendLine();

Add Line break or line of string value

AppendFormat()

sb.AppendFormat("Name : {0} Salary {0:C}", Srinivas,157);

Append Formated sting to existing

Insert

 

var stringBuilder = new StringBuilder("Hi");

stringBuilder.Insert(2, ", welcome to our blog");

 Insert new value on specific index

Replace

 

sb.Replace("learned", "gained");

Replace specific value with new value

Remove

stringBuilder.Remove(0,8);

Remove text from o index to 8 index

Clear 

 

sb.Clear();

Clear current value


When to use string ?

When you don’t require much string concatenation statements go with string.

 

When to use string builder ?

When you required to concatenate string multiple times in your program go with string builder

 example more than 10 time required to concatenate (not sure this time I will give clear metric )

 

what is the benefit of using string builder compare with string

string builder save execution time memory usage when multiple time concatenate string values.



Program to check  string Crete new object on every modification