Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

CA521: Fundamentals of Visual Programming

Unit-I Introduction to .NET framework

.Net Framework

 .Net Framework Architecture,

 Common Language Runtime (CLR),

 Microsoft Intermediate Language (MSIL),

 Just In Time Compiler (JIT),

 Managed Code, Unmanaged Code,

 Common Type System (CTS),

 Common Language Specification (CLS),

 .NET Framework Class Library, Namespace, Assemblies


Que:1 Define the term .NET framework and explain its architecture in details.

Answer:-

Figures:-.NET Framework

The .NET Framework is a service or platform for building, deploying, and


running applications

Net is a new framework for developing web-based and windows-based applications


within the Microsoft environment.

.Net framework is a development and execution environment (platform) of


Microsoft that allow number of languages and reach class library to develop Console
application, Window application, Web application, Mobile application and web
services.

1|Page
The framework offers a fundamental shift in Microsoft strategy: it moves
application development from client-centric to server-centric

The .Net framework consists of 2 main parts:

Common Language Runtime

and Class libraries

Common Language Runtime (CLR):-

Definition:

The CLR stands for “common language runtime” which is the run
time engine & execution environment. For any .Net application and
it is responsible for translating MSIL code into native code.

 It is the execution engine for .NET Framework applications.

 It is the heart or backbone of the .NET.

 It's is the runtime engine provided by the .NET framework.

 It provides an infrastructure for run programs and allows them to


communicate with other parts of the .NET framework.

It provides a number of services, including the following:

o Code loading and execution

o Application memory isolation

o Verification of type safety

o Conversion of IL to native code

o Access to metadata

o Managing memory for managed objects

o Exception handling, including cross-language exceptions

2|Page
o

Source code .Net supported

J#.Net languages

Language Language
compiler compiler

JSC.exe

[ Figure:- Architecture of CLR ]


3|Page
Explanation of runtime execution by CLR:-

Step-1:- Source code

The code which is written in any .Net supported language


(c#.Net,Vb.Net,J#.Net etc) is called source code.

Step-2:- Compiler

The .Net supported languages compiler (csc.exe,vbc.exe,jsc.exe etc.)


translate the given source code into (cpu) machine independent code that
is called MSIL(Microsoft Intermediate language).

Step-3:- JIT

The JIT “Just In time compiler” translate the MSIL code into native code.

Step-4:-

At last the native code will be execute and we can get output according
to our source code.

Features of CLR:-

 Translate MSIL code to native code.

 Code access security.

 Code verification.

 Security management.

 Garbage collection.

 Error handling and exception handling.

Definition - What does Native Code mean?

Native code refers to programming code that is configured to run on a specific


processor. Native code will generally not function if used on a processor other than
the one it was specifically written for unless it is allowed to run over an emulator.

4|Page
Common Type System(CTS):-

Definition:-

The CTS stands “common type system” which is used to declare manages and
use of multiple no. of data. Types for cross language integration, type
safety and improved execution performance.

 CTS allow programs written in different programming languages to easily


share information.

 A class written in C# should be equivalent to a class written in VB.NET.

 Languages must agree on the meanings of these concepts before they can
integrate with one another.

 CLS forms a subset of CTS. This implies that all the rules that apply to
CTS apply to CLS also.

 It defines rules that a programming language must follow to ensure that


objects written in different programming languages can interact with each
other.

 CTS provide cross language integration.

The common type system supports two general categories of types:

1. Value types

2. Reference types

1. Value types

Store directly data on stack. In built data type.

Example: int a;

2. Reference types

Store a reference to the value's memory address, and are allocated


on the heap.

5|Page
Example: SqlConnection cnn = new SqlConnection();

 According to above figure, we can use integer data type in c#.net as int i;
and we can use integer data type like Dim i as integer; and at run time this
are converted into common data type as system.int32 i ; by using CTS.

Common Language Specification(CLS):-

 CLS includes basic language features needed by almost all the


applications.

 It serves as a guide for library writers and complier writers.

 The Common Languages Specification is a subset of the common type


system.

 The Common Language Specification is also important to application


developers who are writing code that will be used by other developers.

Assembly:-

 An assembly is the primary building block of a .NET Framework


application.

 It can either DLL or EXE.

6|Page
 An Assembly is a logical DLL.

 It consists of DLLs or executable.

 It is a collection of functionality that is built, versioned, and deployed as


a single implementation unit ( as one or more files.)

 All managed types and resources are marked either as accessible only within
their implementation unit or as accessible by code outside that unit.

What are private assemblies and shared assemblies?:-

 A private assembly is used only by a single application, and is stored in


that application's install directly (or a subdirectory therein).

 A shared assembly is one that can be referenced by more than one


application.

 In order to share an assembly, the assembly must be explicitly built for


this purpose by giving it a cryptographically strong name (referred to as a
strong name).

 By contrast, a private assembly name need only be unique within the


application that uses it.

Elements of assembly with its structure:-

Assembly:

 The assembly is a set of exe or .dll file & it is a basic building block or
deployment unit which contains MSIL code, Manifest file, type metadata,
resource file.

7|Page
 ILDASM (“Intermediate Dissembler”) command is used to view the
content of assembly (MSIL) file.

Element/Structure of Assembly:-

i) MSIL code:-

 The source code(C# .net)is compiled & convert using language


complier (csc.exe..)code is code MSIL.

 The JIT compiler compile & convert this MSIL code into native code
for execution.

ii) Manifest:-

 The manifest file contain the information about the metadata of


assembly like assembly name, assembly version , list of data type ,
list of resource , dependencies, security settings.

iii) Type metadata:-

 The type metadata file contain the information about the list of data
type variables, properties, method used in MSIL code

iv) Resource file:-

 The resource file contain the information about text file, icon files,
images, sound or video file which can be used in MSIL code.

8|Page
MSIL

Manifest
(console application)

Type metadata

Resource file

9|Page
Metadata:-

 Metadata stored within the Assembly.

 .NET records information about compiled classes as Metadata.

 Metadata means data about data.

 A .NET language compiler will generate the metadata and store this in
the assembly.

 On the .NET Platform programs are compiled into .NET PE (Portable


Executable) files.

 The header section of every .NET PE file contains a special new section
for Metadata.

 Metadata is nothing but a description of every namespace, class, method,


property etc. contained within the PE file.

The CLR uses this metadata to

Locate classes

Load classes

Generate native code

Providing security

.NET Framework Class Library (FCL) or Base Class Library (BCL):-

 The Base Class Library (BCL) is a standard library available to all


languages using the .NET framework.

 In C, <conio.h>, <stdio.h> etc. are header files. We add those header files
in our program to use inbuilt functions.

 Same here, the .NET Framework are collection of classes or namespace


that can be used to develop applications.

10 | P a g e
 The class library consists of data classes, XML classes, Web Forms classes
and Windows Forms classes, Smart devices classes, Input Output classes.

Name Space:-

 Namespace is a logical naming scheme for types that have related


functionality.

 Namespace means nothing but a logical container or partition.

 Namespace allows you to create a system to organize your code. A good


way to organize your Namespace is via a hierarchical system. You put the
more general names at the top of the hierarchy and get more specific as
you go down. This hierarchical system can be represented by nested name
spaces.

 It’s like drives of our computer.

 Like my computer contains C:,D:,E: and F:.My F: contains movies and


videos my C: contains program files so on.

 For example my friend wants movies. So I will directly go to my computer’s


F: because songs are placed there.

 At the root of the hierarchy is the System Namespace.

 The notion of a Namespace plays a fundamental role in the .NET Framework.

 For example, imagine that in a IAC InfoTech industry there is an Executive


named Vijay Chauhan, a General Manager named Vijay chauhan, and a
Tester named is Vijay Chauhan.

 In this case the name Chauhan Vijay is ambiguous.(salary of GM


1,00,000,Executive 50,000,Tester 10,000).

 When the paymaster stands and calls out the names of people to receive
their salary, the GM Chauhan Vijay won’t be happy if he rushes to the table
when the paymaster calls out his name and the envelope contains the
Tester Chauhan Vijay salary only 10,000.

11 | P a g e
 To resolve the naming ambiguity, the reliance Industry can simply define
three Namespace: Executive, General Manager and Tester. Now the three
individuals can be unambiguously referred to by their fully qualified
names:

Executive.Chauhan Vijay

General Manager.Chauhan Vijay

Tester.Chauhan Vijay

 Above three posts Executive, General Manager and Tester like


Namespace. They are used for identifying Chauhan Vijay directly.

 Same like above Namespace provide scope: Two classes have the same
name but they should reside in different Namespace.

 Basically there are two types of Namespace: inbuilt and user define.

 Using key word is used when importing a Namespace in your code.

Garbage Collection (GC):-

 Garbage Collection is a mechanism that allows the computer to detect


when an object can no longer be accessed.

 It then automatically free up the memory


used by that object.

 One of the advantages of CLR is automatic


memory management that uses the garbage
collection mechanism.

 The CLR's garbage collection GC manages


the allocation and release of memory for an
application.

 We do not have to write code to perform


memory management tasks when we develop managed applications.

Managed execution process .NET program:-


12 | P a g e
Step 1:- Write down coding in any language supported by .NET

Step 2:- Select compiler of programming language, for VB.NET select VBC, fir

C# select CSC same for all language wise select compiler.

Step 3:- Compiler converts compile code to Microsoft Intermediate Language

(MSIL) (CIL) (IL) and converting your source code into MSIL and

generates the metadata.

Step 4:- JIT come

Step 5:- JIT compiler translates the MSIL into native code

Step 6:- Final step running code.

Microsoft Intermediate Language(MSIL) or (CIL) or (IL):-

Definition:

The .Net supported language compiler (csc.exe,vbc.exe etc) translate


the given source code which is written in .Net supported
language(c#.net,vb.net) into machine independent code that is called MSIL.

 MSIL is the CPU independent instruction set into which .NET Framework
programs are compiled.

 It contains instructions for loading, storing, initializing, and calling


methods on objects.

 Combined with metadata and the common type system, MSIL allows for
true cross language integration.

 MSIL also known as CIL (Common Intermediate Language) or


IL(Intermediate Language).

JIT:-

Definition:-

13 | P a g e
JIT stands for “Just In Time Compiler” which is responsible to
translate MSIL code to native code.

 It's a smart compiler.

 JIT does not compile whole program each time and every time. It compiles
only that portion of the program which functions are called that time and
suppose Native code is already present then that data will not again compiled.
If changes are made then possible that it will again generates MSIL to Naive.

 Firstly any program compile by its own compiler then it will convert into MSIL
then with the help of JIT;MSIL compile into Native code but CLR does not
convert whole MSIL code to Native code on load time of that application;
instead of it compiles the MSIL instructions as they are called.

Types of JIT:-

Pre-JIT:-

 The Pre-JIT compiler converts the whole MSIL code into


native code in a one compilation cycle.

Econo-JIT:-

 The Econo-JIT compiler convert only those methods which


are called at run time from MSIL code to native code and does
not store its native code into cache memory for reusability.

Normal-JIT:-

 The normal JIT compiler convert only those method which are
called at run time from MSIL code to native code and store its
native code into cache memory for reusability.

Managed Code:-

 Managed code is what Visual Basic .NET and C# compilers create.

14 | P a g e
 Code that targets the common language runtime, the framework, is known
as managed code.

 The source code which is written using any .NET supported & run or
executes under the environment of .NET Framework runtime engine
“CLR” and get all the features provide by the CLR such as MSIL to native
conversion, garbage collection & memory management.

 Error handling & Exception handling, security management, code access


security, is called manage code.

 Example:-

C# .NET, VB.NET, J#.NET ,MSIL etc..

Unmanaged Code:-

 Code that does not targets the common language runtime is known as
unmanaged code.

 Unmanaged code is what you use to make before Visual Basic .NET 2002
released.

 Code that is directly executed by the Operating System is known as un-


managed code.

 Unmanaged code is one that is run by windows Operating System.

 The source code which is not written in .NET supported language and dose
not execute under the environment of .NET runtime engine “CLR” and does
not get feature provide by CLR is called Unmanaged code.

Example:-

 C, C++, JAVA, VB, Activex etc.

Summary of Managed and Unmanaged Code:-

Managed Code:-

15 | P a g e
1. Understandable by CLR.

2. It is executed under the instructions of CLR.

3. Compiled two times. In the first compilation, the compiler will


generate MSIL code .This is known as Managed Code.

Unmanaged Code:-

1. Cannot able to understand the code.

2. The CLR cannot instruct the code.

3. The second time compilation is unmanaged code. It is understood


only by the machine not by the user.

About C#:-

 C# is pronounced C sharp, is a programming language designed for


building a wide range of applications that run on the .NET Framework.

 C# is simple, powerful, type-safe, and object oriented.

Some Facts of C# program:-

 Every line in C# should be end with ;

 C# is case sensitive language.

 Extension of C# program is “.cs”.

 The type of comments are same as C or C++ language.

1. Singleline using //

2. Multiline using /* */

 The comment and uncomment also possible in Visual IDE toolbar’s

16 | P a g e
Differentiate: Value Type v/s Reference Type:-

Value Type:

 The value type stores the actual value.

 The value type data are stored using stack data structure into the
memory.

 The value type data access is faster with compare to reference type
because it is stored using stack data

Example:-

 Int

 Char

 Unions

 Structure

 Boolean

 Enumeration

 The value type variable cannot be assign NULL value.

 All the value type derived from System.valuetype variable then it will not
affect the values of other variables.

Reference Type:-

 The reference type variable can store the reference (address) of other
variables.

 The reference type data are stored using heap data structure into the
memory.

 The reference type data access is slower with compare to value type
because it is stored using heap data structure.

Example:-
17 | P a g e
 Object

 Class

 Interface

 Delegate

 Array

 The reference type variable can be assign NULL value.

 All reference type derived from System.object namespace in the .Net


framework class library.

 If we change the value of any reference type variable then it will affect
the values of other variables.

Differentiate: Boxing v/s Unboxing

Boxing:-

The translation from value type to reference type data is called boxing.

Example:

Int x=100; //value type

object obj =x; //boxing

Unboxing:-

The translation from reference type to value type data is called Unboxing.

Example:-

object obj = 10;

int temp = Convert.ToInt32(obj); //

unboxing
18 | P a g e

You might also like