690 likes | 1.35k Views
Microsoft .NET Gaurav Gupta Dinesh Chandnani CSc 630 Spring 2002 Acknowledgements Microsoft MSDN http://www.msdn.microsoft.com/library Microsoft GotDotNet http://www.gotdotnet.com Sun Microsystems http://www.java.sun.com Csharp Help http://www.csharphelp.com Sam Gentiles Website
E N D
Microsoft .NET Gaurav Gupta Dinesh Chandnani CSc 630 Spring 2002
Acknowledgements • Microsoft MSDN http://www.msdn.microsoft.com/library • Microsoft GotDotNet http://www.gotdotnet.com • Sun Microsystems http://www.java.sun.com • Csharp Help http://www.csharphelp.com • Sam Gentiles Website http://www.project-inspiration.com/sgentile/ • Brinkster Web Hostinghttp://www.brinkster.com • DotNetBuzz http://www.dotnetbuzz.com • .netWire http://www.dotnetwire.com • The IT Portal http://www.theitportal.com/dotnet • .NET Experts http://www.dotnetexperts.com CSc 630: Microsoft .NET
Outline Microsoft Vision • .NET Design Goals • .NET Framework • Visual Studio.NET • Web Services • .NET vs J2EE • Conclusion CSc 630: Microsoft .NET
Microsoft Vision Empower people, any time, any place,and on any device through great software CSc 630: Microsoft .NET
Outline Microsoft Vision • .NET Design Goals • .NET Framework • Visual Studio.NET • Web Services • .NET vs J2EE • Conclusion CSc 630: Microsoft .NET
.NET Design Goals • Unifies programming models • Dramatically simplifies development • Provides robust execution environment • Supports multiple programming languages • Natively supports XML Web Services CSc 630: Microsoft .NET
Outline Microsoft Vision • .NET Design Goals • .NET Framework • Visual Studio.NET • Web Services • .NET vs J2EE • Conclusion CSc 630: Microsoft .NET
VB C++ C# JScript … Visual Studio.NET Common Language Specification ASP.NET: Web Services and Web Forms WindowsForms ADO.NET: Data and XML Base Class Library Common Language Runtime The .NET Framework CSc 630: Microsoft .NET
Terminology "ABC" • CLR: Common Language Runtime • One runtime for many programming languages • Assembly • Container for code, metadata and resources—your new term for what you used to call “D-L-L“ • Intermediate Language(IL) • One intermediate, high-level assembly-style language that is emitted by language compilers • Metadata • Information that describes the shape of data and the runtime behavior of a program CSc 630: Microsoft .NET
Source code VB C# C++ Unmanaged Component Compiler Compiler Compiler Managed code Assembly IL Code Assembly IL Code Assembly IL Code Common Language Runtime JIT Compiler Native Code Operating System Services Execution Model: CLR CSc 630: Microsoft .NET
Common Language Runtime • Robust and secure execution environment • Type safe, garbage-collecting • Common for multiple languages • Deep-integration options • Simplifies deployment and management • No registry involved, zero-impact install • Side-by-site execution of multiple versions • Potentially Multi-Platform ? CSc 630: Microsoft .NET
Common Language Runtime • Execution environment for "managed code" • Managed? • Code resides on disk as IL • Must be translated into machine code • Code references other code • Other code residing in other assemblies must be found • Memory must be managed • .NET employs a garbage collector to do that job • Execution must be as secure as possible • Safeguard code against viruses and worms CSc 630: Microsoft .NET
Assembly Language Compiler Native Code JIT Compiler Execution CLR Execution Model: Conceptual Compilation Code (IL) Source Code Metadata Before installation or the first time each method is called CSc 630: Microsoft .NET
Assembly • Assemblies • contains the code that CLR executes • functional building blocks • self-aware • retrieve any dependant assemblies • does not execute without Assembly Manifest CSc 630: Microsoft .NET
Assembly • Assemblies are loadable entities containing • Assembly metadata • Type metadata • MSIL code • Resources • Assemblies contain: • Modules • Consists of one or multiple physical files • Bundled by a "packing list": The Manifest CSc 630: Microsoft .NET
Manifest: Standard Elements • Manifest is a table with information records • Manifest contains information about: • Assembly name • Version information • Processor and OS • Files that make up this assembly • References to types and resources CSc 630: Microsoft .NET
Modules • Module is a compiled unit • Modules contain metadata and IL • Metadata describes structure • IL describes runtime behavior • Modules cannot be loaded independently • Must be contained in assembly CSc 630: Microsoft .NET
Intermediate Language (IL) • .NET languages are compiled to an Intermediate Language (IL). • CLR accepts the IL code and recompiles it to machine code. • The recompilation is just-in-time (JIT) meaning it is done as soon as a function or subroutine is called. • The JIT code stays in memory for subsequent calls. • In cases where there is not enough memory it is discarded. CSc 630: Microsoft .NET
Outline Microsoft Vision • .NET Design Goals • .NET Framework • Visual Studio.NET • Web Services • .NET vs J2EE • Conclusion CSc 630: Microsoft .NET
.assembly hello {} .assembly extern mscorlib {} .method static public void main() il managed { .entrypoint .maxstack 1 ldstr "Hello World from IL!" call void [mscorlib]System.Console::WriteLine(class System.String) ret } MSIL: Hello World class HelloWorld {public static void Main() {System.Console.WriteLine("Hello World"); } } CSc 630: Microsoft .NET
Metadata • A type must be self descriptive: It must describe properties and methods that it exposes. • Examples: • The type Integer describes what values it takes and what operations it accepts. • The type Check describes what values (e.g., AccountNo and Amount) it takes and what operations (e.g., Cash, Deposit) it accepts. CSc 630: Microsoft .NET
.NET JVM: CLR • JIT (Just-In-Time) • compiles methods • caches the native code • Verify MSIL to be type safe • Managed code can contain platform specific calls and dependencies. CSc 630: Microsoft .NET
Common Type System CSc 630: Microsoft .NET
.NET Class Library • In traditional environments different categories of services are provided to the programmer via libraries such as: C run time library, Win32 APIs, I/O and database access libraries, etc. • These libraries are language dependent, operating system dependent, and often contain simple subroutine calls as opposed to self describing types. • In .NET all services fall into a single, hierarchy organized, language independent class library CSc 630: Microsoft .NET
Generation 1 Generation 0 The Collector In Action • New heap begins with new generation • Accessible references keep objects alive • Preserves / Compacts referenced objects • Objects left merge with older generation • New allocations rebuild new generation CSc 630: Microsoft .NET .NET-25 CSc 630: Microsoft .NET
Garbage Collection • The CLR includes garbage collection. • Managed heap always points to the next available spot, so allocation speed is closer to stack allocation. • Memory is allocated successively, resulting in fewer page faults and improved cache use. • System.GC gives access to the GC: GC::Collect(int generation) etc. CSc 630: Microsoft .NET
Outline Microsoft Vision • .NET Design Goals • .NET Framework • Visual Studio.NET • Web Services • .NET vs J2EE • Conclusion CSc 630: Microsoft .NET
Visual Studio .NET • Supports multi-language • Designs applications more quickly • Builds solutions with rule-enforcement templates • Tests applications for stability CSc 630: Microsoft .NET
VS.NET Core Languages • Visual Basic • Substantial language innovation • First class .NET language • Leverage existing skills • C# • More productive C/C++ language for .NET • Full RAD support • Visual C++ • Still most powerful and flexible language • Enables incremental migration to .NET CSc 630: Microsoft .NET
Perl Python COBOL Eiffel Haskell ML JScript Ada APL C Other Languages. . . • Pascal • C++ • Visual Basic • C# • SmallTalk • Oberon • Scheme • Mercury • Objective Caml • Oz CSc 630: Microsoft .NET
C# • Modern object oriented, type-safe, garbage collected • Familiar to C/C++ programmers. • Integrated COM, Platform API, and XML support • No class libraries, uses only common .NET libraries • Implementation of a new language with full support for the .NET framework. CSc 630: Microsoft .NET
C# C# Java Class structure Single inheritance Interfaces Garbage Collection Code safety Reflection JavaDoc Convenience & Additional Features Properties Indexes Attributes Delegates C++ Feature richness, Direct access to memory Legacy keywords CSc 630: Microsoft .NET
Public interface Icalc { int add(int x, int y); int subtract(int x, int y); } Public class Calculator : Icalc { int add(int x, int y) { return x + y; } int subtract(int x, int y) { return x-y; } } Interface and Class in C# CSc 630: Microsoft .NET
Public Interface Icalc Function Add(X As Integer, Y as Integer) Function Subtract(X As Integer, Y as Integer) EndInterface Public Class Calculator Implements ICalc Function Add(X as Integer, Y as Integer) Implements Icalc.Add Add = x + y End Function Function Subtract(X as Integer, Y as Integer) Implements Icalc.Subtract Subtract = x – y End Function End Class Interface and Class in VB.NET CSc 630: Microsoft .NET
C++ • Managed C++ can be used to write .NET Framework applications • It relies on extensions to the standard language • C++ will be important for non-Framework-based applications • The core semantics of C++ does not match with CLR CSc 630: Microsoft .NET
Cross-Language Interoperability ‘This is a VB.NET code Namespace MyCSClass Public Class CSClass Public Sub CSClass() 'code End Sub ‘returns the length of the passed string Public MyMethod(str As String) As Integer MyMethod = str.Length; End Sub ‘returns n squared Virtual Public MyVirtualMethod(n As Integer) As Integer MyVirtualMethod = n*n; End Sub End Class CSc 630: Microsoft .NET
#using "MyCSClass.dll" usingnamespace MyCSClass; CSClass *cs = new CSClass(); // will return 11 int result; result = cs->MyMethod("Hello World"); // will return 2 squared result = cs->MyVirtualMethod(2); Cross-Language Interoperability Can use components written in different languages How ? CSc 630: Microsoft .NET
Cross-Language Inheritance • Derive a new class in language C from MyClassclass NewClass : public MyCSClass::CSClass • Override virtual method. . . • virtual int MyVirtualMethod( int param ) • And access your new class normally. . . • NewClass *newCls = new NewClass();result = newCls->MyVirtualMethod(param); • All this without the source code to the previous • component or knowledge of it s language. class CPPClass : public MyCSClass::CSClass { public: // returns the cube of the given number virtualint MyVirtualMethod(int n) { return n*n*n; } }; CSc 630: Microsoft .NET
Cross-Language Features Support across components and languages: • Inheritance • Exception handling • Debugging • Good for extending 3rd party components in the language of your choice. CSc 630: Microsoft .NET
Visual Basic Form as a Class • All .NET languages use the same tools (WinForms) to create the user interface of an application as a form • A form a class containing other classes (called controls) such as TextBox, ListBox or Button • The act of drawing a form (such as Form1) generates the VB.NET code that defines the corresponding class named Form1 • As a class, Form1 has methods, properties, and events. • Form1.Show is a method that displays the Form1 on the screen. • Form1.EmpName.Text references the contents of the TextBox EmpName in Form1. • EmpName_Change is the name of the event handler that is invoked when the user changes contents of EmpName TextBox. CSc 630: Microsoft .NET
Server-Side Controls • ASP and JSP provide a language to generate HTML markups. In ASP.NET the complexity of this language is significantly reduced by using server-side controls. • For each HTML control there exists a server-side control in ASP.NET. CSc 630: Microsoft .NET
<script runat="server" language="vb"> Public Sub doClick(sender as object, e as EventArgs) TheLabel.Text = "Hello, world! (from ASP.NET in VB NET,code inline)" End Sub </script> <html> <head><title>In-line ASPX file in VB .NET </title></head> <body> VB .NET ASP.NET application with inline code<P><P> <form runat="server"> <asp:button runat="server" text="Say Hello" onclick="doClick" /> <p> <asp:label runat="server" text="" id="TheLabel" /> </form> </body> </html> VB.NET ASP.NET APPLICATION CSc 630: Microsoft .NET
<script runat="server" language="C#"> void doClick(object sender, EventArgs e) { TheLabel.Text = "Hello, world! (from ASP.NET in C#, code inline)"; } </script> <html> <head><title>In-line ASPX file in C#</title></head> <body> C# ASP.NET application with inline code<P><P> <form runat="server"> <asp:button runat="server" text="Say Hello" onclick="doClick" /> <p> <asp:label runat="server" text="" id="TheLabel" /> </form> </body> </html> C# ASP.NET APPLICATION CSc 630: Microsoft .NET
Why another Data Access API? • Most new applications are • Loosely coupled - even disconnected • More and more use XML to encode data • This is very different from the classical connected, tightly coupled client/server model CSc 630: Microsoft .NET
Mapping ADO.NET & XML Integration Visual Studio.NETDesigners & Controls XSLT, XpathValidation XMLDataDocument DataSet ManagedProvider XMLReader XMLTextReader XMLNodeReader XMLDocument XML Stream SQL Server CSc 630: Microsoft .NET
.NET and DOM XmlDocument doc = newXmlDocument(); doc.Load( "test.xml" ); XmlNode root = doc.DocumentElement; foreach( XmlNode personElement in root.ChildNodes ) Console.WriteLine( personElement.FirstChild.Value.ToString() ); Fred Bill <PEOPLE> <PERSON>Fred</PERSON> <PERSON>Bill</PERSON> </PEOPLE> CSc 630: Microsoft .NET
.NET and XPath // This is C# code XPathDocument xpdoc = new XPathDocument("test.xml"); XPathNavigator nav = xpdoc.CreateNavigator(); XPathExpression expr = nav.Compile("descendant::PEOPLE/PERSON"); XPathNodeIterator iterator = nav.Select(expr); while (iterator.MoveNext()) Console.WriteLine(iterator.Current); CSc 630: Microsoft .NET
Outline Microsoft Vision • .NET Design Goals • .NET Framework • Visual Studio.NET • Web Services • .NET vs J2EE • Conclusion CSc 630: Microsoft .NET
Users store, access and share based information anytime, any place, from any device XML Web Service Message Developers create and deliver compelling solutions to huge customer base Operators run efficient, secure, and reliable data centers for their user base What is .NET Web Services ? Internet CSc 630: Microsoft .NET
.NET Web Services <%@ WebService Language="C#" Class="Hello" %> /* Hello.asmx */ using System.Web.Services; public class Hello: WebService { [ WebMethod ] public string IssueGreeting() { return "Hello, World!"; } } CSc 630: Microsoft .NET