.NET - East Tennessee State University

Download Report

Transcript .NET - East Tennessee State University

4/25/2020

Lecture 1: .NET

What Is It And Why Use It?

.NET - What and Why 1

Software from Components

• In the industrial revolution, engineers learned to build things in a consistent, predictable, repeatable way • They learned to use assembly lines to assemble items from components • Any component of a given type and specification is interchangeable with another of the same type 4/25/2020 .NET - What and Why 2

Why not build software the same way?

Multiple languages and incompatibilities

• Basic, C, C++, COBOL, Visual Basic, C#, F#, Java, Fortran, Perl, Python, Eiffel, Delphi, SQL, Pascal, PL/I, APL, assembly, Scheme, Smalltalk, Prolog, Lisp, RPG, Ada, Snobol, Forth, Algol, Modula-2, HTML, Haskell, JavaScript, Objective C, … • Cannot just take a block of code from a Lisp program, for example, and plug it into a COBOL program and expect it to work • Usually, cannot easily call an Ada method from a Python program, for example 4/25/2020 .NET - What and Why 3

Why not build software the same way?

Different Data Types

• Many different data types • Not implemented the same way in all languages • Implementations vary in size •

Character

type may be 1 byte (

ASCII

or

EBCDIC

) or 2 or more bytes for

Unicode

Integers

may occupy 8 bits, 16 bits, 32 bits, 64 bits, 128 bits, . . .

4/25/2020 .NET - What and Why 4

Why not build software the same way?

Different conventions

• Argument passing may be

left-to-right

or

right to-left

• Arguments in one language may be passed using a

stack

; others use

registers

,

pointers

, or

some other means

; not consistent among languages •

Name collisions

• Same term may be used differently in different languages – a

class name

in one language may be a

keyword

in another 4/25/2020 .NET - What and Why 5

Why not build software the same way?

• Different

platforms

and

architectures

Addresses

and

data

:

16

-bit,

32

-bit,

64

bit,… •

Big-endian

(ABCD) vs.

little-endian

(DCBA) • Different

instruction sets

• Differences in

register architecture

6 4/25/2020 .NET - What and Why

Why not build software the same way?

• Different

operating systems

even on the same hardware • Almost all user software depends on and uses services provided by the

OS

and its subsystems • Different

Operating Systems

approaches, different

levels

have different ways of

implementing

the

services

, different

API’s

, different

conventions

, different

security

of

support

for various activities 7 4/25/2020 .NET - What and Why

Why not build software the same way?

Different Human Languages; Different Cultures

English, French, Japanese, Chinese, German, Arabic, Russian, Hebrew

, … • In the US,

1.23

represents 1 and 23 hundredths, while in many European cultures, the same value would be represented as

1,23

Fahrenheit

vs.

Celsius

; in

US 30

in

Canada 30

degrees is

hot

degrees is

cold

while •

US Dollars

vs.

Canadian Dollars Riyals

,

Dirhams

, ...

,

Euros

,

Yen

,

Rubles

, • Dates:

03/04/2012

is

March 4, 2012 April 3, 2012

in much of Europe in the US, but it is •

Inches, miles, gallons, pounds kilometers, liters,

and

kilograms

vs.

centimeters,

. . .

4/25/2020 .NET - What and Why 8

COM, CORBA, Enterprise Java Beans

• Various companies and groups of companies came up with approaches that could be used to standardize things and allow components to work together • Problems: • • • All approaches were proprietary Approaches incompatible with each other Not based on open standards 9 4/25/2020 .NET - What and Why

.NET

• Based on a

standard

developed by Microsoft , Intel , IBM , and others • Approved as a standard by

ECMA

• Approved as a standard by

ISO

• Standards cover

CTS

,

CLS

,

C#,

and other items • Designed to be

language agnostic

Platform neutral

Open

to development by anyone 4/25/2020 .NET - What and Why 10

The

virtual machine

runs this 4/25/2020 .NET - What and Why Many others including

IronPython

,

IronRuby

,

Cobol

,

Delphi

, etc.

11

Common Type System (CTS)

All .NET languages

support

common types

though not necessarily using the same names – •

System.Int32

is called

int

in

C++

and in

C#,

and

Integer

in

VB

, but they are same type and can be passed back and forth as arguments •

System.Single

is called

Single

in

VB

and

float

in

C++

and

C#,

but all are the same type and are interchangeable in the

.NET

languages • Languages are free to add types, but added types may not always be compatible with other

CTS

languages 12 4/25/2020 .NET - What and Why

Common Language Runtime (CLR)

• All .NET compilers emit

platform-neutral Intermediate Language (IL)

language code

object code rather than

native machine

IL

is the same regardless of

hardware

,

OS

, or

.NET

language

• Output of a project is called an

Assembly

: may be either a

.EXE

or a

.DLL

• Only the

CLR

needs to know what

platform

it is running on 4/25/2020 .NET - What and Why 13

CLR, continued

• •

CLR IL

contains a into

target machine Just-In-Time (JIT)

compiler that turns

native machine language optimized

for its • • • Very fast and efficient Done only once and only if needed Thus code is

compiled

, not

interpreted

as in some languages •

CLR

also handles

garbage-collection

,

exception handling

,

cross-language debugging,

and

distributed debugging

, and other common features Includes classes

runtime support

for thousands of

.NET

14 4/25/2020 .NET - What and Why

IL Example

{ .method public hidebysig static void Main() cil managed .entrypoint

.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = Code size 14 (0xe) .maxstack 8 IL_0000: nop IL_0001: newobj instance void ManageDB.frmTblMgmt::.ctor() IL_0006: call void [System.Windows.Forms]System.Windows.Forms.Application::Run(class [System.Windows.Forms]System.Windows.Forms.Form) IL_000b: nop IL_000c: nop IL_000d: ret } // end of method frmTblMgmt::Main 15 4/25/2020 .NET - What and Why

Runtime Compilation and Execution

Form1 Which language?

C# code C# Compiler Visual Basic .NET code VB.NET compiler JIT compiler

Native code CLR

.NET - What and Why

MSIL

4/25/2020 16

Platform Neutral

• • Because the

IL

code is not targeted at any platform, it is

portable

different HW, SW, etc.

between systems of A (.

NET

)

.exe

a

Windows

and a (.

NET Sun

, or an

IBM mainframe

)

.dll

compiled on system will run on a

Mac

, a

. . . IF . . .

the target machine

compiler has its own

to convert the

IL CLR

with a

JIT

code to

native code

targeted to the machine on which it is to run and to provide the

runtime support for the .NET classes

4/25/2020 .NET - What and Why 17

Common Language Runtime

Base Class Library Support Thread Support COM Marshaler Type Checker Exception Manager Security Engine Debug Engine IL to Native Compilers Code Manager Garbage Collector

4/25/2020

Class Loader

.NET - What and Why 18

Language Interoperability

• The standards that are part of

.NET

insure that: • A Windows control developed in

VB.NET

be used in a

C#

program can • A

method

written in a

business-tier class COBOL.NET

can be invoked by a

VB.NET

Windows Forms

front end in • A .

NET string

in a

Delphi.NET

program compiled using a Borland compiler on a

Windows

computer can be passed to a

C#

method written using a

SSCLI

compiler running on an

Apple OS-X

platform 4/25/2020 .NET - What and Why 19

.NET Implementations

• • Implementations of

.NET

include • • Microsoft’s .

NET Framework

and

Visual Studio.NET

The

Shared Source Common Language Initiative

runs on

BSD Unix

and

Apple OS-X

(

SSCLI

) that •

Mono

others -

open source

effort up until recently led by

Novell

and More than

30

languages support

.NET

: • • Microsoft:

VB.NET, C#, managed C++, C ω, Spec#, F# Python, Perl, Cobol, Delphi, Pascal, Eiffel, Fortran, RPG, Scheme, Smalltalk, Ruby, Forth

, and many others by

non Microsoft

vendors • Thousands of tools are available from third-party vendors to aid in

.NET Framework

development, including over 1000

add-ins

for

Visual Studio .NET

, as well as

compilers

with their own

IDE’s

from

Borland

and

Macromedia

20 4/25/2020 .NET - What and Why

The .NET Framework Components

Visual Basic C++ C# Perl Python XML Web Services ASP.NET

User Interface … ADO.NET and XML .NET Framework Class Library

Base Class Library JIT, GC, Exceptions, Debugging, etc.

Message Queuing

Base OS API

Common Language Runtime COM+ (Transactions, Partitions, Object Pooling) Win32 and Win64 IIS WMI

4/25/2020 .NET - What and Why Web Apps and Services Database support Web Server 21

Thus, …

Solutions/Applications

can be developed in any

.NET language

or

languages

(by

project

) that fully supports the features used by the application and that adheres to the standards •

Different parts

of the application (

solution

) can be developed in

different languages

• A

VB main program

can use a

class

that uses another

class

developed in developed in

F#, C#

for example • In a

.NET web application

, each web page at a web site could be developed in a

separate .NET language

22 4/25/2020 .NET - What and Why