Friday, December 19, 2014

.Net Framework Interview Questions and Answers

1) What are the advantages of .Net?
  • Good Design
  • Object-Oriented Programming – Using C# and .NET which are based on object-oriented Concepts.
  • Language Independence – All the languages which are supported by .Net ( VB.NET, C#, J#, and managed C++ ) are compiled in to common Intermediate Language (IL) . So IL make sure that languages are interoperable.
  • Efficient Data Access – ADO.NET provide fast and efficient way to access RDBMS, file system etc
  • Code Sharing – .To share code between applications, a new concept called assembly is introduced. Assemblies supports versioning.
  • Improved Security
  • Support Dynamic Web Pages – Using ASP.NET.
  • Support for Web Services
2) What is .Net Framework ?
The .NET framework is a programming framework from Microsoft. Developers can use .Net Framework to develop applications,install and run the application on Windows operating systems.

3) What is MS-IL (Microsoft Intermediate Language) ?

When a program is complied in .Net , the source code will be converted into an intermediate language called  Microsoft Intermediate Language (MS-IL) . This is done by Just-In time Compiler (JIT). .Net framework is built in such a way that , Code is Just-In time complied, that is it get complied when it is called rather compiling entire code at the start up. A portion of the code will get complied only once and it will exists till the application exit. This will have a significant improvement in performance since  entire section of the code wont get executed in most cases.

4) What is Common Language Runtime (CLR) ?
Common Language Runtime or CLR is the run-time execution environment of .Net Framework. Converting MS-IL into platform or OS specific code is done by CLR. Currently .Net programs will run only in windows.

5) What is Common Type System (CTS) ?

.Net uses Common Type System (CTS)  for Language Interoperability. CTS defines the predefined data types that are available in IL, so that all languages that target the .NET framework will produce compiled code that is ultimately based on these types. So that a data type defined in a VB.net will be understood by C#. For example, VB.Net uses  “Integer” to define data type Integer. C# uses  “int” to define data type Integer. When VB.Net code is complied , it will convert Integer to Int32 and since C# refers Int to Int32 VB.Net code will be understood by C#.

6) What is Common Language Specification (CLS) ?
Common Language Specification (CLS) is also used for Language Interoperability in tandem with CTS to ensure Language Interoperability. CLS defines a set of minimum standards that all compilers targeting .NET must support. For example VB.Net is not case sensitive. So attribute “EmployeeName” and “employeename” is considered same. But C# is case sensitive. So for language interoperability , C# doesn't allow two variable which differs only in Case.

7) What is Garbage Collector ?

Garbage Collector is used in .Net Framework for memory management. While running an application, application request for memory for its internal use. Framework allocates memory from the heap. Once the process is completed , allocated need to be reclaimed for future use. The process of reclaiming unused memory is taken care by Garbage Collector.

8) Which namespace is used for Asp.net MVC?
System.Web.Mvc namespace contains all the interfaces and classes which supports ASP.NET MVC framework for creating web applications.
 
9) Explain about "pagenLifecycle" a Asp.net MVC?
The page lifecycle of an ASP.NET MVC page is explained as follows:
i) App Initialisation
In this stage, the aplication starts up by running Global.asax’s Application_Start() method.
In this method, you can add Route objects to the static RouteTable.Routes collection.
If you’re implementing a custom IControllerFactory, you can set this as the active controller factory by assigning it to the System.Web.Mvc.ControllerFactory.Instance property.

ii) Routing
Routing is a stand-alone component that matches incoming requests to IHttpHandlers by URL pattern.
MvcHandler is, itself, an IHttpHandler, which acts as a kind of proxy to other IHttpHandlers configured in the Routes table.

iii) Instantiate and Execute Controller
At this stage, the active IControllerFactory supplies an IController instance.

iv) Locate and invoke controller action
At this stage, the controller invokes its relevant action method, which after further processing, calls RenderView().

v) Instantiate and render view
At this stage, the IViewFactory supplies an IView, which pushes response data to the IHttpResponse object
 
10) Explain about the formation of Router Table in Asp.netnMVC?
The Router Table is formed by following the below procedure:
In the begining stage, when the ASP.NET application starts, the method known as Application_Start() method is called.
The Application_Start() will then calls RegisterRoutes() method.
This RegisterRoutes() method will create the Router table.

11) Explain the advantages of using routing in Asp.Net MVC?
Without using Routing in an ASP.NET MVC application, the incoming browser request should be mapped to a physical file.The thing is that if the file is not there, then you will get a page not found error.
By using Routing, it will make use of URLs where there is no need of mapping to specific files in a web site.
This is because, for the URL, there is no need to map to a file, you can use URLs that are descriptive of the user's action and therefore are more easily understood by users.
 
12) State the differences between the Dispose() and Finalize().
CLR uses the Dispose and Finalize methods to perform garbage collection of run-time objects of .NET applications.
The Finalize method is called automatically by the runtime. CLR has a garbage collector (GC), which periodically checks for objects in heap that are no longer referenced by any object or program. It calls the Finalize method to free the memory used by such objects. The Dispose method is called by the programmer. Dispose is another method to release the memory used by an object. The Dispose method needs to be explicitly called in code to dereference an object from the heap. The Dispose method can be invoked only by the classes that implement the IDisposable interface.

13. What is code access security (CAS)?
Code access security (CAS) is part of the .NET security model that prevents unauthorized access of resources and operations, and restricts the code to perform particular tasks.
14. Differentiate between managed and unmanaged code?
Managed code is the code that is executed directly by the CLR instead of the operating system. The code compiler first compiles the managed code to intermediate language (IL) code, also called as MSIL code. This code doesn't depend on machine configurations and can be executed on different machines.
Unmanaged code is the code that is executed directly by the operating system outside the CLR environment. It is directly compiled to native machine code which depends on the machine configuration.
In the managed code, since the execution of the code is governed by CLR, the runtime provides different services, such as garbage collection, type checking, exception handling, and security support. These services help provide uniformity in platform and language-independent behavior of managed code applications. In the unmanaged code, the allocation of memory, type safety, and security is required to be taken care of by the developer. If the unmanaged code is not properly handled, it may result in memory leak. Examples of unmanaged code are ActiveX components and Win32 APIs that execute beyond the scope of native CLR.

15. What are tuples?
Tuple is a fixed-size collection that can have elements of either same or different data types. Similar to arrays, a user must have to specify the size of a tuple at the time of declaration. Tuples are allowed to hold up from 1 to 8 elements and if there are more than 8 elements, then the 8th element can be defined as another tuple. Tuples can be specified as parameter or return type of a method.

16. What are the improvements made in CAS in .NET 4.0?
The CAS mechanism in .NET is used to control and configure the ability of managed code. Earlier, as this policy was applicable for only native applications, the security guarantee was limited. Therefore, developers used to look for alternating solutions, such as operating system-level solutions. This problem was solved in .NET Framework 4 by turning off the machine-wide security. The shared and hosted Web applications can now run more securely. The security policy in .NET Framework 4 has been simplified using the transparency model. This model allows you to run the Web applications without concerning about the CAS policies.
As a result of security policy changes in .NET Framework 4.0, you may encounter compilation warnings and runtime exceptions, if your try to use the obsolete CAS policy types and members either implicitly or explicitly. However, you can avoid the warnings and errors by using the <NetFx40_LegacySecurityPolicy> configuration element in the runtime settings schema to opt into the obsolete CAS policy behavior.

17. What is Microsoft Intermediate Language (MSIL)?
The .NET Framework is shipped with compilers of all .NET programming languages to develop programs. There are separate compilers for the Visual Basic, C#, and Visual C++ programming languages in .NET Framework. Each .NET compiler produces an intermediate code after compiling the source code. The intermediate code is common for all languages and is understandable only to .NET environment. This intermediate code is known as MSIL.

18. What is lazy initialization?
Lazy initialization is a process by which an object is not initialized until it is first called in your code. The .NET 4.0 introduces a new wrapper class, System.Lazy<T>, for executing the lazy initialization in your application. Lazy initialization helps you to reduce the wastage of resources and memory requirements to improve performance. It also supports thread-safety.
19. How many types of generations are there in a garbage collector?
Memory management in the CLR is divided into three generations that are build up by grouping memory segments. Generations enhance the garbage collection performance. The following are the three types of generations found in a garbage collector:
  • Generation 0 - When an object is initialized, it is said to be in generation 0.
  • Generation 1 - The objects that are under garbage collection process are considered to be in generation 1.
  • Generation 2 - Whenever new objects are created and added to the memory, they are added to generation 0 and the old objects in generation 1 are considered to be in generation 2. 
20. What is the role of the JIT compiler in .NET Framework?
The JIT compiler is an important element of CLR, which loads MSIL on target machines for execution. The MSIL is stored in .NET assemblies after the developer has compiled the code written in any .NET-compliant programming language, such as Visual Basic and C#.

JIT compiler translates the MSIL code of an assembly and uses the CPU architecture of the target machine to execute a .NET application. It also stores the resulting native code so that it is accessible for subsequent calls. If a code executing on a target machine calls a non-native method, the JIT compiler converts the MSIL of that method into native code. JIT compiler also enforces type-safety in runtime environment of .NET Framework. It checks for the values that are passed to parameters of any method.

For example, the JIT compiler detects any event, if a user tries to assign a 32-bit value to a parameter that can only accept 8-bit value. 








No comments:

Post a Comment

About Me

Hello, I am Anamika here and working as HR consultant in Bangalore. I completed my MBA in HRM. My motto is creating this blog for those who need job and desperately looking for job change. I am humbly requesting to all visitor, please support me to make this blog to successful. Thanks :)