Wednesday, 25 June 2014

What is Boxing and Unboxing? and explain in detail?

Boxing:
  • Boxing is the process of converting a variable type to reference type.
  • Supports 2 types
    • Implicit boxing
    • Explicit boxing
  • Boxing 20 times Costlier than normal initialization
Unboxing:
  • Unboxing is the process of converting a reference type to value type.
  • Supports only 1 type
    • Explicit Unboxing
  • Unboxing 4 times costlier than normal initialization
Example: Program for boxing and Unboxing:
Output:

  • Boxing is 20 times costlier than normal initialization, because whenever a boxing is done following tasks will be performed internally.
    • Runtime will search for the respective data with in the stack.
    • A copy of this value is made into heap.
    • Reference to this copy is maintained from the object variable.
  • Unboxing is 4 times costlier than normal initialization, because whenever a boxing is done following tasks will be performed internally.
    • Object referenced value is searched within the Heap.
    • A copy of this is made into stack.

What are the categories of data types in CTS and explain in details?

CTS is devided in to two categories:
  1. Values type
  2. Reference type
Value type:
  • The data types which store the data directly in to the memory locations is known as value types.
  • Memory is allocated at Compilation Time.
  • Memory allocation is Made with in the Stack i.e in contiguous memory locations
  • CLR does not provide automatic memory management.
Reference type:
  • The data type which do not store the data into there memory locations rather refers to other memory locations is known as reference types.
  • Memory is allocated at Run Time.
  • Memory allocation made with in the heap i.e Random Memory Locations.
  • CLR provides Automatic memory management.

What is CTS and explain its role?

CTS(Common Type System)

  • As we know Managed code execution process .NET supports many programming languages.
  • Every programming Language has it own data types.
  • One programming Language can not understood other Programming Languages data types.
  • But CLR will execute all programming Languages code, this is possible because CLR will contain its own data types, which is common to all the programming languages 
  • At the time of compilation all languages specific data types are converted in to CLR's Data Type.
  • This Data Type System of CLR which is common to all programming languages of .Net is known as Common Type System.
  • This common type system is divided in to two categories:
    • Value Types
    • Reference Types

What is Unmanaged Code and Unmanaged Code Execution? and what is CCW and RCW?

Unmanaged Code:
  • The code that has written before development of .Net for which MSIL is not available is not executed by CLR directly, rather CLR redirects the code to OS for Execution, which is known as Unmanaged code.
  • The code which has developed outside .Net framework is known as Unmanaged code.
  • Applications that do not run under the control of the CLR are said to be unmanaged, and certain languages such as C++ can be used to write such applications, which, for example, access low - level functions of the operating system. Background compatibility with code of VB, ASP and COM are examples of unmanaged code.
Unmanaged Code Execution:
  • The code execution process is known as Unmaged Code Exection.
  • CLR will not provide any facilities and features of .Net to Unmanaged Code Execution like Language Interoperability, Automatic Management, Common Data Type System, Exception Handling Mechanism, Code Access Security etc.
Unmanged code executed with helper of wrapper classes.

Wrapper classes are two types:
  1. CCW (COM Callable Wrapper)
  2. RCW (Runtime Callable Wrapper)
COM callable wrapper unmanaged code execution


Runtime Callable Wrapper unmanaged code execution





What is Managed Code and Managed Code execution?

Managed Code:
  • The code which MSIL is generated after Language Compiler Compilation is directly executed by CLR is known as Managed Code.
  • Any language that is written in .NET Framework is Managed code.
  • Applications which runs under the control of the CLR is known as Managed code.
  • The resource, which is with in your application domain is, managed code. The resources that are within domain are faster
Managed Code Execution:
  • The code execution process is known as Managed Code Execution.
  • CLR will provide all the facilities and features of .Net to Managed Code Execution like Language Interoperability, Automatic Management, Common Data Type System, Exception Handling Mechanism, Code Access Security etc.



What is Language Interoperability?

Language Interoperability:

  • Providing code execution support that has been written in other programming languages is known as Language Interoperability.
  • Language Interoperability is achieved using Managed and Unmanaged.


What is CLS and Explain its role?

CLS(Common Language Specification)

  • Language Specification: Every Programming Language will have some Syntactical rules used to write the code which is known as Language Specification.
  • As we know Managed code execution process .NET supports many programming languages.
  • Every programming Language has it own Language Specification.
  • One programming Language can not understood other Programming Language Specification.
  • But CLR will execute all programming Languages code, this because
    • CLR can not understand any programming Language Language Specification rather CLR has its own Language Specification (Syntactical Rules) for its MSIL.
    • Any Language Compiler should follow this Language Specification of CLR at the time of compilation and should generate MSIL, CLR's JIT Compiler will generate native code from MSIL and CLR will execute it.
  • This Language Specification of CLR is common to all programming Languages of Managed code execution of .NET and is known as CLS (Common Language Specification)
Role of CLS
  • CLS is responsible to provide language interoperability
  • This is achieved in 2 ways 
    1. Managed Code 
    2. Unmanaged Code.