2. CLR
The Common Language Runtime (CLR) is a special run
time environment that provides the underlying infrastructure
for Microsoft's .NET framework.
This runtime is where the source code of an application is
compiled into an intermediate language called CIL (Common
Intermediate Language), 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
3.
4. Advantages
Portability
Using an intermediate language instead of compiling straight to
native code requires n + m translators instead of n*m translators
to implement it in n languages on m platforms.
Security
The high level intermediate code is more ready for deployment
and runtime enforcement of security.
Interoperability
Every major .NET language supports CLR and all get compiled
to CIL. In that intermediate language, implementation of services
such as security and garbage collection are the same.
5. This allows one library or application of one .NET language to
inherit implementations from classes written in another .NET
language.
This cuts down on the redundant code developers would have to
write to make a system work in multiple languages, allowing for
multi-language system designs and implementations.
Additionally, to keep full component interoperability, the runtime
incorporates all metadata into the component package itself,
essentially making it self-describing.
The main advantage of the .NET Framework is the
interoperability between different languages. As all the
Microsoft .NET languages share the same common runtime
language, they all work well together. For example, you can use
an object written in C# from Visual Basic.NET. The same applies
for all the other Microsoft .NET languages
6. Application related advantages
Automated Garbage Collection
Support for explicitly free threading, which
allows for the creation of multi-threaded,
scalable applications.
Support for uniform exception handling
Use of delegate functions instead of function
pointers for increased type safety and security.
7. MSIL
VB.Net compiles code which is processor
independent.
It is portable to n no of platforms.
This MSIL is then given as input to JIT
Compilers which converts it into
native(machine )code.
At the time of generation of MSIL code all
metadata(methods, properties, events,
data types) gets created.
8. JIT Compilers
Microsoft provides a set of JIT compilers
for each supported platform.
These compilers compile MSIL code into
native machine code.
Unlike traditional compilers JIT doesn’t
compile the full class file in one shot.
Compilation is done on function basis or
file basis.
9. The high level programming languages that need to be
compiled require a runtime, so that the architecture on which
the language runs is provided with details on how to execute
its code.
All the programming languages use its corresponding runtime
to run the application. For example, to run an application
developed using Visual Basic, the computer on which the
application will be run must be installed with the Visual Basic
runtime.
The Visual Basic runtime can run only the applications
developed with Visual Basic and not the ones developed with
any other programming language like Java.
10. In the .NET Framework, all the
Microsoft .NET languages use a common
language runtime, which solves the
problem of installing separate runtime for
each of the programming languages.
Microsoft .NET Common Language
Runtime installed on a computer can run
any language that is Microsoft .NET
compatible.
11. When you compile a Microsoft.NET
language, the complier generates code
written in the Microsoft Intermediate
Language (MSIL). MSIL is a set of
instructions that can quickly be translated into
native code.
A Microsoft.NET application can be run only
after the MSIL code is translated into native
machine code. In .NET Framework, the
intermediate language is complied "just in
time" (JIT) into native code when the
application or component is run instead of
compiling the application at development
time.
12. Compilation
Execution
Compilation & Execution Cycle of .Net application
13. Types of JIT
Pre-JIT :
Per-JIT compiler compiles source code into native code in a
single compilation cycle.
Econo- JIT: Econo-
JIT compiles methods that are called at runtime. However,
these compiled methods are discarded when they’re not
required.
JIT (Normal JIT) –
They’re called “JIT” or “Normal JIT”. Normal JIT only compiles
the methods which are called at runtime.
These methods are compiled the first time they’re called and
then they’re stored in cache. When the same methods are
called again, the compilation code from cache is used for
execution.
14. Managed Code
Managed Code is what Visual Basic .NET and C#
compilers create.
It compiles to Intermediate Language (IL), not to
machine code that could run directly on your
computer.
The IL is kept in a file called an assembly, along
with metadata that describes the classes,
methods, and attributes (such as security
requirements) of the code
This assembly is the one-stop-shopping unit of
deployment in the .NET world.
You copy it to another server to deploy the
assembly there—and often that copying is the only
step required in the deployment.
15. Managed code runs in the Common Language
Runtime. The runtime offers a wide variety of
services to your running code.
In the usual course of events, it first loads and
verifies the assembly to make sure the IL is okay.
Then, just in time, as methods are called, the
runtime arranges for them to be compiled to
machine code suitable for the machine the
assembly is running on, and caches this machine
code to be used the next time the method is
called. (This is called Just In Time, or JIT
compiling, or often just Jitting.)
As the assembly runs, the runtime continues to
provide services such as security, memory
management, threading, and the like. The
application is managed by the runtime
16. Unmanaged code
It is what you use to make before Visual Studio
.NET 2002 was released.
Visual Basic 6, Visual C++ 6, heck, even that 15-
year old C compiler produced unmanaged code.
It compiled directly to machine code that ran on
the machine where you compiled it—and on other
machines as long as they had the same chip, or
nearly the same.
It didn't get services such as security or memory
management from an invisible runtime; it got them
from the operating system, usually by calling an
API provided in the Windows SDK.
17. System Types
System class library
.Net Framework Class Library
It is a library of classes, interfaces and value
types .
It optimizes the development process, provides
access to system functionality .
It is designed to be as a foundation on which
.Net framework applications, components and
controls are built.
18. FCL is an integral component of the .NET framework.
It consists of object oriented collection of reusable
classes that can be used to develop command line, GUI,
web applications etc.
It is designed into a hierarchical tree structure & divided
into namespace.
Before .Net class framework, each programming
required its own class libraries.
All .Net languages share the .Net class framework
requiring no special language specific libraries.
Syntax used to perform the task between .Net languages
looks the same as the same namespace & parameters is
to be used.
19. The .Net framework class library is divided into 2 parts
Base class library
Framework class library.
Base class library
It includes a small subset of the entire class library & is the core
set of classes that serve as the basic API of the common
language runtime.
The classes in mscorlib.dll , system.dll & system.core.dll are
consiered as part of BCL.
Framework class library
It is a superset of the BCL classes & refers to the entire class
library that ships with .Net framework.
It includes winforms, ADO.Net, ASP.Net etc.
20. Namespaces in vb.net
System: Includes essential classes and base classes for commonly
used data types, events, exceptions and so on
System.Collections: Includes classes and interfaces that define
various collection of objects such as list, queues,
hash tables, arrays, etc
System.Data: Includes classes which lets us handle data from data
sources
System.Data.OleDb: Includes classes that support the OLEDB .NET
provider
System.Data.SqlClient: Includes classes that support the SQL
Server .NET provider
System.Diagnostics: Includes classes that allow to debug our
application and to step through our code
System.Drawing: Provides access to drawing methods
21. System.Globalization: Includes classes that specify culture-related
information
System.IO: Includes classes for data access with Files
System.Net: Provides interface to protocols used on the internet
System.Reflection: Includes classes and interfaces that return
information about types, methods and fields
System.Security: Includes classes to support the structure of
common language runtime security system
System.Threading: Includes classes and interfaces to support
multithreaded applications
System.Web: Includes classes and interfaces that support browser-
server communication
System.Web.Services: Includes classes that let us build and use
Web Services
System.Windows.Forms: Includes classes for creating Windows
based forms
System.XML: Includes classes for XML support
22. System.object class
It is the base class of all classes in the .Net framework.
It is the root of the type hierarchy.
Name Description
Determines whether the specified
Equals(Object)
Object is equal to the current Object.
Determines whether the specified
Equals(Object, Object)
object instances are considered equal.
Allows an object to try to free
resources and perform other cleanup
Finalize
operations before it is reclaimed by
garbage collection.
23. Serves as a hash function for a
GetHashCode
particular type.
GetType Gets the Type of the current instance.
Creates a shallow copy of the current
MemberwiseClone
Object.
Determines whether the specified
ReferenceEquals Object instances are the same
instance.
Returns a string that represents the
ToString
current object.
24. Common type system
With common type system all data types are provided as objects in
the System.object class.
This class is accessible by all .Net programming languages &
enforced by CLR.
Also previously type conversions needed to be performed every
time when data was exchanged.
With the CTS, it is no longer necessary to cast data types between
assemblies that are written in different languages.
CTS provides a new standard for .Net assemblies called as type
safe compatibility.
To achieve type safe compatibility, some languages have to adjust
their data type.
Language interoperability is achieved with the help of CTS.
Same data type is available in all .Net compatible languages.
25. Classification of CTS Types
Value types
It directly contain the data that you assign them.
Value types are fixed in size.
Actual values of data are stored in stack.
If you assign a value of a variable to another it will create two
copies.
All primitive data type except string and object are example of
value types. struct and enum are value type.
Reference type
Reference types are not fixed in size.
It directly do not contain any data.
It point to a memory location that contains the actual data.
They are maintained in system managed heap but it also uses
stack to store reference of heap.
26. Two primitive types (string and object) and non-primitive data
types (class, interface & delegate) are examples of reference
type.
27. Basic Value types
VB Keyword Bytes .NET type Description
Byte 1 Byte 0-255
SByte 1 SByte -128 to 127
Short 2 Int16 -32,768 to
+32,767
UShort 2 UInt16 0 to 65535
Integer 4 Int32 -2,147,483,648
to +
2,147,483,647
UInteger 5 UInt32 0 to
4,294,967,295
Long 8 Int64 -9,223,372,036,
854,775,808 to
+9,223,372,036
,854,775,807
28. ULong 8 UInt64 0 to
+18,446,744,
073,709,551,
615
Single 4 Single A non integer
number with
approximately
7 significant
digits
Double 8 Double A non integer
number with
approximately
14 significant
digits
29. Decimal 16 Decimal A non integer
number with
approximately
28 significant
digits (integer
and fraction)
that can
represent values
up to 79,228 X
1024
Char 2 Char A single Unicode
character
Boolean 1 Boolean A True or False
value