What is .net?

advertisement

What is .net?

It is a framework

The .NET Framework is a common environment for building, deploying, and running Web

Services and Web Applications.

The .NET Framework contains common class libraries - like ADO.NET, ASP.NET and

Windows Forms - to provide advanced standard services that can be integrated into a variety of computer systems.

The .NET Framework is language neutral. Language neutral means that suppose if u are developing an inventory system where it records your how many products are purchased and how many are sold, if my purchase module is developed in vb language and sales module in c# language so it is integrated in that inventory system. It is not dependent on the language

It supports 40+ languages like C++, C#, Visual Basic, JScript (The Microsoft version of

JavaScript) and COBOL. Third-party languages - like Eiffel, Perl, Python, Smalltalk,etc and others

It provides a feature-rich application execution environment -

, simplified development - and easy integration between a number of different development languages-

What is Common Language Runtime (CLR)?

It is heart of the .NET framework. Common Language Runtime (CLR) is the engine available in .Net

Framework to compile and run the program. CLR engine does not compile the code in machine code but converts the code in a set of instructions called Microsoft Intermediate Language (MSIL). This MSIL is one of the section of Portable Executable (PE) file, the other being Metadata. PE file automatically get generated when you compile the program code.

The conversion of the program code to MSIL by CLR engine, makes .Net platform and language independent. After the conversion of the program code to MSIL, the code is then translated to

native or machine code. Instead of compiling the program code at development time, the MSIL code gets translated ‘just in time’ (JIT) by JIT compilers.

CLR engine is divided into modules that contain code, metadata, and resources. The code is stored in common intermediate language (CIL) format. The module's metadata includes the types such as names, inheritance relationships, method signatures, and dependency information. The module's resources consist of static read-only data such as strings, bitmaps, and other aspects of the program that are not stored as executable code.

The CLR supports component-based programming. Component development has numerous attractive benefits such as code reuse, proper maintenance of all components by allowing independent bug fixes to each. In addition, the CLR helps developers in managing both allocation and deallocation of memory. This removes two of the largest sources of programmer error: leaks and memory corruption.

CLR is also helpful for security purposes. CLR provide permissions to a component based on what process it runs in, validates the code based on evidence such as information about code at load time and the website from which component was obtained to assign permissions on a component-by-component basis. Moreover, CLR checks the code to see if it has been manipulated. The metadata in a CLR component can contain a digital signature that can be used to verify that the component was written by genuine person and that it has not been modified.

You can verify identity if anyone has tried to modify with the code. For example, if someone tries to change the code of transferring money from the intended recipient to himself the CLR will prevent the altered code from running.

What is MSIL (Microsoft Intermediate Languages)?

A .NET programming language (C#, VB.NET, J# etc.) does not compile into executable code; instead it compiles into an intermediate code called Microsoft Intermediate Language (MSIL). As a programmer one need not worry about the syntax of MSIL - since our source code in automatically converted to

MSIL.

The MSIL defines a set of portable instructions that are independent of any specific cpu. It is the MSIL which u deliver to your customer in the form of a DLL or EXE. When the .net application runs the .net framework in the target computer take care of execution (The target computer should have .net framework installed).

The MSIL code is then send to the CLR (Common Language Runtime) that converts the code to machine language which is then run on the host machine.

Base Class Library (BCL)

The Base Class Library (BCL), sometimes referred to as the Framework Class Library (FCL)

(which is a superset including the Microsoft.* namespaces), is a library of classes available to all languages using the .NET Framework. The BCL provides classes which encapsulate a number of common functions such as file reading and writing, graphic rendering, database interaction,

XML document manipulation, and so forth. The BCL is much larger than other libraries, but has much more functionality in one package.

ADO.NET: Data and XML

ADO.NET is the next generation of Microsoft ActiveX Data Object (ADO) technology.

ADO.NET is heavily dependent on XML for representation of data. It also provides an improved support for the disconnected programming model.

ADO.NET’s DataSet object, is the core component of the disconnected architecture of

ADO.NET. The DataSet can also be populated with data from an XML source, whether it is a file or an XML stream.

ADO.NET is an object-oriented set of libraries that allows you to interact with data sources. Commonly, the data source is a database, but it could also be a text file, an Excel spreadsheet, or an XML file. For the purposes of this tutorial, we will look at

ADO.NET as a way to interact with a data base.

As you are probably aware, there are many different types of databases available. For example, there is Microsoft SQL Server,

Microsoft Access, Oracle, Borland Interbase, and IBM DB2, just to name a few. To further refine the scope of this tutorial, all of the examples will use SQL Server.

What are Web Services?

Web Services provide data and services to other applications.

Future applications will access Web Services via standard Web Formats (HTTP, HTML, XML, and SOAP), with no need to know how the Web Service itself is implemented.

Web Services are main building blocks in the Microsoft .NET programming model

Web services are small units of code

 Web services are designed to handle a limited set of tasks

 Web services use XML based communicating protocols

 Web services are independent of operating systems

 Web services are independent of programming languages

Web services connect people, systems and devices

Benefits of Web Services

 Easier to communicate between applications

 Easier to reuse existing services

 Easier to distribute information to more consumers

 Rapid development

Web Forms

Windows Forms

What is common languages specification (CLS)?

One of the obvious themes(ideas) of .NET is unification and interoperability between various programming languages. In order to achieve this; certain rules must be laid and all the languages must follow these rules. CLS is the collection of the rules and constraints that every language (that seeks to achieve .NET compatibility) must follow. Microsoft have defined three level of CLS compatibility/compliance. The goals and objectives of each compliance level has been set aside. Given below are the three compliance levels with their brief description:

COMPLIANT PRODUCER

The component developed in this type of language can be used by any other language.

CONSUMER

The language in this category can use classes produced in any other language. In simple words this means that the language can instantiate classes developed in other language. This is similar to how COM components can be instantiated by your ASP code.

EXTENDER

Languages in this category can not just use the classes as in CONSUMER category; but can also extend classes using inheritance.

Languages that come with Microsoft Visual Studio namely Visual C++, Visual Basic and C#; all satisfy the above three categories. Vendors can select any of the above categories as the targeted compliance level(s) for their languages.

In short, CLS is Set of rules that exists on paper.

Every language has to follow the rules in CLS to be compatible with .NET.

If you think to develop language that should be included in the .Net then read rules and according to that rules you have to develop the language.

Some of the rules are:-

No language can compile and generate native code directly it must generate IL (Bytecode) code.

No language is allow to have its own datatype.

Cannot create datatype – to ensure consistency, BCL provide datatype.

The CLR is composed of five primary parts:

 Common Type System (CTS)

 Common Language Specification (CLS)

 Common Intermediate Language (CIL)

 Just-in-Time Compiler (JIT)

 Virtual Execution System (VES) principal features of clr:

Interoperability - Because interaction between new and older applications is commonly required, the .NET Framework provides means to access functionality that is implemented in programs that execute outside the .NET environment. Access to COM components is provided in the

EnterpriseServices namespace of the framework, and access to other functionality is provided using the P/Invoke feature.

Common Runtime Engine - Programming languages on the .NET Framework compile into an intermediate language known as the Common Intermediate Language, or CIL; Microsoft's implementation of CIL is known as Microsoft Intermediate Language, or MSIL. In Microsoft's implementation, this intermediate language is not interpreted, but rather compiled in a manner known as just-in-time compilation (JIT) into native code. The combination of these concepts is called

 the Common Language Infrastructure (CLI), a specification; Microsoft's implementation of the CLI is known as the Common Language Runtime (CLR).

Language Independence - The .NET Framework introduces a Common Type System, or CTS. The CTS specification defines all possible datatypes and programming constructs supported by the CLR and how they may or may not interact with each other. Because of this feature, the .NET Framework supports development in multiple programming languages. This is discussed in more detail in the

.NET languages section below.

Base Class Library - The Base Class Library (BCL), sometimes referred to as the Framework Class

Library (FCL), is a library of types available to all languages using the .NET Framework. The BCL provides classes which encapsulate a number of common functions, including file reading and

 writing, graphic rendering, database interaction and XML document manipulation.

Simplified Deployment - Installation of computer software must be carefully managed to ensure that it does not interfere with previously installed software, and that it conforms to increasingly stringent security requirements. The .NET framework includes design features and tools that help address these requirements.

Security - .NET allows for code to be run with different trust levels without the use of a separate sandbox.

CTS

 defines datatypes and programming constructs supported by the CLR

 Provides the data types, values, object types. This helps developers to develop applications in different languages. Where .NET languages share CTS mean all the types used in applications shares the same types defined under CLI.

CTS provides the base set of data types for all the languages supported by .net framework. This means that the size of integer and long variables is the same across all .net compliant programming languages. However each language uses aliases for the base data types provided by

CTS. For eg. Visual basic uses INTEGER whereas c# uses int to represent 4 byte integer value.

This is done for simplicity and clarity

The Common Type System (CTS) is used by every language built on the .NET Framework. A fundamental part of the .NET Framework is Common Language Runtime (CLR), the CTS specifies no particular syntax or keywords, but instead defines a common set of types that can be used with many different language syntaxes. Each language is free to define any syntax it wishes, but if that language is built on the CLR, it will use at least some of the types defined by the CTS.

Everything in the CTS is an object. Not only is everything an object but even more importantly, all objects implicitly derived from a single base class defined as a part of the CTS. This base class is called System.Object.

The functions of Common Type System

 Establishes a framework that helps enable cross-language integration, type safety, and high performance code execution.

 Provides an object-oriented model that supports the complete implementation of many

 programming languages.

Defines rules that languages must follow, which helps ensure that objects written in different languages can interact with each other.

Type categories

The common type system supports two general categories of types: i.

Value types

Value types directly contain their data, and instances of value types are either allocated on the stack or allocated inline in a structure. Value types can be built-in (implemented by the runtime), user-defined, or enumerations. ii.

Reference types

Reference types store a reference to the value's memory address, and are allocated on the heap. Reference types can be self-describing types, pointer types, or interface types. The type of a reference type can be determined from values of self-describing types. Selfdescribing types are further split into arrays and class types. The class types are userdefined classes, boxed value types, and delegates.

Executing CIL

 Source code is converted to Common Intermediate Language and an assembly is created.

 Upon execution of a .NET assembly, its CIL is passed through the Common Language Runtime's

JIT compiler to generate native code. (NGEN compilation eliminates this step at run time.)

The native code is executed by the computer's processor.

Just-In-Time (JIT) Compilation

The Just in time compiler is a facility that is invoked by the CLR to convert the IL into machine code. The .NET framework assemblies (*.dll or *.exe) files cannot be executed by the target processor unless it is converted into native code. When the Assembly is loaded the method calls are invoked for compilation into native code. Since this is done just when the method needs to execute, it is called Just in time compilation.

Just-in-time compilation involves the byte-code being turned into code immediately executable by the CPU. The conversion is performed gradually during the program's execution. JIT compilation provides environment-specific optimization, runtime type safety, and assembly verification. To accomplish this, the JIT compiler examines the assembly metadata for any illegal accesses and handles violations appropriately.

This also generally offers far better performance than interpreters as the compiled code is stored in memory cache at runtime, such that subsequent recompilation or reinterpretation of compiled code can be skipped, while also giving flexibility to automatically recompile and optimise code that is found at runtime to be frequently executed.

Other advantages of a JIT runtime include:

1.

The compilation can be optimized to the targeted CPU and the operating system model where the application runs. For example JIT can choose SSE2 CPU instructions when it detects that the

CPU supports them.

2.

The system is able to collect statistics about how the program is actually running in the environment it is in, and it can rearrange and recompile for optimum performance. This data is normally difficult or even impossible to obtain for conventional compilers.

JIT compilation is considered advantageous in many scenarios because of its portability, flexibility and performance. The only major drawback is the startup time delay.

Metadata

Metadata is information about the compiled classes. It serves the same purpose as a type library in COM. Metadata enables applications to support and discover the interfaces, classes, types, methods, and fields in the assembly. The process of reading metadata is called reflection .

Virtual Execution System

The Virtual Execution System (VES) provides an environment for executing managed code. It provides direct support for a set of built-in data types, defines a hypothetical machine with an associated machine model and state, a set of control flow constructs, and an exception handling model.To a large extent, the purpose of the VES is to provide the support required to execute the

Common Intermediate Language instruction set.

Download