Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

The .NET Framework

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

CMT 307-.NET programming -Introduction to .

NET framework

Chapter One: Introduction to .NET framework Before emergency of .NET framework, programmers used a
1.1 Chapter objectives number of tools to write programmers as depicted before

By the end of this, learners should be able to: ▪ Windows GUI development: Win32 API, MFC, Visual

i). Have thorough understanding of problems programmers ▪ Basic, COM


faced before emergency of .NET framework ▪ Web development: ASP

▪ Java – “Write once, run anywhere.”


ii). Understand how the .NET framework works
▪ Embrace and extend: Visual J++
iii). Understand the role of major components of the .NET
However, all those environments had a number of limitations
framework
as discussed below
iv). Understand how .NET framework provides support for

multi-language 1.2.1 Life As a C/Win32 API Programmer

v). Understand how compilation is done by .NET framework It’s the traditional software development for the Windows. It has

vi). Understand the differences/similarities between J2EE a number of limitations such as

and .NET architectures


✓ C developers are forced to contend with complex

1.2 Life before .NET programming memory management and pointer arithmetic.

1
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

✓ It lacks the benefits provided by the object-oriented (wizards).

approach
However, C++ remains a difficult and error-prone experience.

When programmers combine the thousands of global functions


1.2.3 Visual Basic 6.0 Programmer
and data types defined by the Win32 API to an already
VB 6.0 has ability to build complex user interfaces, code
challenging language, the end result is so many buggy
libraries, and data access logic with minimal hassle and bother.
applications floating around today.
It hides the complexities of the raw Win32 API from view using
1.2.2 Life As a C++/MFC Programmer
integrated code wizards, intrinsic data types, classes, and VB-

C++ is an object-oriented layer on top of C which means specific functions.

programmers can benefit from the famed “pillars of OOP”

(encapsulation, inheritance, abstraction and polymorphism).


However, VB 6.0 is not fully object-oriented e.g. there no
Microsoft Foundation Classes (MFC) provides a set of C++
classical inheritance. Its also impossible to do multithreaded

classes that facilitate the construction of Win32 applications. applications unless you are willing to drop down to low-level

Win32 API calls (which is complex at best and dangerous at


C++ combines the difficult raw Win32 API behind a number of
worst).
classes, magic macros, and numerous code-generation tools

2
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

1.2.4 Life As a Java/J2EE Programmer Component Object Model (COM) is Microsoft’s previous

application development framework which enabled


Java is a pure Object oriented with syntactic roots in C++. It
programmers reuse binary code.
cleans up many unsavory syntactical aspects of C++ a well as

providing programmers with a large number of predefined C++ programmers can build COM classes that can be

“packages” that contain various type definitions. used by VB6. Delphi programmers can use COM classes

built using C.

However, java has a number of limitations such as limited It has a number of challenges such as language independence

ability to access non-Java APIs, little support for true cross- is limited, doesn’t support for classical inheritance) and its

language integration and it’s not appropriate for many extremely complex under the hood.

graphically or numerically intensive


However, The Active Template Library (ATL) provides a set of

applications. C++ classes, templates, and macros to ease the creation of

1.2.5 Life As a COM Programmer COM types.

1.2.6 Windows DNA Programmer

Microsoft corporation has been adding more Internet-aware

3
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

features into its family of operating systems and products. 1.3 .Net framework

NET is a framework and not a programming language that


COM-based Windows Distributed internet Applications
provides is a New programming methodology/framework
Architecture (DNA) is quite complex since Windows DNA
developed by Microsoft in June 2000. Its platform independent /
requires the use of numerous technologies and languages
cross platform as well as language-insensitive.
(ASP, HTML, XML, JavaScript, VBScript, COM(+), and data

access API like ADO).


.NET is an Integrated environment which allows programmers

to build Networked Applications, Distributed Web Services, Web

The result of the above is completely unrelated syntaxes e.g. Applications, mobile applications, Desktop based applications

JavaScript has a syntax much like C, while VBScript is a subset within Microsoft environment. It’s consistent object-oriented

of VB6 which results to a highly confused mishmash of providing a portable as well as managed environment

technologies. Each language and/or technology has its own type

system e.g. An “int” in JavaScript is not quite the same as an It provides tools and technologies necessary compile time and

“Integer” in VB6. The rescuer is Microsoft .NET framework runtime foundation to build and run any language that conforms

to the Common Language Specification (CLS)

4
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

iii. The framework has also been motivated by other

factors such as Object-oriented programming,

compile once and run everywhere and Service-

Oriented Application .

.NET framework is built upon open standard technologies like

XML and SOAP and is towards more open standards rather than
Fig:1.0-.NET is cross platform
Microsoft its proprietary tendencies. It offers a fundamental shift
.NET is motivated by a number of factors such as in Microsoft strategy by moving application development from
i. popularity of electronic devices meaning it’s capable of client-centric to server-centric.
providing interaction between wide varieties of devices

such as cell phones, Personal Digital Assistants, .NET framework offers programmers with a number of services

Personal computers e.t.c such as


ii. it has also been motivated by the fact that
i). Independence from specific language or platform
communication between programs can occur despite
meaning that applications can be written in any .NET
the disparate languages
compatible language e.g. VB.NET, Visual C++ .NET, C#.

This gives programmers flexibility to contribute to

5
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

applications development using the language in which

they are most competent

ii). The framework also allows programmers to run .NET

managed code in a virtual machine (Common Language

Runtime).

iii). It also provides a very good environment to develop

networked applications and Web Services

iv). Provides programming API and unified language

independent development framework

1.4 Components of .NET framework

The main two components of .Net Framework are Common Fig 1.1:-NET architecture
1.4.1. Common Language Runtime (CLR)
Language Runtime (CLR) and .Net Framework Class Library
(FCL) which provides a core services such as ASP.NET, It’s the engine behind the .NET framework that handles
windows, ADO.NET, windows forms, XML support e.tc
execution of all managed application code. It works as a

mediator between Operating Systems and the applications

written in .Net languages that conforms to the Common

6
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

Language Specification (CLS). 11) Interoperation between managed code, COM objects

Some of the services provided CLR include: and pre-existing DLLs (unmanaged code and data)

1) Code management (loading and execution) 12) Automation of object layout

2) Application memory isolation 13) Support for developer services (profiling, debugging,

etc.)
3) Garbage collection

4) Verification of type safety

5) Thread execution

6) Conversion of IL to native code

7) Access to metadata (enhanced type information)


8) Managing memory for managed objects

9) Enforcement of Code Access Security

10) Exception handling including cross language


Fig 1.3 :-CLR architecture
exceptions

7
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

1.4.2. . Net Framework Class Library (FCL) interface development. It’s a super set of what developers

already know as Active Server Pages, with some key


FCL is a huge collection of language-independent and type
advantages: since it runs inside the CLR, it supports any
safe reusable classes, interfaces and values that expedite and
language that runs in the CLR, expanding from VBScript and
optimize the development process and provide access to
Jscript. Also, it provides numerous new services, like cache
system functionality. The libraries are arranged into a logical
management, cluster-ready session management, cookie-less
grouping according to their functionality and usability is called
sessions, browser version-based automatic code generation,
Namespaces.
among other things
FCL provides the consistent base types that are used across

all .NET enabled languages. The Classes are accessed by ▪ Window forms

namespaces, which reside within Assemblies. The System It’s a framework used to design rich clients for windows

Namespace is the root for types in the .NET Framework. platform can be done using Windows Forms which offers

programmers with RAD (Rapid Application Development),


Key services provided by the FCL include
Rich set of controls, Data aware, ActiveX Support, licensing,
▪ ASP.NET (Active Server Pages) Accessibility, Printing support, Unicode support, UI

It provides the core Web infrastructure such as Web Forms for inheritance

UI based development and Web Services for programmatic

8
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

▪ Active Data Object (ADO.NET)

ADO.NET is an evolution of ADO to provide

functionality for data access. The ADO.NET has much richer

support XML

▪ Core base classes

They provide infrastructure services such as security,

transaction management etc. Fig 1.4: .NET applications

1.5 Compilation in .NET


When we write a program using any of the .NET languages like
Applications developed in the .NET platform don’t directly
C#, VB or C++, the source code doesn’t get compiled to
interact with the OS but rather, they talk to the CLR and the
machine code. Each language specific compiler (VB compiler,
CLR manages/handles the execution of the applications.
C# compiler e.t.c) converts the source code to an intermediate

language code which is known as IL code or Microsoft

Intermediate Language (MSIL) or Common Intermediate

Language (CIL) which is a CPU independent set of

9
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

instructions that can be converted to the native code. IL code is

used as the output of a number of compilers and as the input to

a CLR JIT compiler.

The CLR has a number of Just in Time (JIT) compiler each

working on a different architecture depending on the operating

system. The JIT converts the MSIL code into native code to

which is Operating System specific, the overall effect being the Fig 1.5 :- CLR execution
same IL code being able to run on different OS. There is some
During compilation, metadata is always generated and stored
initial performance cost, but the jitted code is cached for further
with the compiled code in a file known as manifest which
execution. A big advantage is CLR can target the specific
contains information about the members, types, references and
architecture in which the code is executing, so some
all the other data that the Common Language Runtime
performance gains are possible.

10
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

this will enable you to execute .NET programs without any

modifications to code.

▪ To achieve language independence since .NET

applications are not tied to particular language and therefore

it’s possible for programs to consist of several .NET

compliant languages. This means old and new components

can be integrated together seamless.

Fig 1.6: CLR execution model


.NET employs two stages to compile a program and there are

two key rationales behind the two phases of complicate

▪ To achieve platform independence since

.Net Framework can be installed on different platforms and

11
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

Fig 1.7:CLR execution summary 1.6 NET compliant Languages

Some of the languages supported by Microsoft include VB.NET,


Advantages associated with CLR execution C++, C#, J#, Jscript, Visual C++. However, there are some third-
Some of the advantages associated with CLR execution parties’ languages such as APL, COBOL, Pascal, Eiffel,
includes Haskell, ML, Oberon, Perl, mercury Python, Scheme,Oz,APL,

1. Support for developer services (debugging) CAML,Scheme, Smalltalk e.t.c

2. Interoperation between managed code and unmanaged 1.7 Common Language Infrastructure (CLI)
code (COM, DLLs).
CLI allows for cross-language development.
3. Managed code environment

4. Improved memory handling

5. Improved “garbage collection”

6. JIT allows code to run in a protected environment as


managed code.

7. JIT allows the IL code to be hardware independent.

8. CLR also allows for enforcement of code access


security.

9. Verification of type safety.

10. Access to Metadata (enhanced Type Information)

12
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

CLI uses three major mechanism to enable .NET support more


than one programming languages i.e.

i). Common Type System (CTS)


ii). Common Language specification (CLS)
iii). Intermediate Language code (IL code)
1.7.1 Common Type System (CTS)

CLR defines a CTS, which is a standard type system used by all

.NET languages meaning that all .NET compliant languages use

the same representation for common data types. All .NET

languages have the same primitive data types. For example, an

int in C#.NET is the same as an int in VB.NET. When

communicating between modules written in any .NET language,

the types are guaranteed to be compatible on the binary level

Fig 1.8:- CLI infrastructure

13
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

enough memory it is discarded thus making JIT process


interpretive.

1.7.3 Common Language Specification (CLS)

Not all languages support all CTS types and features e.g.

• C# is case sensitive, VB.NET is not

• C# supports pointer types (in unsafe mode), VB.NET

does not

• C# supports operator overloading, VB.NET does not


Fig 1.9: CTS data types
CLS was drafted to promote language interoperability. It’s a set
1.7.2 Intermediate Language (IL/MSIL)
of specifications that all languages and libraries need to follow.

.NET languages are not compiled to machine code. They are Any language that conforms to the CLS is a .NET language and
compiled to an Intermediate Language (IL). CLR accepts the IL
it has the ability to take full advantage of FCL. This will ensure
code and recompiles it to machine code.
interoperability between languages.
The recompilation is just-in-time (JIT) meaning it is done as soon
as a function or subroutine is called. The JIT code stays in
memory for subsequent calls. In cases where there is not Some of those rules and standards imposed by CLR for example:

1. Object declaration, creation and use

14
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

2. Data types, language libraries ❑ J2EE- its platform Independent but Java
Development Kit (JDK) should exist on target
3. Error and exception handling
machine
4. Interactive Development Environment (IDE)
❑ .NET-Supports Windows platform but Common
1.8 Comparison & contrast of .NET & J2EE Architecture
Language Runtime (CLR) should exist on target
We compare the two frameworks from the following machine. Can also support other platforms provided it
perspectives
has its own JIT complier.
▪ Execution Engine
▪ Language support
❑ J2EE-Java source code compiles into machine-
independent byte code. The Runtime Environment ❑ J2EE-Tied to Java but supports other languages via

is Java Virtual Machine (JVM) interface technology

❑ .NET-Any compliant language compiles into ❑ .NET-its Language independent supporting any
MSIL/IL/CIL. The Runtime environment is language if mapping exists from that language to
Common Language Runtime( CLR)
IL
Both JVM and CLR support services, such as code
▪ Tools support
verification, garbage collection, and code security.
❑ J2EE-there are many IDE for programming in Java
▪ Cross platform portability
e.g. NetBeans, eclipse, blueJ,Jcreator,JDeveloper,
android studio

15
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020
CMT 307-.NET programming -Introduction to .NET framework

❑ .NET-supports only one IDE for writing the code i.e.


visual studio.

1.8 Chapter summary

1.9 Chapter exercise

1.11 Further reading suggestions

16
Edward Kioko|Email:-kioko@cuea.edu|Mobile number: +725-695-782| © 2020

You might also like