Overview of .NET Framework

Document Sample
Overview of .NET Framework Powered By Docstoc
					Overview of .NET Framework
What will we learn today
 .NET Evolution

 .NET Platform

 .NET Framework Architecture

 Basics of .Net Framework Library

 Summary
.NET Evolution
The .NET Evolution


       Code and

        Before COM, applications were
        completely separate entities with
        little or no integration
The .NET Evolution

          COM provides a way for
          components to integrate.
          However, each component
          must provide the “plumbing”
          and objects cannot directly
The .NET Evolution

      With the .NET Framework
      common language runtime,
      components are built on a
      common substrate. No
      “plumbing” is needed and
      objects can directly interact
.NET Platform
                        What is .NET?
   A platform
     The .NET Framework

       Visual Studio.NET

       .NET Enterprise Servers
           Database, Messaging, Integration, Commerce, Proxy, Security,
            Mobility, Orchestration, Content Management

       .NET Building Block Services
           Passport

       Goal: make it incredibly easy to build powerful Web
        applications and Web services
    .Net Framework Design Goals

          Simplify development
             More power, less plumbing
      Unify programming models
      Across all languages and application types
Utilize web standards and best practices
       Rich XML, standard protocols, stateless
   Easier to deploy, run, & maintain
       For components, versioning, availability
Benefits of .NET Framework
.NET Framework Architecture
        .NET Framework Architecture
VB     C++    C#    JScript    …

 Common Language Specification

                                      Visual Studio.NET
ASP.NET: Web Services    Windows
   and Web Forms          Forms

      ADO.NET: Data and XML

        Base Class Library

     Common Language Runtime
        .NET Framework Architecture

VB     C++    C#    JScript    …

 Common Language Specification

                                      Visual Studio.NET
ASP.NET: Web Services    Windows
   and Web Forms          Forms

      ADO.NET: Data and XML

        Base Class Library

     Common Language Runtime
Common Language Runtime - Overview

 Highlights
    Common type system
        Mapping of data types. Programming language  Framework

    Just-in-time (JIT) compilers
        JIT compiles intermediary language (MSIL) into native code
        Highly optimized for platform or device

    Garbage collector

    Permission and policy-based security

    Exceptions

    Threading

    Diagnostics and profiling
Common Language Runtime
Diagram Base Class Library Support
      Thread Support              COM Marshaler

       Type Checker            Exception Manager

      Security Engine             Debug Engine

  MSIL to Native         Code           Garbage
  Compilers (JIT)       Manager       Collector (GC)

                      Class Loader
        .NET Framework Architecture
VB     C++    C#    JScript    …

 Common Language Specification

                                      Visual Studio.NET
ASP.NET: Web Services    Windows
   and Web Forms          Forms

      ADO.NET: Data and XML

        Base Class Library

     Common Language Runtime
          .NET Framework - Overview
                A Unified Programming Model
               Consistent API availability regardless of
                 language and programming model

                           .NET Framework

                           Subclassing,                        Stateless,
                              Power,                       Code embedded
                          Expressiveness                    in HTML pages

 VB Forms                     MFC/ATL                           ASP

                              Windows API
                   Things become simpler

Windows API
HWND hwndMain = CreateWindowEx(0, "MainWClass", "Main Window",
  (HWND)NULL, (HMENU)NULL, hInstance, NULL);
ShowWindow(hwndMain, SW_SHOWDEFAULT);

.NET Framework

Form form = new Form();
form.Text = "Main Window";
               Web Standards/Practices

• The .NET Framework supports
   –    HTML, XML, SOAP, XSLT, XPath
•Web services enables internet scale distributed apps
   –    State-full connected model does not work
   –     Loosely connected web services enables scalable apps
•XML support is built in deeply
  -    Data, remoting, serialization, documentation, config
        .NET Framework Architecture

VB     C++    C#    JScript    …

 Common Language Specification

                                      Visual Studio.NET
ASP.NET: Web Services    Windows
   and Web Forms          Forms

      ADO.NET: Data and XML

        Base Class Library

     Common Language Runtime
 Common Language
 Specification languages compiled into MSIL
 All .NET programming
 (Microsoft Intermediate Language)

 The Common Language Specification (CLS) is a set of
 rules that a language compiler has to adhere to, in order
 to create .NET programs that can run on CLR.
        .NET Framework Architecture

VB     C++    C#    JScript    …

 Common Language Specification

                                      Visual Studio.NET
ASP.NET: Web Services    Windows
   and Web Forms          Forms

      ADO.NET: Data and XML

        Base Class Library

     Common Language Runtime
   Types of Supported Languages

 Object Oriented

 Procedural

 Functional

 Common Language Specification

 Same Tool can be used for all languages
.NET Core Languages

   C++
     Attribute based programming
     Managed Extensions for C++

   C#
     Modern, object oriented, type-safe language
     Bringing RAD to the C++ developer

   Visual Basic.Net
     Object oriented language provides code reusability
     Maximum scalability with Free Threading
     Easier maintainability with Structured Exception Handling
    Third Party Languages
   Perl –
   Python –
   Cobol –
   Pascal –
   Eiffel –
   Haskell –
   Mercury –
   APL –
   Scheme –
   SmallTalk –
   Oberon –
   Standard ML –
        .NET Framework Architecture

VB     C++    C#    JScript    …

 Common Language Specification

                                      Visual Studio.NET
ASP.NET: Web Services    Windows
   and Web Forms          Forms

      ADO.NET: Data and XML

        Base Class Library

     Common Language Runtime
Visual Studio® .NET
The complete development environment for building distributed applications for Windows®
and the Web

                                                 Most productive tool for creating
                                                  and consuming Web services
        Visual Studio .NET
                                                 Open, extensible development
            .NET Framework
                                                 High productivity tools for team-
                                                  based enterprise Web
              Windows                             development
         Application Services
                                                 End-to-end tools for enterprise
      Communication Protocols                     lifecycle productivity
Common Language Runtime
       In Details
                          Common Language Runtime


                                             Base Classes
Common Language Runtime

                           native code


                               IL to

                                 GC, stack walk, code manager
                                         Class loader and layout
    Common Language Runtime

       Manages running code
                Verifies type safety
     Provides garbage collection, error handling
     Code access security for semi-trusted code

  Provides common type system
    Value types (integer, float, user defined, etc)
                 Objects, Interfaces

Provides access to system resources
            Native API, COM interop, etc.
  Services of the CLR

 Memory Management
 Threads
 Garbage collection
 Exception handling
 Security
 Application Isolation
 Data Interaction
 Encryption Services
 Deployment
One Runtime For All Languages

 CLR is an open standard
 Any language can make use of CLR services
 Any language can use classes written in any other
  language (consumer)
 Any language can (code) inherit classes written in any
  other language (extender)
 A language can become a provider
                 CLR Execution Model
Source      VB              C#             C++
          Compiler       Compiler        Compiler

Managed   Assembly       Assembly        Assembly
code       IL Code        IL Code         IL Code

   Common Language Runtime

                      JIT Compiler

                           Native Code

                     Operating System Services
CLR Simplifies Development
Completely eliminates COM plumbing
             No more…
                =>self describing components
                =>hierarchical namespaces
            .IDL files
                 =>source code to metadata

                =>structured exceptions
                =>root object class
                =>garbage collector
                     Garbage Collection

       Process of automatically freeing up memory when an
        object it been allocated to is no longer being used

       Prevents the following errors:
         Forgetting to destroy objects
         Attempting to destroy the same object more than once
         Destroying an active object
Anatomy of .NET applications




               Type                 Type
               •Methods             •Methods
               •Properties          •Properties
               •Fields              •Fields

ParcelTracker.DLL   myAssembly.DLL                Util.DLL

   Metadata         Assembly Metadata          Type Metadata
    IL/native         Type Metadata               IL Code
                         IL Code
 Single Module
                                   Multiple Modules
    Intermediate Language (IL)
     Assembly Language of CLR
     Code is never interpreted

  VC                              Standard JIT

  Managed vs. Unmanaged

 Managed Code makes use of CLR services
 Unmanaged Code does not use any services
 Garbage Collector can be turned off
 CLR offers mechanisms for managed code to interact
  with unmanaged code
 Interoperation with hardware specific code and other
 Ability to reuse old code
Runtime Control Flow
                                       reference to
                        IL to native   type
                       code compiler
                         Managed       First call to
           Code           Native       method
          Managers        Code

 IL is verified by a verifier and guaranteed to be type safe

 Checks for type casts, memory initialization, array

 Checks stack operations

 Multiple versions of component can be installed on

 A single process can use different version of component
 at same time

 Zero-impact installation and uninstallation (copy)
.NET Framework Components
        in Details
 .NET Framework Namespaces

ASP.NET              Windows

ADO.NET                  XML

    Base Class Library
             System.Web                                   System.Windows.Forms

  Services                 UI                    Design            ComponentModel
 Description          HtmlControls
 Discovery            WebControls
 Protocols                                                   System.Drawing

 Caching                   Security               Drawing2D                 Printing
Configuration         SessionState                  Imaging                   Text

             System.Data                                       System.Xml

    ADO                     SQL                      XSLT               Serialization
   Design              SQLTypes                      XPath


 Collections                  IO                 Security                Runtime
Configuration                 Net            ServiceProcess          InteropServices

 Diagnostics               Reflection              Text                 Remoting

Globalization              Resources             Threading            Serialization
Windows Forms
Windows Forms

 Rich, powerful client UI
    Control anchoring, visual inheritance
    Shared across all .NET languages

 Secure
    Fully-trusted local application

 Full Web Service integration
.Net Framework Library
    Looking Back

   Language Dependent Runtime Libraries
        C-Runtime library
        C++ Standard Template Library
        Visual Basic Runtime
            API holes plugged with ActiveX controls

   Discriminatory access to functionality
        Many APIs unsupported by Visual Basic
        Advanced tasks often require C/C++
   Core functionality scattered all over Windows
        ActiveX controls, System DLLs, SDKs, IE
    The .NET Framework Library

   One-stop, well-organized class framework
        OS-independent subset submitted to ECMA
            Standardization backed by Microsoft, HP, Intel
        Subset includes most things covered here
   Integrates all current Windows technologies
        Everything in one place – for all languages
        Windows Forms, GDI+, Printing for Windows Dev
        Web Forms, Web Services, Networking for Net Dev
        Supports Active Directory, WMI, MSMQ, Services
 The System Namespace
 System.Object

 The not-so-primitive "primitive" types

 String and text classes

 Dates, times and calendars

 System console support
 The Root of Everything: System. Object

 Base class for each and every type
    Inheritance from System.Object is typically implicit
    All simple and complex types share the same base
 Single base-class makes framework consistent
    Collection classes can be used for everything
    Intrinsic model for handling variant types
    Strongly typed. No pointers, no structures
        Much less error prone than COM's VARIANT type
 System.Object is a reference type
 Value types (internally) inherit from ValueType
    Special class derived from Object
 System. Object’s Methods (1/2)
 bool System.Object.Equals(Object o)
    Reference identity for reference types (default)
    Overridden for value types to test value identity
 void System.Object.Finalize()
    To be overridden by subclasses
    Called when object is garbage collected
 int System.Object.GetHashCode()
    i.e. used with System.Collections.HashTable
    Should be overriden to return good hashes
        Good hash distribution speeds up hash tables
    Default implementation: Identity-based hash
 System. Object’s Methods (2/2)

 System.Type System.Object.GetType()
    Retrieves the type object for the object's class
    GetType() is the entry point for .NET Reflection
 System.Object System.Object.MemberwiseClone()
    Creates a exact clone of "this" object
    Works through Reflection with any class
 System.String ToString()
    To be overriden; Returns text representation
    Default returns qualified name of "this" class
    Not designed for user messages (use IFormattable)
 The “Primitive” Types

 Traditionally perceived as "magic" or "special"
    There is no primitive-type magic-ness in .NET!
    Very SmallTalk-like model
    "Primitive" types are regular framework types
 However, still exposed as language-intrinsic types
    C#: bool, int, long, string, double, float
    Visual Basic.NET: Boolean, Integer, String
 "Primitives" are mostly value-types
    Exception: System.String is reference type
 "Primitive" Types are not so primitive anymore
    Full featured classes, rich functionality
 System. String

 System.String is the cross-language string
    One storage method, one API, unified handling
    Locale-aware, always Unicode
 Fully-featured string handling capabilities
    Forward and reverse substring searches
        IndexOf(), LastIndexOf(), StartsWith(), EndsWith()
    Whitespace stripping and padding
      Trim(), PadLeft(), PadRight()
    Range manipulation and extraction
      Insert(), Remove(), Replace(), Substring(), Join(), Split()
    Character casing and advanced formatting
      ToLower(), ToUpper() and
      Format() much like C's printf but safe
 System. Text

 StringBuilder
    Super-efficient for assembling large strings

 Encoders and Decoders
    Support character encoding and conversions

    ASCII, UTF-8, UTF-7, Windows Codepages

    Unicode encoder for full UTF-16 compliant streams
      Encoder can write and decoder detect byte-order marks
      Supports big-endian and little-endian Unicode encoding
 Date and Time Support

 System.DateTime class for dates and times
    Virtually unlimited date values (100 AD to 9999 AD)
    Date and Time arithmetics built-in
        AddDays(), AddSeconds()
    Sophisticated, locale-aware formatting and parsing
 System.TimeSpan for durations
    Can represent arbitrary timespans
    Can express span in arbitary units by conversion
 System.TimeZone for time-zone support
 The Console

 System.Console class for console I/O
 Supports standard in, standard out, standard error
 Writing to the console
   Write() or WriteLine()
   Supports String.Format syntax
        Console.Write("Snowwhite and the {0} dwarfs", 7)
 Reading from the console
    Read() reads on characters
    ReadLine() reads one full line
 Other System Goodies

 System.URI class
    Two-way parsing and construction of URIs

 System.Random class
    Random number generator

 System.Radix class
    Numeric base-system conversions (eg. Dec/Hex)

 System.Convert class
    One-stop place for core type conversions

• Introduction to .NET(Wrox Publication)

Shared By: