14
030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 1 | Page 030010401- GUI Programming Unit-6: Introduction to .NET Framework BCA 4 th Semester Note: - This material is prepared by Ms. Preeti P Bhatt. The basic objective of this material is to supplement teaching and discussion in the classroom. Student is required to go for extra reading in the subject through library work.

Unit6

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 1 | P a g e

030010401- GUI Programming

Unit-6: Introduction to .NET Framework

BCA 4th Semester

Note: - This material is prepared by Ms. Preeti P Bhatt. The basic

objective of this material is to supplement teaching and discussion

in the classroom. Student is required to go for extra reading in the

subject through library work.

Page 2: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 2 | P a g e

Topic Covered

.NET framework: Evolution and Benefits

Architecture of .NET framework

Common Language Runtime:

– CLR functions, managed code, unmanaged code, memory management

.NET Framework Class Library

Common Language Specification

Metadata and Assemblies:

– Assembly contents, manifest, GAC, strong name assembly, private and shared

assemblies, side by side execution

Page 3: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 3 | P a g e

1. .NET Introduction

Definition: .Net is a collection of tools and technologies and language that all are work

together in a framework to provide a solution need for develop application.

.NET is Microsoft’s strategy of software that provides service to people any time, any place, on any device.

.NET is a new framework for developing web-based and windows-based applications within the Microsoft environment.

It also known as Software Platform or Language neutral

Benefits Of .NET

• Consistent programming model: - – .NET provides a consistent object oriented programming model across different

language. • Cross – platform support:-

– Any windows platform that supports CLR can execute a .NET application. • Language Interoperatibility:-

– It is a feature that enable program written in different languages to interact with each other.

– This allows reusability of code and improves the efficiency of development process.

– You can inherit visual basic class in C#. • Automatic management of resources:-

– You do not need to manually free the application resources, such as file, memory, and network and database connection.

• Ease of deployment:- – It make task of deployment easier. – Easy deployment of application by installing new application.

Page 4: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 4 | P a g e

2. .NET Framework

The .NET framework exposes numerous classes to the developer. These classes allow the

development of rich client applications and Web based applications.

.Net Framework component

Common Language Runtime(CLR)

Base Class Library (BCL)

ASP. Net and XML

Web form and Window Form

Common Language specification (CLS)

Block Diagram of .NET Framework

C++ C# VB Perl J# ..........

Visual

Studio

.NET

Common Language Specification

(CLS)

ASP.NET

Web Forms, Web

Services

Windows

Form

ADO.NET (Data and XML)

Base Class Library (BCL)

Common Language Runtime (CLR)

Operating System

2.1 Common Language Runtime

At the base is the common language runtime.

It is the heart of the .Net Framework; it is the engine that compiles and run the application.

It uses MSIL (Microsoft Intermediate Language) format code which is language independent for execution. The MSIL code is translated by JIT (Just in Time Compiler) compiler.

CLR manages code execution at runtime.

It include Common Type System

• It include common type, standard interface convention, make cross language

inheritance.

Memory Management

• Allocation and management of memory

Life cycle Monitoring

CLR also does reference counting for object and handles garbage collection.

Page 5: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 5 | P a g e

2.2 Base Class Library (BCL)

It is a second entity of .NET framework which is designed to integrate with CLR.

It is also known as Framework class Library (FCL).

The Base Class Library (BCL) is a standard library available to all languages using the .NET Framework.

Class libraries implement a large number of common functions such as

File reading and writing,

Graphic rendering,

Database interaction,

XML document manipulation.

The .NET class libraries are available to all CLI (Common Language Infrastructure) compliant languages.

The .NET Framework class library is divided into two parts:

Base Class Library

Framework Class Library

2.3 ASP. Net and XML

It is also known as Data Access Layer. With this we can access relational databases.

It work with XML and provide the Disconnected Data Model

This layer includes the next generation of standard system service such as ADO.NET and XML.

It is a part of BCL. It consists of two parts:

1) Data Provider: Connection, Command, DataAdapter, Data Reader 2) DataSet

These services are brought under the control of framework, making them universally available and standardizing their usage across language.

2.4 Web form & Web Services and Window Form

a. Web form & Web Services • Web forms

It provide toll for web application. It is a part of ASP.NET.

Manageable code

Logical evolution of ASP (compiled)

• Web service is a method of communication between two electronic devices over

the web.

Page 6: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 6 | P a g e

b. Window Form or Win Form It used to create the GUI for windows desktop application.

It has rich variety of windows controls and user with win Forms.

2.5 Common Language specification (CLS)

Common Language Specification (CLS) is a set of basic language features that .Net Languages needed to develop Applications and Services, which are compatible with the .Net Framework.

It is a set of rules and constraints that all languages must follows which want to be compatible with .NET framework.

Language Support VB, C++, C#, J#, JScript

3. Common Language Runtime

At the base is the common language runtime.

It is the heart of the .Net Framework; it is the engine that compiles and run the application.

It uses MSIL (Microsoft Intermediate Language) format code which is language independent for execution. The MSIL code is translated by JIT (Just in Time Compiler) compiler.

CLR manages code execution at runtime.

It include Common Type System

• It include common type, standard interface convention, make cross language

inheritance.

Memory Management

• Allocation and management of memory

Life cycle Monitoring

CLR also does reference counting for object and handles garbage collection.

Component of CLR

Page 7: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 7 | P a g e

• Common Type System (CTS)

• It is responsible for interpreting the data types into the common format.

• IL compiler (Intermediate Language)

• The IL Compiler takes in the IL code and converts it to the host machine

language.

• Security

• Security component in the CLR ensures that the assembly (the program being

executed) has permissions to execute certain functions.

• Garbage Collector

• Its function is to recover the memory when the object is no longer in use, this

avoids memory leaks.

• Class Loader

• Purpose is to load the classes needed by the executing application.

Working of CLR

Code running under the control of the CLR is often termed managed code.

Two step of compilation

1. Compilation of source code to IL (Intermediate Language) • The .Net program is compiled in to special type of code called the Microsoft

Intermediate Language (MSIL) – When .NET code is compiled, the output of compiler is not an executable

file but a file that contains special type of code called MSIL code, which is a special low-level set of instructions understood by CLR.

2. Compilation of IL to platform-specific(native code) code by the CLR • This MSIL is turned into executable code using a JIT (Just In Time) complier.

– When .NET programs are executed, the CLR activates JIT compiler. – The JIT compiler converts MSIL code into native code on a demand.

Page 8: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 8 | P a g e

Benefits of CLR

• Automatic memory management: - – The CLR provides the Garbage Collection feature for managing the life time of

object. • Standard Type System: -

– The CLR Implement a formal Specification called the Common Type System (CTS). CTS are important part of rules that ensures that objects written in different language can interact with each other.

• Language interoperability: - – It is the ability of an application to interact with another application written in a

different programming language • Platform Independence: -

– The Compiler compiles code language, which is CPU-independent. This means that the code can be executed from any platform that supports the .Net CLR.

• Security Management: - – In .Net platform, Security is achieved through the code access Security (CAS)

model. • Type Safety: -

– This feature ensures that object is always accessed in compatible ways. Therefore the CLR will prohibit a code from assign a 10-byte value to an object that occupies 8 bytes.

– Versioning and deployment services: - – It supports side - by - side execution of multiple version of the same component,

even within the same process.

Page 9: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 9 | P a g e

Important Terms

Manage Code “The code that is developed with a language compiler that target the CLR is called manage code”.

Managed Code in Microsoft .Net Framework, is the code that has executed by the Common Language Runtime (CLR) environment.

Manage code is code that is executed directly by CLR. The application created by manage code automatically have CLR services, such as type checking, security automatic garbage collection.

Unmanaged Code

“The code that is developed without considering the conventional and requirements of the CLR is called unmanaged code”.

Unmanaged code directly compiled to the machine code and runs on the machine where it has been compiled.

CLR does not provide services, such as type checking, security automatic garbage collection to unmanaged code.

Unmanaged code executes in CLR environment with minimal services.

For example, unmanaged code may run with limited debugging and without garbage collection process.

Manage code consists of MSIL and Metadata

Memory management

One of the important services that CLR provides during managed executions is automatic memory management.

CLR uses garbage collection to manage the allocation and release of memory.

MSIL Code

NET programs are compiled by the language compilers into assemblies that consist of Microsoft Intermediate Language (MSIL) instructions.

MSIL: It is a CPU-independent set of instructions that can be efficiently converted to native code.

MSIL is also known as IL or CIL.

CLR compiles MSIL in just-in-time (JIT) manner – each function is compiled just before execution.

Page 10: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 10 | P a g e

JIT Compiler

Just in Time (JIT) Compiler gets its name because it compiles your managed code into executable native code on the fly. That is, it compiles the IL just as it's needed.

During the code execution time, the Managed Code compiled only when it is needed, that is it converts the appropriate instructions to the native code for execution just before when each function is called. This process is called Just In Time (JIT) compilation, also known as Dynamic Translation.

4. Base Class Library (BCL)

The .Net Framework class library provides the core functionality of .Net Framework architecture.

The .Net Base Class Library (BCL) includes a huge collection of reusable classes, interfaces, and value types that provide access to system functionality.

Framework class library (FCL) is huge library of reusable types meant to be used by managed code.

It is an object oriented library used in component based application.

Important Point in FCL:

The classes, interface, structures, and enumerated value are collectively referred as type.

Different type in .NET framework is arranged in hierarchy of namespace.

The system namespace is root namespace in .NET framework.

All class have base class including user defined types.

Namespace

Namespaces are the way to organize .NET Framework Class Library into a logical grouping according to their functionality, usability as well as category they should belong to.

Namespaces are logical grouping of types for the purpose of identification.

The .NET Framework Class Library (BCL) is a large collection of thousands of Classes. These Classes are organized in a hierarchical tree.

The System Namespaces is the root for types in the .NET Framework.

We can uniquely identify any Class in the .NET Base Class Library (BCL ) by using the full Namespaces of the class .

Page 11: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 11 | P a g e

5. Common Language Specification (CLS)

Common Language Specification (CLS) is a set of basic language features that .Net

Languages needed to develop Applications and Services, which are compatible with the .Net

Framework.

When there is a situation to communicate Objects written in different .Net languages, those

objects must expose the features that are common to all the languages.

Common Language Specification (CLS) ensures complete interoperability among

applications, regardless of the language used to create the application.

“The CLS defines a superset of the CTS to enable cross-language interoperability”.

The CLS defines a (large) superset of the CTS that a language must obey if it wishes to

interoperate with other CLS-compliant languages.

For example, the CLS requires support for most CTS value types, including Boolean, Byte,

Char, Decimal, Int16, Int32, Int64, Single, Double, and more.

Page 12: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 12 | P a g e

Common Type System

Common Type System (CTS) describes a set of types that can be used in different .Net languages in common.

That is the Common Type System (CTS) ensure that objects written in different .Net languages can interact with each other.

These types can be

Value Types Reference Types.

The Value Types are passed by values and stored in the stack.

The Reference Types are passed by references and stored in the heap.

Common Type System (CTS) provides base set of Data Types which is responsible for cross language integration.

6. Metadata and Assembly

Metadata A data about data is known as metadata.

It describes program that is in the form of binary information stored in CLR portable executable (PE) file or in memory.

– When compilation of code take place in PE file, the metadata is inserted into one part of the file,

– While code is converted in to MSIL and inserted in to other part of file.

Metadata contains the following:

– Assembly Information:

• Its identity like name, version, culture public key, the type of assembly,

other assembly and security permission.

– Information about Type

Page 13: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 13 | P a g e

• Name, visibility, base class, interface used, and members.

– Attribute information

• This modifies the type and members of class.

Assembly

Microsoft .Net Assembly is a logical unit of code, it contains code that the Common Language Runtime (CLR) executes.

When you compile an application, the MSIL code created is stored in an assembly.

Assembly: It is a collection of types and resource information that are built to work together and form a logical unit of functionality.

Every Assembly you create contains one or more program files and a Manifest.

There are two types’ program files.

Executable (EXE) and

Dynamic linking Library Assemblies (DLL).

Assembly can be divided in two types

– Static Assembly: It includes interface, classes, and resources and stored in PE files on a disk.

– Dynamic Assembly: you can create dynamic assemblies that run directly from memory; therefore there is no need of saving them on disk before execution.

o After execution you can store then in a disk.

Manifest Assembly:

An assembly manifest is a text file containing metadata about .NET assemblies.

– Manifest describes the relationship and dependencies of the components in the assembly,

– Versioning information, scope information and the security permissions required by the assembly.

– Information stored in assembly manifest

• Assembly name, version number, culture, list of all file in assembly.

GAC: Global Assembly Cache

• It is a central place for registering assemblies, so that different application on the

computer can use it later on.

• Assembly must be made sharable by registering them in GAC only, when needed,

otherwise the assembly must be kept private.

• Deploy assembly in GAC using any one of the following

– An installer that is designed to work with GAC

Page 14: Unit6

030010401 BCA 4th Semester

Preeti P Bhatt Department of Computer Science, UTU. 14 | P a g e

– The global assembly cache tool known as Gacutil.exe

– Window explorer to drag assemblies into cache.

Strong name assembly

A strong name assemblies contains the assemblies' identity – Assembly’s name, version number, culture information, public key and digital

signal. Using private key, the assembly file containing the manifest generates the strong name.

Benefits of strong assembly

– Provides uniqueness to the names by generating a private key. – Ensures that the version you are using comes from the same publisher that

creates the version. – Facilities integrated checks, which ensures that content of assembly have not

changed since last build.

Private and Shared assembly

Private Assembly

When single application uses assembly, it is called private assembly.

Example: You have created a DLL containing information about your business logic and placed it in same folder in which the client application has been installed. So DLL can only be used by your client program.

Shared Assembly

Shared assembly are placed in the global assembly cache so that they can be used by multiple application

Example: You have created DLL that needs to be reused in different application. Instead of downloading copy of DLL in each and every client application, the DLL can be placed in global assembly cache.

Side – by – Side Executions

It is a process where multiple version of an application or component are stored and executed on the same computer.

Means you have multiple version of application and component that uses a particular version of runtime on same computer at same time.