Sunteți pe pagina 1din 33

Lesson 01:

The .NET Framework


and the Common
Language Runtime

Objectives
What you will learn...
The .NET Framework
How applications developed for the framework are executed.
The different components of the framework and their
functionalities.
How the .NET Framework differs from other similar systems.

Lesson 2: Introduction to C#

Microsoft .NET Framework


an integral Windows component that provides a large
body of pre-coded solutions to common program
requirements such as security, manageability, and
productivity.
It is the Microsoft web services strategy of connecting
people, systems, information and devices through
software.
first released last 2002.
.NET Framework 2.0 (November 2005) remains the current
version as of April 2006.
Lesson 2: Introduction to C#

Microsoft .NET Framework


designed to work with non-Microsoft technologies and
existing Microsoft technologies.
can be hosted by unmanaged components that load the
Common Language Runtime (CLR).
supports the development of third-party runtime hosts.

Lesson 2: Introduction to C#

Goals of the .Net Framework


provide a consistent object-oriented programming
environment
Consistency must be maintained whether object code is stored
and executed locally, executed locally but Internet-distributed, or
executed remotely.

provide a code-execution environment that minimizes


software deployment and versioning conflicts.
A .NET framework component called the Common Language
Runtime makes sure that a certain application has the right
version of every resource that it needs for execution

Lesson 2: Introduction to C#

Goals of the .Net Framework: cont


provide a code-execution environment that promotes
safe execution of code.
Different applications are given different levels of trust,
determining the set of operations that an application is allowed
to execute.

provide a code-execution environment that eliminates


the performance problems of scripted or interpreted
environments.
interpreted environments performance is typically slower
compared to a compiled environment.

Lesson 2: Introduction to C#

Goals of the .Net Framework: cont


make the developer experience consistency across
widely varying types of applications, such as Windowsbased applications and Web-based applications.
It feels almost the same designing and programming a windowsbased and a web-based application using the .NET Framework.

build all communication on industry standards to ensure


that code based on the .NET Framework can integrate
with any other code.
This ensures interoperability with a wide range of technologies
and platforms.

Lesson 2: Introduction to C#

The .NET Framework Architecture


.NET languages are the top
layers.
The Common Language
Specification (CLS) serves
as the foundation of the
multi-language layer.
The CLR is the closest to
the native environment
because works closely with
the operating environment .
Lesson 2: Introduction to C#

.NET Framework Execution Model


Each of the languages
available in .NET has its
own language compiler.
These compilers produce
Microsoft Intermediate
Language (MSIL).
This MSIL, together with the metadata, are used to create
assemblies that are to be executed by the Common Language
Runtime (CLR).
These ILs, after being executed by the CLR, are converted back
to platform specific code (managed native code) by the Just In
Time Compiler (JIT).
Lesson 2: Introduction to C#

.NET Framework Components


Common Language Runtime

It serves as an application
virtual machine that allows the
applications to be executed
regardless of the capabilities of
the CPU which will execute the
application.
It provides core services to
running applications like
security services, memory
management, and exception
handling.

Lesson 2: Introduction to C#

10

.NET Framework Components


.NET Framework Class Library

A collection of reusable types


that tightly integrate with the
common language runtime.
The class library is object
oriented, providing types from
which your own managed code
can derive functionality.
Managed code code that run
within the Common Language
Runtime.

Lesson 2: Introduction to C#

11

.NET Framework Components


ADO.NET: Data and XML

ADO.NET provides consistent


access to data sources such as
Microsoft SQL Server, as well
as data sources exposed
through OLE DB and XML.
Data-sharing consumer
applications can use ADO.NET
to connect to these data
sources and retrieve,
manipulate, and update data.

Lesson 2: Introduction to C#

12

.NET Framework Components


Web Forms and XML Web
Services

ASP.NET is a programming
framework built on the CLR that
can be used on a certain server
to build web applications.
ASP.NET Web Forms are used
to provide easy ways of building
dynamic web user interfaces or
UIs.

Lesson 2: Introduction to C#

13

.NET Framework Components


User Interface for Windows

Client user interfaces can be


built using
System.Windows.Forms
namespace classes.
These classes allow you to
implement the standard
windows UI in .NET-based
applications.

Lesson 2: Introduction to C#

14

.NET Framework: Comparisons


The .NET Framework VS Java EE
The .NET Framework and Suns JVM both use their own
intermediate byte-code, MSIL for .NET, Java bytecode for the
JVM.
MSIL is designed for Just In Time compilation while Java
bytecode was originally designed to be interpreted.
As for runtime, tests show that the most common actions to be
performed at runtime on .NET are performed on an average two
times faster than in Java.

Lesson 2: Introduction to C#

15

.NET Framework: Comparisons


The .NET Framework VS Java EE: cont
.NET is currently only fully available on Windows platforms while
Java is fully available on many platforms. Java EE does provide
the same functionality to other Microsoft technologies.

Lesson 2: Introduction to C#

16

.NET Framework: Comparisons


The .NET Framework VS COM
Component Object Model (COM) is a technology for large-scale
software systems.
COM is used by developers to create re-usable software
components.
It has been stated by Microsoft that .NET will eventually replace
COM as a software component architecture.
Microsoft hopes that developers start writing new applications
for the Win32 platform using .NET instead of COM.
Lesson 2: Introduction to C#

17

The Common Language Runtime


Applications written for the .NET Framework execute in
a software environment known as the Common
Language Runtime or CLR.
can be considered as the foundation of the .NET
Framework.
serves as an application virtual machine.
supports both Object Oriented Languages and
procedural languages
Lesson 2: Introduction to C#

18

The Common Language Runtime


provides important services to running applications.
The CLR does garbage collection.
automatically takes care of the object layout and
references to objects
managed data - data that is allocated and freed by the .NET
runtime's garbage collector.

Lesson 2: Introduction to C#

19

The Common Language Runtime


Compilation: Recall

Each of the languages available in .NET has its own language


compiler.
These compilers produce Microsoft Intermediate Language
(MSIL).
Lesson 2: Introduction to C#

20

The Common Language Runtime


Compilation: Recall

This MSIL, together with


the metadata, are used to
create assemblies that are
to be executed by the
Common Language
Runtime (CLR).

Fig. Code snippet from an MSIL code

These ILs, after being


executed by the CLR, are
converted back to platform
specific code (managed
native code) by the Just In
Time Compiler (JIT).

Lesson 2: Introduction to C#

21

The Common Language Runtime


Compilation cont

As codes are compiled, Microsoft Intermediate Language (MSIL,


IL, CIL) and metadata that describes the types, member, and
references in a programmers code are produced.
The code will then be compiled into an assembly composed of
both the MSIL and the metadata.
These assemblies may be represented by one or more DLL or
EXE files.
Lesson 2: Introduction to C#

22

The Common Language Runtime


Compilation cont

The DLL and EXE files come in CLR Portable Executable (PE)
format.
Every loadable PE file contains metadata that carry information
about the components and resources they were built with.
The CLR uses this information to make sure that the component
or application has the specified version of every resource that it
needs, thus solving the common problem known as DLL Hell.
Lesson 2: Introduction to C#

23

The Common Language Runtime


Difference between a DLL and an EXE file
DLL (Dynamic-link library)
-

Microsoft's implementation of the shared library concept in the


Microsoft Windows operating systems.
The initial purpose for DLLs was saving both disk space and
memory required for applications.
Any code which many applications share could be separated into
a DLL which only exists as a single disk file and a single instance
in memory.

Lesson 2: Introduction to C#

24

The Common Language Runtime


Difference between a DLL and an EXE file: cont
EXE (Executable)
-

EXE is a common file extension denoting an executable (a


program) file in MS-DOS, Microsoft Windows, and OS/2 operating
systems.
EXE files occupy more space when compared to DLLs since EXE
files do processes when executed while DLLs are composed only
of classes available for use for other programs and the like.

Lesson 2: Introduction to C#

25

The Common Language Runtime


CLR Assemblies
An assembly is a logical unit of deployment.
An application may be composed of one or more assemblies.
Some of these assemblies may be loaded from the network or
can even be generated during runtime.

Lesson 2: Introduction to C#

26

The Common Language Runtime


CLR Assemblies: cont
An assembly may be composed of the following:

Manifest
Serves as an inventory list of
the assembly or PE file if ever
the assembly consists of a
number of PE files.

Lesson 2: Introduction to C#

27

The Common Language Runtime


CLR Assemblies: cont
Metadata
-

Contains information on the components located in the assembly


like:

Version
Types defined and used by the assembly
Assemblies dependencies on other assemblies

Metadata can contain attributes.


Attributes - descriptions or annotations of any kind that can be
attached to any named entity.

Lesson 2: Introduction to C#

28

The Common Language Runtime


CLR Assemblies: cont
Microsoft Intermediate Language (MSIL, IL Intermediate
Language, CIL Common Intermediate Language)
-

Used by the CLR together with the metadata to provide


functionality to a managed code.

Resources
- Files that are bundled to the assemblies that use them.

Lesson 2: Introduction to C#

29

The Common Language Runtime:


Features
security services
components are given different degrees of trust depending on a
number of factors that include their origin.

code access security


This ensures users that an executable file embedded in a web
page can, lets say, play an animation or music without ever
accessing the users personal data, file system, or network.

Code Robustness
The Common Type System or CTS allows applications written
using different programming languages can interoperate with one
another.
Lesson 2: Introduction to C#

30

The Common Language Runtime:


Features
eliminates many common software issues
One example of which is the automatic memory management
which resolves the two most common application errors,
memory leaks and invalid memory references.

accelerates developer productivity


The CLR allows programmers to write their programs in the
development language of their choice while still taking full
advantage of the runtime, the class library, and components
written using other development languages.

Lesson 2: Introduction to C#

31

The Common Language Runtime:


Features
ability to support past and present applications
Interoperability between the managed and unmanaged code
enables the developers to continue to use necessary COM
components and DLLs.

enhances performance
Managed code is never interpreted even though the CLR
provides many standard runtime services.
Examples:
- just-in-time (JIT) compiling
- memory manager

Lesson 2: Introduction to C#

32

The Common Language Runtime:


Features
can be hosted by high-performance, server-side
applications
This infrastructure allows the programmer to use the managed
code to write their business logic while still taking advantage of
the performance of high-level enterprise servers that support
runtime hosting.

Lesson 2: Introduction to C#

33

S-ar putea să vă placă și