You are on page 1of 26

Introduction to .

NET Framework

Gholamali Semsarzadeh
July 2001

July 22, 2001

Introduction to .NET

What Is .NET
.Net is a new framework for developing windows-based
and web-based applications within the Microsoft
environment.
The framework offers a new set of software
development tools that are superior to the old tools.
The framework offers a fundamental shift in Microsoft
strategy: it moves application development from clientcentric to server-centric.

July 22, 2001

Introduction to .NET

Agenda

Common language runtime (CLR)


.NET class library
Cross language application development
Tools for developing Windows applications
Tools for developing Web applications

July 22, 2001

Introduction to .NET

Common Language Runtime (CLR)


CLR works like a virtual machine in executing all languages.
Currently it supports two:
C# is the new version of C++ containing all features of
Java.
VB.NET is the new version of VB containing full object
orientation and equal in power to C#.
All .NET languages must obey the rules and standards
imposed by CLR. Examples:
Object declaration, creation and use
Data types,language libraries
Error and exception handling
Interactive Development Environment (IDE)
July 22, 2001

Introduction to .NET

Intermediate Language (IL)


.NET languages are not compiled to machine code.
They 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
thus making JIT process interpretive.

July 22, 2001

Introduction to .NET

Common Data Types


CLR provides a set of primitive types that all languages
must support. The data types include:
Integerthree types 16/32/64 bits
Floattwo types: 32/64 bits
Boolean and Character
Date/time and Time span
The primitive types can be collected into
Arrays
Structures
Combination of the two
July 22, 2001

Introduction to .NET

Common Type System


IL is completely object-oriented. It requires everything
to be the type of a class, structure or interface.
Examples of types:
Integer
String
Rectangle
Customer
Contract
Chart
Recordset
Check
Financial Institution
July 22, 2001

Introduction to .NET

Examples of Types

Type
Declaration

Usage
(Properties)

Usage
(Methods)

Dim i As Integer

i=100

i+1

Dim r As Rectangle

r.Width*r.Height

r.Area

Dim c As Chart

c.BackColor=red

c.AddSeries (points)

Dim r As RecordSet r.Rate*r.Hours

R=SqlText

Dim c As Check

c.Cash

July 22, 2001

c.Amount=100

Introduction to .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.

The Metadata is an integral part of an executable such as


CHART.DLL. The DLL describes two things about the Chart
type: what it does and how it does it.
July 22, 2001

Introduction to .NET

Assembly
To allow others to use a type, the developer must
package it in an assembly.
A component (delivered in an assembly) is the building
block for software construction.
Structurally an assembly consists of a manifest and one
or more modules. Each module consists of metadata
(in IDL) and one or more types (in IL).

July 22, 2001

Introduction to .NET

10

Manifest
The manifest identifies an assembly and declares its
contents.
It describes:
Identity of an assembly
Its security requirements
The identity of other assemblies it depends on
The types exposed by the assembly

July 22, 2001

Introduction to .NET

11

.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, statistical 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.
July 22, 2001

Introduction to .NET

12

.NET Class Library 2


The organization of the Class Library is similar to the file
system:
Each folder is a NameSpace
Each file is an assembly exposing one or more types
The root of the Class Library is the System
NameSpace
The Class Library contains 25 second level
NameSpaces such as Data, I/O, WinForms,
Security, etc. that contain thousands of types
exposing all services of the operating system.
All components developed by the users or vendors
must be added to the Class Library before they can
be used.
July 22, 2001

Introduction to .NET

13

VB.NET
The .NET version of Visual Basic is as powerful as C#
and is incompatible with its previous version VB 6.0.
It contains the following new features all of which are
enforced by CLR and are common with C#:
Common IDE (Interactive Development Environment)
Common type system
Common object orientation capabilities
Common language library
Common error and exception handling
Common form drawing tools
Common Web page design tools
July 22, 2001

Introduction to .NET

14

The OBJECT Class


OBJECT is the type from which all other types are derived.

The properties and methods that are shared by all objects


are constructed in the OBJECT class. They include:
Equals
GetType
Clone (duplicate)
GetHashCode
ToString
The OBJECT type in VB.NET replaces the VARIANT type
in previous versions of VB.
July 22, 2001

Introduction to .NET

15

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. Examples:
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.
July 22, 2001

Introduction to .NET

16

Inheritance Hierarchy of a Form


The following hierarchy shows how the Visual Basic
Form Class is derived from the Object class.
Object: The base class for everything
RefObject: Objects called by reference
Component: RefObjects that can be reused
Control: components with visual interface
RichControl: controls with advanced visual
presentation such as color, font, docking capability
ScrollableControl: controls that can be scrolled
ContainerControl: Controls that can hold other
controls and change focus among them
Form: Base Form class from which application
specific forms are derived
July 22, 2001

Introduction to .NET

17

Inheriting From User Forms


The class Form is located in the NameSpace
System.WinForms.
The act of drawing a form (Form1) in the IDE generates
VB code containing the following declarations
Imports System.WinForms
Public Class Form1 Inherits Form

The user then adds additional controls and code to


Form1. Form1 can now be used as the base class for
Form2 using the following declaration:
Imports System.WinForms
Public Class Form2 Inherits Form1
July 22, 2001

Introduction to .NET

18

Visual Basic and WebForms


In a manner similar to drawing a WinForm, the VB
programmer can now draw a WebForm (I.e., a Web
Page)and attach event handlers to it.
WinForm controls such as Text, Image, and Anchor are
similar to WinForm controls.
A Web page, just like a form, is a class with its own
methods, properties and events. It can be inherited by
other Web pages.
VB can thus be used to develop Web-based applications.
July 22, 2001

Introduction to .NET

19

Visual Basic and Web Services


A Web Service a class (running on a Web Server) whose one or
more methods are designated as WebMethods.
A WebMethod can be called from any client across the Internet.
The protocol for exchange of information is called SOAP (Simple
Object Activation Protocol). It wraps the calling sequence in XML,
invokes the remotely located method, and returns the computed
results in XML.
DCOM distributes logic over tightly connected nodes on a LAN.
SOAP distributes logic over nodes that are loosely connected
across the Internet.
July 22, 2001

Introduction to .NET

20

Web Applications in .NET


The central question in creation of Web pages is weather an HTML
markup is instruction or data:
<html><body>
<p>This is some text.</p>
</body></html>
The perspective varies depending on whether or not we are using
HTML or DHTML to respond to user inputs
ASP (or JSP) to generate HTML markups
No matter how the Web page is generated the code behind it is very
ad-hoc and non-structured. In the .NET platform, ASP.NET attempts
to solve some of these problems.
July 22, 2001

Introduction to .NET

21

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 (such as a list box or an input text box)
there exists a server-side control in ASP.NET. When a Browser
requests a specific ASP.NET page in its URL the following events
happen:
The ASP.NET program is executed
Each server-side control in that program generates a
corresponding HTML control
As the final result, the ASP.NET program generates an HTML
page that is targeted to the version of the Browser that
requested the page.
July 22, 2001

Introduction to .NET

22

Example:Server-Side Controls
ASP.NET code for displaying a listbox:
<ASP:ListBox ID=List1 RUNAT=Server>
<ASP:ListItem>Jan</ASP:ListItem>
<ASP:ListItem>Feb</ASP:ListItem>
<ASP:ListItem>Mar</ASP:ListItem>
</ASP:ListBox>
Corresponding HTML code:
<SELECT Size=3>
<Option>Jan</Option>
<Option>Feb</Option>
<Option>Mar</Option>
</SELECT>
July 22, 2001

Introduction to .NET

23

Server-Side Processing
A server-side control can detect a user event (e.g., a
mouse click) and execute a server-side script that
contains the code (the event handler) to handle that
event.
The event is generated on the client-side but
handled on the server-side.
The event handler typically changes the properties
and calls the methods of various controls on the
ASP.NET page.
At the termination of the event handler a new HTML
page is posted back to the Browser.

July 22, 2001

Introduction to .NET

24

Example: Server-Side Processing


<%@ import Namespace=system.data %>
<%@ import Namespace=system.data.SQL %>
<html>
<head><Script LANGUAGE=VB, RUNAT=Server >
Sub Page-load( )
Dim SqlCmd As NEW SQLDataSetCOmmand (
Server=localhost;database=Books,
select * from Authors )
Dim ds As New DataSet
SqlCmd.FillDataSet(ds, Authors)
Grid1.DataSource=ds.Tables(Authors).DefaultView
Grid1.DataBind
End Sub
</Script>
</head>
<body>
<ASP:DataGrid ID=Grid1 RUNAT=Server />
</body></html>
July 22, 2001

Introduction to .NET

25

ASP.NET Benefits
ASP.NET Uses .NET languages to generate HTML pages. HTML
page is targeted to the capabilities of the requesting Browser
ASP.NET Program is compiled into a .NET class and cached the
first time it is called. All subsequent calls use the cached version.

ASP.NET programs are developed using the same IDE tools as


VB Programs. There are however two important differences:
The code behind the controls is executed on the server
The Web application does not need the CLR or the .NET
Class Library to executeany Browser will do.

July 22, 2001

Introduction to .NET

26

You might also like