Net Fundamentals TDG - Injazat What is Dot Net.ppt
Contents NET Framework Core Components Common Language Runtime (CLR) Class Library Next Generation Windows Services (NGWS) Changes Since 1.0 & 1.1 Changes Since 2.0 & 3.0 .Net 3.5 SP1 (Codename “Arrowhead”) .Net Framework Current “Layer Cake” The Most Important Feature Of .NET 4.0 .Net Framework 4.0 Assemblies Garbage Collection Names You Need To Know About What Really Happens Namespaces Tools Provided By The .NET Framework The Common Type System Controlling Access To A Method Or Field Using Value Types Built-in Value Types
NET framework Core components The .NET framework has two major components: Common Language Runtime (CLR) Class Library Net framework works like the Domino Objects only much lower level and very complete It is part of the OS (or can be added) Replaces win32 API calls - mostly Decoupled from OS Supports many programming languages with the CLR (Common Language Runtime)
Terminology "ABC" CLR: Common Language Runtime One runtime for many programming languages Intermediate Language (IL) One intermediate, high-level assembly-style language that is emitted by language compilers Assembly Container for code, metadata and resources – your new term for what you used to call "D-L-L" Metadata Information that describes the shape of data and the runtime behavior of a program
Common Language Runtime (CLR) The CLR is the foundation upon which the .NET Framework has been built. The runtime manages code at execution time and provides all the core services such as memory management, thread management and remoting. It also enforces strict type safety and ensures code accuracy in order to provide security and robustness to the applications. This capability to manage code at runtime is the distinguishing feature of the CLR. All code that is managed by the CLR is known as managed code while other codes are known as unmanaged code. CLR Features 1. CLR manages memory, thread execution, code execution, compilation code safety verification and other system services. 2. For security reasons, managed code is assigned varying degrees of trust based on origin. This prevents or allows the managed component from performing file access operations, registry access operations or other sensitive functions even within the same active application. 3. The Runtime enforces code robustness by implementing strict type and code verification infrastructure called Common type System (CTS). The CTS ensures that all managed code is self describing and all Microsoft or third party language compiler generated codes conform to CTS. This enables the managed code to consume other managed types and enforce strict type fidelity and type safety. 4. CLR eliminates many common software issues like handling of object layout, references to objects and garbage clearance. This type of memory management prevents memory leaks and invalid memory references. 5. The CLR also accelerates developer productivity. The programmer is free to choose the language of the application without worrying about compatibility and integration issues. He is also enabled to take advantage of the runtime and the class library of the .NET Framework and also harvest components from other applications written in different languages by different developers. This implicitly eases the process of migration. 6. Though CLR aims to be futuristic software, it lends support to existing applications. The interoperability between the managed and unmanaged codes makes this process extremely simple. 7. The design of the CLR is geared towards enhancing performance. The Just-in-time (JIT) compiling enables managed code to run in the native machine language of the system executing it. During the process the memory manager removes the possibilities of fragmented memory and increases memory locality-of-reference to enhance performance. 8. Finally, server side applications can host runtime. High performance servers like Microsoft SQL Server and Internet Information Services can host this CLR and the infrastructure so provided can be used to write business logic while enjoying the best benefits of enterprise server support.
Class Library The Class Library is an object oriented collection of reusable types. It is comprehensive and the types can be used to develop command line applications or GUI applications such as Web forms or XML Web services. Unmanaged components that load CLR into their processes can be hosted by the .NET Framework to initiate the execution of managed code. This creates a software environment that exploits both the managed and unmanaged codes. The.NET Framework also provides a number of runtime hosts and supports third party runtime hosts Class LibraryFeatures 1. The class library is a collection of reusable types that integrate with the CLR. 2. It is object oriented and provides types from which user defined types can derive functionality. This makes for ease of use and is time saving. 3. Third party components can be integrated seamlessly with classes in the .NET framework. 4. It enables a range of common programming tasks such as string management, data collection and file access. 5. It supports a variety of specialized development scenarios such as console application development, Windows GUI applications, ASP.NET Applications, XML Web services.
Next Generation Windows Services (NGWS) Microsoft started development on the .NET Framework in the late 1990s originally under the above name. By late 2000 the first beta versions of .NET 1.0 were released. Net 2.0 Net 1.1 Net 1.0 REST LINQ AJAX
Changes since 1.0 & 1.1 Changes since 1.0 Built-in support for mobile ASP.NET controls. Previously available as an add-on for .NET Framework, now part of the framework. Security changes – enable Windows Forms assemblies to execute in a semi-trusted manner from the Internet, and enable Code Access Security in ASP.NET applications. Built-in support for ODBC and Oracle databases. Previously available as an add-on for .NET Framework 1.0, now part of the framework. .NET Compact Framework – a version of the .NET Framework for small devices. Internet Protocol version 6 (IPv6) support. Numerous API changes. Changes since 1.1 Numerous API changes. A new hosting API for native applications wishing to host an instance of the .NET runtime. The new API gives a fine grain control on the behavior of the runtime with regards to multithreading, memory allocation, assembly loading and more (detailed reference). It was initially developed to efficiently host the runtime in Microsoft SQL Server, which implements its own scheduler and memory manager. Full 64-bit support for both the x64 and the IA64 hardware platforms. Language support for generics built directly into the .NET CLR. Many additional and improved ASP.NET web controls. New data controls with declarative data binding. New personalization features for ASP.NET, such as support for themes, skins and webparts. .NET Micro Framework – a version of the .NET Framework related to the Smart Personal Objects Technology initiative.
Changes since 2.0 & 3.0 Changes since 2.0 .NET Framework 3.0 consists of four major new components: Windows Presentation Foundation (WPF), formerly code-named Avalon; a new user interface subsystem and API based on XML and vector graphics, which uses 3D computer graphics hardware and Direct3D technologies. See WPF SDK for developer articles and documentation on WPF. Windows Communication Foundation (WCF), formerly code-named Indigo; a service-oriented messaging system which allows programs to interoperate locally or remotely similar to web services. Windows Workflow Foundation (WF) allows for building of task automation and integrated transactions using workflows. Windows CardSpace, formerly code-named InfoCard; a software component which securely stores a person’s digital identities and provides a unified interface for choosing the identity for a particular transaction, such as logging in to a website. Changes since version 3.0 New language features in C# 3.0 and VB.NET 9.0 compiler Adds support for expression trees and lambda methods Extension methods Expression trees to represent high-level source code at runtime. Anonymous types with static type inference Language Integrated Query (LINQ) along with its various providers LINQ to Objects LINQ to XML LINQ to SQL Paging support for ADO.NET ADO.NET synchronization API to synchronize local caches and server side datastores Asynchronous network I/O API Peer-to-peer networking stack, including a managed PNRP resolver Managed wrappers for WMI and Active Directory APIs Enhanced WCF and WF runtimes, which let WCF work with POX and JSON data, and also expose WF workflows as WCF services. WCF services can be made stateful using the WF persistence model. Support for HTTP pipelining and syndication feeds. ASP.NET AJAX is included New System.CodeDom namespace.
.Net 3.5 SP1 (codename “Arrowhead”) will reportedly enhance support for occasionally connected applications, and provide built-in support for the Microsoft ASP.NET Model-View-Controller (MVC) Framework. “Arrowhead” will increase the cold-start performance (startup when no other .NET Framework application has been started previously) of .NET Framework applications, by as much as 25 – 40%. It will also hardware accelerate some WPF effects such as shadows, as well as general performance and API enhancements across the WPF stack. In addition, a set of WPF controls, including a DataGrid will also be included. ADO.NET Entity Framework has also been added which gives the database based application programmer a ORM (Object Relational Mapping) tool.
.Net Framework Current “Layer Cake”
The Most Important Feature of .NET 4.0 .NET 4.0 is going to include some core changes, particularly in the area of parallel processing that is going to be very important to some people, and will eventually make it into all of our consciousness. .NET 4.0 will also include another chance for Entity Framework, .NET 4.0 will bring Azure and cloud computing to the forefront. .NET 4.0 is likely to offer patterns that will be the most important change in my coding since the huge changes brought on by LINQ (and supporting techniques like extensions and lambdas) of .NET 3.5. The most important feature of .NET 4.0 is Windows Workflow 4.0. (Windows Workflow 4.0 is a complete rewrite of workflow. It's a brand new product. More than just rewriting, it represents a rethinking of the problem.) And real business value is what its all about
.Net Framework 4.0
COM support: a personal view
Common Language Runtime Base Class Library Core types and services Common Language Runtime Assembly load and execution
Common Language Runtime VB.NET … C# Base Class Libraries Common Type System Security Class Loader, GC, JIT, Execution Support
Common Language Runtime VB.NET IronPython C# Base Class Libraries Dynamic Language Runtime Common Type system Security Class Loader, GC, JIT, Execution Support
Assemblies As in the Windows DNA world where DLLs and EXEs are the building blocks of applications, in the .NET world, it is the assembly that is the used as the foundation of applications.
Garbage collection The .NET Framework is a garbage-collected environment. Garbage collection is the process of detecting when objects are no longer in use and automatically destroying those objects, thus freeing memory.
Names you need to know about The Common Language Infrastructure (CLI) A subset of the .NET framework is the CLI. The CLI includes the functionality of the Common Language Runtime and specifications for the Common Type System, metadata and Intermediate language. A subset of the Framework Class Library incorporates the base class library, a Network library, a Reflection library, an XML library and Floating point and Extended Array Library. The shared source implementation of the CLI is available for both the FreeBSD and Windows operating Systems. The Common Language Specification (CLS) The CLR supports the CLS which is a subset of it. Additionally the CLR supports a set of rules that language and compiler designers follow. It provides robust interoperability between the .NET languages and the ability to inherit classes written in one language in any other .NET language. Cross language debugging also becomes a possibility in this scenario. It must be noted that the CLS rules apply only to publicly exposed features of a class. Classes A blueprint of an object is called a class. All definitions of haw a particular object will be instantiated at runtime, its properties and methods and storage structures are defined in the class. Classes are used by developers for creating instances of the class at runtime using the keyword “New”. Namespaces This is the key part of the .NET Framework. It provides scope for both preinstalled framework classes and custom developed classes. Vb.NET uses the “Imports” keyword to enable the use of member names from the namespace declared. C# uses the “using” keyword. In both cases the System Namespace is also imported so that the Console window can be written without explicitly referring to the System.Console. Assemblies Assemblies are also known as managed DLLs. They are the fundamental unit of deployment for the .NET platform. The .NET framework itself is made of a number of assemblies. An assembly contains the Intermediate language generated by the language compiler, an assembly manifest, type metadata and resources. They can be private or public. They are self describing and hence different versions of the same assembly can be run simultaneously. Intermediate language (IL) This is a processor independent representation of executable code. It is similar to assembly code and specific to the CLR. It is generated by the language compilers that target the CLR. At runtime, the CLR just-in-time compiles the IL to native code for execution. The tool ngen.exe which is part of the .NET framework pre-compiles assemblies to native code at install time and caches the precompiled code to the disk.
Names you need to know about Managed execution This refers to code whose execution is managed by the CLR. It includes memory management, access security, cross-language integration for debugging and exception handling etc. These assemblies are required for the creation of metadata on the code and the assemblies so that the CLR can manage the execution of the code. Manifests, Metadata and Attributes Metadata and manifests are key aspects of managed code execution. The portions of an assembly that contains descriptive information about the types contained in the assembly, the members exposed by the assembly and the resources required by the assembly are called manifests. Metadata is contained within the manifest. This metadata describes the assembly and some of it is generated by the language compiler at compile time. Other metadata may be added by the developer at design time. Declarations added to the code to describe or modify some aspect of the code’s behavior at runtime are known as Attributes. These are stored with an assembly as metadata. They serve many useful purposes in the .NET Framework Object Orientation in the .NET Framework Objects are the core of Object oriented programming. Classes are blueprints of objects and contain all the methods and properties of the object. Encapsulation, inheritance and polymorphism are attributes of an object. Encapsulation means the ability of an object to hide its internal data from outside view and allow access to only that data that is publicly available. Inheritance is the ability to derive one class from another. New classes can be created from existing classes and the new class inherits all the properties and methods of the old class and new methods and events can be added to the new class. This is useful when users want to create specialized classes. Polymorphism is the ability of multiple classes derived from the same base class to expose methods in the same name, regardless of the underlying process of implementation. Rapid Development and Reuse The object orientation of the .NET Framework provides for faster development and deployment of applications. The use of classes, derived classes to provide common functionality has gone a long way in reducing development time. Object orientation is also the crucial element in the development of the code-behind concept and the latest code beside concept. Code behind allows developers to separate executable code form the HTML markup of the user interface. The executable code is placed in a module called code behind file. This file contains a class that inherits from the Page class. The ASP.NET page inherits from code-behind class and the two are compiled at runtime into a single executable assembly. The BETA 2.0 has added a number of functionalities to aid in rapid development. We will be looking at these changes in the next unit “What’s new in BETA 2.0” Choosing a Language An important aspect of the .NET framework is that developers can continue to use the language of their choice in application development. The cross language interoperability in .NET makes it possible to create an application in any .NET supported language as all languages will work together smoothly using the CLR which translates all languages into Intermediary language.
What really happens Intermediate Language (IL) Code This is the code that was produced by the compiler as it compiled the source code. IL is later compiled by the CLR into native CPU instructions.
Namespaces The .NET Framework is made up of hundreds of classes. Many of the applications that you build in .NET are going to take advantage of these classes in one way or another. Because the number of classes is so large and you will need to get at them in a logical fashion, the .NET Framework organizes these classes into a class structure called a namespace. There are a number of namespaces, and they are organized in an understandable and straightforward way. You can import a namespace into your application in the following manner: VB Imports System.Data Imports System.Data.OleDb C# using System.Data; using System.Data.OleDb; Or in your ASPNet pages for (VB and C#) <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %>
tools provided by the .NET framework The different types of tools provided are Configuration and Deployment tools, debugging tools, security tools and General tools.
tools provided by the .NET framework
tools provided by the .NET framework
The Common Type System Field. A data variable that is part of the object’s state. Fields are identified by their name and type. Method. A function that performs an operation on the object, often changing the object’s state. Methods have a name, signature, and modifiers. The signature specifies the calling convention, number of parameters (and their sequence), the types of the parameters, and the type of value returned by the method. Property To the caller, this member looks like a field. But to the type implementer, this member looks like a method (or two). Properties allow an implementer to validate input parameters and object state before accessing the value and to calculate a value only when necessary; they also allow a user of the type to have simplified syntax. Finally, properties also allow you to create read-only or write-only “fields.” Event. A notification mechanism between an object and other interested objects.
controlling access to a method or field Private Callable only by other methods in the same class type. Family Callable by derived types, regardless of whether they are within the same assembly. Note that many languages (like C++ and C#) refer to family as protected. Family and Assembly Callable by derived types, but only if the derived type is defined in the same assembly. Assembly. Callable by any code in the same assembly. Note that many languages refer to assembly as internal. Family or Assembly Callable by derived types in any assembly and by any types in the same assembly. Note that C# refers to family or assembly as protected internal. Public. Callable by any code in any assembly.
Using Value Types There are three general value types: Built-in types User-defined types Enumerations
Built-in Value Types BEST PRACTICES Optimizing performance with built-in types The runtime optimizes the performance of 32-bit integer types (Int32 and UInt32), so use those types for counters and other frequently accessed integral variables. For floating-point operations, Double is the most efficient type because those operations are optimized by hardware.
C# 4.0 vs. Visual Basic 10 This is how close will become C# and VB in next release: The items in * black-bold are new features…