DIT 006-Introduction to Visual Basic .
NET framework
Chapter One: Introduction to .NET framework Before emergency of .NET framework, programmers used a
1.1 Chapter objectives number of tools to write programmers as depicted before
By the end of this, learners should be able to: ▪ Windows GUI development: Win32 API, MFC, Visual
i). Have thorough understanding of problems programmers ▪ Basic, COM
faced before emergency of .NET framework ▪ Web development: ASP
▪ Java – “Write once, run anywhere.”
ii). Understand how the .NET framework works
▪ Embrace and extend: Visual J++
iii). Understand the role of major components of the .NET
However, all those environments had a number of limitations
framework
as discussed below
iv). Understand how .NET framework provides support for
multi-language 1.2.1 Life As a C/Win32 API Programmer
v). Understand how compilation is done by .NET framework It’s the traditional software development for the Windows. It has
vi). Understand the differences/similarities between J2EE a number of limitations such as
and .NET architectures
✓ C developers are forced to contend with complex
1.2 Life before .NET programming memory management and pointer arithmetic.
1
Edward Kioko|Email:-kioko@[Link]|Mobile number: +725-695-782| © 2020
DIT 006-Introduction to Visual Basic .NET framework
✓ It lacks the benefits provided by the object-oriented (wizards).
approach
However, C++ remains a difficult and error-prone experience.
When programmers combine the thousands of global functions
1.2.3 Visual Basic 6.0 Programmer
and data types defined by the Win32 API to an already
VB 6.0 has ability to build complex user interfaces, code
challenging language, the end result is so many buggy
libraries, and data access logic with minimal hassle and bother.
applications floating around today.
It hides the complexities of the raw Win32 API from view using
1.2.2 Life As a C++/MFC Programmer
integrated code wizards, intrinsic data types, classes, and VB-
C++ is an object-oriented layer on top of C which means specific functions.
programmers can benefit from the famed “pillars of OOP”
(encapsulation, inheritance, abstraction and polymorphism).
However, VB 6.0 is not fully object-oriented e.g. there no
Microsoft Foundation Classes (MFC) provides a set of C++
classical inheritance. Its also impossible to do multithreaded
classes that facilitate the construction of Win32 applications. applications unless you are willing to drop down to low-level
Win32 API calls (which is complex at best and dangerous at
C++ combines the difficult raw Win32 API behind a number of
worst).
classes, magic macros, and numerous code-generation tools
2
Edward Kioko|Email:-kioko@[Link]|Mobile number: +725-695-782| © 2020
DIT 006-Introduction to Visual Basic .NET framework
1.2.4 Life As a Java/J2EE Programmer Component Object Model (COM) is Microsoft’s previous
application development framework which enabled
Java is a pure Object oriented with syntactic roots in C++. It
programmers reuse binary code.
cleans up many unsavory syntactical aspects of C++ a well as
providing programmers with a large number of predefined C++ programmers can build COM classes that can be
“packages” that contain various type definitions. used by VB6. Delphi programmers can use COM classes
built using C.
However, java has a number of limitations such as limited It has a number of challenges such as language independence
ability to access non-Java APIs, little support for true cross- is limited, doesn’t support for classical inheritance) and its
language integration and it’s not appropriate for many extremely complex under the hood.
graphically or numerically intensive
However, The Active Template Library (ATL) provides a set of
applications. C++ classes, templates, and macros to ease the creation of
1.2.5 Life As a COM Programmer COM types.
1.2.6 Windows DNA Programmer
Microsoft corporation has been adding more Internet-aware
3
Edward Kioko|Email:-kioko@[Link]|Mobile number: +725-695-782| © 2020
DIT 006-Introduction to Visual Basic .NET framework
features into its family of operating systems and products. 1.3 .Net framework
NET is a framework and not a programming language that
COM-based Windows Distributed internet Applications
provides is a New programming methodology/framework
Architecture (DNA) is quite complex since Windows DNA
developed by Microsoft in June 2000. Its platform independent /
requires the use of numerous technologies and languages
cross platform as well as language-insensitive.
(ASP, HTML, XML, JavaScript, VBScript, COM(+), and data
access API like ADO).
.NET is an Integrated environment which allows programmers
to build Networked Applications, Distributed Web Services, Web
The result of the above is completely unrelated syntaxes e.g. Applications, mobile applications, Desktop based applications
JavaScript has a syntax much like C, while VBScript is a subset within Microsoft environment. It’s consistent object-oriented
of VB6 which results to a highly confused mishmash of providing a portable as well as managed environment
technologies. Each language and/or technology has its own type
system e.g. An “int” in JavaScript is not quite the same as an It provides tools and technologies necessary compile time and
“Integer” in VB6. The rescuer is Microsoft .NET framework runtime foundation to build and run any language that conforms
to the Common Language Specification (CLS)
4
Edward Kioko|Email:-kioko@[Link]|Mobile number: +725-695-782| © 2020
DIT 006-Introduction to Visual Basic .NET framework
iii. The framework has also been motivated by other
factors such as Object-oriented programming,
compile once and run everywhere and Service-
Oriented Application .
.NET framework is built upon open standard technologies like
XML and SOAP and is towards more open standards rather than
Fig:[Link] is cross platform
Microsoft its proprietary tendencies. It offers a fundamental shift
.NET is motivated by a number of factors such as in Microsoft strategy by moving application development from
i. popularity of electronic devices meaning it’s capable of client-centric to server-centric.
providing interaction between wide varieties of devices
such as cell phones, Personal Digital Assistants, .NET framework offers programmers with a number of services
Personal computers e.t.c such as
ii. it has also been motivated by the fact that
i). Independence from specific language or platform
communication between programs can occur despite
meaning that applications can be written in any .NET
the disparate languages
compatible language e.g. [Link], Visual C++ .NET, C#.
This gives programmers flexibility to contribute to
5
Edward Kioko|Email:-kioko@[Link]|Mobile number: +725-695-782| © 2020
DIT 006-Introduction to Visual Basic .NET framework
applications development using the language in which
they are most competent
ii). The framework also allows programmers to run .NET
managed code in a virtual machine (Common Language
Runtime).
iii). It also provides a very good environment to develop
networked applications and Web Services
iv). Provides programming API and unified language
independent development framework
1.4 Components of .NET framework
The main two components of .Net Framework are Common Fig 1.1:-NET architecture
1.4.1. Common Language Runtime (CLR)
Language Runtime (CLR) and .Net Framework Class Library
(FCL) which provides a core services such as [Link], It’s the engine behind the .NET framework that handles
windows, [Link], windows forms, XML support [Link]
execution of all managed application code. It works as a
mediator between Operating Systems and the applications
written in .Net languages that conforms to the Common
6
Edward Kioko|Email:-kioko@[Link]|Mobile number: +725-695-782| © 2020
DIT 006-Introduction to Visual Basic .NET framework
Language Specification (CLS). 11) Interoperation between managed code, COM objects
Some of the services provided CLR include: and pre-existing DLLs (unmanaged code and data)
1) Code management (loading and execution) 12) Automation of object layout
2) Application memory isolation 13) Support for developer services (profiling, debugging,
etc.)
3) Garbage collection
1.4.2. . Net Framework Class Library (FCL)
4) Verification of type safety
FCL is a huge collection of language-independent and type
5) Thread execution
safe reusable classes, interfaces and values that expedite and
6) Conversion of IL to native code
optimize the development process and provide access to
7) Access to metadata (enhanced type information) system functionality. The libraries are arranged into a logical
8) Managing memory for managed objects
grouping according to their functionality and usability is called
9) Enforcement of Code Access Security Namespaces.
10) Exception handling including cross language FCL provides the consistent base types that are used across
exceptions all .NET enabled languages. The Classes are accessed by
7
Edward Kioko|Email:-kioko@[Link]|Mobile number: +725-695-782| © 2020
DIT 006-Introduction to Visual Basic .NET framework
namespaces, which reside within Assemblies. The System ▪ Window forms
Namespace is the root for types in the .NET Framework. It’s a framework used to design rich clients for windows
platform can be done using Windows Forms which offers
Key services provided by the FCL include
programmers with RAD (Rapid Application Development),
▪ [Link] (Active Server Pages)
Rich set of controls, Data aware, ActiveX Support, licensing,
It provides the core Web infrastructure such as Web Forms for
Accessibility, Printing support, Unicode support, UI
UI based development and Web Services for programmatic
inheritance
interface development. It’s a super set of what developers
▪ Active Data Object ([Link])
already know as Active Server Pages, with some key
[Link] is an evolution of ADO to provide
advantages: since it runs inside the CLR, it supports any
functionality for data access. The [Link] has much richer
language that runs in the CLR, expanding from VBScript and
support XML
Jscript. Also, it provides numerous new services, like cache
▪ Core base classes
management, cluster-ready session management, cookie-less
They provide infrastructure services such as security,
sessions, browser version-based automatic code generation,
transaction management etc.
among other things
8
Edward Kioko|Email:-kioko@[Link]|Mobile number: +725-695-782| © 2020
DIT 006-Introduction to Visual Basic .NET framework
1.5 Compilation in .NET C# compiler e.t.c) converts the source code to an intermediate
Applications developed in the .NET platform don’t directly language code which is known as IL code or Microsoft
interact with the OS but rather, they talk to the CLR and the Intermediate Language (MSIL) or Common Intermediate
CLR manages/handles the execution of the applications. Language (CIL) which is a CPU independent set of
instructions that can be converted to the native code. IL code is
used as the output of a number of compilers and as the input to
a CLR JIT compiler.
The CLR has a number of Just in Time (JIT) compiler each
working on a different architecture depending on the operating
system. The JIT converts the MSIL code into native code to
Fig 1.4: .NET applications which is Operating System specific, the overall effect being the
same IL code being able to run on different OS. There is some
When we write a program using any of the .NET languages like
initial performance cost, but the jitted code is cached for further
C#, VB or C++, the source code doesn’t get compiled to
execution. A big advantage is CLR can target the specific
machine code. Each language specific compiler (VB compiler,
9
Edward Kioko|Email:-kioko@[Link]|Mobile number: +725-695-782| © 2020
DIT 006-Introduction to Visual Basic .NET framework
architecture in which the code is executing, so some 7. JIT allows the IL code to be hardware independent.
performance gains are possible. 8. CLR also allows for enforcement of code access
security.
During compilation, metadata is always generated and stored 9. Verification of type safety.
with the compiled code in a file known as manifest which 10. Access to Metadata (enhanced Type Information)
contains information about the members, types, references and 1.7 NET compliant Languages
all the other data that the Common Language Runtime Some of the languages supported by Microsoft include [Link],
C++, C#, J#, Jscript, Visual C++. However, there are some third-
1.6 Advantages associated with CLR execution
parties’ languages such as APL, COBOL, Pascal, Eiffel,
Some of the advantages associated with CLR execution Haskell, ML, Oberon, Perl, mercury Python, Scheme,Oz,APL,
includes
CAML,Scheme, Smalltalk e.t.c
1. Support for developer services (debugging)
1.8 Common Language Infrastructure (CLI)
2. Interoperation between managed code and unmanaged
code (COM, DLLs). CLI allows for cross-language development.
3. Managed code environment
4. Improved memory handling
5. Improved “garbage collection”
6. JIT allows code to run in a protected environment as
managed code.
10
Edward Kioko|Email:-kioko@[Link]|Mobile number: +725-695-782| © 2020
DIT 006-Introduction to Visual Basic .NET framework
CLI uses three major mechanism to enable .NET support more
than one programming languages i.e.
i). Common Type System (CTS)
ii). Common Language specification (CLS)
iii). Intermediate Language code (IL code)
1.7.1 Common Type System (CTS)
CLR defines a CTS, which is a standard type system used by all
.NET languages meaning that all .NET compliant languages use
the same representation for common data types. All .NET
languages have the same primitive data types. For example, an
int in C#.NET is the same as an int in [Link]. When
communicating between modules written in any .NET language,
the types are guaranteed to be compatible on the binary level
Fig 1.8:- CLI infrastructure
11
Edward Kioko|Email:-kioko@[Link]|Mobile number: +725-695-782| © 2020
DIT 006-Introduction to Visual Basic .NET framework
1.7.3 Common Language Specification (CLS)
Not all languages support all CTS types and features e.g.
• C# is case sensitive, [Link] is not
• C# supports pointer types (in unsafe mode), [Link]
does not
• C# supports operator overloading, [Link] does not
CLS was drafted to promote language interoperability. It’s a set
of specifications that all languages and libraries need to follow.
Fig 1.9: CTS data types
Any language that conforms to the CLS is a .NET language and
1.7.2 Intermediate Language (IL/MSIL)
it has the ability to take full advantage of FCL. This will ensure
.NET languages are not compiled to machine code. They are
interoperability between languages.
compiled to an Intermediate Language (IL). CLR accepts the IL
Some of those rules and standards imposed by CLR for example:
code and recompiles it to machine code.
The recompilation is just-in-time (JIT) meaning it is done as soon 1. Object declaration, creation and use
as a function or subroutine is called. The JIT code stays in
2. Data types, language libraries
memory for subsequent calls. In cases where there is not
3. Error and exception handling
enough memory it is discarded thus making JIT process
interpretive. 4. Interactive Development Environment (IDE)
12
Edward Kioko|Email:-kioko@[Link]|Mobile number: +725-695-782| © 2020
DIT 006-Introduction to Visual Basic .NET framework
1.9 Comparison & contrast of .NET & J2EE Architecture machine. Can also support other platforms provided it
has its own JIT complier.
We compare the two frameworks from the following
perspectives
▪ Language support
▪ Execution Engine
❖ J2EE-Tied to Java but supports other languages via
❑ J2EE-Java source code compiles into machine- interface technology
independent byte code. The Runtime Environment
is Java Virtual Machine (JVM) ❖ .NET-its Language independent supporting any
language if mapping exists from that language to IL
❑ .NET-Any compliant language compiles into
MSIL/IL/CIL. The Runtime environment is ▪ Tools support
Common Language Runtime( CLR)
❖ J2EE-there are many IDE for programming in Java e.g.
Both JVM and CLR support services, such as code
NetBeans, eclipse, blueJ,Jcreator,JDeveloper, android
verification, garbage collection, and code security.
studio
▪ Cross platform portability
❖ .NET-supports only one IDE for writing the code i.e.,
❑ J2EE- its platform Independent but Java visual studio.
Development Kit (JDK) should exist on target
1.8 Chapter summary
machine
1.9 Chapter exercise
❑ .NET-Supports Windows platform but Common
1.10 Further reading suggestions
Language Runtime (CLR) should exist on target
13
Edward Kioko|Email:-kioko@[Link]|Mobile number: +725-695-782| © 2020