.NET
.NET (Pronounced dot net) is a framework from Microsoft , that provides a programming platform which can be used to develop a wide range of applications––– from Web to Mobile to Windows-based applications (It is not a programming language by itself).
Framework
Infrastructure -> Transportation, Building, Chemistry Lab, Physics Lab, Thermodynamics, Library, Electricity, Internet, Lift
University - > School of Engineering, School of Education, School of Arts, School of Law, School of Management, School of medical science.
.NET Framework
A programming infrastructure created by Microsoft for building, deploying and running following applications.
- Console Applications (cmd)
- Windows Applications (Notepad, Paint, Photoshop, MS - Word)
- Windows Services (Services.msc)
- Web application (stackoverflow.com, bing.com)
- Mobile application
Once a framework is installed in the machine, we can continue the application development instead of developing from the scratch.
Suppose you want to construct a building.
Option 1: We can build from the scratch (we need more time, we need more money, and we need more man power).
Option 2: I will give you ready made foundation with 1st floor, you can implement from second floor onwards.
.NET Framework is like second option.
It is very easy to develop application using .NET because of 2 features:
- .NET Framework
- Visual Studio
Features of .NET Technology
- Language independent
- Language interoperability
- Platform independent
- Garbage Collection (Memory management)
- Version compatibility
- Easy deployment
1. Language independent
.NET is not dependent on only one language. It supports more than 30+ programming languages like
- C, C++ => C#.NET
- VB => VB.NET
- Java => J#.NET
- VC++ => VC++.NET
- Classic ASP => ASP.NET
- Cobol => cobol.net,
- Pascal => pascal.net
2. Language interoperability
.NET allows the developers to write different parts of the project in different languages. The IL (Intermediate Language) code generated from one .NET language can be reused in any other .NET languages. This is known as language interoperability.
For example:
First module in C#.net (C#.NET code --- >(csc)--- > MSIL)
Second module in vb.net (VB.NET code --- >(vbc)--- > MSIL)
We can combine both modules as a single application.
C#.NET code is converted into intermediate language code using CSC (C Sharp compiler) and VB.NET code is converted into intermediate language using vbc (Visual Basic Compiler).
3. Platform independent
Platform independent means compile the code in one platform and run it in any platform.
Is .NET platform independent?
It is partially platform independent because it supports only few operating systems like windows, LINUX and Mac.
Whenever a program runs on all the operating systems, we should say it is “platform independency”.
Whenever a program runs on single operating systems, we should say it is “platform dependency”.
Whenever a program runs few operating systems, we should say it is “partial platform independency”.
4. Garbage Collection
Garbage collection is the process of removing unwanted resources when they are no longer required.
This is the .NET method of making sure that the memory used by an application is freed up completely when the application is no longer in use.
Prior to .NET this was mostly the responsibility of programmers, and a few simple errors in code could result in a progressive slowdown of your computer followed by a system crash.
Examples of garbage collection are
• A File handle which is no longer required: If the application has finished all operations on a file, then the file handle may no longer be required.
• The database connection is no longer required: If the application has finished all operations on a database, then the database connection may no longer be required.
.NET garbage collection works by inspecting the memory of your computer every so often and removing anything from it that is no longer needed.
Garbage = the variable that are created within the program.
Variable a,b,c; c=a+b;
c, c++ = Manual garbage collection.
.NET = Automatic Garbage Collection (At the end of .net program, .net automatically deletes all the variables that are created within the program.)
5. Version compatibility
Applications that are developed by using a particular version of the .NET Framework can run without modificaiton on a later version.
6. Easy deployment
The .NET Framework provides easy deployment of applications by installing new applications or components that do not have an adverse effect on the existing applications.
.NET Framework Architecture
.NET Languages
These are the programming languages we use to develop our application. We can choose between any languages as per our comfort. All the languages have the full access to .NET framework. However some .NET features are specially design for C#.
Common Language Specification
CLS stands for Common Language Specification and it is a subset of CTS.
The common language specification (CLS) is a collection of rules and guidelines for languages to follow so that code written in one .NET language can be used by another .NET language (i.e., language interoperability). Informally CLS is a simply a contract between programming language designers and class library authors.
It was always a dream of Microsoft to unite all different languages into one umbrella and CLS is one step towards that.
Example of rules
- One rule is that we cannot have member with same name with case difference only i.e., we should not have add and Add(). This many work in C# because it is case sensitive but if try to use that C# code in VB.NET, it is not possible because VB.NET is not case sensitive.
- One another rule is that you cannot use multiple inheritance within .NET Framework. AS you know C++ supports multiple inheritance but, when you will try to use that C++ code within C#, it is not possible because C# doesn't support multiple inheritance.
- C# uses + for concatenation whereas VB.NET uses &.
- C# allows operator overloading but VB .NET does not.
Common Type System (CTS)
Common Type System ensures that data type defined in two different languages get compiled to a common data type so that code written in one .NET language can be used by another .NET language. 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).
Example:
When we declare an int data type in C# and integer data type in VB.NET then they are converted to system int32. These types can be Value Types or Reference Types.
Example of rules
Value Types:
Value types will directly store the value directly into the memory location. These types work with stack mechanism only. CLR allocates memory for these at Compiler Time.
Reference Types:
Reference Types will contain a memory address of value because the reference types won't store the variable value directly in memory. These types work with Heap mechanism. CLR allocates memory for these at Runtime.
.NET Framework class library
.NET Framework Class Library (Base Class Library) is the collection of classes, namespaces, interfaces and value types that are used for .NET applications. It can be used for developing applications such as console application, Windows forms, Web forms, Windows and Web services etc. Developers just need to import the Base Class Library (BCL) in their language code and use its predefined methods and properties to implement common and complex functions like reading and writing to file, graphics rendering, database interaction, and XML document manipulation.
Common Language Runtime (CLR)
The key component of Microsoft .NET Framework is CLR.
It is the run-time environment in the .NET Framework that runs the codes and helps in making the development process easier by providing following additional services.
- Memory management
- Garbage collection
- Thread management
- Security
- Type safety
- Exception handling
- Memory management
Programmer need not to worry about on managing the memory if the programs are running under the CLR as it provides memory management. Programmatically, when our program needs memory, CLR allocates the memory.
- Garbage Collection
Garbage Collection automatically release memory of unused objects in an application and can be done by CLR.
- Thread management
The execution of code in parallel is called Threading and threads are responsible for multitasking that runs under CLR.
- Security
CLR enforces security permissions at code level security, folder level security, and machine-level security.
- Type safety
Type Checkers like CLS or CTS will verify types used in the application standards supported by CLR, this provides type safety. The MSIL code which is compiled output of the written code in any language supported by .NET Framework is same at this stage.
- Exception handling
When an exception occurs in a program, the .NET framework runtime handles the problem by creating an exception object, populates it with information related to the error.
Compilation & Execution Process in .NET Framework
MSIL (Microsoft Intermediate Language)
When you compile code that uses the .NET Framework library, you don’t immediately create operating system – specific native code. Instead, you compile your code into Microsoft Intermediate Language (MSIL) code.
MSIL is not directly executable code. It is neutral to every operating system and not representing to any operating system including windows operating system where we have used windows operating system for compilation process.
JIT (Just in Time)
Our code gets compiled two times. On the first pass, it is compiled from higher language (like C#, VB.NET) to MSIL (Microsoft Intermediate Language) by CSC (C# Compiler) or VBC (VB.NET Compiler). On the second pass, the MSIL code is compiled into native code / machine language by CLR which is understandable by the operating system. Only at this point can the OS execute the application. This process is called Just-In-Time JIT compilation because it does not occur until the assembly is on the target machine.
Three types of JIT compiler
1. Pre-JIT compiler
Pre-JIT compiles complete source code into native code in a single compilation cycle.
2. Econo-JIT compiler
Econo-JIT compiles only those methods that are called at runtime. However, these compiled methods are removed from cache when they are not required.
3. Normal-JIT compiler
Normal-JIT compiles only those methods that are called at runtime. When the same methods are called again, the compiled code from a cache is used for execution.
In the past, it was often necessary to compile your code into several applications, each of which targeted a specific operating system. This is now unnecessary, because JIT compilers (as their name suggests) use MSIL code, which is independent of the machine, operating system, and CPU. The beauty of all this is that it requires a lot less work on your part – in fact, you can forget about system – dependent details and concentrate on the more interesting functionality of your code.
Assume that you have developed dot net application on windows OS using windows specific dot net framework. If you want to execute this application on Linux machine then you have to install Linux specific dot net framework on this Linux machine (you can get Linux Specific dot net framework from mono projects). For UNIX platform, you should have Unix-type of CLR.
IDE (Integrated Development Environment)
An integrated development environment (IDE) is a software application that provides facilities to computer programmers for software development.
Usually, Integrated Development Environment software is very user-friendly software along with easy-to-use interface, which provides suggestions for syntaxes for programmers, provides IntelliSense for line-by-line code suggestions, the graphical user interface having buttons and menus to interact with, editors and plugins which can be embedded with it and many other features.
Example:
Microsoft Visual Studio
Eclipse, (JAVA, c, c++, Pearl and Ruby)
Xcode (Objective C, Objective C++, JAVA)
NetBeans (JAVA, php, C, C++)
IDLE (Python)
Web IDEs (ShiftEdit, Cloud9, Codeanywhere)
Introducation to C#
C# is a modern object-oriented programming language developed in 2000 by Anders Hejlsberg at Microsoft as a rival to Java.
The name "C sharp" was inspired by the musical notation where a sharp indicates that the written note should be made a semitone higher in pitch. This is similar to the language name of C++, where "++" indicates that a variable should be incremented by 1 after being evaluated. The sharp symbol also resembles a ligature of four "+" symbols (in a two-by-two grid), further implying that the language is an increment of C++.
Difference between C# and VB.NET
C# |
VB.NET |
- C# is the C family and it is evolved from C. So it possesses all the features of Java, Python, C++ and also a number of other languages. |
- VB.NET is much similar to normal English language, so it is very easy to learn it. Example, it uses words like AND where other languages use symbols like &. |
- C# is case sensitive. |
- VB.NET is not |
- C# supports operator overloading. |
- VB.NET does not. |
- Unstructured error handling is not supported in C#. |
- Both structured and unstructured error handling is supported in VB.NET. |
- C# support pointer type. |
- VB.NET doesn't. |
Features of OOP
- Class
- Objects (Identity, State, Behavior)
- Encapsulation
- Abstraction
- Access Modifiers / Access Specifiers (Public, Private, Protected)
- Inheritance (Single, Multiple, Multi-level, Hierarchical)
- Polymerphism (Static Polymorphism, Dynamic Polymorphism)
Note: For detail information please refer chapter 4. OOP
Scope of .NET Technology
In a very short time .NET technology became the boon for the software developers community. Microsoft announced C# language in 1999 and couple of years later .NET was introduced. After 19 years, here we are, .NET and C# is still here.
Now it's been considered as the most growing career option, which clearly indicates that .NET development still rules. .NET is now part of many international markets like USA, UAE, UK, South Africa and other developing countries and is heading forward. With its every new version .NET technology is evolving at a fast pace and creating amazing job opportunities for the developer.
- Today, it is the 4th most popular programming language.
- It is also the 3rd largest community on StackOverflow (which was built using C#) with more than 1.1 million topics.
- 70% of the application in the industry are either develop in .NET or JAVA. It's not going anywhere soon.
- 8 to 10% of the world programmer are developing application using C#.
- According to Xamarin, over 1.4 million developers were using Xamarin's products in 120 countries around the world.
Websites that are built using ASP.NET Technology
- www.stackoverflow.com
- www.w3schools.com
- www.codeproject.com
- www.microsoft.com
- www.godaddy.com
- www.dell.com