Components Of .NET

.NET Introduction

 
.NET is not a programming language but it is a tool that provides an environment to write the code and run the applications. .NET support 63 programming languages in which 11 languages developed by Microsoft and 52 programming languages developed by another organization.
 
The components of .NET  are CLR, Garbage Collector, JIT Compiler and base class library,
 
.NET Introduction
 

CLR (Common Language Runtime)

 
CLR is responsible for providing common syntax, automatic memory management, and common data type. Also, the responsibility of CLR is generating native code from MSIL Code.
 

CLS (Common Language Specification)

 
As we know that .NET support 63 programming language and also we know that each and every language has their own syntax for writing code and one language does not support the syntax of another language. That means .NET has features of common syntax which are supported by all 63 programming languages.
 

CTS (Common Type System)

 
As we know that .NET support 63 programming languages and also we know that each and every language has their own data type system and One language does not support data type of another language. That means .NET has features of Common Data type which is supported by all 63 programming languages.
 
Example
 
There is integer data type in C# .NET,
  1. int i = 123;  
There is Integer data type in J# .NET
 
Dim I As Integer
 
As we are looking both languages have their own data type system. But these languages will support the common data type of .NET which is:
 
Int 32
 

Garbage Collector

 
Garbage Collector is responsible for automatic memory management of objects. Also, the responsibility of the garbage collector is removing the object from memory that has no use. In Garbage Collector Memory divided into 3 generations and these generations are Generation 0, Generation 1, and Generation 2.
 
When a new object creates it gets stored in Generation 0 and the process gets repeated till generation 0 is full. When Generation 0 size gets full then there 2 processes will be performed. First Process is marking the object which is not reachable for a long time. And in the Second process object will remove from the memory that has marked early and the remaining object will get transferred to Generation 1. This process will repeat also for Generation 2. There are 3 methods for removing objects from Memory. These methods are (1) Dispose () (2) Finalize () (3) gc.Collect ().
  • Dispose Method: Dispose method is used to remove the object from memory that has no reference this method gets called by the User.
  • Finalize Method: Finalize method is used to clean up the object from memory. This method gets called by System.
  • Gc.Collect Method: This method is used for removing the object from memory forcefully.
JIT Compiler: JIT Compiler is responsible for compiling the MSIL Code and generate the Native Code. There are the following 3 types of JIT compiler,
  • Normol Jitter: Normal jitter is a Default jitter that compiles the code line by line and it stores the cache of compiled code.
  • Echono Jitter: Echono jitter compiles the selected line of code and it does not contain the cache of compiled code.
  • Pre Jitter: Pre Jitter Compile the code from top to button and also it stores the cache of compiled code.
Why we use ngen.exe
 
Ngen.exe is a tool that is used to compile the MSIL code and generate native code. We use the ngen.exe tool because it stores all the compiled code in a separate disk which is known as image generation files. The code compiled by ngen.exe can be reused but the JIT compiler does not store compiled data.
 
Code Compilation in .NET
 
.NET support 63 programming language and each and every language has their own compiler. Language compiler the source code and generate MSIL (Microsoft Intermediate Language) then MSIL code gets transferred to CLR and JIT compiler compiles this code and generates native code.
 
Code Compilation in .NET
 
In .NET there are 2 phases of a compilation of code. In the first phase, source code gets compiled by the source code language compiler and generates IL code and in the second phase, IL code gets compiled and generates native code. This 1st Phase is slower than the 2nd Phase. Code compilation in .NET is graphically represented above.