net overview. 2 objectives introduce.net –overview –languages –libraries –development and...
Post on 20-Dec-2015
220 views
TRANSCRIPT
![Page 1: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/1.jpg)
.NET Overview
![Page 2: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/2.jpg)
2
Objectives
• Introduce .NET– overview– languages– libraries– development and execution model
• Examine simple C# program
![Page 3: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/3.jpg)
3
development platform servers services
.NET Overview
• .NET is a sweeping marketing term for a family of products– development tools and languages– platform– application management servers– value-added services
LanguagesCompilersVisual Studio .NET
Common Language RuntimeFramework Libraries
SQL ServerBizTalkSharePoint...
My ServicesAlertsPassport...
![Page 4: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/4.jpg)
4
Overview of .NET
• Consistent development modelThe .NET Framework proves an object-oriented and consistent development model for different types of applications, such as Windows Forms applications, Web applications, and Web services.
• Robust execution environmentThe .NET Framework provides an execution environment that maximizes security, robustness, and performance of applications while minimizing deployment and versioning conflicts.
• Support for standardsThe .NET Framework is built around industry standards such as Extensible Markup Language (XML), Simple Object Access Protocol (SOAP), Common Language Infrastructure (CLI), and C#.
![Page 5: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/5.jpg)
5
Evolution of the platform
• .NET is the next evolutionary step for the Microsoft platform– new languages largely replace classic C++ and Visual Basic– new runtime model reduces need for COM style integration– XML web services used in place of DCOM– Windows Forms replace MFC– ASP.NET improves on ASP– etc.
![Page 6: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/6.jpg)
6
Software development
• .NET software development and execution has many actors– languages– libraries– compilers– intermediate language– execution engine
![Page 7: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/7.jpg)
7
Languages
• Many .NET programming languages available– C#– VB.NET– C++– etc.
• Language choice typically based on many factors– programmer background– problem domain– language features– corporate mandate
![Page 8: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/8.jpg)
8
Language power
• All languages can access .NET infrastructure
C#
class Hello{ static void Main() { System.Console.WriteLine("hello"); }}
VB.NET
Class Goodbye
Shared Sub Main() System.Console.WriteLine("goodbye") End Sub
End Class
![Page 9: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/9.jpg)
9
Language interoperability
• All .NET languages can interoperate
C# callingVB.NET
class Hello{ static void Main() { System.Console.WriteLine(Greeting.Message()); }}
Class Greeting Shared Function Message() As String Return "hello" End FunctionEnd Class
![Page 10: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/10.jpg)
10
C#
VB.NET
Language variability
• Not all .NET languages have exactly the same capabilities– differ in small but important ways
class Hello{ static void Main() { int i; uint u; }}
Class Greeting Shared Sub Main() Dim i as Integer End SubEnd Class
signed integer
unsigned integer
signed integer only
![Page 11: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/11.jpg)
11
Common Language Specification
• Common Language Specification (CLS) defines type subset– required to be supported by all .NET languages– limiting code to CLS maximizes language interoperability– code limited to CLS called CLS compliant
public class Calculator{ public uint Add(uint a, uint b) { return a + b; }}
not CLS compliantto use uint in publicinterface of public class
![Page 12: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/12.jpg)
12
.NET is cross-platform
• .NET apps run on any supported platform
.EXE
?Win64 Win32
(XP,2K,98)WinCE
• Linux via Mono• FreeBSD via Rotor
.DLL.DLL
![Page 13: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/13.jpg)
13
How is this possible?
• .NET applications are not stand-alone apps– require presence of .NET Framework = CLR + FCL
other FCL components
CLR (MSCOREE.dll)
JIT Compiler
Process
Underlying OS and HW
Core FCL
(MSCOR
LIB.dll)
.DLL.DLL.EXE
obj code
• CLR = Common Language Runtime
• FCL = Framework Class Library
![Page 14: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/14.jpg)
14
.NET Framework class library
Library
• Extensive set of standard libraries available– for wide range of application types– called .NET Framework class library
Collections
Web development
Input/Output
Database access
Windows Forms GUI
Networking
XML processing
Threading
Reflection
Debugging
![Page 15: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/15.jpg)
15
Framework Class Library (FCL)
System
System.Data System.Xml
System.Web
SqlTypes
SqlClient
Common
OleDb
XPath
XSL
Globalization
Diagnostics
Configuration
Collections
Resources
Reflection
Net
IO
Threading
Text
ServiceProcess
Security RuntimeInteropServices
Remoting
Serialization
Serialization
Configuration SessionState
Caching Security
ServicesDescription
Discovery
Protocols
UIHtmlControls
WebControls
System.Drawing
Imaging
Drawing2D
Text
Printing
System.Windows.Forms
Design ComponentModel
Schema
![Page 16: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/16.jpg)
16
Writing Windows Programs
• Application Programming Interfaces (API)– Win16 - Windows 3.1 [Segmented Memory]– Win32 - Windows 95/98/NT/2000/XP [Flat Memory]
• Differences between 9X & NT families• Unsupported functions [Security, etc.]• Unicode vs ASCII
• All windows programs use the API, but not all equal– API is C-centric, some things are difficult in VB– Programs are monolithic, can't be part VB, part C
• MS .NET is "unified API" on top of Win32
![Page 17: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/17.jpg)
17
Compilation
• Compilers produce Intermediate Language (IL)– IL is not executable– similar to assembly language– processor independent
C# code VB.NET code <other> code
VB.NET compilerC# compiler <other> compiler
IL IL IL
![Page 18: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/18.jpg)
18
IL
• C# compiler translates C# source code into IL
C# source
IL.locals init ([0] class Calc c, [1] int32 sum)newobj instance void Calc::.ctor()stloc.0 // c = ptr to new objectldloc.0ldc.i4.2 // pass second argldc.i4.4 // pass first argcallvirt instance int32 Calc::Add(int32,int32)stloc.1 // sum = retval
Calc c = new Calc();int sum = c.Add(2, 4);
C# compiler
![Page 19: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/19.jpg)
19
CLR
Execution engine
• Common Language Runtime (CLR) is the execution engine– loads IL– compiles IL– executes resulting machine code
ILRuntimecompiler
Executemachine code
![Page 20: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/20.jpg)
20
Cache
JIT runtime compile
• IL is compiled into machine code at runtime by the CLR– compiles methods as needed– called just in time (JIT) compile
• JIT compilation model:– first time method is called the IL is compiled and optimized– compiled machine code is cached in transient memory– cached copy used for subsequent calls
IL code F() G() H()
JIT runtimecompiler
Execute
machine code for F()
![Page 21: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/21.jpg)
21
IL?
• IL is the assembly language of the .NET platform– IL = "Intermediate Language"– JIT compiler converts IL to asm lang of underlying HW
'** simply adds 2 integers together and returns the result…Public Function Add(ByVal x As Integer, ByVal y As Integer) As Integer Add = x + yEnd Function
![Page 22: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/22.jpg)
22
NGEN install time compile
• Can compile IL into machine code when app installed– use native image generator ngen.exe– can speed startup time since code pre-compiled– but cannot do as many optimizations– original IL must still be available for type information
CLR
IL ngen Executenativeimagecache
machine code
![Page 23: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/23.jpg)
23
Execution command
• CLR automatically invoked when .NET application executed
C:\> MyApphello
execute
![Page 24: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/24.jpg)
24
Implications of .NET architecture
1. Your clients will need .NET Framework– available via Redistributable .NET Framework (20MB)– 2 versions, v1.0 (2002) and v1.1 (2003)– runs on 98, NT (6a), 2000, XP, 2003
2. Design trade-off…+ managed execution (memory mgmt, security, …)+ portability– slower execution (10%?)
• JIT compiler has potential to close performance gap
![Page 25: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/25.jpg)
25
MyApp.cs
C# program
• C# program basics– source file has .cs extension– namespace used to group related types– class defines new type– Main is application entry point– WriteLine writes output– { and } delimit code block
namespace MyNamespace{ class MyApp { static void Main() { System.Console.WriteLine("hello"); } }}
![Page 26: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/26.jpg)
26
Building console executable
• Can use C# compiler to build console executable– use /t[arget]:exe– use /out:<name> to specify output file name
• Default values can simplify use– default target type is console executable– default name adds .exe to base name of file containing Main
C:\> csc /target:exe /out:MyApp.exe MyApp.csexplicitoptions
C:\> csc MyApp.csimplicitoptions
![Page 27: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/27.jpg)
27
Building Windows executable
• Can use C# compiler to build windows executable– use /t[arget]:winexe
C:\> csc /target:winexe MyWinApp.csbuild Windowsapplication
![Page 28: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/28.jpg)
28
Building library
• Can use C# compiler to build library– use /t[arget]:library
• Controlling output file name:– can use /out:<name> to specify output file name– default: adds .dll to base name of first input file
C:\> csc /target:library /out:MyLib.dll MyLib.cscreatelibrary
![Page 29: NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d445503460f94a216c8/html5/thumbnails/29.jpg)
29
Summary
• .NET requires multiple steps to develop and run software– code in one of the many .NET languages– compile into IL– install the CLR– execute
• CLR JIT compiles IL at runtime– always executes compiled code– never interpreted
• Can target CLS compliance– to maximize language interoperability