David Chappell ring D EV ET Ja · 2002-10-29 · va David Chappell Principal Chappell &...

Preview:

Citation preview

DEV

345Com

paring .NET and Java

David C

happellPrincipalC

happell & A

ssociatesw

ww

.davidchappell.com

Stan

dard

Lib

rary

Application Platform

s Today

Op

erating

System

Ru

ntim

e En

viron

men

t

Brow

serA

ppsW

eb Services

Apps

Other

Apps

LocalA

pps

GU

IS

ervicesT

ransactionS

ervicesW

ebS

criptingD

ataA

ccessM

oreR

emote

Access

DEV

349The M

icrosoft .NET

component m

odelBertrand M

eyerProfessor of Softw

are Engineering, ETH Zürich

Scientific advisor, Eiffel Software, Santa Barbara

Component developm

ent with

COM

and CORBA

Component “Bus”

Servercom

ponentClient

component

IDL Stub

IDL spec

module R

eservation{interface Flight_booking {Price ticket_price

(in Date day, in Flight num

ber)raises (invalid_date, invalid_num

ber);exception invalid_date {D

ate when; };

readonly attribute string name;

...}};

The role of IDL

•Provide language-neutral interfacedescription of a m

odule’s operations•

As a result, enable clients and suppliers

written in different im

plementation

languages

The trouble with ID

L•

Programm

ers must w

rite IDL interface in

addition to actual software

•If from

an O-O

language, IDL duplicates

information present in the code, e.g. C

++header file, Eiffel contract form

•Perils of duplication

•ID

L compiler goes the w

rong way!

•H

owever: som

e tools ease the process.

Pre-.NET approaches: sum

mary

•O

bject technology is best known basis

•Inform

ation hiding is key•

O-O

sufficient by itself: need forautonom

ous components

•Current approaches too heavy: extra w

ork toturn m

odule (e.g. class) into component

•ID

L is a killer

DEV

200.N

ET Framew

ork Overview

Chris Anderson

Software A

rchitect, .NET Client

Microsoft Corporation

.NET Fram

ework

Design G

oals

•D

ramatically sim

plifies development and

deployment

•U

nifies programm

ing models

•Provides robust and secure executionenvironm

ent•

Supports multiple program

ming languages

Framew

ork, Languages,A

nd Tools

Op

erating

System

Op

erating

System

Co

mm

on

Lan

gu

age R

un

time

Co

mm

on

Lan

gu

age R

un

time

Base C

lass Lib

raryB

ase Class L

ibrary

AD

O.N

ET

and

XM

LA

DO

.NE

T an

d X

ML

AS

P.N

ET

AS

P.N

ET

Web

Fo

rms W

eb S

ervicesW

eb F

orm

s Web

Services

Mo

bile In

ternet T

oo

lkitM

ob

ile Intern

et To

olkit

Win

do

ws

Win

do

ws

Fo

rms

Fo

rms

Co

mm

on

Lan

gu

age S

pecificatio

nC

om

mo

n L

ang

uag

e Sp

ecification

VB

VB

C+

+C

++

C#

C#

JScrip

tJS

cript

J#J#

Visual Studio.NET Visual Studio.NET

Framew

ork, Languages, And Tools

Op

erating

System

Op

erating

System

Co

mm

on

Lan

gu

age R

un

time

Co

mm

on

Lan

gu

age R

un

time

Base C

lass Lib

raryB

ase Class L

ibrary

AD

O.N

ET

and

XM

LA

DO

.NE

T an

d X

ML

AS

P.N

ET

AS

P.N

ET

Web

Fo

rms W

eb S

ervicesW

eb F

orm

s Web

Services

Mo

bile In

ternet T

oo

lkitM

ob

ile Intern

et To

olkit

Win

do

ws

Win

do

ws

Fo

rms

Fo

rms

Co

mm

on

Lan

gu

age S

pecificatio

nC

om

mo

n L

ang

uag

e Sp

ecification

VB

VB

C+

+C

++

C#

C#

JScrip

tJS

cript

J#J#

Visual Studio.NET Visual Studio.NET

The .NET Evolution

Befo

re CO

M, ap

plicatio

ns w

ereB

efore C

OM

, app

lication

s were

com

pletely sep

arate entities

com

pletely sep

arate entities

with

little or n

o in

tegratio

nw

ith little o

r no

integ

ration

Ap

plicatio

nA

pp

lication

Co

de an

d d

ataC

od

e and

data

structu

resstru

ctures

The .NET Evolution

CO

M p

rovid

es a way fo

rC

OM

pro

vides a w

ay for

com

po

nen

ts to in

tegrate;

com

po

nen

ts to in

tegrate;

Ho

wever, each

Ho

wever, each

com

po

nen

t mu

st pro

vide

com

po

nen

t mu

st pro

vide

the

the “ “p

lum

bin

gp

lum

bin

g” ” an

d an

do

bjects can

no

to

bjects can

no

td

irectly interact

directly in

teract

The .NET Evolution

With

the .N

ET

Fram

ewo

rkW

ith th

e .NE

T F

ramew

ork

com

mo

n lan

gu

age ru

ntim

e,co

mm

on

lang

uag

e run

time,

com

po

nen

ts are bu

ilt on

aco

mp

on

ents are b

uilt o

n a

com

mo

n su

bstrate; N

oco

mm

on

sub

strate; No

“ “plu

mb

ing

plu

mb

ing

” ” is need

ed an

d is n

eeded

and

ob

jects can d

irectly interact

ob

jects can d

irectly interact

Assem

bly

Assem

bly

Compilation A

nd Execution

So

urce

So

urce

Co

de

Co

de

Lan

gu

age

Lan

gu

age

Co

mp

ilerC

om

piler

Co

mp

ilation

Co

mp

ilation

At in

stallation

or th

eA

t installatio

n o

r the

first time each

first time each

meth

od

is calledm

etho

d is called

Execu

tion

Execu

tion

JITJIT

Co

mp

ilerC

om

piler

Native

Native

Co

de

Co

de

Code (IL)Code (IL)

Metadata

Metadata

Simplify D

evelopment

•Com

pletely eliminates CO

M plum

bing•

No m

ore…–

Registration–

GU

IDs

–.ID

L files–

HRESU

LTs–

IUnknow

n–

AddRef/Release

–CoCreateInstance

=>self described apps=>self described apps

=>hierarchical namespaces

=>hierarchical namespaces

=>unified object model

=>unified object model

=>structured exceptions=>structured exceptions

=>comm

on root object=>com

mon root object

=>garbage collector=>garbage collector

=> =>” ”newnew

” ” operator operator

Simplify D

evelopment

•Com

mon Type System

–Com

mon instance and type definition

•Enables clean O

O program

ming

–Classes and interfaces

–Constructors, properties, m

ethods, events–

Cross language inheritance•

Built-in interoperability–

With CO

M–

With native (W

in32® style) D

LLs

Robust Environment

•A

utomatic lifetim

e managem

ent–

All objects are garbage collected

•Exception handling–

Error handling first class and mandatory

•Type-safety–

No buffer overruns, N

o unsafe casts, Uninitialized

variables

Secure Environment

•Security designed-in

•Code access security enforcem

ent–

Security based on the identity of code–

Adm

inistratively configurable via policy•

ASP.N

ET integrated authenticationof user–

Window

s identity, Passport®, form

s-based, …•

Cryptography library with X

ML

DSIG

support–

Digital signature for X

ML (w

ww

.w3.org/signature)

Simplify D

eployment A

ndM

anagement

•Zero-im

pact install–

Applications and com

ponents can be shared orprivate

•Side-by-side execution–

Multiple versions of the sam

e component can co-

exist on a system•

Assem

blies–

Contain dependency information

Op

erating

System

Op

erating

System

Co

mm

on

Lan

gu

age R

un

time

Co

mm

on

Lan

gu

age R

un

time

Base C

lass Lib

raryB

ase Class L

ibrary

AD

O.N

ET

and

XM

LA

DO

.NE

T an

d X

ML

AS

P.N

ET

AS

P.N

ET

Web

Fo

rms W

eb S

ervicesW

eb F

orm

s Web

Services

Mo

bile In

ternet T

oo

lkitM

ob

ile Intern

et To

olkit

Win

do

ws

Win

do

ws

Fo

rms

Fo

rms

Co

mm

on

Lan

gu

age S

pecificatio

nC

om

mo

n L

ang

uag

e Sp

ecification

VB

VB

C+

+C

++

C#

C#

JScrip

tJS

cript

J#J#

Visual Studio.NET Visual Studio.NET

Framew

ork, Languages, And Tools

Unify Program

ming M

odels

Win

do

ws A

PI

Win

do

ws A

PI

.NE

T F

ramew

ork

.NE

T F

ramew

ork

Co

nsisten

t AP

I availability reg

ardless o

fC

on

sistent A

PI availab

ility regard

less of

lang

uag

e and

pro

gram

min

g m

od

ellan

gu

age an

d p

rog

ramm

ing

mo

del

AS

PA

SP

Stateless,

Stateless,

Co

de em

bed

ded

Co

de em

bed

ded

in H

TM

L p

ages

in H

TM

L p

ages

MF

C/A

TL

MF

C/A

TL

Su

bclassin

gS

ub

classing

, ,P

ow

er,P

ow

er,E

xpressiven

essE

xpressiven

ess

VB

Fo

rms

VB

Fo

rms

RA

D,

RA

D,

Co

mp

ositio

n,

Co

mp

ositio

n,

Deleg

ation

Deleg

ation

How

Much Sim

pler?W

ind

ow

s AP

IW

ind

ow

s AP

IHWND HWND

hwndMain hwndMain

= =

CreateWindowExCreateWindowEx

( ( 0, " 0, "

MainWClassMainWClass

", "Main Window",", "Main Window",

WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,

WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,

CW_USEDEFAULT, CW_USEDEFAULT,

CW_USEDEFAULT, CW_USEDEFAULT,

CW_USEDEFAULT, CW_USEDEFAULT,

CW_USEDEFAULT, CW_USEDEFAULT,

(HWND)NULL, (HMENU)NULL,

(HWND)NULL, (HMENU)NULL,

hInstancehInstance

, NULL);, NULL);

ShowWindowShowWindow

( (hwndMainhwndMain

, SW_SHOWDEFAULT);, SW_SHOWDEFAULT);

UpdateWindowUpdateWindow

( (hwndMainhwndMain

););

.NE

T F

ramew

ork

.NE

T F

ramew

ork

Dim Dim

form form

As NewAs New

Form() Form()

form.Text = "Main Window"form.Text = "Main Window"form.Show()form.Show()

Factored And Extensible

•The Fram

ework is not a “black box”

•A

ny .NET class is available for you to extend

through inheritance–

Gives developers m

uch more head room

•Plug and Play com

ponents and!subsystems

The .NET Fram

ework Library

Base C

lass Lib

raryB

ase Class L

ibrary

AD

O.N

ET

and

XM

LA

DO

.NE

T an

d X

ML

Web

Fo

rms W

eb S

ervicesW

eb F

orm

s Web

Services

Mo

bile In

ternet T

oo

lkitM

ob

ile Intern

et To

olkit

Win

do

ws

Win

do

ws

Fo

rms

Fo

rms

AS

P.N

ET

AS

P.N

ET

System

S

ystem

System

.Data

System

.Data

System

.Xm

lS

ystem.X

ml

System

.Web

System

.Web

Glo

balizatio

nG

lob

alization

Diag

no

sticsD

iagn

ostics

Co

nfig

uratio

nC

on

figu

ration

Co

llection

sC

ollectio

ns

Reso

urces

Reso

urces

Reflectio

nR

eflection

Net

Net

IO IO

Th

readin

gT

hread

ing

Text

Text

ServiceP

rocess

ServiceP

rocess

Secu

rityS

ecurity

Co

mm

on

Co

mm

on

OleD

bO

leDb

SQ

LT

ypes

SQ

LT

ypes

Sq

lClien

tS

qlC

lient

XP

athX

Path

XS

LT

XS

LT

Ru

ntim

eR

un

time

Intero

pS

ervicesIn

terop

Services

Rem

otin

gR

emo

ting

Serializatio

nS

erialization

Serializatio

nS

erialization

Co

nfig

uratio

nC

on

figu

ration

Sessio

nS

tateS

ession

State

Cach

ing

Cach

ing

Secu

rityS

ecurity

Services

ServicesD

escriptio

nD

escriptio

n

Disco

veryD

iscovery

Pro

toco

lsP

roto

cols

UI

UIHtm

lCo

ntro

lsH

tmlC

on

trols

Web

Co

ntro

lsW

ebC

on

trols

System

.Draw

ing

System

.Draw

ing

Imag

ing

Imag

ing

Draw

ing

2DD

rawin

g2D

Text

Text

Prin

ting

Prin

ting

System

.Win

do

ws.F

orm

sS

ystem.W

ind

ow

s.Fo

rms

Desig

nD

esign

Co

mp

on

entM

od

elC

om

po

nen

tMo

del

The .NET Fram

ework Library

Base Framew

orkS

ystemS

ystem

Th

readin

gT

hread

ing

Text

Text

ServiceP

rocess

ServiceP

rocess

Secu

rityS

ecurity

Reso

urces

Reso

urces

Reflectio

nR

eflection

Net

Net

IO IO Glo

balizatio

nG

lob

alization

Diag

no

sticsD

iagn

ostics

Co

nfig

uratio

nC

on

figu

ration

Co

llection

sC

ollectio

ns

Ru

ntim

eR

un

time

Serializatio

nS

erialization

Rem

otin

gR

emo

ting

Intero

pS

ervicesIn

terop

Services

Data A

nd XM

LS

ystem.D

ataS

ystem.D

ata

System

.Xm

lS

ystem.X

ml

SQ

LT

ypes

SQ

LT

ypes

SQ

LC

lient

SQ

LC

lient

Co

mm

on

Co

mm

on

OleD

bO

leDb

Serializatio

nS

erialization

XP

athX

Path

XS

LT

XS

LT

ASP.N

ETS

ystem.W

ebS

ystem.W

eb

Cach

ing

Cach

ing

Co

nfig

uratio

nC

on

figu

ration

Services

Services

UI

UI

Sessio

nS

tateS

ession

State

Htm

lCo

ntro

lsH

tmlC

on

trols

Web

Co

ntro

lsW

ebC

on

trols

Descrip

tion

Descrip

tion

Disco

veryD

iscovery

Secu

rityS

ecurity

Pro

toco

lsP

roto

cols

Window

s® Form

s

System

.Draw

ing

System

.Draw

ing

Draw

ing

2DD

rawin

g2D

Imag

ing

Imag

ing

Prin

ting

Prin

ting

Text

Text

System

.Win

do

ws.F

orm

sS

ystem.W

ind

ow

s.Fo

rms

Desig

nD

esign

Co

mp

on

entM

od

elC

om

po

nen

tMo

del

Op

erating

System

Op

erating

System

Co

mm

on

Lan

gu

age R

un

time

Co

mm

on

Lan

gu

age R

un

time

Base C

lass Lib

raryB

ase Class L

ibrary

AD

O.N

ET

and

XM

LA

DO

.NE

T an

d X

ML

AS

P.N

ET

AS

P.N

ET

Web

Fo

rms W

eb S

ervicesW

eb F

orm

s Web

Services

Mo

bile In

ternet T

oo

lkitM

ob

ile Intern

et To

olkit

Win

do

ws

Win

do

ws

Fo

rms

Fo

rms

Co

mm

on

Lan

gu

age S

pecificatio

nC

om

mo

n L

ang

uag

e Sp

ecification

VB

VB

C+

+C

++

C#

C#

JScrip

tJS

cript

J#J#

Visual Studio.NET Visual Studio.NET

Framew

ork, Languages, And Tools

Languages•

The .NET Platform

is language neutral–

All .N

ET languages are first class players–

You can leverage your existing skills

•Com

mon language specification

–Set of features guaranteed to be in all languages

•W

e are providing–

Visual Basic

®, C++, C#, J#, JScript ®

•Third-parties are building–

APL, CO

BOL, D

elphi, Pascal, Eiffel, Haskell, M

L,O

beron, Perl, Python, Scheme, Sm

alltalk…

Standardization•

A subset of the .N

ET Framew

ork and C#subm

itted to ECMA

–A

dopted as International standards inD

ec. 2001–

In the ISO fast-track process now

–Co-sponsored w

ith Intel, Hew

lett-Packard•

Comm

on language infrastructure–

Based on comm

on language runtime and base

framew

ork–

Layered into increasing levelsof functionality

Summ

ary•

The .NET Fram

ework

–D

ramatically sim

plifies development and

deployment

–U

nifies programm

ing models

–Provides robust and secure executionenvironm

ent–

Supports multiple program

ming languages

DEV

349The M

icrosoft .NET

component m

odelBertrand M

eyerProfessor of Softw

are Engineering, ETH Zürich

Scientific advisor, Eiffel Software, Santa Barbara

Execution scheme under .N

ET

IL code(plus

metadata)

Loader

Managed code

Unjittedroutine call

Execution

Language compilers

JIT + verifier

EiffelVB

C++C#

.NET languages

The basic .NET com

ponent unitResult of com

pilation is an assembly

Assem

bly is a set of classesU

nit of:•

Delivery and deploym

ent•

Nam

ing (through namespaces)

•Security (level for granting perm

issions)•

Versioning &

side-by-side execution

Self-documenting through “m

anifest”

The Single Product Principle

•There is one product: SO

FTWA

RE

Eiffel: use single, seamless notation

throughout the development cycle

Rely on tools to produce documentation

Maintain just one product!

Single Product Principle in .NET

•It’s all in the metadata!

Definition:

•M

etadata is information about a m

odule’sexternal properties, not necessarily neededfor executing the m

odule, but retained aftercom

pilation along with the binary code

Examining an assem

bly with ildasm

How

is the metadata stored?

•Stuffed into PE (Portable Executable)form

at•

To Window

s, result of compiling an

assembly looks like ordinary binary

(*.dll or *.exe), but contains all kindsof supplem

entary information

•W

ill execute on .NET only

The Portable Executable (PE) format

Execution model: the role of

metadata

IL code(plus

metadata)

Loader

Managed code

Unjittedroutine call

Execution

Language compilers

JIT + verifier

EiffelVB

C++C#

.NET languages

Metadata contents

•M

anifest: assembly description

–N

ame, version, culture

–Security properties: N

eeded permissions

–Public key if present

–D

ependencies on other assemblies

•List of classes

•For each class:–

Features: methods, fields, properties, events

–Signatures (argum

ent and result types) of each–

Interfaces it implem

ents•

Custom

attributes (see next)

Working w

ith metadata

Letting a program access m

etadata:•

Use System

.Reflection

Examining m

etadata interactively:•

Use ILD

asmC

an convert metadata to:

•X

ML

•C

OM

type libraries (regasm)

To produce metadata:

•U

se System.R

eflection.Emit

.NET com

ponent model

•Single product principle: full reflectivity;assem

blies are self-documenting

•(G

roups of) classes directly yield components

•N

o extra plumbing

•N

o IDL

•Full application of O

bject-Oriented principles

•M

ulti-language interoperability

Recommended