Dot Net Interview Questions – Set 04

What are the advantages of Web Services?

The advantages of Web Services are:

i. It is simple to build and supported by a variety of platforms.

ii. It can extend its interface and add new methods without affecting the client’s operations.

iii. It is stateless and firewall-friendly.

What is Garbage collection?

Garbage collection is used to prevent memory leaks during execution of programs. There is a low-priority process name as garbage collector manages the allocation and deallocation a memory for applications. It also checks for the unreferenced variables and objects. If there is ny object which is no further used by application the Garbage collector frees up the memory from that object.

What is a Hashtable?

The Hashtable class is a collection that stores key-value pairs. It organizes the pairs based on the hash code of each key and uses it to access elements in the collection.

Explain the differences between value type and reference type.

Following are the main differences between value type and reference type:

  • Value type contain variable while reference type doesn’t contain value directly in its memory
  • In reference type, memory is allocated in managed heap and in value type memory allocated in stack.
  • Reference type ex-class value type-struct, enumeration

Name some OOP languages.

Simula was the first OOP language and Java, JavaScript, Python, C++, Visual Basic. NET, Ruby, Scala, PHP are few others.

Describe the garbage collection process.

Garbage collection is an essential process of the .NET Framework that performs memory usage optimization to allow for greater effectiveness of the platform. Answering this question allows you to show you’re an expert on the subject of .NET. It demonstrates knowledge of the framework that goes beyond just repeating theoretical concepts.

Example: “The .NET Framework uses the garbage collector to release unused code lying in the memory. The garbage collector will release code at different times for the three different generations divided within the memory. Since the code objects in Generation 0 are generally short-lived, the garbage collector will frequently release the code objects here, where objects in Generations 1 and 2 will be released less often.

In the first phase of garbage collection, the collector identifies a list of live objects. Then, the collector updates the references for the objects the collector will compact. In phase three, the collector reclaims the spaces taken up by the dead code objects. The code that remains is then transported to an older segment.”

Other questions that ask about the essential features of .NET might include:

  • What is the difference between Server.Transfer and Response.Redirect?
  • What is passport authentication?
  • What is CAS?

What is the difference between session object and application object?

The session object is used to maintain the session of each user.

For example: If a user enters into the application then he will get a session id. If he leaves from the application then the session id is deleted. If he again enters into the application, he will get a different session id.

But in the case of application object the id is maintained for whole application.

Discuss what garbage collection is and how it works. Provide a code example of how you can enforce garbage collection in .NET.

Garbage collection is a low-priority process that serves as an automatic memory manager which manages the allocation and release of memory for the applications. Each time a new object is created, the common language runtime allocates memory for that object from the managed Heap. As long as free memory space is available in the managed Heap, the runtime continues to allocate space for new objects. However, memory is not infinite, and once an application fills the Heap memory space, garbage collection comes into play to free some memory. When the garbage collector performs a collection, it checks for objects in the managed Heap that are no longer being used by the application and performs the necessary operations to reclaim the memory. Garbage collection will stop all running threads, it will find all objects in the Heap that are not being accessed by the main program and delete them. It will then reorganize all the objects left in the Heap to make space and adjust all the Pointers to these objects in both the Stack and the Heap.

To enforce garbage collection in your code manually, you can run the following command (written in C#):

System.GC.Collect();

What are the disadvantages of cookies?

The main disadvantages of cookies are:

  • Cookie can store only string value.
  • Cookies are browser dependent.
  • Cookies are not secure.
  • Cookies can store only small amount of data.

Explain the difference between a class and an object.

In short, a class is the definition of an object, and an object is instance of a class.

We can look at the class as a template of the object: it describes all the properties, methods, states and behaviors that the implementing object will have. As mentioned, an object is an instance of a class, and a class does not become an object until it is instantiated. There can be more instances of objects based on the one class, each with different properties.