Introduction to .NET Framework ppsx

22 221 0
  • Loading ...
    Loading ...
    Loading ...

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Tài liệu liên quan

Thông tin tài liệu

Ngày đăng: 01/08/2014, 09:21

Introduction to .NET Framework Chapter 14 The .NET Framework enables you to create robust and scalable applications. The .NET Framework consists of Common Language Runtime, Common Language Specification, and the Just-In-Time compiler. Before you can use Visual Studio .NET for creating a console-based application, you need to understand the .NET Framework and the Visual Studio .NET Integrated Development Environment. This chapter introduces the features and components of the .NET Framework. It explains the process of creating and executing a console application in the Visual Studio .NET IDE. In this chapter, you will learn to:  Identify the components of the .NET Framework  Use the Visual Studio .NET IDE Objectives Introduction to .NET Framework 14.3 ¤NIIT N ote Microsoft introduced the .NET Framework with the intention of bridging the gap in interoperability between applications. This framework aims at integrating various programming languages and services. It is designed to make significant improvements in code reuse, code specialization, resource management, multilanguage development, security, deployment, and administration. It consists of all the technologies that help in creating and running robust, scalable, and distributed applications. The .NET offers a complete suite for developing and deploying applications. This suite consists of the .NET Products, .NET Services, and .NET Framework:  .NET Products: Microsoft has already introduced Visual Studio .NET, which is a tool for developing .NET applications by using programming languages such as Visual Basic, Visual C#, and Visual C++. These products aim at allowing developers to create applications, which are capable of interacting seamlessly with each other. To ensure interaction between various applications, all .NET products use eXtensible Markup Language (XML) for describing and exchanging data between applications. XML is a –platform independent markup language. It allows computers to store data in a format, which can be interpreted by any other computer system. Therefore, XML can be used to transfer structured data between heterogeneous systems. XML is used as a common data interchange format in a number of applications.  .NET Services: .NET helps you to create software as Web services. A Web Service is an application or business logic that is accessible through standard Internet protocols such as Hypertext Transfer Protocol (HTTP) and Simple Object Access Protocol (SOAP). You can identify the service by a Uniform Resource Locator (URL). Its public interfaces and bindings are described using XML. Therefore, users can subscribe to such a service and use it as long as they need it, regardless of the hardware and software platform. Microsoft has come up with its own set of Web services, known as My Services. These services are based on the Microsoft Passport Authentication service, which is used in their Web applications such as Hotmail. This service allows users to access data by linking calendars, phonebooks, address books, and personal references to the passport authentication service. In addition, third party products and services can be integrated easily with the .NET environment. Identifying the Components of the .NET Framework 14.4 Introduction to .NET Framework ¤NIIT  .NET Framework: It is the foundation on which you design, develop, and deploy applications. It is consistent and simplified programming model that helps you to easily build robust applications. It is the core of the .NET infrastructure because it exists as a layer between the .NET applications and the underlying operating system. In other words, the .NET Framework encapsulates much of the basic functionality, such as debugging and security services, which was earlier built in various programming languages, in the form of a collection of services and classes. The following figure shows the various components of the .NET Framework. The Components of the .NET Framework The .NET Framework consists of three main components: Common Language Runtime, .NET Framework Base Classes, and the user and program interfaces. Common Language Runtime (CLR) The CLR is one of the most essential components of the .NET Framework. CLR is the environment where all programs using .NET technologies are executed. It provides services such as code compilation, memory allocation, and garbage collection. The CLR allows the execution of code across different platforms by translating code into Intermediate Language (IL). IL is a low level language that the CLR understands. IL is converted into machine language during execution by the Just-In-Time (JIT) compiler. During JIT compilation, code is also checked for type safety. Type safety ensures that objects are always accessed in a compatible way. If you try to assign an 8-byte value to a variable of size 4 bytes, the CLR will detect and trap such an attempt. Common Language Runtime .NET Framework Base Class Libraries Windows Forms Web Forms and Web Services Console Applications Components of the .NET Framework Introduction to .NET Framework 14.5 ¤NIIT CLR consists of a set of common rules followed by all the languages of the .NET Framework. This set of rules is known as Common Language Specification (CLS). CLS enables an object or application to interact with the objects or applications of other languages. The classes that follow the rules specified by CLS are termed as CLS-compliant classes. The classes defined in the .NET Framework class library are CLS-compliant. One of the specifications defined in CLS is Common Type System (CTS), which provides a type system that is common across all languages. CTS define how data types are declared, used, and managed in the code at run time. The CTS also defines the rules that ensure that the data types of objects written in various languages are able to interact with each other. For example, the size of integer and long variables is the same across all CLS-compliant programming languages. While executing the program, CLR plays an important role. Identifying the Process of Compilation Compilation is the process of creating an executable program from a source code. The source code consists of instructions for the compiler, and an executable program consists of instructions for the processor. Therefore, compilation converts source code to machine language. However, when you compile a program in .NET, the conversion of source code to machine language happens in two stages. In the first stage, the compiler translates code into an IL instead of machine language or assembly language. In the second stage the conversion of IL to machine language is done at run time by the JIT compiler. Irrespective of the CLS compliant language used to develop the application, the source code always gets translated into IL. In addition, during the process of compilation, the compiler also produces metadata about code. Metadata contains the description of code, such as classes and interfaces, dependencies, and the versions of the components, used in the application. IL and metadata constitute an assembly. Assemblies contain metadata, which describe the assembly’s internal version number and details of all the data and object types they contain. When you compile a VC# application, Visual Studio .NET creates an assembly that is a single file with the extension .exe or .dll. Assemblies can also contain one or more modules. For example, larger game projects may be planned in such a way that several individual developers work on separate modules, all creating a single assembly. 14.6 Introduction to .NET Framework ¤NIIT The following figure shows the process of code compilation. Program Code Compiler IL Metadata Assembly + Code Compilation Identifying the Process of Code Execution During execution, CLR performs the following steps:  Loading assemblies and identifying namespaces: Assemblies are loaded in the memory. After loading assemblies, CLR identifies namespaces for code in assemblies. Namespaces are a collection of classes. The .NET Framework uses namespaces to organize its classes in a hierarchy. Namespaces implicitly have public access and this cannot be changed.  JIT compilation: Before execution, IL is converted into machine language by the JIT compiler. Next, during the verification process, The IL code is examined to confirm the following points: z The memory locations that code needs to access are available z Methods are called only through properly defined types z IL has been correctly generated  Garbage collection: The garbage collection process begins after the JIT compilation and manages the allocation and deallocation of memory for an application. Whenever you create an object, the CLR allocates memory for the object from the managed heap. A managed heap is a region of the memory that is available for program execution. If sufficient memory is not available on the managed heap, the garbage collection process is invoked. The code developed in .NET is called managed code. The CLR manages the compilation and execution of the managed code to ensure proper functioning of the code. For example, the CLR takes care of garbage collection, exception handling, and type safety for the managed code. The unit of execution in the CLR is an assembly. An assembly contains IL and metadata that was generated during compilation. It contains code that the CLR executes. All assemblies contain a manifest, which contains information such as assembly name, Introduction to .NET Framework 14.7 ¤NIIT version, and the list of files that form the assembly. The IL code cannot be executed if it does not have an associated assembly. Instead of compiling the complete IL code, the JIT compiler compiles only the code that is required during execution. It saves the time and memory required to convert the complete IL into machine language. The following figures shows the process of code compilation and execution. SetTopScore() IgnoreScore() SetTopScore() Visual C# Code IL Code IgnoreScore() Code Compilation Code Execution In the preceding figures, two methods are shown, SetTopScore() and IgnoreScore(). The SetTopScore() method will be invoked only if the current score of the player is higher than the top score of the game. The IgnoreScore() method will be invoked when SetTopScore() IgnoreScore() SetTopScore() JIT SetTopScore() is invoked IL Code Machine Language 14.8 Introduction to .NET Framework ¤NIIT the player is not the top scorer and you do not want to add the player to the list of top scorers. If the player has scored more than the top score, only the method SetTopScore()will be invoked. When it is invoked, the code for the SetTopScore() method will be compiled by the JIT compiler. However, the code for the method IgnoreScore() will not be converted to machine language by the JIT compiler because this method is not invoked. The .NET Framework Class Library The .NET Framework class library works with any .NET language, such as VB.NET, VC++ .NET, and VC#. This class library is built on the object-oriented nature of the runtime. The library provides classes that can be used in the code to accomplish a range of common programming tasks, such as string management, data collection, database connectivity, and file access. One of the most important features of the .NET Framework class library is that it can be used in a consistent manner across multiple languages. This means that you can use the same set of classes for performing a specific task in VC# as well as in VC++. The .NET Framework class library comprises namespaces, which are contained within assemblies. Let us look at what these two terms mean. Namespaces Namespaces help you to create logical groups of related classes and interfaces, which 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. Namespaces can be used to avoid any naming conflicts between classes, which have the same names. For example, you can use two classes with the same name in an application provided they belong to different namespaces. You can access the classes belonging to a namespace by simply importing the namespace into the application. The .NET Framework uses a dot (.) as a delimiter between classes and namespaces. For example, System.Console represents the Console class of the System namespace. Namespaces are also stored in assemblies. Assemblies An assembly is a single deployable unit that contains all the information about the implementation of classes, structures, and interfaces. The assembly stores all the information about itself. This information is called metadata and includes the name and version number of the assembly, security information, information about the dependencies, and a list of the files that constitute the assembly. Introduction to .NET Framework 14.9 ¤NIIT All the applications developed using the .NET Framework are made up of assemblies. Assemblies and the metadata provide the CLR with the information required for executing an application. For example, if an application uses a component, the assembly keeps track of the version number of the component used in the application. The assembly provides this information to the CLR while the application is being executed. Assemblies also play an important role in deployment and versioning. User and Program Interfaces At the presentation layer, .NET provides three types of user interfaces. They are Windows Forms, Web Forms, and Console Applications. Windows Forms are used in Windows-based applications, whereas Web Forms are used in Web-based applications for providing an interactive user interface. They provide a Web browser-based user interface. You can create character-based console applications that can be executed from the command line. .NET provides a program interface, Web Services, to communicate with remote components. Advantages of the .NET Framework Some of the advantages offered by the .NET Framework are:  Consistent programming model: The .NET Framework provides a common OOPs model across languages. This object model can be used in code to perform several tasks, such as reading from and writing to files, connecting to databases, and retrieving data.  Multi-platform applications: There are several versions of Windows most of which run on x86 CPUs. Some versions, such as Windows CE and 64-bit Windows, run on non-x86 CPUs as well. A .NET application can execute on any architecture that is supported by the CLR. In future, a CLR version could even be built for non-windows platforms.  Multi-language integration: .NET allows multiple languages to be integrated. For example, it is possible to create a class in VC# that derives from a class implemented in VB.NET. To enable objects to interact with each other regardless of the language used to develop them, a set of language features has been defined in CLS. This specification includes the basic language features required by many applications. The CLS enhances language interoperability. The CLS also establishes certain requirements, which help you to determine whether your managed code conforms to the CLS. Most of the classes defined in the .NET Framework class library are CLS-compliant.  Automatic resource management: While creating an application, a programmer may be required to write code for managing resources such as files, memory, 14.10 Introduction to .NET Framework ¤NIIT network connections, and database resources. If a programmer does not free these resources, the application may not execute properly. The CLR automatically tracks resource usage and relieves a programmer of the task of manual resource management.  Ease of deployment: One of the goals of the .NET Framework is to simplify application deployment. .NET applications can be deployed simply by copying files to the target computer. Deployment of components has also been simplified. Till now, Microsoft’s Component Object Model (COM) has been used for creating components. However, COM suffers from various problems relating to deployment. For example, every COM component needs to be registered before it can be used in an application. Moreover, two versions of a component cannot run side-by-side. In such a case, if you install a new application that installs the newer version of the component, the newly installed application may function normally. However, the existing applications that depend on the earlier version of the component may stop functioning. As against this, the .NET Framework provides zero-impact deployment. Installation of new applications or components does not have an adverse effect on the existing applications. In the .NET Framework, applications are deployed in the form of assemblies. An assembly stores metadata. Therefore, registry entries are not required for storing information about components and applications. In addition, assemblies also store information about the versions of components used by an application. Therefore, the problems relating to versioning are also eliminated in the .NET Framework. [...]... Window The Code Editor The code editor allows you to enter and edit code You may use this editor to add code for your class NIIT Introduction to NET Framework 14.19 The code editor is shown in the following figure The Code Editor Compiling and Executing Project To compile and execute the application, you need to perform the following steps: 1 Select Build Build Solution or press F6 to compile the application... project is to be created in the Location combo box You can use the Browse button to browse to the folder in which the new project is to be created Click the OK button Introduction to NET Framework 14.13 User Interface Elements of Visual Studio NET IDE When you work with a console application project in Visual Studio NET, you can use the following main elements in Visual Studio NET IDE Standard Toolbar... buttons of the toolbar enable you to perform tasks common to many Windows-based programs, such as opening a new or an existing file, saving or printing a file, cutting and pasting text and objects, and undoing or redoing the most recent actions Other standard toolbar buttons offer functions more specific to Visual Studio NET applications The name and functions of the various tools of the Standard toolbar... window, Class View window, and the Code Editor window In addition, Visual Studio NET provides the Start Page and the Project Properties window The Start Page allows you to perform several tasks and the Project Properties helps you to set the projects compilation and configuration values 14.14 Introduction to NET Framework NIIT Standard Toolbar The Standard toolbar is located below the menu bar It provides... Crystal Reports Application 5 You need to select the option from the Debug menu to execute a game developed in Visual Studio NET 6 State whether the given statement is true or false: JIT compilation saves time and memory required to convert the complete IL into machine language NIIT Introduction to NET Framework 14.21 Summary In this chapter, you learned that: The NET Framework is made up of many components,... you to work on multiple projects within the same instance of the Visual Studio NET IDE NIIT Introduction to NET Framework 14.11 A solution containing multiple projects is shown in the following figure Solution Project 1 Items Project 1 Project 2 Project 2 Items Miscellaneous Files Solution Containing Multiple Projects To create a console application in Visual Studio, you need to create a project To. .. Debugging Compiles and Executes the current project Standard Toolbar Buttons NIIT Introduction to NET Framework 14.15 The Start Page When you start Visual Studio NET, it displays the Start Page - Microsoft Visual Studio window The Start Page is the default home page for the browser provided within the Visual Studio NET IDE This allows you to perform several tasks, such as specifying your preferences,... application 2 Select Debug Start Debugging or press F5 to execute the application 14.20 Introduction to NET Framework NIIT Practice Questions 1 What is Just-In-Time compilation? 2 Which CLR feature ensures that data types are accessible across different applications? 3 What is project output? 4 Which Visual C# template allows you to create a custom control that can be used in a GUI game? a Windows Control... Code Editor window for that item, making it convenient to move through the code in the project The Class View window has two buttons, one for sorting the items in the Class View window and the other for creating a new folder If the Class View window is not visible, you can open it either by selecting View Class View or by pressing the Ctrl+Shift+C keys simultaneously 14.18 Introduction to NET Framework. .. NET Framework When a program is compiled using Visual Studio NET the compiler translates the code into the IL instead of machine language The JIT compiler is used to translate code from IL into machine language The CLR is the environment where all NET applications are executed The Visual Studio NET IDE provides you with a common interface for developing various kinds of applications for the NET Framework . Introduction to .NET Framework Chapter 14 The .NET Framework enables you to create robust and scalable applications. The .NET Framework consists of Common Language. Identify the components of the .NET Framework  Use the Visual Studio .NET IDE Objectives Introduction to .NET Framework 14.3 ¤NIIT N ote Microsoft introduced the .NET Framework with the intention. services can be integrated easily with the .NET environment. Identifying the Components of the .NET Framework 14.4 Introduction to .NET Framework ¤NIIT  .NET Framework: It is the foundation on which
- Xem thêm -

Xem thêm: Introduction to .NET Framework ppsx, Introduction to .NET Framework ppsx, Introduction to .NET Framework ppsx