Introduction Dot Net333
Introduction Dot Net333
NET
What is .NET?
• Introduced in 2002, Microsoft’s architecture
for applications in the Internet age
– Increased robustness over classic Windows apps
– New programming platform
– Built for the web
• .NET is a platform that runs on the operating
system
• Split with Windows RT (will discuss later)
1
.NET
• Sits on top on the OS (currently all the Windows;
Linux/Unix subset also available – Mono Project)
• Provides language interoperability across
platforms
• Strong emphasis on Web connectivity, using XML
web services to connect and share data between
smart client devices, servers, and developers/users
– Later versions (current 4.5) added WPF, LINQ, Parallel
extensions, Metro support
• Platform/language independent
History
• Development began in 1998
• Beta 1 released Oct, 2000
• Beta 2 released July, 2001
• Finalized in Dec, shipping in Feb 2002
• Vista shipped with .NET Framework 3.0
(Runtime)
2
.NET Overview
• Three main elements:
– The Framework (CLR, FCL, ASP, WinForms)
– The Products (Windows, Visual Studio, Office)
– The Services (My Services)
• Framework Goals
– Improved reliability and integrated security.
– Simplified development and deployment.
– Unified API, multi-language support.
• XML is the .NET “Meta-Language”.
• All MS server products now .NET-enabled.
.NET Framework
C# VB.NET C++.NET Other
Operating System
3
.NET 4.5 on Windows 8
http://dougseven.com/2011/09/15/a-bad-picture-is-worth-a-thousand-long-discussions/
4
.NET Framework Class Library
• Framework – you can call it and it can call
you
• Large class library
– Over 9000 classes in .NET 4
– Major components
• Base Class: Networking, security, I/O, files, etc.
• Data and XML Classes
• Web Services/UI
• Windows UI
Framework Libraries
• Web Services
– Expose application functionalities across the Internet, in the same
way as a class expose services to other classes.
– Each Web service can function as an independent entity, and can
cooperate with one another.
– Data described by XML.
• ASP.NET
– Replacement for the Active Server Technology.
– Web Forms provide an easy way to write interactive Web
applications, much in the same way as “normal” Windows
applications.
5
Framework Libraries
• Provides facilities to generate Windows
GUI-based client applications easily
• Form-oriented
• Standard GUI components
– buttons, textboxes, menus, scrollbars, etc.
• Event-handling
6
Some .NET Languages
• C# Perl
Smalltalk
• COBOL VB.NET
• Eiffel VC++
• Fortran F#
Scheme
• Mercury
….
• Pascal
• Python
More are under
• Ruby development
• SML
VB.NET and C#
• VB.NET introduces long sought-after features:
– Inheritance
– Parameterized Class Constructors
– Function Overloading
– Multi-Threading
– Structured Error Handling
– Creating NT Services
• VB.NET not backward compatible with VB6.
• C#
– Flagship, modern, object-oriented language
– Similar to C++/Java
– Considered the most powerful language of .NET
7
.NET vs. J2EE
• Both are similar in many ways:
– Server- and client-side model for building enterprise applications.
– Virtual machine designed to inspect, load, and execute programs in
a controlled environment.
– APIs for creating both fat- and thin-client models.
– APIs for foundation services (data access, directory, remote object
calls, sockets, forms).
– Development environment for dynamic web pages.
• J2 Enterprise Edition
– Language-Dependent & Platform-Independent
• .NET
– Language-Independent & Platform Dependent (for the most part)
J2EE: Language-Specific,
Platform- Independent
Person.java Linux
Java VM
Person
Java VM
bytecodes
Deploy Windows
Java VM
Company
Address bytecodes
bytecodes
Android
Address.java
Java VM
Company.java
8
.NET: Language-Independent,
(Mostly) Platform- Specific
Person.vb (Visual Basic) Windows
CLR
Person
CLR
MSIL
Deploy Windows
CLR
Company
Address MSIL
MSIL
Others?
Address.cs (C#)
CLR
Company.cbl
(Cobol)
J2EE
• The core (JVM and standard class libraries) are
mature.
• 3-4 million Java programmers.
• J2EE implementations are not entirely cross-
platform.
• Java’s true potential is realized only when all (or
most) development is done in Java.
• Changing the Java language specification has an
enormous impact on the entire platform.
9
.NET
• .NET built into Windows; running an executable
invokes the CLR automatically instead of
explicitly invoking the JVM
• .NET added improvements such as native XML
support, new features to CLR; spurred Java 8
• About 3 million C++ developers, 3-8 million VB
developers, around 1 million C# developers
• Today, most development and deployment is
Windows
10
PL Job Trends - % Postings
11
Do you have to use Windows?
• Open source implementations of .NET
• Today there exists Xamarin’s Mono, Corel's Rotor and the
Free Software Foundation's Portable .NET projects
• Rotor: the Shared Source Common Language
Infrastructure (SSCLI)
– Started as “Project 7” with Academic Microsoft Research
– With universities and programming language researchers,
developed several languages for the CLR
• Mono
– Implementation of ECMA C# and CLI for Linux
– http://www.mono-project.com
Mono
• http://www.mono-project.com/Main_Page
• Mono provides the necessary software to develop
and run .NET client and server applications on
Linux, Solaris, Mac OS X, Windows, and Unix.
• Sponsored by Xamarin
• Mono allows your existing binaries to run on
Linux with copy-deployment.
• Mono API coverage is limited to portions of .NET
4 and parts of .NET 4.5
12
Mono
• Core: mscorlib, System, System.Security and System.XML
assemblies.
– ADO.NET: System.Data and various other database providers.
– ASP.NET: WebForms and Web Services are supported. Work on
WSE1/WSE2 has also started.
– Compilers: C#, VB.NET and various command line tools that are part of
the SDK.
– Open Source, Unix and Gnome specific libraries.
• Other components like Windows.Forms, Directory.Services,
Enterprise Services and JScript are partially covered
• Some other smaller and less used components do not have yet a
Mono equivalent
13
Simple Application Deployment
• Unlike COM, no “plumbing” code needed to
connect separate components
– Components can be developed in different
programming languages
• Thousands of classes to reuse
• Automatic garbage collection
• Memory is managed
– Common bugs like memory leaks, buffer overruns are
not possible (if using 100% managed code)
Multiple Languages
• Common Type System makes interoperability
seamless between languages
• Class in one language can inherit from a class in
another language
• Exceptions can be thrown across languages
• Makes it easier to learn a new .NET language
since the same tools and classes are in place
• Can debug across languages
14
The Common Type System
• At the core of the Framework is a universal type system called the
.NET Common Type System (CTS).
• Everything is an object - but efficient
– Boxing and Unboxing
• All types fall into two categories - Value types and Reference types.
– Value types contain actual data (cannot be null). Stored on the stack.
Always initialized.
– Three kinds of value types: Primitives, structures, and enumerations.
• Language compilers map keywords to the primitive types. For
example, a C# “int” is mapped to System.Int32.
15
The Common Type System
Object
Int64 Char
Single Currency
Double DateTime
Decimal TimeSpan
Primitive Types
16
MSIL and JIT Compilation
• Metadata in the load file along with the MSIL enables code
to be self-describing - no need for separate type libraries,
IDL, or registry entries.
• When code is executed by the CLR, a JIT compilation step
occurs.
– Code is compiled method-by-method to native machine code as
methods are invoked
– Results in performance slowdown when a program is first
executed, but can be efficient for code that is never executed
– Subsequent invocations reuse compiled code, so no slowdown
Delegates
• A new concept that is central to the programming model of
the CLR.
• Delegates are like function pointers, but are actually type-
safe, secure, managed CLR objects.
• The CLR guarantees that a delegate points to a valid
method.
• You get the benefits of function pointers without the
dangers.
• Each delegate is based on a single method signature.
• Commonly used for callbacks.
• Delegates are basis of event handlers.
17
Packaging: Modules, Types,
Assemblies, and the Manifest
• A “module” refers to a managed binary, such as an EXE or
DLL.
• Modules contain definitions of managed types, such as
classes, interfaces, structures, and enumerations.
• An assembly can be defined as one or more modules that
make up a unit of functionality. Assemblies also can
“contain” other files that make up an application, such as
bitmaps and resource files.
• An assembly is the the fundamental unit of deployment,
version control, activation scoping, and security
permissions.
18
Packaging: Modules, Types,
Assemblies, and the Manifest
• An assembly contains a “manifest”, which is a catalog of component
metadata containing:
– Assembly name.
– Version (major, minor, revision, build).
– Assembly file list - all files “contained” in the assembly.
– Type references - mapping the managed types included in the assembly
with the files that contain them.
– Scope - private or shared.
– Referenced assemblies.
• In many cases, an assembly consists of a single EXE or DLL -
containing the module’s MSIL, the component metadata, and the
assembly manifest. In other cases, the assembly may consist of many
DLLs, with the manifest in its own file.
• No MSIL code can ever be executed unless there is a manifest
associated with it.
19
Differences from JVM (prior to 1.5)
• Branches
– Limited to 64K in JVM
• Structures and Unions
– No support for these in JVM
– Union supports Variant Records
• When a field in the structure is selected from
multiple possible types e.g., Struct.X could be an
int or a boolean
• Automatic Boxing and Unboxing
20
ILDASM
• Can examine assemblies, assembly code
with the ILDASM tool
• Here is ILDASM run on
VideoUnScramble.exe
Assembly Manifest
21
Assembly Components
IL_008d: ldc.i4.0
IL_008e: stloc.1
IL_008f: br.s IL_00aa
22
Summary
• Next we will study C#
• C# does not exist in isolation but has a close
connection with the .NET framework
• .NET
– CLR is a Java-like platform, but multi-language
– SrcMSILJITNative Code
– .NET framework includes many class libraries
23