Thursday, August 20, 2009

.Net Framework





.NET is a Framework that consists of two main components: the common language runtime and the .NET Framework class library. That's difficult to sum up in a sentence. A more practical definition would be that .NET is a new environment for developing and running software applications, featuring easy development of web-based services, run-time services available to components written in a variety of programming languages, and inter-language and inter-machine interoperability.

Features:
· Interoperability with other environments
· Support for developing language-independent applications
· Support for OOPs
· Support for Web applications.
· Support for Web service


.NET base class library
The .NET base class library is a collection of object-oriented types and interfaces that provide object models and services for many of the complex programming tasks you will face. Most of the types presented by the .NET base class library are fully extensible, allowing you to build types that incorporate your own functionality into your managed code.
The .NET Framework base class library contains the base classes that provide many of the services and objects you need when writing your applications. The class library is organized into namespaces. A namespace is a logical grouping of types that perform related functions


What is CLR?
The common language runtime can be thought of as the environment that manages code execution. It provides core services, such as

1. Class loader, which loads classes into the runtime.
2. MSIL to native code compiler, which converts MSIL code into native code.
3. Code manager, which manages the code during execution.
4. Garbage collector, which performs automatic memory management.
5. Security engine, which enforces security restrictions.
6. Type checker, which enforces strict type checking.
7. Thread support, which provides multithreading support to applications.
8. Exception manager, which provides a mechanism to handl the run-time exceptions.
9. Debug engine, which allows you to debug different types of applications.
10. COM marshaler, which allows .NET applications to exchange data with COM applications.
11. Base class library support, which provides the types that the applications need at run time.

For a program to run within the common language runtime and benefit from the managed execution environment, you need to write the source code of the program in a CLS-compliant language. The compilers of CLS-compliant languages compile the source code and generate an intermediate code, called MSIL code, and metadata. The MSIL code contains a CPU-independent set of instructions, which describes how to load, store, initialize, and call methods on objects. MSIL code also contains instructions that enable you to perform arithmetic and logical operations, access memory directly, control the flow of execution, handle exceptions, and perform other operations. Before you execute the MSIL code, you need to compile it into CPU-specific instructions. To execute the code, the runtime requires information about the code that is in the metadata. The metadata describes the code and defines the types that the code contains as well as references to other types that the code uses at run time. The MSIL code and the metadata are located in a portable executable file.

When you execute a portable executable file, the class loader loads the MSIL code and the metadata from the portable executable file into the run-time memory. Before the code is executed, it is passed to the native code compiler for compilation. The IL to native code compiler contains just-in-time (JIT) compilers for different CPU architectures and compiles the IL code into a native instruction set. The IL to native code compilation occurs when a method is called for the first time. For subsequent calls to the method, the existing JIT-compiled code is executed. Figure 1.4 shows the JIT compilation process.

What is CTS?
Common Type System (CTS) describes how types are declared, used and managed in the runtime and facilitates cross-language integration, type safety, and high performance code execution.
As discussed earlier, .NET aims at providing interoperability between applications. To create interoperable applications, you need a set of standard data types that would be used across applications. In addition, you require a set of guidelines to create user-defined classes and objects for the .NET Framework. These standards data types and the set of guidelines are contained in CTS. To ensure interoperability across applications, CTS includes only those data types and features that are compatible across languages. Consider an example of an application of which a part is created using C++. Subsequently, to provide a visual interface, you need to re create the entire application in Visual Basic. This means that you need to re create all the classes that you have used in the C++ application. This is because C++ and Visual Basic are not interoperable. The CTS feature for the .NET Framework simplifies such tedious tasks. If you create a class in any of the languages in the .NET Framework, you can use the same class in another language that is supported by the .NET Framework.
What is CLS?
The CLS is simply a specification that defines the rules to support language integration in such a way that programs written in any language, yet can interoperate with one another, taking full advantage of inheritance, polymorphism, exceptions, and other features. These rules and the specification are documented in the ECMA proposed standard document;
CLS is defined as a set of rules that a .NET language should follow to allow you to create applications that are interoperable with other languages. However, to achieve interoperability across languages, you can only use
objects with features listed in the CLS. These features are called CLS-compliant features.
For example C# supports uint32, which is a 32-bit unsigned integer data type that is not CLS-compliant. The uint32 data type is not supported by Visual Basic


. NET. If you use the u i n t 3 2 data type in a C# class , the class might not be interoperable with Visual Basic .NET applications. Only a CLS-compliant code is fully interoperable across languages. Although you can use the non-CLS fe a t u re in a . N ET language cl a s s , the class might not be available to other .NET languages. CLS works closely with CTS and MSIL to ensure language interoperability. You can also call CLS as a subset of CTS and MSIL, because CLS does not include all the features of CTS and MSIL. A compiler might not support some of the features of CTS and MSIL and still be CLS-compliant.


Following are some of the features of CLS:
· Global methods and variables are not allowed in a CLS-compliant language.
· Some data types, such as unsigned data types, are not allowed in a CLS compliant language.
· Unique names should be used in a CLS-compliant language. Even if the language is case- sensitive, you must use distinct names for different variables.
· Languages that are case-insensitive should be able to differentiate between the names.
· Any exception that you want to handle must be derived from the base class Exception.
· Pointers are not supported by a CLS-compliant language.










No comments:

Post a Comment