Inside .net framework

29
Inside .Net Framework By Prof. Sheetal R. Uplenchwar

description

 

Transcript of Inside .net framework

Page 1: Inside .net framework

Inside .Net Framework

By Prof. Sheetal R. Uplenchwar

Page 2: Inside .net framework

CLR

The Common Language Runtime (CLR) is a special run time environment that provides the underlying infrastructure for Microsoft's .NET framework.

This runtime is where the source code of an application is compiled into an intermediate language called CIL (Common Intermediate Language), originally known as MSIL (Microsoft Intermediate Language).

When the program is then run, the CIL code is translated into the native code of the operating system using a just-in-time (JIT) compiler.

This intermediate language is used to keep the environment platform-neutral and as a result, supports all .NET languages such as C# or VB.NET

Page 3: Inside .net framework
Page 4: Inside .net framework

Advantages Portability

Using an intermediate language instead of compiling straight to native code requires n + m translators instead of n*m translators to implement it in n languages on m platforms.

Security The high level intermediate code is more ready for deployment

and runtime enforcement of security. Interoperability

Every major .NET language supports CLR and all get compiled to CIL. In that intermediate language, implementation of services such as security and garbage collection are the same.

Page 5: Inside .net framework

This allows one library or application of one .NET language to inherit implementations from classes written in another .NET language.

This cuts down on the redundant code developers would have to write to make a system work in multiple languages, allowing for multi-language system designs and implementations.

Additionally, to keep full component interoperability, the runtime incorporates all metadata into the component package itself, essentially making it self-describing.

The main advantage of the .NET Framework is the interoperability between different languages. As all the Microsoft .NET languages share the same common runtime language, they all work well together. For example, you can use an object written in C# from Visual Basic.NET. The same applies for all the other Microsoft .NET languages

Page 6: Inside .net framework

Application related advantagesAutomated Garbage CollectionSupport for explicitly free threading, which

allows for the creation of multi-threaded, scalable applications.

Support for uniform exception handlingUse of delegate functions instead of function

pointers for increased type safety and security.

Page 7: Inside .net framework

MSILVB.Net compiles code which is processor

independent.It is portable to n no of platforms.This MSIL is then given as input to JIT

Compilers which converts it into native(machine )code.

At the time of generation of MSIL code all metadata(methods, properties, events, data types) gets created.

Page 8: Inside .net framework

JIT CompilersMicrosoft provides a set of JIT compilers

for each supported platform.These compilers compile MSIL code into

native machine code.Unlike traditional compilers JIT doesn’t

compile the full class file in one shot. Compilation is done on function basis or

file basis.

Page 9: Inside .net framework

The high level programming languages that need to be compiled require a runtime, so that the architecture on which the language runs is provided with details on how to execute its code.

All the programming languages use its corresponding runtime to run the application. For example, to run an application developed using Visual Basic, the computer on which the application will be run must be installed with the Visual Basic runtime.

The Visual Basic runtime can run only the applications developed with Visual Basic and not the ones developed with any other programming language like Java.

Page 10: Inside .net framework

In the .NET Framework, all the Microsoft .NET languages use a common language runtime, which solves the problem of installing separate runtime for each of the programming languages.

Microsoft .NET Common Language Runtime installed on a computer can run any language that is Microsoft .NET compatible.

Page 11: Inside .net framework

When you compile a Microsoft.NET language, the complier generates code written in the Microsoft Intermediate Language (MSIL). MSIL is a set of instructions that can quickly be translated into native code.

A Microsoft.NET application can be run only after the MSIL code is translated into native machine code. In .NET Framework, the intermediate language is complied "just in time" (JIT) into native code when the application or component is run instead of compiling the application at development time.

Page 12: Inside .net framework

CompilationExecution

Compilation & Execution Cycle of .Net application

Page 13: Inside .net framework

Types of JITPre-JIT :

Per-JIT compiler compiles source code into native code in a single compilation cycle.

Econo- JIT: Econo- JIT compiles methods that are called at runtime. However,

these compiled methods are discarded when they’re not required.

JIT (Normal JIT) – They’re called “JIT” or “Normal JIT”. Normal JIT only compiles

the methods which are called at runtime. These methods are compiled the first time they’re called and

then they’re stored in cache. When the same methods are called again, the compilation code from cache is used for execution.

Page 14: Inside .net framework

Managed CodeManaged Code is what Visual Basic .NET and C#

compilers create. It compiles to Intermediate Language (IL), not to

machine code that could run directly on your computer.

The IL is kept in a file called an assembly, along with metadata that describes the classes, methods, and attributes (such as security requirements) of the code

This assembly is the one-stop-shopping unit of deployment in the .NET world.

You copy it to another server to deploy the assembly there—and often that copying is the only step required in the deployment.

Page 15: Inside .net framework

Managed code runs in the Common Language Runtime. The runtime offers a wide variety of services to your running code.

In the usual course of events, it first loads and verifies the assembly to make sure the IL is okay.

Then, just in time, as methods are called, the runtime arranges for them to be compiled to machine code suitable for the machine the assembly is running on, and caches this machine code to be used the next time the method is called. (This is called Just In Time, or JIT compiling, or often just Jitting.)

As the assembly runs, the runtime continues to provide services such as security, memory management, threading, and the like. The application is managed by the runtime

Page 16: Inside .net framework

Unmanaged code

It is what you use to make before Visual Studio .NET 2002 was released.

Visual Basic 6, Visual C++ 6, heck, even that 15-year old C compiler produced unmanaged code.

It compiled directly to machine code that ran on the machine where you compiled it—and on other machines as long as they had the same chip, or nearly the same.

It didn't get services such as security or memory management from an invisible runtime; it got them from the operating system, usually by calling an API provided in the Windows SDK.

Page 17: Inside .net framework

System TypesSystem class library.Net Framework Class Library

It is a library of classes, interfaces and value types .

It optimizes the development process, provides access to system functionality .

It is designed to be as a foundation on which .Net framework applications, components and controls are built.

Page 18: Inside .net framework

FCL is an integral component of the .NET framework. It consists of object oriented collection of reusable

classes that can be used to develop command line, GUI, web applications etc.

It is designed into a hierarchical tree structure & divided into namespace.

Before .Net class framework, each programming required its own class libraries.

All .Net languages share the .Net class framework requiring no special language specific libraries.

Syntax used to perform the task between .Net languages looks the same as the same namespace & parameters is to be used.

Page 19: Inside .net framework

The .Net framework class library is divided into 2 parts Base class library Framework class library.Base class library It includes a small subset of the entire class library & is the core

set of classes that serve as the basic API of the common language runtime.

The classes in mscorlib.dll , system.dll & system.core.dll are consiered as part of BCL.

Framework class library It is a superset of the BCL classes & refers to the entire class

library that ships with .Net framework. It includes winforms, ADO.Net, ASP.Net etc.

Page 20: Inside .net framework

Namespaces in vb.net

System: Includes essential classes and base classes for commonly used data types, events, exceptions and so onSystem.Collections: Includes classes and interfaces that define various collection of objects such as list, queues, hash tables, arrays, etcSystem.Data: Includes classes which lets us handle data from data sourcesSystem.Data.OleDb: Includes classes that support the OLEDB .NET providerSystem.Data.SqlClient: Includes classes that support the SQL Server .NET providerSystem.Diagnostics: Includes classes that allow to debug our application and to step through our codeSystem.Drawing: Provides access to drawing methods

Page 21: Inside .net framework

System.Globalization: Includes classes that specify culture-related informationSystem.IO: Includes classes for data access with FilesSystem.Net: Provides interface to protocols used on the internetSystem.Reflection: Includes classes and interfaces that return information about types, methods and fieldsSystem.Security: Includes classes to support the structure of common language runtime security systemSystem.Threading: Includes classes and interfaces to support multithreaded applicationsSystem.Web: Includes classes and interfaces that support browser-server communicationSystem.Web.Services: Includes classes that let us build and use Web ServicesSystem.Windows.Forms: Includes classes for creating Windows based formsSystem.XML: Includes classes for XML support

Page 22: Inside .net framework

System.object class It is the base class of all classes in the .Net framework. It is the root of the type hierarchy.

Name Description

Equals(Object) Determines whether the specified Object is equal to the current Object.

Equals(Object, Object) Determines whether the specified object instances are considered equal.

Finalize

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

Page 23: Inside .net framework

GetHashCode Serves as a hash function for a particular type.

GetType Gets the Type of the current instance.

MemberwiseClone Creates a shallow copy of the current Object.

ReferenceEquals Determines whether the specified Object instances are the same instance.

ToString Returns a string that represents the current object.

Page 24: Inside .net framework

Common type system With common type system all data types are provided as objects in

the System.object class. This class is accessible by all .Net programming languages &

enforced by CLR. Also previously type conversions needed to be performed every

time when data was exchanged. With the CTS, it is no longer necessary to cast data types between

assemblies that are written in different languages. CTS provides a new standard for .Net assemblies called as type

safe compatibility. To achieve type safe compatibility, some languages have to adjust

their data type. Language interoperability is achieved with the help of CTS. Same data type is available in all .Net compatible languages.

Page 25: Inside .net framework

Classification of CTS Types Value types

It directly contain the data that you assign them. Value types are fixed in size. Actual values of data are stored in stack. If you assign a value of a variable to another it will create two copies. All primitive data type except string and object are example of value

types. struct and enum are value type. Reference type

Reference types are not fixed in size. It directly do not contain any data. It point to a memory location that contains the actual data. They are maintained in system managed heap but it also uses stack

to store reference of heap.

Page 26: Inside .net framework

Two primitive types (string and object) and non-primitive data types (class, interface & delegate) are examples of reference type.

Page 27: Inside .net framework

Basic Value typesVB Keyword Bytes .NET type Description

Byte 1 Byte 0-255

SByte 1 SByte -128 to 127

Short 2 Int16 -32,768 to +32,767

UShort 2 UInt16 0 to 65535

Integer 4 Int32 -2,147,483,648 to + 2,147,483,647

UInteger 5 UInt32 0 to 4,294,967,295

Long 8 Int64 -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807

Page 28: Inside .net framework

ULong 8 UInt64 0 to +18,446,744,073,709,551,615

Single 4 Single A non integer number with approximately 7 significant digits

Double 8 Double A non integer number with approximately 14 significant digits

Page 29: Inside .net framework

Decimal 16 Decimal A non integer number with approximately 28 significant digits (integer and fraction) that can represent values up to 79,228 X 1024

Char 2 Char A single Unicode character

Boolean 1 Boolean A True or False value