Module 3: Using Microsoft .NET- Based Languages
description
Transcript of Module 3: Using Microsoft .NET- Based Languages
Module 3:Using Microsoft .NET-
Based Languages
Overview
Overview of the .NET-Based Languages Comparison of the .NET-Based
Languages
Lesson: Overview of the .NET-Based Languages
Multiple Language Support The Common Language Runtime The Common Language Runtime
Components Runtime Compilation and Execution
Multiple Language Support The .NET Framework is designed to support
many languages• More than 20 languages currently supported
• Microsoft provides Visual Basic .NET, C#, Visual J# .NET, and JScript .NET
Benefits of multiple-language support• Code modules are reusable• API access is the same for all languages• The right language is used for the right task• Performance is roughly equal between all
languages
The Common Language Runtime
One runtime for all . NET-Based Languages Manages threads and memory
- Garbage collection Enforces code security
- No uninitialized variables
- Exception Handling Eliminates DLL versioning problems
- Multiple versions of a DLL can run simultaneously
- Applications can specify a version of a DLL to use
The Common Language Runtime Components
.NET Framework Class Library Support.NET Framework Class Library Support
Thread SupportThread Support COM MarshalerCOM Marshaler
Type CheckerType Checker Exception ManagerException Manager
MSIL to NativeMSIL to NativeCompilersCompilers
CodeCodeManagerManager
GarbageGarbageCollectorCollector
Security EngineSecurity Engine Debug EngineDebug Engine
Class LoaderClass Loader
Runtime, Compilation and Execution
Nativecode
C# code Visual Basic .NET code
Which language?
Visual Basic .NETcompiler
C#compiler
MSILJITcompiler
default.aspx
Runtime
HTM
L
Runtime, Compilation and Execution
Language Compilation- A web browser request a Web page from a Web server that is running IIS. - The requested Web page, default.aspx, is compiled with the appropriate language compiler, depending on the language that is used to write the page. - The application is compiled to MSIL
Runtime, Compilation and Execution
JIT Compilation
- The MSIL is handled by the runtime.
- The runtime uses a JIT compiler to compile the MSIL to native code.
- After the application is JIT compiled, it is cached so that it does not need to be recompiled for each request.
Runtime, Compilation and Execution
Application Execution
- After the application is compiled , the runtime executes the application on the Web server and then generates the HTML and script that is returned to the client.
Lesson: Comparison of the .NET-Based Languages
Visual Basic .NET C# Choosing a Language
Visual Basic .NET
Visual Basic .NET is the latest version of Visual Basic True object-oriented language
Visual Basic Scripting Edition (and JScript) are still used for client-side script
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer = 0Dim x As Double = TextBox1.TextFor i = 0 To 4 x *= 2 Label1.Text = Label1.Text & x & ","Next
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer = 0Dim x As Double = TextBox1.TextFor i = 0 To 4 x *= 2 Label1.Text = Label1.Text & x & ","Next
End Sub
C#
C# is a new language Similar to Java, Visual C++, and
Pascal
protected void Button1_Click(object sender, EventArgs e){ int i = 0; double x = Convert.ToDouble(TextBox1.Text); for (i=0; i<=4; i++) { x *= 2; Label1.Text = Label1.Text + x + ","; }}
protected void Button1_Click(object sender, EventArgs e){ int i = 0; double x = Convert.ToDouble(TextBox1.Text); for (i=0; i<=4; i++) { x *= 2; Label1.Text = Label1.Text + x + ","; }}
Choosing a Language .NET Framework class library is the same regardless of
language Performance
• All languages are compiled to MSIL
• Only performance difference is how each language compiler compiles to MSIL
• The runtime compiles all MSIL the same, regardless of its origin
Development experience• C# is similar to Java, C, Visual C++, and Pascal• Visual Basic .NET is similar to Visual Basic
Browser compatibility
• ASP.NET code is server-side code, so browser compatibility is not an issue
Review
Overview of the .NET-Based Languages Comparison of the .NET-Based
Languages
Exercise
What role does the CLR play in running ASP.NET page?
What is the role of JIT compilation? List FOUR languages that are currently
supported by .NET. What is garbage collection and why is it
so useful in the .NET Framework?
~ End of Module 3 ~