Transcript To .Net or not to .Net - Institut for Datalogi: Velkommen
Java vs. .Net
Livslang Uddannelse August 20
th
, 2004
Bent Thomsen PhD, DIC, Cand.Scient, EurIng, CEng, FBCS, MACM, MIEEE [email protected]
Department of Computer Science Aalborg University 1
What is Microsoft .Net?
• It is a vision – The platform for the digital future – ‘.NET is Microsoft’s platform for a new computing model built around XML Web Services’
Microsoft Corporation Annual Report, 2001
• It is a brand name – Applied to many things • It is a set of products and technologies – Infrastructure – Tools – Servers – Services • .Net is Microsoft’s core business Strategy 2
A Unified Programming Model
Consistent API availability regardless of language and programming model RAD, Composition and Delegation VB Object Model
.NET Framework
Subclassing, Power and Expressiveness
MFC/ATL
Stateless, code embedded in HTML pages
ASP Windows API
3
.NET Technologies
• The .NET Framework – The CLR with support for XML Web services and more – Supporting Visual Basic.NET, C#, C++, and more • The .Net development tools – Visual Studio.Net
• The .NET Enterprise Servers – BizTalk Server 2003, SQL Server 2003, Commerce Server 2003 and more • The .Net Services – Passport, My Services, bCentral, expedia and more 4
Microsoft .NET
Web services support across the Microsoft platform
Clients Services Servers
5
The Core of .NET Framework: FCL & CLR
• Common Language Runtime – Garbage collection – Language integration – Multiple versioning support (no more DLL hell!) – Integrated security • Framework Class Library – Provides the core functionality: ASP.NET, Web Services, ADO.NET, Windows Forms, IO, XML, etc.
6
.NET Framework
Common Language Runtime
– – – – CLR manages code execution at runtime Memory management • Kills entire classes of bugs (e.g., memory corruption, ref counting) Thread management, etc.
Auto-versioning, no more DLL Hell
Common Language Runtime Operating System
7
.NET Framework
Base Class Library
– Object-oriented collection of reusable types – Collections, I/O, Strings, …
.NET Framework (Base Class Library) Common Language Runtime Operating System
8
.NET Framework
Data Access Layer
– Access relational databases – Disconnected data model – Work with XML
ADO .NET and XML .NET Framework (Base Class Library) Common Language Runtime Operating System
9
.NET Framework
ASP.NET & Windows Forms
– Create application’s front-end – Web-based user interface, Windows GUI, Web services, …
ASP .NET
Web Forms Web Services Mobile Internet Toolkit
ADO .NET and XML Windows Forms .NET Framework (Base Class Library) Common Language Runtime Operating System
10
.NET Framework
System.Web
Services
Description
Discovery
Protocols
UI
HTML Controls
Web Controls System.Windows.Forms
Design Component Model Cache Configuration Security Session State ADO.NET
Design System.Data
SQL Client SQL ServerCE System.Drawing
Drawing 2D Imaging Printing Text System.XML
XML Document Xslt/XPath Serialization Reader/Writers Collections Security Text Globalization IO Net Reflection Resources System Configuration Service Process Diagnostics Threading
Runtime
Interop Services
Remoting
Serialization
11
.NET Framework
Programming Languages
– Use your favorite language
C++ C# VB.NET
Perl ASP .NET
Web Forms Web Services Mobile Internet Toolkit
J# ADO .NET and XML … Windows Forms .NET Framework (Base Class Library) Common Language Runtime Operating System
12
.NET Framework
Common Language Specification C++ Common Language Specification … ASP .NET
Web Forms Web Services Mobile Internet Toolkit
Windows Forms ADO .NET and XML .NET Framework (Base Class Library) Common Language Runtime Operating System
13
Common Type System (CTS)
• All .NET languages have the same primitive data types. An
int
in C# is the same as an
int
in VB.NET, COBOL.Net, Haskell, … • When communicating between modules written in any .NET language, the types are guaranteed to be compatible on the binary level • Types can be: – Value types – passed by value, stored in the stack – Reference types – passed by reference, stored in the heap • Strings are a primitive data type now 14
Common Language Specification (CLS)
• • • Any language that conforms to the CLS is a .NET language A language that conforms to the CLS has the ability to take full advantage of the Framework Class Library (FCL) CLS is standardized by ECMA 15
.NET Languages
• • • • • Languages provided by Microsoft – C++, C#, J#, VB.NET, JScript Third-parties languages – Perl, Python, Pascal, APL, COBOL, Eiffel, Haskell, ML, Oberon, Scheme, Smalltalk… Advanced multi-language features – Cross-language inheritance and exceptions handling Object system is built in, not bolted on – No additional rules or API to learn All compile to .Net Assemblies – Contains MSIL and metadata 16
Intermediate Language
• .NET languages are compiled to an Intermediate Language (IL) • IL is also known as MSIL or CIL • CLR compiles IL in just-in-time (JIT) manner – each function is compiled just before execution • The JIT code stays in memory for subsequent calls • Recompilations of assemblies are also possible 17
Example of MSIL Code
.method private hidebysig static void Main() cil managed { .entrypoint
// Code size 11 (0xb) .maxstack 8 IL_0000: ldstr "Hello, world!" IL_0005: call void [mscorlib]System.Console::WriteLine(string) IL_000a: ret } // end of method HelloWorld::Main 18
.Net Assemblies
Compilation Source Code C++, C#, VB or any .NET language
Compiler
csc.exe or vbc.exe
Assembly DLL or EXE
19
.Net Execution Model
Common Language Runtime Source code VB Compiler Managed code Assembly IL Code C# Compiler Assembly IL Code C++ Compiler Assembly IL Code Common Language Runtime JIT Compiler Native Code Operating System Services
20
Managed Code Execution
DEVELOPMENT
Source code public static void Main(String[] args ) try { f=new FileStream(“C:\\test.txt",FileMode.Create); w.Close(); public static void Main(String[] args ) try { Console.WriteLine("Exception:"+e.ToString()); } } f=new FileStream(“C:\\test.txt",FileMode.Create); w=new StreamWriter(f); w.Close(); Console.WriteLine("Exception:"+e.ToString()); } } Compiler Assembly PE header + MSIL + Metadata + EH Table
DEPLOYMENT
PEVerify Host Evidence Policy Manager
EXECUTION
Assembly info Module + Class list
Policy Granted permissions Permission request ( class ) Assembly Loader Class Loader Vtable + Class info ( method ) JIT + verification NGEN GAC, app. directory, download cache Native code + GC table CLR Services GC Exception Class init Security 21 • Role-based Security – What the user is allowed to do within the application – .NET Roles = Windows Active Directory ® groups • Code Access Security – What the code is allowed to do on this machine – Evidence Based (Policies, Permissions, Evidence) • Cryptography Built In to .NET FX 22 • • • Evolution, not revolution, of language used by developers worldwide Builds on existing technology while adding power – True OOP – Multithreading – NT Services – Web Services The fastest way to build scalable applications for industry 23 • • • • Native support for XML Web services Fully integrated with Visual Studio .NET development environment Full access to the .NET Framework – ASP.NET, ADO.NET, Windows Forms – Integration with >20 other languages Protection of existing investments – Use java language syntax on .NET – Move applications and skills forward 24 Continue to provide most powerful and flexible language • Better ANSI/ISO conformance • Enable seamless, incremental use of .NET Framework • Enhanced ATL Servers • Improved ATL and MFC Clients • Enhanced STL 25 Component Oriented Language • C# is the first “component oriented” language in the C/C++ family • Component concepts are first class: – Properties, methods, events – Design-time and run-time attributes – Integrated documentation using XML • Enables one-stop programming – No header files, IDL, etc. – C++ heritage – simplification with no unnecessary sacrifices • If you are serious about .Net you need to learn C# 26 • Hello world using System; class HelloWorld { public static void Main() { Console.WriteLine(“Hello World!"); } } >csc HelloWorld.cs >Hello World! 27 • Properties public class button { private string caption; public string Caption { get { return caption; } set { if (value != null) caption = value; } } } button b = new button(); b.Caption = “abc” string s = b.Caption; 28 • Parameter Passing By Value By Reference public static void Swap( ref { int z = x; x = y; y = z; } int x, ref int y) 29 • Pointers – Not recommended for use public struct Node { public int value; public unsafe Node* next; } public unsafe . . . class A { public class A { public unsafe . . . void B (char *p) { 30 • Boxing / Unboxing – Allows value types to be converted to and from objects automatically ArrayList list = new ArrayList(); int z = 100; list.Add(1); list.Add(13.12); list.Add(z); //integers are automatically boxed //when they are added to the list 31 • Versioning – C# requires developers to clearly state their intent • Use of the keyword ‘new’ and ‘override’ Class Derived B { new public void x () { . . . Class Derived B { public override . . . void x () { 32 • Generics • Anonymous methods • Iterators • Partial types 33 public class List < T > { private T [] elements; private int count; } public void Add( T element) { if (count == elements.Length) Resize(count * 2); elements[count++] = element; } } public T this[int index] { get { return elements[index]; } List • Development tool that contains a rich set of productivity and debugging features – Supports managed and unmanaged applications – Supports C#, C++, VB.NET, … – Many useful tools and wizards – Windows Forms Designer – ASP.NET Web Forms Designer – Web Services support – SQL Server integration with ADO.NET and XML • VS.NET is not part of the .NET Framework – Not necessary to build or run managed code – The .NET Framework SDK includes command line compilers 35 • From Visual Studio.NET you can: – Write code – Design user interface – Study documentation – Debug – Test – Deploy • Same tools for all languages • Same tools for all platforms 36 37 38 • Web Form – Next Generation ASP Page • Win Form – Next Generation Win32 App • Web Services – Key to Interoperability • Others – – Server Objects – Console Applications – Window Services – Mobile Clients – Many more… 39 • • • • • • Server-side Web Forms and Web Services separate code from content – Developer productivity increases – – – components Tools easily use ASP.NET Any programming language: full VB, JScript, C++, COBOL, Perl, etc. 40% to 70% reduction in lines of code Compiled No-touch deployment system Intelligent state management Backwards compatible with ASP Controls sense client and adapt output: HTML, DHTML, WML 40 • A Component That Uses XML & HTTP To Define and Deliver A Service – Global reach – Based on open set of standards – Reuse across platforms – Works with any operating system, programming language, or network – Expose legacy code • Different systems can actually talk 41 Open Standards & Protocols • XML – Universal data format – Standards-based integration – User-customizable • HTTP – Ubiquitous protocol – Universally understood 42 • • • Expose functionality as service – No need to learn XML, SOAP, or WSDL – Interface is automatically generated – Seamless deployment Reuse existing Web Services – VS.NET generates the plumbing – Full IntelliSense support Build and consume with any VS language 43 Visual Studio .Net and the Net Framework • Built-in Support for Developing and Consuming Web Services – Based entirely on open standards – Automatically generates WSDL – Automatically provides test page – Attribute based – No heavy coding needed [WebMethod] Public Function HelloWorld() as String return “Hello World” Compiler End Function WSDL Test Page Web Service Object 44 • • • Rich, powerful client UI – Control anchoring, visual inheritance – Shared across all .NET languages – No-touch deployment Secure – Semi-trusted browser component – Fully-trusted local application Full Web Service integration 45 • .Net Compact Framework – PocketPC, XScale, ARM, … • SSCLI – BSD Unix, Mac OS X • Mono – Linux 46 • Target mobile and embedded devices • Portable subset of .NET Framework – No new ‘compact’ namespaces – Visual Basic .NET and C# compiler support in v1 • Leverage Visual Studio .NET – Run managed .EXEs and .DLLs directly – Debug with Visual Studio .NET • Peacefully co-exist with host OS – Run on native threads, P/Invoke to call native code 47 • Verifiable type safe execution – No uninitialized variables, unsafe casts, bad array indexing, bad pointer math • Garbage Collection – No ref-counting, no leaks • JIT compilation • Error handling with exceptions • Common type system – Call, inherit, and source-level debug across different languages • • • • • No ASP.NET COM Interop – Good support for calling native DLLs • • P/Invoke – PlatformInvoke enables calls to Win32 DLLs – Support for calling COM objects using dll wrappers – No support for writing COM/ActiveX objects – No Install-time JIT (nGen) No Reflection Emit No Remoting – Client web services is fully supported No Generic Serialization – Datasets can be serialized to XML – No binary Serialization • Class libraries are a subset (about 25%) • Different size and scalability characteristics • Compact Additions – IrDA support – SQL Server CE managed classes – Device-specific controls 50 System.Web Services Description Discovery Protocols UI HTML Controls Web Controls System.Windows.Forms Design Component Model Cache Configuration Security Session State ADO.NET Design System.Data SQL Client SQL ServerCE System.Drawing Drawing 2D Imaging Printing Text System.XML XML Document Xslt/XPath Serialization Reader/Writers Collections Security Text Globalization IO Net Reflection Resources System Configuration Service Process Diagnostics Threading Runtime Interop Services Remoting Serialization 51 System.Web Services Description Discovery Protocols UI HTML Controls Web Controls System.Windows.Forms Design Component Model Cache Configuration Security Session State System.Drawing Drawing 2D Printing Imaging Text ADO.NET System.Data SQL Client Design SQL ServerCE System.XML XML Document Serialization Xslt/XPath Reader/Writers Collections Security Text Globalization IO Net Reflection Resources System Configuration Service Process Diagnostics Threading Runtime Interop Services Remoting Serialization 52 • Create a New Smart Device Application Project • Choose the platform and type of project • Add additional forms, controls, and code 53 • Smart Device Projects are used to develop applications that target the .NET Compact Framework • Supported devices include: – Pocket PC 2000, 2002 and 2003 – Pocket PC 2002 Phone Edition – SmartPhone 2003 – Custom-designed embedded devices built with the Windows CE .NET 4.1 operating system • Supported languages are Visual Basic and C# 54 • Mono Project – Open Source C# compiler, CLR and Framework Class Library – Runs on various platforms and hardware: • Linux, Unix, FreeBSD, Windows – JIT-compiler for x86 • s390, SPARC, PowerPC – interpreter for these hardware architectures – Supports also: • ADO.NET and XML • Windows Forms (not fully) • ASP.NET • Web Services 55 • Mono Project – Runs .NET portable executables on Linux, e.g. mono myapp.exe – Compiles .NET applications to portable executables, e.g. mcs myapp.cs – The obtained .exe file can taken and run on Windows • DotGNU Portable.NET – Build and execute .NET applications on GNU/Linux, Windows, Solaris, NetBSD, FreeBSD, and MacOS X 56 • Evolutionary – Existing Skills Migrate Smoothly – Interoperates with Existing Applications – Extension of WinDNA Architecture • Revolutionary – Common Language Runtime – Deployment / Versioning (Ends DLL Hell) – Web Services & XML Integration – Evidence Base Code Access Security 57 – .Net is Microsoft’s core strategy • .Net will be part of OS in the next generation of Windows • Lot’s of innovation in Longhorn – Avalon, indigo, WinFS 58.NET Security
Visual Basic .NET
Visual J# .NET
Visual C++ .NET
Visual C# .NET
C#
C#
C#
C#
C#
C#
C# 2.0 Language Enhancements
Generics
Visual Studio .NET
VS.NET – Single Development Environment
Visual Studio .NET
Referencing the Framework
.NET Applications
ASP.NET
What Is an XML Web Service?
Web Services
VS.NET and Web Services
Software as a Service
Windows Forms
.Net on other Platforms
.Net CF
Execution Engine Commonalities
Execution Engine Differences
Other Differences
.NET Framework
.NET Compact Framework
How to Create a Smart Device Application
What Are Smart Device Projects?
.NET Framework on Linux
.NET Framework on Linux (2)
.NET (R)Evolutionary
Future of .Net