C# Unit 1st: Akhil

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

C# unit 1st Akhil

INTRODUCTION TO .NET FRAMEWORK


What Is .NET ? Software platform Language neutral In other words: .NET is not a language (Runtime and a library for writing and executing written programs in any compliant language) .Net is a new framework for developing web-based and windows-based applications within the Microsoft environment. The framework offers a fundamental shift in Microsoft strategy: it moves application development from client-centric to server-centric.

The .NET framework exposes numerous classes to the developer. These classes allow the development of rich client applications and Web based applications alike. In the above slide these classes have been divided into 4 areas.

C# unit 1st Akhil


ASP.NET provides the core Web infrastructure such as Web Forms for UI based development and Web Services for programmatic interface development, User interface development on the Windows platform can be done using Windows Forms ADO.NET and XML provide the functionality for data access. Finally, the core base classes provide infrastructure services such as security, transaction management etc.

THE .NET FRAMEWORK .NET FRAMEWORK SERVICES


Common Language Runtime Windows Forms ASP.NET Web Forms Web Services ADO.NET, evolution of ADO Visual Studio.NET Common Language Runtime Common, secure execution environment. Well drill into this in some detail in the first parts of the presentation. Windows forms Framework for building rich clients A demonstration will highlight some of these features, such as the delegate-based event model. ASP.NET ASP.NET,the platform services that allow to program Web Applications and Web Services in any .NET language ASP.NET Uses .NET languages to generate HTML pages. HTML page is targeted to the capabilities of the requesting Browser ASP.NET Program is compiled into a .NET class and cached the first time it is called. All subsequent calls use the cached version. Logical Evolution of ASP Supports multiple languages Improved performance Control-based, event-driven execution model More productive Cleanly encapsulated functionality The first incarnation of ASP proved very successful. As part of the .NET Framework, Microsoft support ASP.NET. ASP.NET is a logical evolution of ASP, but addresses many of the issues associated with ASP. ASP.NET is now compiled and not interpreted. A great deal of work has also been done to make sure that ASP.NET development becomes cleaner and more productive.

Web forms Manageable code (non spaghetti) Logical evolution of ASP (compiled) Again, well drill into a hint at the power of Web Forms with a demonstration

C# unit 1st Akhil


Web Services Programming the Internet to leverage the "power at the edge of the cloud". We will cover this in detail, as this along with the CLR is one of the more powerful aspects of .NET Framework. A technical definition A programmable application component accessible via standard Web protocols

Technically a Web Service is A programmable application component accessible via standard Web protocols. In other words, its a component that can be called remotely, over the internet, from a client application.

Take our previous example of a Web application that required stock information. This Web application possibly would not have that information readily at hand. However, what if another Web application (possibly on another machine, on the other side of the planet) did? Further more what if this remote machine exposed a component with a method such as GetStockPrice (string strCompanyName). Surely this would make life much easier, making separate Web sites act like one big application. Web service consumers can send and receive messages using XML, and therefore the audience of clients is unlimited. ADO.NET, evolution of ADO ADO.NET(Data and XML) New objects (e.g., DataSets) Separates connected / disconnected issues Language neutral data access Uses same types as CLR Great support for XML New objects (e.g., DataSets, Datareader) Visual Studio.NET Most productive development environment gets better and fully supports the .NET Framework Windows Forms Framework for Building Rich Clients RAD (Rapid Application Development) Rich set of controls Data aware ActiveX Support Licensing Accessibility Printing support Unicode support UI inheritance ASP.NET Web Forms Allows clean cut code Code-behind Web Forms Easier for tools to generate Code within is compiled then executed Improved handling of state information Support for ASP.NET server controls

C# unit 1st Akhil


Data validation Data bound grids The Web Form is basically an ASP.NET file (.ASPX) that makes use of the new features of ASP.NET. ASP.NET in conjunction with Web Forms eliminate a number of the traditional problems associated with ASP. ASP.NET provides the developer with the option of separating the code from the UI elements using code-behind forms. Using such a mechanism will also make Form tools much easier to develop. ASP.NET also conquers one of the annoying side effects of using ASP state. Imagine that a user has filled in an ASP generated form and then hits the submit button. At this stage IIS (server side) will regenerate the form and as a side effect all the information that the user entered into the form will be erased. In many situations this is unacceptable, and many an ASP developer has struggled to find work arounds (most of which may not be considered elegant). Fortunately, ASP.NET allows controls to maintain state. ASP.NET supports a number of new rich server controls. These controls can be used to improve data connectivity (data bound controls) and data validation.

COMMON LANGUAGE RUNTIME (CLR)


CLR works like a virtual machine in executing all languages. All .NET languages must obey the rules and standards imposed by CLR. Examples: Object declaration, creation and use Data types,language libraries Error and exception handling Interactive Development Environment (IDE) Development Mixed language applications Common Language Specification (CLS) Common Type System (CTS) Standard class framework Automatic memory management Consistent error handling and safer execution Potentially multi-platform Deployment Removal of registration dependency Safety fewer versioning problems CTS is a rich type system built into the CLR Implements various types (int, double, etc) And operations on those types CLS is a set of specifications that language and library designers need to follow This will ensure interoperability between languages

C# unit 1st Akhil

Intermediate Language (IL)


.NET languages are not compiled to machine code. They are compiled to an Intermediate Language (IL). CLR accepts the IL code and recompiles it to machine code. The recompilation is just-in-time (JIT) meaning it is done as soon as a function or subroutine is called. The JIT code stays in memory for subsequent calls. In cases where there is not enough memory it is discarded thus making JIT process interpretive. Languages provided by MS VB, C++, C#, J#, JScript Third-parties are building APL, COBOL, Pascal, Eiffel, Haskell, ML, Oberon, Perl, Python, Scheme, Smalltalk MSIL : (Microsoft Intermediate language) or IL(Intermediate Language) is machine independent code generated by .NET framework after the compilation of program written in any language by you. MSIL : (Microsoft Intermediate language) or IL(Intermediate Language) is machine independent code generated by .NET framework after the compilation of program written in any language by you. MSIL or IL is now known as CIL(Common Intermediate Language). Let's see some other definitions: MSIL is the CPU-independent instruction set into which .NET Framework programs are compiled. It contains instructions for loading, storing, initializing, and calling methods on objects. Combined with metadata and the common type system, MSIL allows for true cross-language integration. Prior to execution, MSIL is converted to machine code. It is not interpreted. (souce MSDN) When compiling to managed code, the compiler translates your source code into Microsoft intermediate language (MSIL), which is a CPU-independent set of instructions that can be efficiently converted to native code.(Source MSDN) Common Intermediate Language (CIL, pronounced either "sil" or "kil") (formerly called Microsoft Intermediate Language or MSIL) is the lowest-level human-readable programming language in the Common Language Infrastructure and in the .NET Framework. Languages which target the .NET Framework compile to CIL, which is assembled into bytecode. CIL is an object-oriented assembly language, and is entirely stack-based. It is executed by a virtual machine.

C# unit 1st Akhil


CIL was originally known as Microsoft Intermediate Language (MSIL) during the beta releases of the .NET languages. Due to standardization of C# and the Common Language Infrastructure, the bytecode is now officially known as CIL. Because of this legacy, CIL is still frequently referred to as MSIL, especially by long-standing users of the .NET languages.

What is "Common Type System" (CTS)? CTS defines all of the basic types that can be used in the .NET Framework and the operations performed on those type. All this time we have been talking about language interoperability, and .NET Class Framework. None of this is possible without all the language sharing the same data types. What this means is that an int should mean the same in VB, VC++, C# and all other .NET compliant languages. This is achieved through introduction of Common Type System (CTS)

CTS (Common Type System) : Common Type System is the part of .NET Framework built in with CLR which is responsible for defining , managing different language's operation supported by .NET Framework. CTS (Common Type System) : Common Type System is the part of .NET Framework built in with CLR which is responsible for defining , managing different language's operation supported by .NET Framework. Let's see some other definitions: The common type system is a rich type system, built into the common language runtime, that supports the types and operations found in most programming languages. The common type system supports the complete implementation of a wide range of programming languages. (Source MSDN) The Common Type System (CTS) is a standard that specifies how Type definitions and specific values of Types are represented in computer memory. It is intended to allow programs written in different programming languages to easily share information. As used in programming languages, a Type can be described as a definition of a set of values (for example, "all integers between 0 and 10"), and the allowable operations on those values (for example, addition and subtraction). (Source Wikipedia) Use / Importance of CTS: CTS are responsible for cross language Integration (Means you can have a dll which is written in C# and to be used in VB.Net application) and Type Safety. Enforce a set of rules that a programming language must follow.

Common Language Specification (CLS),


CLS is the collection of the rules and constraints that every language (that seeks to achieve .NET compatibility) must follow. It is a subsection of CTS and it specifies how it shares and extends one another libraries. Not all languages support all CTS types and features C# supports unsigned integer types, VB.NET does not C# is case sensitive, VB.NET is not

C# unit 1st Akhil


C# supports pointer types (in unsafe mode), VB.NET does not C# supports operator overloading, VB.NET does not CLS was drafted to promote language interoperability vast majority of classes within FCL are CLS-compliant

JUST-IN TIME COMPILATION


In the .NET Framework, all the Microsoft .NET languages use a Common Language Runtime, which solves the problem of installing separate runtimes for each of the programming languages. When the Microsoft .NET Common Language Runtime is installed on a computer then it can run any language that is Microsoft .NET compatible. Before the Microsoft Intermediate Language (MSIL) can be executed, it must be converted by a .NET Framework Just-In-Time (JIT) compiler to native code, which is CPU-specific code that runs on the same computer architecture as the JIT compiler. JIT (JUST-IN-TIME) COMPILER:

A Web Service or Web Forms file must be compiled to run within the CLR. Compilation can be implicit or explicit. Although you could explicitly call the appropriate compiler to compile your Web Service or Web Forms files, it is easier to allow the file to be complied implicitly. Implicit compilation occurs when you request the .asmx via HTTP-SOAP, HTTP-GET, or HTTP-POST. The parser (xsp.exe) determines whether a current version of the assembly resides in memory or in the disk. If it cannot use an existing version, the parser makes the appropriate call to the respective compiler (as you designated in the Class property of the .asmx page). When the Web Service (or Web Forms page) is implicitly compiled, it is actually compiled twice. On the first pass, it is compiled into IL. On the second pass, the Web Service (now an assembly in IL) is compiled into machine language. This process is called Just-In-Time JIT compilation because it does not occurs until the assembly is on the target machine. The reason you do not compile it ahead of time is so that the specific JITter for your OS and processor type can be used. As a result, the assembly is compiled into the fastest possible machine language code, optimized and enhanced for your specific configuration. It also enables you to compile once and then run on any number of operating systems.

How JIT Works? Before MSIL(MS Intermediate Language) can be executed, it must converted by .net Framework Just in time (JIT) compiler to native code, which is CPU specific code that run on some computer architecture as the JIT compiler. Rather than using time and memory to convert all the MSIL in portable executable (PE) file to native code, it converts the MSIL as it is needed during execution and stored in resulting native code so it is accessible for subsequent calls. The runtime supplies another mode of compilation called install-time code generation. The install-time code generation mode converts MSIL to native code just as the regular JIT compiler does, but it converts larger units of code at a time, storing the resulting native code for use when the assembly is subsequently loaded and executed. As part of compiling MSIL to native code, code must pass a verification process unless an administrator has established a

C# unit 1st Akhil


security policy that allows code to bypass verification. Verification examines MSIL and metadata to find out whether the code can be determined to be type safe, which means that it is known to access only the memory locations it is authorized to access.

JIT Types: In Microsoft .NET there are three types of JIT (Just-In-Time) compilers which are Explained as Under:

Pre-JIT Compiler (Compiles entire code into native code completely) Econo JIT Compiler (Compiles code part by part freeing when required) Normal JIT Compiler (Compiles only that part of code when called and places in cache

Description:

Pre-JIT COMPILER Pre-JIT compiles complete source code into native code in a single compilation cycle. This is done at the time of deployment of the application.

Econo-JIT COMPILER: Econo-JIT compiles only those methods that are called at runtime. However, these compiled methods are removed when they are not required.

Normal-JIT COMPILER: Normal-JIT compiles only those methods that are called at runtime. These methods are compiled the first time they are called, and then they are stored in cache. When the same methods are called again, the compiled code from cache is used for execution. These methods are compiled the first time they are called, and then they are stored in cache. When the same methods are called again, the compiled code from cache is used for execution.

You might also like