




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
it is used to develop its knowledge
Typology: Exercises
1 / 224
This page cannot be seen from the preview
Don't miss anything!





























































































India Community Initiative
Special thanks to the following who have put in sincere efforts to write and bring this tutorial together.
Akila Manian (MVP) | Ajay Varghese (MVP) | Amit Kukreja | Anand M (MVP) | Aravind Corera (MVP) | Arvind Rangan | Balachandran | Bipin Joshi (MVP) | C S Rajagopalan | G Gokulraj | G Arun Prakash | Gurneet Singh (MVP) | Kunal Cheda (MVP) | Manish Mehta (MVP) | Narayana Rao Surapaneni (MVP) | Pradeep | Saurabh Nandu (MVP) | Shankar N.S. | Swati Panhale | Reshmi Nair
6.7 Understanding CSharp and VB.NET as Object Oriented Programming languages
1. Getting Ready
Section Owner: Ajay Varghese (MVP) Content Contributors: Bipin Joshi (MVP)
Welcome friends to the exciting journey of Microsoft .NET. If you are looking for information about what .NET is all about, what it can do for you or how it can help you and your customers, you have come to the right place. This section is intended to tell you about these and many more things. After covering this section you will be ready to delve into details of .NET.
The section is divided into following sub-sections:
The first sub-section will introduce you with how .NET evolved and the path of .NET since its Beta releases.
The second sub-section will introduce you with various flavors of...NET and their respective SDKs. It also gives overview of Visual Studio.NET – an excellent IDE for developing .NET applications.
It is necessary to understand the features of .NET that make it robust, programmer friendly, powerful and flexible. The third sub-section is intended just for that. It gives overview of technical features that make .NET shine over traditional programming environments.
The final sub-section tells you how to install .NET framework SDK, what are the system requirements and related topics.
Sometime in the July 2000, Microsoft announced a whole new software development framework for Windows called .NET in the Professional Developer Conference (PDC). Microsoft also released PDC version of the software for the developers to test. After initial testing and feedback Beta 1 of .NET was announced. Beta 1 of the .NET itself got lot of attention from the developer community. When Microsoft announced Beta 2, it incorporated many changes suggested by the community and internals into the software. The overall ‘Beta’ phase lasted for more than 1 ½ years. Finally, in March 2002 Microsoft released final version of the .NET framework.
One thing to be noted here is the change in approach of Microsoft while releasing this new platform. Unlike other software where generally only a handful people are involved in beta testing, .NET was thrown open to community for testing in it’s every pre-release version. This is one of the reasons why it created so many waves of excitement within the community and industry as well.
Microsoft has put in great efforts in this new platform. In fact Microsoft says that its future depends on success of .NET. The development of .NET is such an important event that Microsoft considers it equivalent to transition from DOS to Windows. All the future development – including new and version upgrades of existing products – will revolve around .NET. So, if you want to be at the forefront of Microsoft Technologies, you should be knowing .NET!
Now, that we know about brief history of .NET let us see what .NET has to offer.
Contrary to general belief .NET is not a single technology. Rather it is a set of technologies that work together seamlessly to solve your business problems. The following sections will give you insight into various flavors and tools of .NET and what kind of applications you can develop.
Visual Studio.NET comes in different editions. You can select edition appropriate for the kind of development you are doing. Following editions of VS.NET are available:
Visual Studio .NET Professional edition offers a development tool for creating various types of applications mentioned previously. Developers can use Professional edition to build Internet and Develop applications quickly and create solutions that span any device and integrate with any platform.
Visual Studio .NET Enterprise Developer (VSED) edition contains all the features of Professional edition plus has additional capabilities for enterprise development. The features include things such as a collaborative team development, Third party tool integration for building XML Web services and built-in project templates with architectural guidelines and spanning comprehensive project life-cycle.
Visual Studio .NET Enterprise Architect (VSEA) edition contains all the features of Visual Studio .NET Enterprise Developer edition and additionally includes capabilities for designing, specifying, and communicating application architecture and functionality. The additional features include Visual designer for XML Web services, Unified Modeling Language (UML) support and enterprise templates for development guidelines and policies.
A complete comparison of these editions can be found at http://msdn.microsoft.com/vstudio/howtobuy/choosing.asp
In addition to these editions, special language specific editions are available. They are:
These editions are primarily for hobbyist, student, or beginner who wants to try their hands on basic language features.
A complete comparison of these standard editions with professional edition of VS.NET can be found at:
http://msdn.microsoft.com/vcsharp/howtobuy/choosing.asp http://msdn.microsoft.com/vbasic/howtobuy/choosing.asp
In order to run application developed using .NET Framework the machine must have certain ‘runtime’ files installed. They are collectively called as .NET redistributable. This is analogous to traditional Visual Basic applications that required Visual Basic runtime installed on target computers. .NET redistributable provides one redistributable installer that contains the common language runtime (more on that later) and Microsoft .NET Framework components that are necessary to run .NET Framework applications. The redistributable is available as a stand-alone executable and can be installed manually or as a part of your application setup.
You can download .NET redistributable at http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url =/msdn-files/027/001/829/msdncompositedoc.xml
More technical information about .NET redistributable can be found at http://msdn.microsoft.com/library/default.asp?url=/library/en- us/dnnetdep/html/dotnetfxref.asp
Note that if you have installed .NET Framework SDK, there is no need of installing redistributable separately. Also, note that there is difference between .NET Framework SDK and .NET redistributable in terms of purpose and tools and documentation supplied. .NET Framework SDK is intended to ‘develop’ applications where as .NET redistributable is intended to ‘run’ .NET applications.
Now days the use of mobile and wireless devices is ever increasing. PDAs, mobile phones, Smartphones, handheld PCs and HTML pagers are becoming common. As compared to full blown desktop computers, Mobile devices are generally resource-constrained. There are limitations on what they can display and in which form. For example you can easily display graphical menus in desktop applications but the same may not be possible for cell phones.
Today there are many vendors making CPUs and development tools for mobile devices. However, their standards are much varying. For example devices running Windows CE will have different tools and standards of development than Palm OS. Also, programming model for such devices is an issue of debate. For example, Wireless Application Protocol (WAP) was considered a ‘standard’ for mobile devices but it introduced disadvantages of its own such as requirement of
its own set of underlying standards and markup. MMIT shields these details from the developer and allows ‘uniform code’ for any target device. Based on the capabilities of target device the output is rendered.
More information about MMIT can be obtained from http://msdn.microsoft.com/vstudio/device/mitdefault.asp
Now that we know some basics of .NET, let us see what makes .NET a wonderful platform for developing modern applications.
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.
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.
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. The garbage collector takes care of freeing unused objects at appropriate intervals.
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.
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.
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.
o Microsoft Windows XP – (Microsoft Windows XP Professional if you want to run ASP.NET) o Microsoft Windows NT® 4.
Note: If you want to simply run .NET applications then you can also run them on Microsoft Windows XP Home edition, Windows Millennium Edition (Windows ME) and Windows 98.
Here are some URLs that you will find handy in making your system up-to-date for above software requirements.
Internet Explorer 6 can be downloaded from http://www.microsoft.com/windows/ie/downloads/ie6/default.asp
Microsoft Data Access Components 2.7 can be downloaded from http://www.microsoft.com/data/download_270RTM.htm
Various Windows service packs and patches can be obtained from http://www.microsoft.com/downloads/search.asp
As mentioned earlier .NET framework SDK is freely downloadable from MSDN site. Visit http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url =/msdn-files/027/000/976/msdncompositedoc.xml and download it now.
The total download size is 137,363,456 bytes (approximately 131 Mb). For your convenience Microsoft has provided multi-part version of the entire download. If you are unable to download the SDK from MSDN web site, check out popular PC magazines around. Many of them contain .NET Framework SDK on their companion CD.
Note: If you already have a previous version of .NET installed on the machine then it must first be uninstalled. Refer ReadMe files that ship with .NET framework SDK. These files contain valuable information related to installation, system requirements and trouble shooting.
In order to start the installation, you need to run the setup program that is available with the download mentioned above. A wizard will guide you with necessary process. It will also allow you to select various components of the framework.
After the installation is complete it is a good idea to apply .NET framework Service pack 1. The service pack fixes some of the bugs. It can be downloaded from: http://msdn.microsoft.com/netframework/downloads/sp1/default.asp
Coming Next…
By the time you must have got idea about what .NET is and what it can do for you. You probably will have installed .NET on your machine waiting eagerly to try hands on it. However, before you go into the code level details, it is essential that you firmly understand certain fundamentals. In the next section we will demystify some intrinsic concepts and features of .NET framework.
Fig Showing 2 – Tier Client Server Model
Through the appearance of Local-Area-Networks, PCs came out of their isolation, and were soon not only being connected mutually but also to servers. Client/Server- computing was born. A two-tiered application is an application whose functionality can only be segmented into two logical tiers, presentation services and data services. The presentation services of a two-tiered application are responsible for gathering information from the user, interacting with the data services to perform the application's business operations, and presenting the results of those operations to the user. The Presentation services are also called the presentation layer because it presents information to the user. Things you might find in a presentation layer include a Web browser, a terminal, a custom-designed GUI, or even a character-based user interface. Client-Server architecture was a major buzzword in the early 90's, taking initially dumb terminal applications and giving them a fancy windows-like front end, using PCs with terminal emulators which presented pretty GUIs (Graphical user interface) or later Visual Basic etc front-ends. A web browser talking to a web server is an example of a client talking to a server. Here there is presentation logic (presentation tier) happening at the client, and data/file access (data access tier) and logic happening at the server. One reason why the 2-tier model is so widespread is because of the quality of the tools and middleware that have been most commonly used since the 90’s: Remote-SQL, ODBC, relatively inexpensive and well-integrated PC-tools (like Visual Basic, Power-Builder, MS Access, 4-GL-Tools by the DBMS manufactures). In comparison the server side uses relatively expensive tools. In addition the PC-based tools show good Rapid-Application- Development (RAD) qualities i.e. simpler applications can be produced in a comparatively short time. The 2-tier model is the logical consequence of the RAD-tools’ popularity.
3 – Tier: Client Server
Browser based Interface html /xml J l
Win32 Client Applications (Vi l B i f )
Sql Server
Oracle RDBMS
Mail Server
File System
Business Layer
Data Service Layer
Presentation Layer
COM / COM +
COM / ASP
IIS / Apache
Business Rules and Process
HTTP
Fig Showing 3 – Tier or N- Tier Client Server Model
In a three-tiered application, the presentation services are responsible for gathering information from the user, sending the user information to the business services for processing, receiving the results of the business services processing, and presenting those results to the user. The most popular architecture on the web currently, mostly taking the form of web browser processing client side presentation in the form of HTML/DHTML, etc, the web server using some scripting language (ASP) and the database server (SQL Server for example) serving up the data.
The basic functionalities of 3 – Tier or N-Tier follows are
The presentation services tier is responsible for:
information started being available but with limited functionality. With the development of the Windows Distributed Internet Architecture, we started to see Web sites that allowed simple transactions to occur. Clients on browsers could access Web sites that had COM components available to them that allowed them to retrieve information from the database. So now we gained the capability to simulate the environment of the Win platform. The client software – the browser – can access information on a server. But as with the Win32 environment, we are limited in the way in which the information is presented to us. Customization is neither widespread nor broadly developed.
Let us look into limitations of these technologies.
Limitations in Win32 Clients
In a client-server environment visual tool such as Visual Basic, are often used to create a rich user interface. The drawbacks is that such client software is difficult to deploy and maintain, requiring and install on every client and a change to every client when an upgrade is needed.
DLL conflicts on the client are frequent because of variations in the version of the operating system and other software installed on the client.
Visual Basic is the most common language used to write middle-tier components. This requires high level of expertise in COM. Since these middle-tire components are implemented using Microsoft Transaction Server on Windows NT or COM+ services on Windows 2000. These components use stateless designs, which can look very different from the stateful designs often used in client-based components.
COM components, in the middle tier must work together, Versioning all the components properly so that they understand each other's interfaces can be a challenge. This requires a highly sophisticated skill level and a well - controlled deployment process.
COM works well on Microsoft platforms. But it suffers from lack of interoperability with other platforms. One of the most important ways functionality can be reused is for a software component to inherit another component, But COM does not support inheritance.
Visual Basic is the most popular language for developing applications with the DNA model, this is used in two major roles - forms based VB Clients and COM components. This VB6 language has its own limitations it doesn’t have the capability of multithreading, lack of OOPS concepts, Poor error handling ability and poor integration
with other languages. Hence it makes it unsuitable for development of object-based frameworks.
Today’s applications need to use the Win32 API for a variety of purposes like monitor widows messages, manipulate controls, reading and writing to INI files and socket programming etc. But these widows API are hard to program for variety of reasons, like it is not object oriented and complex calls to the functions with long lists of arguments, since Win32 API is written in C++ language, getting calling conventions right on data types is messy.
Limitations in DNA-Based Internet Development or Browser based clients
With DNA - based software development, creating software that is accessed by a user locally is done very differently from development for the Internet. The Visual Basic forms for client-server user interfaces versus the use of Active Server Pages for Internet user interfaces. Even though both situations involve designing and implementing GUI based user interfaces the tools and programming techniques used are quite different.
ASP lacks in state management between post backs. Every time a page is rendered, the programmer must make sure that all the visual controls like text boxes, dropdowns have their information loaded. It is the programmer's responsibility to manage the state in the user interface and to transfer state information between pages. This causes developers to have to write a lot of code for the internet user interfaces that is not relevant to business problem being solved.
If the Internet application is going to run on a group of Web Servers, then considerable additional work is necessary to design a state management system that is independent of particular server.
Browser based clients are somewhat more difficult to create, and offer a more limited user interface with fewer controls and less control over layout of the screen and handling of screen events. It is possible to create rich user interfaces using DHTML, but it requires lot of coding and also browser compatibility issues rises, for which a separate coding or two version of the same page have to be maintained, keeping in mind, the browser we are targeting.
The Internet has caused server-based applications to become much more popular than ever before and has made the connectionless request/response programming model common. But communicating between servers—especially among those running on different platforms—is difficult, and because most substantial Internet applications are Database-Centric, the ability to access a wide variety of data sources easily is more important than ever.