You are on page 1of 41

1

1-Understand the basics of .NET frame work


.NET
. > stands for extension.
NET > stands for Network Enabled Technologies.
.NET stands for extension to Network Enabled Technologies.
.NET is a platform or environment with collection of services towards
different types of application development & execution.
It supports CUI App, GUI App, Distributed App, Web Based App, Mobile
App etc.
.NET 1.0 beta version is released in the year 2000 but its actual release
is provided in the year 2001.
The current version is .NET 3.5 and recently .net 4.0 was also
introduced.

.NET 3.5 = .NET 3.0 + AJAX + LINQ + Language Enhancements


WPF > Windows Presentation Foundation
WCS > Windows Card Space
WCF > Windows Communication Foundation
WWF > Windows Workflow Foundation
AJAX > Asynchronous Javascript & XML
LINQ > Language Integrated Query

What is .NET Framework


The .NET Framework (pronounced dot net) is a software framework that runs primarily
on Microsoft Windows.
The Microsoft .Net Framework is a platform that provides tools and technologies you
need to build Networked Applications as well as Distributed Web Services and Web
Applications.
It includes a large library and supports several programming languages which allows
language interoperability (each language can use code written in other languages).
The .NET library is available to all the programming languages that .NET supports.

Programs written for the .NET Framework execute in a software environment (as
contrasted to hardware environment), known as the Common Language Runtime
(CLR), an application virtual machine that provides important services such as
security, memory management, and exception handling.
The class library and the CLR together constitute the .NET Framework.
The .NET Framework's Base Class Library provides user interface, data access,
database connectivity, cryptography, web application development, numeric
algorithms, and network communications.
Programmers produce software by combining their own source code with the .NET
Framework and other libraries.
The .NET Framework is intended to be used by most new applications created for the
Windows platform.
Microsoft also produces a popular integrated development environment largely
for .NET software called Visual Studio.

A complete listing of the releases of the .NET Framework:

2)components of .NET :
A programming infrastructure created by Microsoft for building, deploying, and running
applications and services that use .NET technologies, such as desktop applications and
Web services.

The .NET Framework contains three major parts:

the Common Language Runtime


the Framework Class Library

ASP.NET.

CLR:
The Common Language Runtime (CLR) is a special run time environment that provides
the underlying infrastructure for Microsoft's .NET framework.
The Common Language Runtime (CLR) is the runtime environment of the .Net
Framework , that executes and manages all running code like a Virtual Machine.
The main function of Common Language Runtime (CLR) is to convert the Managed
Code into native code and then execute the Program.
This runtime is where the source code of an application is compiled into an intermediate
language called CIL , originally known as MSIL (Microsoft Intermediate Language).
When the program is then run, the CIL code is translated into the native code of the
operating system using a just-in-time (JIT) compiler.
This intermediate language is used to keep the environment platform-neutral and as a
result, supports all .NET languages such as C# or VB.NET.

General advantages:
Portability
Security
Interoperability
Flexibility

Short for Common Language Runtime, a runtime environment that manages the
execution of .NET program code and provides services such as memory and exception
management, debugging and profiling, and security.
The CLR is a major component of the .NET framework.
CLR also is known as the Virtual Execution System (VES).

FCL:
The Framework Class Library (FCL) is a standard library and one of the components of
Microsoft .NET Framework.
The .Net Framework Class Libraries (FCL) are arranged into a logical grouping
according to their functionality and usability is called Namespaces.
The Classes are accessed by namespaces, which reside within Assemblies.
The FCL is a collection of thousands of reusable classes (within hundreds of
namespaces), interfaces and value types.
The Base Class Library is a part of FCL and provides the most fundamental
functionality, which includes classes in namespaces System, System.CodeDom,
System.Collections, System.Diagnostics, System.Globalization, System.IO,
System.Resources and System.Text.[
The .Net Framework class library (FCL) classes are object oriented and easy to use in
program developments.
The services provided by the FCL include runtime core functionality (basic types and
collections, file and network I/O, accessing system services, etc.), interaction with
databases, consuming and producing XML, and support for building Web-based and
desktop-based client applications, and SOAP-based XML Web services.

ASP.NET:
ASP.NET is a web application framework developed and marketed by
Microsoft to allow programmers to build dynamic web sites, web
applications and web services.

It was first released in January 2002 with version 1.0 of the .NET Framework, and is the
successor to Microsoft's Active Server Pages (ASP) technology.
ASP.NET is built on the Common Language Runtime (CLR), allowing programmers to
write ASP.NET code using any supported .NET language.

Why .NET is required:


Problems before .NET: Platform Dependancy
Error Handling
Language Interoperability
Distributed Technology
Web Based Application
Mobile Application

Platform Dependency: The application targets to particular o/s is called platform dependent application.
Example:-Let an application is developed in vb6.0 language to windows o/s.
If we try to run that application to another o/s it is not going to executed, it is dependent
on that particular o/s.
Solution:- .NET language compiler will produce IL(Intermediate Language) code, it is
platform independent code. It is going to be executed on any o/s.
Error Handling: C language -> Defining constants for error handling
VB language > An error goto label
VC++ language -> An error goto label
Different language has got different approach for error handling this is called
unstructured error handling, it doesnt support cross language error handling.

The exception thrown by vc++ language cannot be handled in vb language


because the compiler of different language before .NET supports its own
approach for error handling, if one language throw an error to another language
the compiler of that particular language is not designed to find the error.
Solution:- .NET supports structured error handling called Exception Handling.
It supports cross language error handling.
Language Interoperability:-

One language produced code used by another language application is called language
interoperability.
Language interoperability can be achieved before .NET using COM (Component Object
Model).
COM comes with a set of drawbacks: COM is specific to windows OS
COM is object based, no inheritance is supported
Soluction:- .NET is providing Assemblies concept to overcome COM drawbacks towards
language interoperability.

Distributed Technology:-

Distributed is a concept of maintaining application logic scattered on different system.

As shown in above diagram the application is running in Rohini Branch but the actual
logic is performed in Main Branch.
This is possible due to distributed system where same application is running on different
branch but its actual logic or implementaion is performed in Main Branch with the
database.
Before .NET distributed technology can be implemented using DCOM (Distributed
COM).
DCOM comes with set of drawbacks: It supports microsoft application communication only under windows network
It doesnt support internet based approach
Solution:- .NET is providing Remoting, Web services & Windows Communication
Foundation (WCF) towards distributed system.
.NET APP > Remoting -> .NET App
[Windows] [Linux]
J2EE App -> Web Services > .NET App
[Windows] [Linux]

Web Based Application


Before .NET Asp 3.0 can be used to develop dynamic web page with server side coding.
Asp 3.0 supports scripting language [vbscript, javascript] towards server side coding.
These scripting language are interpreter based. This makes execution slow and effect
webserver performance.

Solution:- .NET is providing Asp.net to overcome drawbacks of Asp 3.0


Mobile Application: Mobile application development can be classified into 2 steps:-

Mobile Normal Application [Smart device App]:It is used for developing games, editors, etc towards mobile device
Mobile Web Application:It is used for developing webpage towards mobile device
Before .NET mobile normal application can be developed using vc++ internal
programming, it will be very complex & time consuming.
Before .NET mobile web application development is not possible.
Solution:- .NET supports mobile normal app with easier approach by providing smart
device project
.NET supports mobile web app development with MMIT [Microsoft Mobile Internet
Toolkit]

Importance of DLL
1.Reusability

If the programmer has to used same line of instruction(code) for different


application it will be time consuming and wastage of memory.
So common line of instruction are packeged into dll file and provides to different
application for its development.
As shown in above figure different application of Tata Company reuses the same
dll file(cals.dll) for application development.
The programmer has no need to write the same 1lakh of instruction for different
application.
2.Better Maintainance:
If any changes to be carried out, the programmer has no need to make changes to
each and every application folder, just make the to dll file and provides to
different application.

The changes to dll will reflected to all the application,this provides better
maintainance.
3.Language Interoperability:

One language code can be used in another language is called language


interoperability.

As shown in above figure the application development for wipro company 20 employee
are involved. 10 employee are good VC++ programmer while rest employee are good in
VB programming.
The module developed by VB programmer are packaged into dll file and provides it to
VC++ programmer for application development.
Before .NET language interoperability can be achieved using COM (Component
Object Module).
COM comes with set of drawbacks, it is avoided in .NET by providing Assemblies
concept.
Difference Between EXE and DLL
EXE:
Exe is self executable code,it is called as standalone application [Desktop app].
Example:-To copy Dos cmd (copy.exe)
For windows o/s calculator (calc.exe)
For windows explorer (explorer.exe)
DLL(Dynamic Link Labrary):
DLL is not a self executable, it is called as library file. The code written in dll file is
substituted into exe.
It is similar to header file in C language.
.NET High Level Language
Intermediate Language is similar to assembly level language, developer cannot write IL
code towards application development, it will be very complex & time consuming

10

Developer requires high level language towards .NET


Microsoft is providing open option to industry where any company can develop language
compiler to .NET, the minimum criteria providing IL code with CLS type support
Microsoft is providing 4 high level language:1.
2.
3.
4.

VB.NET
C#.NET
VC++.NET
Vj#.NET

Other companies also provides high level language are called third party language
o Cobol.NET
o Pascal.NET
o Fortan.NET
o Smalltalk.NET
o Python.NET
.NET supports 25 + high level language

Features of .NET
Now that we know some basics of .NET, let us see what makes .NET a wonderful
platform for developing modern applications.
Rich Functionality out of the box:

.NET framework provides a rich set of functionality out of the box.


It contains hundreds of classes that provide variety of functionality ready to use in
your applications.

This means that as a developer you need not go into low level details
of many operations such as file IO, network communication and so on.

Easy development of web applications

ASP.NET is a technology available on .NET platform for developing dynamic


and data driven web applications.
ASP.NET provides an event driven programming model (similar to Visual Basic 6
that simplify development of web pages (now called as web forms) with complex
user interface.
ASP.NET server controls provide advanced user interface elements (like calendar
and grids) that save lot of coding from programmers side.

OOPs Support

The advantages of Object Oriented programming are well known.


.NET provides a fully object oriented environment.

The philosophy of .NET is Object is mother of all.

11

Languages like Visual Basic.NET now support many of the OO features that were
lacking traditionally.

Even primitive types like integer and characters can be treated as objects
something not available even in OO languages like C++.

Multi-Language Support

Generally enterprises have varying skill sets.


For example, a company might have people with skills in Visual Basic, C++, and
Java etc.

It is an experience that whenever a new language or environment is invented


existing skills are outdated.

This naturally increases cost of training and learning curve.

.NET provides something attractive in this area.

It supports multiple languages.

This means that if you have skills in C++, you need not throw them but just
mould them to suit .NET environment.

Currently four languages are available right out of the box namely Visual
Basic.NET, C# (pronounced as C-sharp), Jscript.NET and Managed C++ (a
dialect of Visual C++).

There are many vendors that are working on developing language compilers for
other languages (20+ language compilers are already available).

The beauty of multi language support lies in the fact that even though the syntax
of each language is different, the basic capabilities of each language remain at par
with one another.

Multi-Device Support

Modern lift style is increasingly embracing mobile and wireless devices such as
PDAs, mobiles and handheld PCs. . .
.NET provides promising platform for programming such devices.
.NET Compact Framework and Mobile Internet Toolkit are step ahead in this
direction.

Automatic memory management

While developing applications developers had to develop an eye on system


resources like memory.
Memory leaks were major reason in failure of applications.
.NET takes this worry away from developer by handling memory on its own.

12

The garbage collector takes care of freeing unused objects at appropriate


intervals.

Compatibility with COM and COM+

Before the introduction of .NET, COM was the de-facto standard for
componentized software development.
Companies have invested lot of money and efforts in developing COM
components and controls.

The good news is you can still use COM components and ActiveX controls
under .NET.

This allows you to use your existing investment in .NET applications.

.NET still relies on COM+ for features like transaction management and object
pooling.
In fact it provides enhanced declarative support for configuring COM+
application right from your source code.
Your COM+ knowledge still remains as a valuable asset.

No more DLL Hell


If you have worked with COM components, you probably are aware of
DLL hell.

DLL conflicts are a common fact in COM world.

The main reason behind this was the philosophy of COM one version of
component across machine.

Also, COM components require registration in the system registry.

.NET ends this DLL hell by allowing applications to use their own copy of
dependent DLLs.

Also, .NET components do not require any kind of registration in system registry.

Strong XML support

Now days it is hard to find a programmer who is unaware of XML. XML has
gained such a strong industry support that almost all the vendors have released
some kind of upgrades or patches to their existing software to make it XML
compatible.
Currently, .NET is the only platform that has built with XML right
into the core framework.
.NET tries to harness power of XML in every possible
way.
In addition to providing support for manipulating and transforming XML
documents,
.NET provides XML web services that are based on standards like
HTTP, XML and SOAP.

Ease of deployment and configuration

Deploying windows applications especially that used COM components were

13

always been a tedious task.


Since .NET does not require any registration as such, much of the deployment is
simplified. This makes XCOPY deployment viable.
Configuration is another area where .NET especially ASP.NET shines over
traditional languages.

The configuration is done via special files having special XML


vocabulary.

Since, most of the configuration is done via configuration files, there is no need to
sit in front of actual machine and configure the application manually.
This is more important for web applications; simply FTPing new configuration
file makes necessary changes.

Security

Windows platform was always criticized for poor security mechanisms.


Microsoft has taken great efforts to make .NET platform safe and secure for
enterprise applications.

Features such as type safety, code access security and role based authentication
make overall application more robust and secure.

Microsoft intermediate language :


MSIL stands for Microsoft Intermediate Language.
We can call it as Intermediate Language (IL) or Common Intermediate Language (CIL).
Microsoft .Net Languages Source Code are compiled into Microsoft Intermediate
Language (MSIL) .
Microsoft Intermediate Language (MSIL) is a CPU independent set of instructions that
can be converted to the native code.
Microsoft Intermediate Language (MSIL) includes instructions for loading, storing,
initializing, and calling methods on objects, as well as instructions for arithmetic and
logical operations, control flow, direct memory access, exception handling, and other
operations.
Metadata also created in the course of compile time with Microsoft Intermediate
Language (MSIL) and stored it with the compiled code .
Metadata is completely self-describing .
Metadata is stored in a file called Manifest, and it contains information about the
members, types, references and all the other data that the Common Language
Runtime (CLR) needs for execution .
The Common Language Runtime (CLR) uses metadata to locate and load classes,
generate native code, provide security, and execute Managed Code.

14

Both Microsoft Intermediate Language (MSIL) and Metadata assembled together is


known as Portable Executable (PE) file.
Portable Executable (PE) is supposed to be portable across all 32-bit operating systems
by Microsoft .Net Framework.
During the runtime the Common Language Runtime (CLR)'s Just In Time (JIT)
compiler converts the Microsoft Intermediate Language (MSIL) code into native code to
the Operating System.
The native code is Operating System independent and this code is known as Managed
Code , that is, the language's functionality is managed by the .NET Framework .
The Common Language Runtime (CLR) provides various Just In Time (JIT) compilers,
and each works on a different architecture depends on Operating Systems, that means the
same Microsoft Intermediate Language (MSIL) can be executed on different
Operating Systems.

When you create a VB .NET application :

Your code is compiled into the CLR's Intermediate Language


(named MSIL,
or IL for short)

The CLR's Intermediate Language is like bytecodes in Java.

When you run the application :


-

The Intermediate Language code is translated into the binary code


your computer can understand by some special compilers built
into the CLR.

Common type system(CTS):


Common Type System (CTS) describes a set of types that can be used in different .Net
languages in common .
That is, the Common Type System (CTS) ensure that objects written in different .Net
languages can interact with each other.

15

For Communicating between programs written in any .NET complaint language, the
types have to be compatible on the basic level .
These types can be Value Types or Reference Types .
The Value Types are passed by values and stored in the stack.
The Reference Types are passed by references and stored in the heap.
Common Type System (CTS) provides base set of Data Types which is responsible for
cross language integration.
The Common Language Runtime (CLR) can load and execute the source code written
in any .Net language, only if the type is described in the Common Type System (CTS).
Most of the members defined by types in the .NET Framework Class Library (FCL)
are Common Language Specification (CLS) compliant Types.
(or)
CLR can understand only one language IL [Intermediate Language]
Types supported by IL is called CTS
Basic types supported by IL: byte, int16, int32, uint16, uint32
User defined types: Structure, Class, Interface
Classification of Types:
The CTS can be classified into the following two general categories that are further divided
into subcategories:
Value Types: Contain data assigned by the user. The objects of the Value types are allocated
on the stack. Value types can be built-in, user-defined, or enumerations.
Reference Types: Contain the reference of the datas memory address. The objects of the
Reference types are allocated in a heap. They can be pointer types, interface types, or selfdescribing types. The self-describing types can be arrays and class types.
The Base class of all the types is the System.Object class.
The following figure shows the hierarchy of the types:

16

Hierarchial Representation of Different Types

Runtime Engine

17

.NET framework consist of two parts:1. Language Libraries:It includes the classes and methodes for application development
2. Runtime Engine:It mainly carries out the execution of developed application
Runtime Engine is a software component to perform code conversion, threading, memory
management
Input Code > Runtime Engine -> Output Code
Java is providing runtime engine called JVM [Java Virtual Machine]
Byte Code > JVM > o/s Native Code
.NET is providing runtime engine called CLR [Common Language Runtime]
IL Code > CLR > o/s Native Code
IL code is platform independent code
CLR is layer above o/s

Common Language Specification(CLS):


Common Language Specification (CLS) is a set of basic language features that .Net
Languages needed to develop Applications and Services , which are compatible with the
.Net Framework.
When there is a situation to communicate Objects written in different .Net Complaint
languages, those objects must expose the features that are common to all the languages.
Common Language Specification (CLS) ensures complete interoperability among
applications, regardless of the language used to create the application.
Common Language Specification (CLS) defines a subset of Common Type System
(CTS) .

18

Common Type System (CTS) describes a set of types that can use different .Net
languages have in common, which ensure that objects written in different languages can
interact with each other.
Most of the members defined by types in the .NET Framework Class Library (FCL)
are Common Language Specification (CLS) compliant Types.
(or)
The set of types to be supported by .NET high level language [vb.net, c#.net] is called
common language specification
It is subset of CTS.

Just In Time Compiler:


The .Net languages , which is conforms to the Common Language Specification (CLS),
uses its corresponding runtime to run the application on different Operating Systems .
During the code execution time, the Managed Code compiled only when it is needed,
that is it converts the appropriate instructions to the native code for execution just before
when each function is called.
This process is called Just In Time (JIT) compilation, also known as Dynamic Translation
.
With the help of Just In Time Compiler (JIT) the Common Language Runtime (CLR)
doing these tasks.
The Common Language Runtime (CLR) provides various Just In Time compilers (JIT)
and each works on a different architecture depending on Operating System.
That is why the same Microsoft Intermediate Language (MSIL) can be executed on
different Operating Systems without rewrite the source code.
Just In Time (JIT) compilation preserves memory and save time during application
initialization.

19

Just In Time (JIT) compilation is used to run at high speed, after an initial phase of slow
interpretation.
Just In Time Compiler (JIT) code generally offers far better performance than
interpreters.

.Net Namespaces
The .NET Framework class library has thousands of classes which are needed for
developing and deploying solutions.
In order to organize all those classes for ease of use .NET Framework uses namespaces.
This Gives the Classes their own space and prevents conflicts between the various names
in these classes.
For instance if two classes contain a method Paint(), then to avoid conflicts in names we
can place these classes in two different namespaces.
Thus namespaces allow classes to be grouped in a consistent, hierarchical manner.
Namespaces are the way to organize .NET Framework Class Library into a logical
grouping according to their functionality, usability as well as category they should belong
to, or we can say Namespaces are logical grouping of types for the purpose of
identification.
The .NET Framework Class Library (FCL ) is a large collection of thousands of Classes.
These Classes are organized in a hierarchical tree.
The System Namespaces is the root for types in the .NET Framework.
We can uniquely identify any Class in the .NET Framework Class Library (FCL ) by
using the full Namespaces of the class .
In .Net languages every program is created with a default Namespaces .
Programmers can also create their own Namespaces in .Net languages.

Garbage Collection:
The .Net Framework provides a new mechanism for releasing unreferenced objects from
the memory (that is we no longer needed that objects in the program) ,this process is
called Garbage Collection (GC).

20

When a program creates an Object, the Object takes up the memory.


Later when the program has no more references to that Object, the Object's memory
becomes unreachable, but it is not immediately freed.
The Garbage Collection checks to see if there are any Objects in the heap that are no
longer being used by the application.
If such Objects exist, then the memory used by these Objects can be reclaimed.
So these unreferenced Objects should be removed from memory , then the other new
Objects you create can find a place in the Heap.
The reclaimed Objects have to be Finalized later.
Finalization allows a resource to clean up after itself when it is being collected.
This releasing of unreferenced Objects is happening automatically in .Net languages by
the Garbage Collector (GC).
The programming languages like C++, programmers are responsible for allocating
memory for Objects they created in the application and reclaiming the memory when that
Object is no longer needed for the program.
In .Net languages there is a facility that we can call Garbage Collector (GC) explicitly in
the program by calling System.GC.Collect.

Advantages of .NET over COM:


What is COM(Component Object Model):

COM is a platform-independent, distributed, object-oriented system for creating


binary software components that can interact.
Component Object Model (COM) is a binary-interface standard for software
componentry introduced by Microsoft in 1993.
It is used to enable interprocess communication and dynamic object creation
in a large range of programming languages.
The term COM is often used in the Microsoft software development industry as
an umbrella term that encompasses the OLE, OLE Automation, ActiveX,
COM+ and DCOM technologies.

Main disadvantage of using COM components is dll hell


problem

21
dll hell:Previously, before .NET, this used to be a major issue.
"DLL Hell" refers to the set of problems caused when multiple applications
attempt to share a common component like a dynamic link library (DLL) or a
Component Object Model (COM) class.
In the most typical case, one application will install a new version of the
shared component that is not backward compatible with the version already
on the machine.
Although the application that has just been installed works well, existing
applications that depended on a previous version of the shared component
might no longer work.
In some cases, the cause of the problem is even more subtle.
In many cases there is a significant delay before a user discovers that an
application has stopped working.
As a result, it is often difficult to remember when a change was made to the
machine that could have affected the application.
A user may remember installing something a week ago, but there is no
obvious correlation between that installation and the behavior they are now
seeing.
The reason for these issues is that version information about the different
components of an application aren't recorded or enforced by the system.
Also, changes made to the system on behalf of one application will typically
affect all applications on the machine.
One reason why it was hard to build an isolated application was the run-time
environment typically allowed the installation of only a single version of a
component or an application.

This restriction means that component authors must write their code in a way
that remains backward compatible, otherwise they risk breaking existing
applications when they install a new component.
In practice, writing code that is forever backward compatible is extremely
difficult, if not impossible.
Also components were shared because disk space and memory was
expensive.
In the past few years, hard disk and memory prices have dropped
dramatically, and disk space is no longer a premium.

22
But as applications have increased in size and in modularity not so long ago
many applications were entirely self-contained in a single .exe file - the DLL
sharing issue has not been addressed, and the problem has grown over time.

Com Dll vs .Net Dll


COM DLL

.NET DLL

Com Dll is a binary standard towards .Net Dll contains IL code towards
Windows o/s.
CLR.
Com doesnt support inheritance, it is .Net Dll support inheritance, it is
object based.
object oriented.
Com Dll is invalid without registry
entry in o/s, this is drawback when
dll is required for specific
application.

.Net Dll supports 2 types:1> Private Assembly -> specific to


application, no registry entry needed
2> Shared Assembly > set of
application, requires GAC registry
entry.

Com Dll goes with versioning


problem where window registry
cannot maintain multiple version of
same Com Dll, this problem is called
DLL HELL

.Net Dll doesnt have versioning


problem where GAC can maintain
multiple versions of same assembly
& supports side by execution

List .net languages:


A#
APL
ASP.NET:
ASM to IL
AsmL
ASP (Gotham)
Basic

CIL
Cobol

Lisp

NetCOBOL
(Fujitsu)
Net Express
(Micro

DotLisp
IronScheme

L#

Ruby

IronRub
y
Ruby/.N
ET
Bridge

23
VB .NET
(Microsoft)
VB .NET
(Mono)
BETA
Boo
BlueDragon
C
lcc
cscc
C#
C#
(Microsoft)
C# (Mono)
Cw
C++
(Microsoft)
Cat

Focus)

CQL
CULE.NET
E#
Eiffel
F#
Forth
Fortran

Fortran
(Lahey)
Fortran
(Silverfrost)

Haskell (VHS)
IronPython
Java
J#
(Microsoft)
Java
(IKVM .NET)
JNBridge
JScript .NET
Lego.NET

FOIL

leXico
LOLCODE
Lua.NET
M#
Mercury
Metaphor
MixNet
Mondrain
Nermerle
Oberon
Ook# .NET
OMeta#
Pan#
Pascal

Chrome
Delphi

Component
Pascal

Ruby.NE
T

Smalltalk

S#
#Smallt
alk

Smalltal
k and
.NET

Scala
SML .NET
Spec#
Tachy
TickleSharp
Zonnon

PerlNET
PHP
Prolog

Introduction to Visual Basic .NET:


Visual Basic .NET is the next generation of Microsoft's popular Visual Basic
programming languages.
Some programmers refer to the new incarnation as VB 7, but this is incorrect.
Visual Basic is very popular for it's friendly working (graphical) environment.
Visual Basic .NET is actually not backwards-compatible with VB6, meaning that code
written in the old version will not compile under VB.NET.
Visual Basic. NET is an extension of Visual Basic programming language with many new
features in it.
The changes from VB to VB .NET are huge, ranging from the change in syntax of the
language to the types of projects we can create now and the way we design applications.
Visual Basic .NET was designed to take advantage of the .NET Framework base classes
and runtime environment.
It comes with power packed features that simplify application development.

Briefly on some changes:

24

The biggest change from VB to VB .NET is, VB .NET is Object-Oriented now. VB


.NET now supports all the key OOP features like Inheritance, Polymorphism, Abstraction
and Encapsulation. We can now create classes and objects, derive classes from other
classes and so on. The major advantage of OOP is code reusability
The Command Button now is Button and the TextBox is TextBox instead of Text as in
VB6
Many new controls have been added to the toolbar to make application development
more efficient
VB .NET now adds Console Applications to it apart from Windows and Web
Applications. Console applications are console oriented applications that run in the DOS
version
All the built-in VB functionality now is encapsulated in a Namespace (collection of
different classes) called System
New keywords are added and old one's are either removed or renamed
VB .NET is strongly typed which means that we need to declare all the variables by
default before using them
VB .NET now supports structured exception handling using Try...Catch...Finally syntax
The syntax for procedures is changed. Get and Let are replaced by Get and Set
Event handling procedures are now passed only two parameters
The way we handle data with databases is changed as well. VB .NET now uses
ADO .NET, a new data handling model to communicate with databases on local
machines or on a network and also it makes handling of data on the Internet easy. All the
data in ADO .NET is represented in XML format and is exchanged in the same format.
Representing data in XML format allows us for sending large amounts of data on the
Internet and it also reduces network traffic when communicating with the database
VB .NET now supports Multithreading. A threaded application allows to do number of
different things at once, running different execution threads allowing to use system
resources
Web Development is now an integral part of VB .NET making Web Forms and Web
Services two major types of applications

Features of Visual Basic .NET:


1) Visual Basic .NET provides the easiest, most productive language and tool for
rapidly building Windows and Web applications.
2) Visual Basic .NET comes with enhanced visual designers, increased application
performance, and a powerful integrated development environment (IDE).
3) It also supports creation of applications for wireless, Internet-enabled hand-held
devices.
4) The following are the features of Visual Basic .NET with .NET Framework 1.0
and Visual Basic .NET 2003 with .NET Framework 1.1.
5) This also answers why should I use Visual Basic .NET, what can I do with it?

25

Powerful Windows-based Applications

Visual Basic .NET comes with features such as a powerful new forms designer, an
in-place menu editor, and automatic control anchoring and docking.
Visual Basic .NET delivers new productivity features for building more robust
applications easily and quickly.
With an improved integrated development environment (IDE) and a significantly
reduced startup time, Visual Basic .NET offers fast, automatic formatting of code
as you type, improved IntelliSense, an enhanced object browser and XML
designer, and much more.

Building Web-based Applications

With Visual Basic .NET we can create Web applications using the shared Web
Forms Designer and the familiar "drag and drop" feature.
You can double-click and write code to respond to events.

Visual Basic .NET 2003 comes with an enhanced HTML Editor for working with
complex Web pages.

We can also use IntelliSense technology and tag completion, or choose the
WYSIWYG editor for visual authoring of interactive Web applications.

Simplified Deployment

With Visual Basic .NET we can build applications more rapidly and deploy and
maintain them with efficiency.
Visual Basic .NET 2003 and .NET Framework 1.1 makes "DLL Hell" a thing of
the past. Side-by-side versioning enables multiple versions of the same
component to live safely on the same machine so that applications can use a
specific version of a component. XCOPY-deployment and Web auto-download of
Windows-based applications combine the simplicity of Web page deployment and
maintenance with the power of rich, responsive Windows-based applications.

Powerful, Flexible, Simplified Data Access

You can tackle any data access scenario easily with ADO.NET and ADO data
access.
The flexibility of ADO.NET enables data binding to any database, as well as
classes, collections, and arrays, and provides true XML representation of data.

Seamless access to ADO enables simple data access for connected data binding
scenarios.

Using ADO.NET, Visual Basic .NET can gain high-speed access to MS SQL
Server, Oracle, DB2, Microsoft Access, and more.

26

Improved Coding

You can code faster and more effectively.

A multitude of enhancements to the code editor, including enhanced IntelliSense,


smart listing of code for greater readability and a background compiler for realtime notification of syntax errors transforms into a rapid application development
(RAD) coding machine.

Direct Access to the Platform

Visual Basic developers can have full access to the capabilities available in .NET
Framework 1.1.
Developers can easily program system services including the event log,
performance counters and file system.

The new Windows Service project template enables to build real Microsoft
Windows NT Services.

Programming against Windows Services and creating new Windows Services is


not available in Visual Basic .NET Standard, it requires Visual Studio 2003
Professional, or higher.

Full Object-Oriented Constructs

You can create reusable, enterprise-class code using full object-oriented


constructs.
Language features include full implementation inheritance, encapsulation, and
polymorphism.
Structured exception handling provides a global error handler and eliminates
spaghetti code.

XML Web Services

XML Web services enable you to call components running on any platform using
open Internet protocols.
Working with XML Web services is easier where enhancements simplify the
discovery and consumption of XML Web services that are located within any
firewall. XML Web services can be built as easily as you would build any class in
Visual Basic 6.0.
The XML Web service project template builds all underlying Web service
infrastructure.

Mobile Applications

27

Visual Basic .NET 2003 and the .NET Framework 1.1 offer integrated support for
developing mobile Web applications for more than 200 Internet-enabled mobile
devices.
These new features give developers a single, mobile Web interface and
programming model to support a broad range of Web devices, including WML 1.1
for WAPenabled cellular phones, compact HTML (cHTML) for i-Mode
phones, and HTML for Pocket PC, handheld devices, and pagers.
Please note, Pocket PC programming is not available in Visual Basic .NET
Standard, it requires Visual Studio 2003 Professional, or higher.

COM Interoperability

You can maintain your existing code without the need to recode.
COM interoperability enables you to leverage your existing code assets and offers
seamless bi-directional communication between Visual Basic 6.0 and Visual Basic
.NET applications.

Reuse Existing Investments

You can reuse all your existing ActiveX Controls.


Windows Forms in Visual Basic .NET 2003 provide a robust container for
existing ActiveX controls.

In addition, full support for existing ADO code and data binding enable a smooth
transition to Visual Basic .NET 2003.

Upgrade Wizard

You upgrade your code to receive all of the benefits of Visual Basic .NET 2003.
The Visual Basic .NET Upgrade Wizard, available in Visual Basic .NET 2003
Standard Edition, and higher, upgrades up to 95 percent of existing Visual Basic
code and forms to Visual Basic .NET with new support for Web classes and
UserControls.

Integrated development environment:


An integrated development environment (IDE) (also known as
integrated design environment, integrated debugging
environment or interactive development environment) is a software
application that provides comprehensive facilities to computer
programmers for software development.

28

An IDE normally consists of:

a source code editor


a compiler and/or an interpreter

build automation tools

a debugger

Visual Studio .NET IDE (Integrated Development Environment) is the


Development Environment for all .NET based applications which comes with rich
features.
VS .NET IDE provides many options and is packed with many features that
simplify application development by handling the complexities.
The Visual Studio IDE consists of several sections, or tools, that the developer
uses while programming.
As you view the IDE for a new project you generally have four sections in view:

The Toolbox on the left


The Solution Explorer on the right

The Properties window

The Code / Design view in the middle

Toolbox:
The Toolbox is a palette of developer objects, or controls, that are placed on forms or web
pages, and then code is added to allow the user to interact with them.
An example would be TextBox, Button and ListBox controls.
With these three controls added to a Windows Form object the developer could write
code that would take text, input by the application user, and added to the ListBox after
the button was clicked.

Solution Explorer:
This is a section that is used to view and modify the contents of the project.
A Visual Studio Windows Application Project will generally have a Form object with a
code page, references to System components and possibly other modules with special
code that is used by the application.

Properties Windows:
The properties windows shows all the control (like textbox) properties to be change at
design time.

29

Most of this properties can be change at run time with some code, but basically most of
this properties change the way the control is display on your application.

Code / Design view:


This is where the magic takes place. Forms are designed graphically.
In other words, the developer has a form on the screen that can be sized and modified to
look the way it will be displayed to the application users.
Controls are added to the form from the Toolbox, the color and caption can be changed
along with many other items.
This center window of the IDE is also where developers write the code that makes
everything in the application work.
The code is written in modules, or files, that are either connected to an object (Forms) or
called specifically when needed.

VB.NET Help System:


Visual Studio .NET includes an online reference called
-MSDN Library for Visual Studio.Net
Using MSDN Library you can learn more about :
o Visual Studio.NET development environment,
o The Visual Basic Programming language,
o The resources in the .NET Framework and
o The remaining tools in Visual Studio.NET suit.
You can access Help information in many ways.
To get the
information

Do this

30
About the task you are
currently working on

By topic or activity

Click the Dynamic Help tab in the development


environment to see a list of Help topics related to
the features you are using
(Or)
Click Dynamic Help on the Visual Studio Help menu.
On the Visual Studio Help menu, click Contents

While working in the


Code Editor

Click the keyword or program statement you are


interested in, and then press F1.

To get the
information

Do this

While working in a
dialog box
By searching for a
specific keyword

Click the Help button in the dialog box

About contacting
Microsoft for
product support

On the Help menu, click Technical Support.

On the Help menu, click Search and type the


term you are looking for.

You must install MSDN Library Documentation on your system during


setup in order to display the Dynamic Help window when you work in
Visual Studio.NET.
To install MSDN Library Documentation:

Insert the MSDN CD ROM included with Visual Studio.NET 2003 and then
Run MSDN setup.

How to save debug and distribute VB.NET


application:
Saving VB.NET Application:

When you begin creating an application you have to give it a name.

To save any changes you made to your application :

Click on the Save All button on the Standard Toolbar


(Or)

Click on the Save All command on the File menu.

Save All Command saves everything in your project .

31
i.e. it saves

The project files,


any form files,
any code modules, and
other related components in your application.

To save only the item you are currently working on..(form or code
module or any other component)

Click on the Save command on the File menu


(Or)

Click on the Save button on the Standard Toolbar.

To save the current item with a different name :

Click on the Save As command on the File menu

Debugging application in VB.NET:

Errors are normally referred to as bugs.


o Bugs/Errors are of 3 main types.
o Syntax error
o Logic error
o Runtime error
The process of going through the code to identify the cause of
errors and fixing them is called Debugging.

The most common type of errors, syntax errors, occur when the
compiler cannot compile the code.
Syntax error:

o A syntax error refers to a mistake in a statement's syntax.


Eg. when keywords are typed incorrectly or an
incorrect construct is parsed
o Syntax error is a fatal error that the programmer must correct
before being able to fully compile the program.
o It can be indicated by the compilers
o When we build the project, syntax errors are automatically
detected and underlined in code, in visual studio .NET.
Logical Errors:
o Logical Errors occur when the application compiles and executes
correctly, but does not output the desired results.
o These are the most difficult types of errors to trace because
there might be no indications about the source of the error.
o The only way to detect and correct logical errors is by feeding
test data into the application and analyzing the results.
Runtime Error:

32
o
o
o

A Runtime Error (Exception) is a problem that arise when the program


is executed.
Run-Time errors occur when the application attempts to perform a task
that is not allowed. This includes tasks that are impossible to carry out,
such as dividing by zero, etc.
To handle run-time errors, we need to write code (normally, using
Try...Catch...Finally) so that they don't halt execution of our application.

How to Debug?

Debugging is a methodical process of finding and reducing the


number of bugs, or defects, in a computer program.

The basic steps in debugging are:

Recognize that a bug exists

Isolate the source of the bug

Identify the cause of the bug

Determine a fix for the bug

Apply the fix and test it

Tools

Walk through your program

Display the variables at certain points, trace the program

Use of professional debugger

Modern debuggers usually allow you to step through your program and
look at the values of variables

Also the debugger will allow you to set breakpoints, which are
statements in your programs that you mark and tell the debugger to
suspend program execution when it gets there.

Stepping through Code:

Modern debuggers usually allow you to step through your program and
look at the values of variables

Also the debugger will allow you to set breakpoints, which are
statements in your programs that you mark and tell the debugger to
suspend program execution when it gets there.

Tools

33

Start, Stop, Break, Restart

Step Into

Step Out

Executes the next statement even if its inside a new


procedure

Finishes executing the current procedure and stops when


control returns to the calling procedure

Step Over

Executes the next statement. If that statement is a


procedure, the procedure is executed without stopping

Autos, Locals, Watch windows

Call Stack window

Now start the program by clicking the Run button on the toolbar or hitting the
F5 key.

The Output Window

This window displays status messages for various features in the IDE.
The window consists of multiple panes that can be accessed by the
combo box selection just below the title.
These separate panes can display build messages, debug messages, or
they can even be configured to output from .bat or .com files that
would normally show up in a DOS window.
To access the Output window, select Other Windows from the View
menu, and choose Output, or select CTRL+ALT+O.
Start the program again. Note the messages displayed at this point in
the Output window.
The Build pane should be visible as the application initializes and
messages relating to building and starting the program will scroll by. As
the form becomes visible, the Debug pane of the Output window will
be displayed.
If the Output window is not visible for any reason, simply select
CTRL+ALT+O at any time, or locate the tabs that will toggle between it
and the Command window.
The Debug pane of the Output window displays information regarding
the current execution of the program.

The Breaking Point

Breakpoints are a great way to stop the execution of your program at


predefined points in your code.
Applying the breakpoints is an easy task.
Simply open a section of code and click on the far left of the design
window in the gray area, as in the example below.

34

Right-click over the breakpoint indicator to display a menu of


additional options.
It is worth mentioning Outlining.
Outlining is a tool for organizing code into a more readable format.
Highlight a portion of code, then right-click and select the Outlining
submenu.
Hide Selection will collapse the marked selection of code and put an
indicator (+ . . .) to be used to expand it again as needed.
Also the hidden code can be quickly viewed without expanding by
simply performing a mouse-over of the collapsed code indicator.
The Breakpoints window is a practical dialog that will display all of your
marked breakpoints and certain settings associated with each.
To open this window, select the Debug menu, Windows then
Breakpoints, or press CTRL+ALT+B. The window contains a toolbar and
a list of breakpoints:

Type the variable assignment, Variable name = Value, in the


Immediate Command window and then ENTER.
The mouse-over feature in the code pane now reveals the value of the
variable
In the Immediate Command window, you can also display the assigned
value by typing the print function (?Variable name), or even just doing
a mouse-over of the Variable name of the variable there.

35

Within the Immediate Command window, we can now begin to test all
sorts of scenarios and see what expression is going to give the desired
result:
?int((EmpSalary + 1000)/1000) * 1000
?int((20000 + 1000)/1000) * 1000
RoundSalary = Math.Ceiling(EmpSalary/1000)*1000
We can skip over the statement in our code and instead execute
whatever statement we choose.
Place the mouse over the breakpoint and drag the yellow arrow down
to the TotalCost variable assignment below
Place the mouse over the breakpoint and drag the yellow arrow down
to the TotalCost variable assignment below.

This will cause execution to begin here when we start again.


Select the Debug menu and then Continue, or click on the Run button
on the toolbar.
In Visual Basic .NET, any code changes in break mode require that the
project be rebuilt before the code changes can take effect.

Building an Executable file

Windows applications created with Visual Studio have the file name
extension .exe and can be run on any system that contains Microsoft
Windows and the necessary support files.
(Visual Basic installs these support filesincluding the .NET Framework
files automatically.)
Visual Studio can create two types of executable files for your project:
a debug build and a release build.
Debug builds are created automatically by Visual Studio when you
create and test your program
They are stored in a folder called bin\debug within your project folder
The debug executable file typically contains debugging information
that makes the program run slightly slower
Release builds are optimized executable files stored in the bin\release
folder within your project.
To customize the settings for your release build,
Click the [ProjectName] Properties command on the Project
menu,
there you see a list of options.
You can make necessary changes

Deploying Applications

36
o
o
o

Once an application is developed and if we want to distribute that


application, we need to deploy that.
Deployment is the process where we create an executable file which can be
installed on any machine where the application can run.
We can use the built-in deployment feature that comes with Visual Basic to
create a Windows Installer file - a .msi file for the purpose of deploying
applications.
Let's look at the process with an example. Let's assume we have a form with
a TextBox and a Button. When the Button is clicked the TextBox should
display "This application is Deployed". Let's name this application as Deploy.
The code for the click event of the Button looks like this:
Private Sub Button1_Click(By Val sender as System.Object, By Val e
as System.EventArgs)Handles Button1.Click
TextBox1.Text="This application is Deployed"
End Sub

o
o
o
o

Next, we need to create an executable (exe) file for this application.


To do that select Build->Build from the main menu which builds Deploy.exe.
Next, we need to create an installer file for Deploy (which is the example)
which is a file with .msi extension.
To do that, select File->Add Project->New Project which opens the new
project dialogue. On the left side, Project Types menu click on Other
Project Types then Select "Setup and Deployment Projects" icon in the
projects type box and Setup Wizard in the templates box. It looks like the
image below (according to visual studio 2008):

Click OK to open the Setup Wizard. The Setup wizard window looks like the image
below:

37

Click next on the above pane to take you to second pane in the Wizard.
The new pane allows us to create deployment projects both for Windows and
Web Applications.
Here, select the radio button which says "Create a setup for Windows Application"
as this is deploying a windows application and click next.
It looks like the image below:

38

Clicking next opens a new pane which has options like Deploying only primary output
from the project or both the project and source code or content files.
Check the checkbox which you want, in this case check the checkbox that says
"Primary Output from Deploy" and click next.
It looks like the image below:

Clicking next opens a new pane which asks if you want any additional files to be
added. If you wish, you can include other files, like an icon for the application. In this
example don't include any files and click next. It looks like the image below:

39

Doing that brings up the last pane of the Setup Wizard which looks like the image
below. Click Finish on this pane.

Clicking finish opens up a File System window which looks like the image below.

40

This window allows us to create shortcuts to the application on the desktop and in
our Programs Menu.
To create a shortcut, right-click on the folder "User's Desktop" and select "Create
Shortcut to User's Desktop". Rename the shortcut to "Deployment".
If we want a shortcut to the application from our Programs Menu, right-click on
"User's Program Menu" folder and select "Create Shortcut to User's Program Menu".
Rename the shortcut to "Deployment".
Once you are finished with it, click on "Application Folder" and open it's properties.
In the properties window set the property "Always Create" to True.
Set the same for "User's Desktop" and "User's Programs Menu" folders.
If you want any additional information to include with the set-up project, like the
manufacturer, author etc, click on Setup1 project and open it's properties. You can
set additional information here.
Once your are done with it build the project by right-clicking on Setup1 and selecting
Build.
The building process status will be shown in the status bar at the bottom of visual
studio IDE.
This builds the application. The setup file is created in the debug folder of Setup1
project.

41

You might also like