Visual Programming
Visual Programming
.NET Framework
Programmer can choose from a various programming language available on the .NET
platform. The most common ones are VB.NET and C#.NET.
Features of .NET
1. Platform Independent
It automatically manages the resources (file, memory, database etc). In .NET we have
garbage collector that periodically checks for unused objects (memory space) in
our code, and automatically free up that space if it is no longer needed in the
program.
Exception Handling - Exceptions are errors which occur when theapplication is executed.
Examples of exceptions are:
✓ If an application tries to open a file on the local machine, but thefile is not
present.
✓ If the application tries to fetch some records from a database, butthe
connection to the database is not valid.
A File handle which is no longer required. If the application has finished alloperations on a file,
then the file handle may no longer be required.
2. Class Library
The .NET Framework includes a set of standard class libraries. A class library is a
collection of methods and functions that can be used for the corepurpose.
For example, there is a class library with methods to handle all file-level operations. So,
there is a method which can be used to read the text from a file. Similarly, there is a
method to write text to a file.
3. Language
The types of applications that can be built in the .Net framework is classified broadly into the
following categories.
ASP.Net – This is used for developing web-based applications, which are made to run
on any browser such as Internet Explorer, Chrome or Firefox.
The Web application would be processed on a server, which would have Internet
Information Services Installed.
The result of the execution is then sent to the client machines, and the outputis shown in
the browser.
MSIL
A .NET programming language (C#, VB.NET, J# etc.) does not compile into executable code;
instead, it compiles into an intermediate code called Microsoft Intermediate Language (MSIL).
As a programmer one need not worry about the syntax of MSIL - since our source code in
automatically converted to MSIL. The MSIL code is then send to the CLR (Common Language
Runtime) that converts the code to machine language which is then run on the host machine.
Once we have compiled our code to MSIL CLR accept the MSIL code then again recompilation
is done CLR containsJIT(Just in time) compiler to recompiled MSIL code into native code. MSIL
is similar to Java Byte code. A Java program is compiled into Java Byte code (the .class file)
by a Java compiler, the class file is then sent to JVM which converts it into the host machine
language.
CLR
JIT
Native
Compil
Sourc e Code /
MSIL Compile
Machin OUTPUT
e
eCode
Code
CLR is the heart of .NET framework. CLR is similar to the JVM(Java Virtual
Machine) in java. Whenever we write code that code is converted into intermediate
language after first compilation. And this intermediate language is executed on
CLR(Common Language runtime).So, we need CLR to execute the intermediate
language. Also, whole program is monitored by CLR.
Components of CLR
As name signify code manager means managing code. Code manager manage code
during execution i.e., when we run our code. It also allocates memory to objects.
2. Type Checker
As name signify type checker means checking type but which type. It checksdata type of
variable. For example, we declare a variable as follows:
Dim a As IntegerDim b as
DoubleDim c as String
So, checking data type of these variables a, b and c is taken care by type checker.
3. Debug Engine
Debugging means finding the errors. Debug engine find and remove the bugs(errors) into
the code.
4. Class Loader
Class loader loads data in runtime. We can say that class loader loads all
libraries(collection of classes, methods, functions, interfaces) which are associated in the
intermediate language code.
5. Exception Manager
Errors are classified into two categories
1. Compile-Time errors
2. Run-Time errors
All the syntax error done in program i.e., mistakes that is done duringdeveloping or typing
program is called compile-time error.
Sometimes program run successfully but it terminated or may cause systemto crash i.e.,
logically program is correct but error comes during execution
of program called run time error. So, to manage the normal flow of program cause by
run time error CLR contains exception manager. Ex : Division by 0.
It manages the exception in both managed and unmanaged code.
* Note :
1. Whenever user convert source code to the intermediate language this is the
managed code.
2. Whenever user convert source code directly to machine code this is
unmanaged code.
6. Thread support
When user open multiple independent program (like Game, Music app, paint app) on
window called as multiprogramming.
When user open multiple tabs on let’s say in browser (google chrome) whichmeans same
type of tasks perform together (like opening Gmail, Facebook, translator etc ) called
multithreading. So, .NET supports thread which meansmultiple application can be created
at a same time on same environment.
7. Security checker
When an application has database where all files of user are saved like some user id,
passwords etc. and that data cannot be access by outside world. So, that task is of security
checker which resources should be access by which user i.e., anybody cannot access
everything.
8. Garbage collector
In .NET we have garbage collector that periodically checks for unused objects
(memory space) in our code, and automatically free up that space if it is no longer needed
in the program.
CTS
CTS stands for Common type System. It deals with the data type. So here we have several
languages and each and every language has its own data type and one language data type
cannot be understandable by other languages but .NET Framework language can
understand all the data types.C# has an int data type and VB.NET has Integer data type.
Hence a variable declared as an int in C# and Integer in VB.NET, finally after
compilation, uses the same structure Int32 from CTS.
Languag Datatyp
e CLR Datatype
e
int C#
C#.NET compiler
Int32
VB.NET compiler
VB.NET intege
r
CLS
CLS stands for Common Language Specification and it is a subset of CTS.It defines a
set of rules and restrictions that every language must follow which runs under the .NET
framework. The languages which follow these set of rules are said to be CLS Compliant.
In simple words, CLS enables cross-language integration or Interoperability.
For Example
10
if we talk about C# and VB.NET then, in C# every statement must have to end with a
semicolon. It is also called a statement Terminator, but in VB.NET each statement should
not end with a semicolon(;).
So, these syntax rules which you have to follow from language to languagediffer but CLR
can understand all the language Syntax because in .NET eachlanguage is converted into
MSIL code after compilation and the MSIL codeis language specification of CLR.
The MSIL is the language that all of the .NET languages compile down to. After they are
in this intermediate language, a process called Just-In-Time (JIT) compilation occurs
when resources are used from your application at runtime. JIT allows “parts” of your
application to execute when they are needed, which means that if something is never
needed, it will never compiledown to the native code. By using the JIT, the CLR can cache
code that is used more than once and reuse it for subsequent calls, without going through
the compilation process again.
11
verification, the code is examined to ensure that it is not corrupt, it is type safe, and the
code does not interfere with existing security policies that are in place on the system.
Namespaces
Namespaces help you to create logical groups of related classes and interfaces that can
be used by any language targeting the .NET framework. Namespaces allow you to
organize your classes so that they can be easily accessed in other applications.
Namespace can also be used to avoid any naming conflicts between classes that have the
same names. For example, you can use two classes with the same name in an application
provided theybelong to different namespaces. You can access the classes belonging to a
namespace by simply importing the namespace into an application. The
.NET framework uses a dot (.) as a delimiter(separator) between classes and
namespaces.
Ex. import System.Windows.Forms represents the windows form button class of the
System namespace.
System is the basic namespace used by every .NET code. There are lots of namespace
user the system namespace.
For example,
System.IO,
System.Net,
System.Collections,
System.Threading,
System.Drawing, etc.
12
Button class
namespaces are :
System: Includes essential classes and base classes for commonly used data
types, events, exceptions and so on.
13
User can define own namespace as follows :
Namespace namespaceName
Syntax :
Namespace Namespace1
class code
End Class
End Namespace Ex
Namespace College
Namespace students
imports System
Class Addstudents
End Function
End Class
End Namespace
End Namespace
14
add new students in college. In this way we create an hierarchy of namespace
and create class. This namespace we can import and reuse in any other
application.
Garbage Collection
✓ Reclaims objects that are no longer being used, clears their memory,and
keeps the memory available for future allocations. Managed objects
automatically get clean content to start with, so their constructors don't haveto
initialize every data field.
✓ Provides memory safety by making sure that an object cannot use the
content of another object.