Top Banner
UNIT 1 Introduction to ASP.Net By: Hitesh Santani
41

Introduction to .Net

Apr 15, 2017

Download

Software

Hitesh Santani
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to .Net

UNIT 1 Introduction to ASP.Net

By: Hitesh Santani

Page 2: Introduction to .Net

What is Web?

By: Hitesh Santani

• Web is a large and public network with which we can access the information from anywhere in the world.

• Generally, people call it The Internet.• The information which is available on web, is

in many forms like text, images, audio and video.

• This information is embedded into web pages through which we can access them.

Page 3: Introduction to .Net

What is a Website?

By: Hitesh Santani

A website is a collection of web pages. These web pages are made up of HTML, CSS,

Javascript, jQuery and a server side programming language like ASP.Net, PHP, JSP, Java Servlets etc.

A website can only be used using a web browser.

Example: www.gmail.co.in

Page 4: Introduction to .Net

How Internet works?

By: Hitesh Santani

Client

Request

HTTP REQU

EST

INTERNET

HTTP Request REQUEST

RESPONSEHTTP Response

HTTP Response

Response

Server Database

Page 5: Introduction to .Net

How Internet works?

By: Hitesh Santani

• A client is a user who wishes to use the website for the info.• A server is a machine where the actual website is stored.

This server is connected with the internet.• The clients use a browser or any other HTTP supported

software to communicate with the server through internet.• HTTP (Hyper Text Transfer Protocol) is a protocol which

governs the rules related to Hyper Text Transmission in between two machines on a network.

• Whenever, we type in a URL into the address bar of a browser, an HTTP Request is generated and is sent to the server.

• The server then processes this request and replays with an HTTP Response which contains the HTML output.

Page 6: Introduction to .Net

What is .Net?

By: Hitesh Santani

First of all, .Net is not a language but it is a framework.

It is a software platform with which you can create windows and web applications.

It provides you all the required features which can make your work of developing applications easy.

Page 7: Introduction to .Net

Architecture of .Net

By: Hitesh Santani

VB C#

Common Language Specification (CLS)

ASP .NetWeb

ServicesWeb

Forms

WindowsForms

ADO .Net and XML

Base Class Library (BCL) or Framework Class Library (FCL)

Common Language Runtime

Operating System

C++ J# ……Language Compilers

.Net Framework

Page 8: Introduction to .Net

Language Compilers

By: Hitesh Santani

There are compilers available separately for each and every language individually.

The task being assigned to the compilers for the .Net framework, is to convert the source code of the programs into MSIL Code.

Page 9: Introduction to .Net

Compilation Process in .Net

By: Hitesh Santani

.vb .cs ……

VBCompiler

C#Compiler ……

Common Language Runtime (CLR)

Operating System

Sour

ce

Code

Sour

ce

Code

Sour

ce

Code

Nati

ve

Code

MSIL Code

Page 10: Introduction to .Net

MSIL Code

By: Hitesh Santani

• MSIL Code stands for Microsoft Intermediate Language Code which is also called IL Code.

• This MSIL Code can not be executed by the hardware.

• MSIL Code solves a major problem i.e. creating a separate compiler for each of the languages to convert the source code to a particular device type.

• That’s why it is given to the CLR to generate Native Code (Machine Code) from it.

• This Native Code can be executed by the hardware.

Page 11: Introduction to .Net

Common Language Specification (CLS)

By: Hitesh Santani

Common Language Specification (CLS) is a set of rules.

These rules must be followed by any language which wants to be .Net compliant and wants to run it’s programs in CLR.

CLS is a subset of Common Type System (CTS).

Page 12: Introduction to .Net

Common Type System (CTS)

By: Hitesh Santani

• Common Type System (CTS) allows program written in different programming languages to share information easily.

• This means that we can use a class which is written in C# in VB.Net.

• Languages must agree on these concepts before they can integrate with one another.

• CTS defines the rules which must be followed by the languages to ensure smooth data sharing between them.

• Thus, CTS provides Cross Language Integration or Language Interoperability.

• CTS supports two categories of types: Value types and Reference types.

Page 13: Introduction to .Net

By: Hitesh Santani

Value types: Which stores the data directly in stack. In built data types come under this category.

Reference types: Which stores the reference or address instead of

storing the data directly. This type of data is stored in heap instead of

stack. Objects are example of this category.

Page 14: Introduction to .Net

Framework Class Library (FCL)

By: Hitesh Santani

• Framework Class Library (FCL) which is also known as Base Class Library (BCL), is a set of readily available classes.

• It is the in built set of classes which we can directly use on the fly after importing them into the programs.

• These are like the header files which we used to have in C or C++.

• This class library consists of thousands of classes which are categorized into namespaces so that we can remember them easily.

Page 15: Introduction to .Net

Namespaces

By: Hitesh Santani

• A namespace is a logical collection/grouping of classes.• It helps us out to categorize the library classes in

according to their purpose.• Because of the namespaces, we do not have to

remember names of each and every class.• We just need to remember the name of the namespace

to which the class belongs.• A namespace is just a logical container for the library

classes.• Namespaces can be used to differentiate two different

classes with the same name using a Fully Qualified Name. A Fully Qualified Name is a combination of the class name and the namespace’s name to which the class belongs.

• The topmost namespace in the .Net framework is System. The rest of the namespaces are a part of the System namespace.

Page 16: Introduction to .Net

Common Language Runtime (CLR)

By: Hitesh Santani

• CLR is one of the main components of .Net.• It’s the execution engine and environment of

the framework.• It stays in between the .Net framework and

the underlying Operating System.• It loads and executes the code.• It provides all the services which the program

may need at run-time.• Every language that wants it’s programs to

run in CLR, must obey the rules being imposed by CLR.

Page 17: Introduction to .Net

Compiled Code

By: Hitesh Santani

In order to serve the request given by the user, ASP.Net must first compile the code. We can write the ASP.Net code in any of the languages supported by .Net framework.

When we compile the code, it is translated into MSIL which is language-independent.

Then this MSIL is converted into machine-specific instructions.

Page 18: Introduction to .Net

Benefits of Compiled Code

By: Hitesh Santani

• Stability: When the code is compiled, it is checked for syntax error, type safety etc so that many errors can be eliminated from the later stage.

• Performance: The execution of the compiled code is faster then the scripts such as VBScript.

• Security: Compiled code is difficult to read. So no one can convert the compiled code back into the source code.

• Interoperability: We are able to use assemblies written in different languages as MSIL supports any .Net languages.

Page 19: Introduction to .Net

Inline Code (In-Page Code)

By: Hitesh Santani

Traditional developers were using this approach.

Client-side and Server-side code is intermixed into a single page.

Becomes very difficult to maintain the events and event handlers in a large single page.

Its written in the <script> tag.

Page 20: Introduction to .Net

Code Behind

By: Hitesh Santani

• Separate files are maintained for Client-side and Server-side code.

• One file contains HTML which is the .aspx file.• The other file contains the server-side code

which is called Code Behind file. It can be either .vb or .cs.

• Separates the design layout and the coding part.

• At the time of compilation, both files are combined and one class is generated which is used to serve the user requests.

Page 21: Introduction to .Net

Object Oriented Concepts

By: Hitesh Santani

Class Fields Properties Methods Events

Objects Constructors Destructors Encapsulation

Inheritance Abstraction

Abstract Class Interface Polymorphism Method Overriding Partial Classes

Page 22: Introduction to .Net

Class

By: Hitesh Santani

The class is a template through which we can create an object.

In .Net, it contains fields, properties, methods (procedures and functions) and events.

Syntax:[Access Modifier] [Shadows] [MustInherit|NotInheritable] Class

<name> [Implements <interfacename>]Statements

End Class

Page 23: Introduction to .Net

Fields

By: Hitesh Santani

They are the variables in the class. They can be read or set directly. They store the actual data which is being

given to an object. Example:

Public Class MyClassPublic x As Integer

End Class

Page 24: Introduction to .Net

Properties

By: Hitesh Santani

• Properties are retrieved and set like fields.• They are implemented using Property Get and Property

Set procedures which provide more control on how values are set or returned.

• Example:Public Class MyClass

Private Name As StringPublic Property FullName() As String

GetReturn Name

End GetSet(ByVal Value As String)

Name = ValueEnd Set

End PropertyEnd Class

Page 25: Introduction to .Net

Methods

By: Hitesh Santani

• Methods represent the object’s built-in procedures.• For example, a class named Employee may have

methods named CalculateSalary and CalculateLeaves.

• We can defined methods by adding procedures and functions to the class.

• Example:Public Class Employee

Public Sub CalculateSalary()Write(“-------”)End SubPublic Sub CalculateLeaves()Write(“-------”)End Sub

End Class

Page 26: Introduction to .Net

Objects

By: Hitesh Santani

They are the basic runtime entities. They are the variables of the class.

It is said to be the instance of the class. Example:

Dim obj as MyClass

Page 27: Introduction to .Net

Constructor

By: Hitesh Santani

They are the special procedures that are invoked automatically when an object of a class is created.

Example:Public Sub New(ByVal newValue as Integer)

value = newValueEnd Sub

Page 28: Introduction to .Net

Destructor

By: Hitesh Santani

• We know how to create constructor, but what about destructor?

• It is also executed automatically when an object is about to be destroyed.

• We can place code to clean up the reserved resources in a destructor.

• In VB.Net, we can use the Finalize method for this purpose. The Finalize method is called automatically when an object is marked as unusable and is to be destroyed.

• Example:Public Class MyClass

Protected Overrides Sub Finalize()StatementsEnd Sub

End Class

Page 29: Introduction to .Net

Encapsulation

By: Hitesh Santani

• The process of combining data members and methods in a single unit is called Encapsulation.

• When using Data Encapsulation, data is not accessed directly, it is only accessible through the functions available within the class.

• Data Encapsulation enables the important concept of Data Hiding.

• Protecting data from unauthorized access is called Data Hiding.

Page 30: Introduction to .Net

Inheritance

By: Hitesh Santani

• It is the process by which object of one class acquires the properties (members) of another class.

• It’s the process of forming a new class from an existing class.

• The existing class is called a parent/super/base class.

• The new class is called child/sub/derived class.• It is important because it supports hierarchical

classification and code reusability. • We can add new features to a class without even

touching it by deriving a new class.• To inherit the class, Inherits keyword is used with

the derived class.

Page 31: Introduction to .Net

By: Hitesh Santani

Example:Public Class Person

‘Members of Person classEnd ClassPublic Class Employee Inherits Person

‘Members of Employee classEnd Class

Page 32: Introduction to .Net

Abstraction

By: Hitesh Santani

It is a mechanism of representing essential features without including background details.

Data Abstraction increases the power of programming language by creating user defined data types.

When the classes use the concept of data abstraction, they are also known as Abstract Data Types (ADT).

Page 33: Introduction to .Net

Abstract Class

By: Hitesh Santani

MustInherit keyword is used to declare a class that cannot be instantiated and can be used only as a base class.

It is also called an Abstract Base Class (ABC).

Page 34: Introduction to .Net

Interface

By: Hitesh Santani

• Example:Public Interface person

Sub SetName(ByVal PersonName As String)Function GetName() As String

End InterfacePublic Class employee Implements person

Dim Name As StringSub SetName(ByVal PersonName As String) Implements person.SetName

Name = PersonNameEnd SubFunction GetName() As String Implements person.GetName

Return NameEnd Function

End Class

Page 35: Introduction to .Net

Polymorphism

By: Hitesh Santani

Poly means many and morphism means forms i.e. one name many forms.

The ability of functions and operators to act in different ways on different data types is called polymorphism.

To use one function name for many different purposes is known as function overloading.

Overloads keyword is used.

Page 36: Introduction to .Net

By: Hitesh Santani

• Example:Overloads Function Add(ByVal a1 As Integer,

ByVal a2 As Integer) As IntegerReturn a1+a2

End FunctionOverloads Function Add(ByVal a1 As Integer,

ByVal a2 As Integer, ByVal a3 As Integer) As IntegerReturn a1+a2+a3

End Function

Page 37: Introduction to .Net

Method Overriding

By: Hitesh Santani

The process in which a subclass provide a specific implementation of a method, that is already provided by one of its super classes is called Method Overriding.

The implementation in the subclass overrides (replaces) the implementation in the superclass.

Page 38: Introduction to .Net

By: Hitesh Santani

• Following keywords are for method overriding:– Overridable: Allows a property or method in a

class to be overridden.– Overrides: Overrides an Overridable property or

method.– NotOverridable: Prevents a property or method

from being overridden. Public methods are NotOverridable by default.

– MustOverride: Requires that a derived class override the property or method. MustOverride methods must be declared in MustInherit classes.

Page 39: Introduction to .Net

Event Driven Programming

By: Hitesh Santani

Page 40: Introduction to .Net

Event Driven Programming

By: Hitesh Santani

• Event: An event is a user action which he/she has performed for a purpose. Examples are clicking or double clicking a button, typing a character, hovering mouse pointer etc.

• Event Source: An event source is an element on the screen on which the user performs the action which triggers the event.

• Event Handler: An event handler is a set of statements which has been written to handle a specific event.

• Event Dispatcher: This is the module which handles all the triggered events and calls the appropriate event handler function.

Page 41: Introduction to .Net

Any Questions in this unit?

By: Hitesh Santani