Archive for October, 2006

The output of a compiler includes metadata, which

Tuesday, October 31st, 2006

located at those addresses. Thus, we can speak of physically moving (i.e., deploying) the neighborhood. A .NET application consists of one or more assemblies. Logically speaking, an assembly is just a set of specifications. In particular: An assembly specifies the (MSIL) code that is associated with the assembly. This code lies in a Portable Executable (PE) file. (PE files are the traditional file types for Microsoft’s code, but the format is extended for .NET applications.) An assembly specifies security permissions for itself, if any. An assembly specifies a list of data types and provides scoping for those types. Every data type in a .NET application must specify the assembly to which it belongs. The scoping provided by an assembly means that different types may have the same name, as long as they belong to different assemblies and can therefore be distinguished by means of the assembly to which they belong. Microsoft refers to this by saying that an assembly provides atype boundary. An assembly specifies rules for resolving external types and external references, including references to other assemblies. In this way, assemblies form a reference scope boundary. Included in this information are any version dependencies for the external references. An assembly specifies which of its parts are exposed outside the assembly and which are private to the assembly itself. In addition to these specifications listed, an assembly is an object (or logical unit) that possesses certain properties: An assembly has version properties. This includes a major and minor version number, as well as a revision and build number. Indeed, an assembly is the smallest unit that has versioning properties. Put another way, all elements of an assembly (types and resources) are versioned as a unit they are assigned the version numbers of the assembly to which they belong. In other words, an assembly is a versioning unit. An assembly forms a deployment unit. More specifically, at any given time, a .NET application only needs access to the assemblies that specify the code under execution. Other assemblies that make up the application need not be present if the code they specify is not currently needed for execution. These assemblies can be retrieved upon demand, so that the downloading of applications can be more efficient. Finally, we note that multiple versions of a single assembly can be run at the same time, on the same system, or even in the same process. This is referred to as side-by-side execution. The specifications in an assembly are collectively referred to as the assembly’s manifest. The data in the manifest is also called metadata. Specifically, the manifest contains: The name of the assembly Version information for the assembly Security information for the assembly A list of all files that are part of the assembly Type reference information for the types specified in the assembly A list of other assemblies that are referenced by the assembly Custom information, such as a user-friendly assembly title, description, and product information (company name, copyright information, and so on) Physically, an assembly consists of one or more files files that contain code, as well as resources, such as bitmaps. The assembly’s manifest can be a separate file or part of another file in the assembly.
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services

The output of a compiler includes metadata, which

Tuesday, October 31st, 2006

4.5 Assemblies and VB .NET To a VB .NET programmer, an assembly is similar to a traditional DLL or EXE file, except that it contains additional information, such as reference and type information (which in COM was often contained in a separate OLB or TLB file, called a type library). When a VB .NET application is compiled, the compiler creates an assembly for the target EXE or DLL. In the .NET environment, namespaces are part of assemblies. An assembly can contain many namespaces, and namespaces can be nested. For instance, the System namespace is the fundamental namespace in the .NET environment. This is not the time to go into details, but one example will be useful. The System namespace identifies the Array class (Microsoft likes to say that the namespace contains classes.) One of the members of the Array class is the Copy method, which copies a portion of one array to another array. Thus, we can write code such as the following: Imports System ‘ Optional since System is always imported Dim array1( ) As Integer = {1, 2, 3, 4} Dim array2(3) As Integer Array.Copy(array1, array2, 3) To use an existing assembly in a VB .NET project, you must do two things: Add a reference to the assembly to your project. There are two exceptions to this rule, however. A reference to the assembly containing the System namespace (mscorlib.dll) is added automatically, as is a reference to the assembly containing the language being used (for VB .NET, this is Microsoft.VisualBasic.dll). Access the member or members of the namespace, as described later in this section. To access a member of a namespace, you can use its fully qualified name. For example, to create an instance of the Timers class, which is found in the System.Timers namespace, you can use a code fragment like the following: Dim oTimer As New System.Timers.Timer(2000) Since using fully qualified names tends to be relatively cumbersome, you can include an Imports statement at the beginning of a code file, before any references to variables or classes. Its syntax is: Imports [aliasname = ] namespace where aliasname is an optional alias for the namespace, and namespace is its fully qualified name. For example, if you import the System.Timers namespace as follows: Imports System.Timers you do not have to qualify a reference to the Timer class, which can be instantiated as follows: Dim oTimer As New Timer(2000) In the event that there is a naming conflict (either two namespaces have identically named types, or a named type conflicts with a name in your project), you can specify an alias for the namespace, as follows: Imports TI = System.Timers and then instantiate a Timer object as follows:
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services

The output of a compiler includes metadata, which

Tuesday, October 31st, 2006

The output of a compiler includes metadata, which is information that describes the objects that are part of an application, such as: Data types and their dependencies Objects and their members References to required components Information (including versioning information) about components and resources that were used to build the application Metadata is used by the CLR to do such things as: Manage memory allocations Locate and load class instances Manage object references and perform garbage collection Resolve method invocations Generate native code Make sure that the application has the correct versions of necessary components and resources Enforce security The metadata in a compiled software component makes the component self-describing. This implies that components, even those written in another language, can interact with the given component directly. Objects that are managed by the CLR are referred to as managed data. (It is also possible to use unmanaged data in applications.) 4.3 Managed Execution Managed execution is the name given for the process of creating applications under the .NET Framework. The steps involved are as follows: 1. Write code using one or more .NET compilers. Note that for software components to be useable by components that are written in other languages, these components must be written using only language features that are part of the Common Language Specification (CLS). 2. Compile the code. The compiler translates source code to Microsoft Intermediate Language (MSIL) and generates the necessary metadata for the application. 3. Run the code. When code is executed, the MSIL is compiled into native code (which is CPU- specific code that runs on the same computer architecture as the compiler) by a Just In Time (JIT) compiler. If required, the JIT checks the code for type safety. If the type-safety check fails, an exception is thrown. Code that cannot access invalid memory addresses or perform other illegal operations that may result in an application crash is called type-safe code. Code that is verified to be type-safe by the JIT is called verifiably type-safe code. Due to limitations in the verification process, code can be type-safe and yet not be verifiably type-safe. 4.4 Assemblies The purpose of an assembly is to specify a logical unit, or building block, for .NET applications that encapsulate certain properties. The term assembly refers to both a logical construct and a set of physical files. To draw an analogy on the logical side, we might use the term neighborhood to refer to a zip code, a neighborhood name, and a list of street addresses. On the physical side, a neighborhood consists of the actual houses that are
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services

3.7 Scope and Accessibility in Class Modules The

Tuesday, October 31st, 2006

Chapter 4. The .NET Framework: General Concepts In this chapter, we discuss some of the main concepts in the .NET Framework. This is intended as a general overview, just to give you the “lay of the .NET land,” so to speak. For more information, see Thuan Thai and Hoang Q. Lam’s .NET Framework Essentials (O’Reilly, 2001). 4.1 Namespaces The notion of a namespace plays a fundamental role in the .NET Framework. In general, a namespace is a logical grouping of types for the purpose of identification. For example, imagine that in a certain business there is an executive named John Smith, a secretary named John Smith, and a custodian named John Smith. In this case, the name John Smith is ambiguous. When the paymaster stands on a table and calls out the names of people to receive their pay checks, the executive John Smith won’t be happy if he rushes to the table when the paymaster calls out his name and the envelope contains the custodian John Smith’s pay check. To resolve the naming ambiguity, the business can simply define three namespaces: Executive, Secretarial, and Custodial. Now the three individuals can be unambiguously referred to by their fully qualified names: Executive.John Smith Secretarial.John Smith Custodial.John Smith The .NET Framework Class Library (FCL), which we look at in more detail in Chapter 5, consists of several thousand classes and other types (such as interfaces, structures, and enumerations) that are divided into over 90 namespaces. These namespaces provide basic system services, such as: Basic and advanced data types and exception handling (the System namespace) Data access (the System.Data namespace) User-interface elements for standard Windows applications (the System.Windows.Forms namespace) User-interface elements for web applications (the System.Web.UI namespace) In fact, the VB .NET language itself is implemented as a set of classes belonging to the Microsoft.VisualBasic namespace. (The C# and JScript languages are also implemented as a set of classes in corresponding namespaces.) For information on accessing the members of a namespace, see Section 4.5 later in this chapter. Namespaces are not necessarily unique to the Framework Class Library; you can also create your own namespaces by using the Namespace statement at the beginning of a code file. 4.2 Common Language Runtime (CLR), Managed Code, and Managed Data The Common Language Runtime (CLR) is an environment that manages code execution and provides application-development services. Compilers such as VB .NET expose the CLR’s functionality to enable developers to create applications. Code that is created under this environment is called managed code . Note that COM components are not managed code, although they (as well as other unmanaged code) can be used in applications that are built under the CLR.
Note: If you are looking for good and high quality web space to host and run your java application check Vision java hosting services

3.7 Scope and Accessibility in Class Modules The

Tuesday, October 31st, 2006

As we have discussed, if a member variable is declared using the Shared keyword, then it is shared by all objects in the class. More accurately, the member exists independently of any object of the class. In this case, the member can be accessed (within its scope) through qualification by the class name, as in: Class1.classvariable = 100 Note that the member can also be accessed through qualification by an object name, but this has the same effect as access through qualification by the class name there is only one copy of the member. If the member is declared without using the Shared keyword, then class/object access refers to accessibility through qualification by the name of an existing object, as in: Dim c As New Class1 c.classvariable = 100 The scope for class/object access can be one of the following: The declaring class only The declaring project The declaring project and any external software component that holds a reference to the declaring project Table 3-2 describes the effects of the various access modifiers. Table 3-2. Access modifiers in class modules Direct-access scope Class/object scope Private Declaring class Declaring class Protected All derived classes Declaring class Friend Derived in-project classes Declaring project Protected Friend All derived classes Declaring project Public All derived classes All projects Unfortunately, it does not seem possible to make a simple statement about the effect of the access modifiers Friend and Protected independently. It would have been much clearer to have separate sets of access modifiers for direct-access scope and class/object scope, instead of intertwining the concepts as shown in Table 3-2. Oh well.
Note: If you are looking for good and high quality web space to host and run your java application check Vision java hosting services

3.7 Scope and Accessibility in Class Modules The

Tuesday, October 31st, 2006

3.7 Scope and Accessibility in Class Modules The notion of scope in class modules is more involved than it is in standard modules. As far as local variables (block-level and procedure-level) are concerned, there is no difference we have block scope and procedure-level scope. However, variables declared in the Declarations section of a class module can be assigned one of the following access modifiers: Public Private Friend Protected ProtectedFriend (For standard modules, only Public, Private, and Friend are allowed.) Note that class modules themselves can be declared with any one of the three access modifiers: Public, Private, or Friend (Protected is not allowed). When a class module declaration specifies one of these access modifiers, this simply restricts all of its members to that level of access, unless a member’s access is further restricted by the access modifier on the member declaration itself. For instance, if the class has Friend access, no member can have Public access. (Put another way, the Public access is overridden by the Friend class access.) On the other hand, all four access modifiers apply to members of the class module?that is, to variable, constant, enum, and procedure declarations within the class module. The complications come because there are actually three types of access to a class member, and these generally have different scopes. To clarify, let’s make the following definitions, which are not standard but descriptive. For example, consider a variable declaration in the Declaration section of a class module named Class1: AccessModifier classvariable As Integer This variable can be accessed in the following ways: Direct access Refers to accessing the member without any qualification, as in: classvariable = 100 When attempting to access a variable using direct access (that is, without qualification), the variable’s scope takes one of three forms: The declaring class only The declaring class and its derived classes within the declaring project only The declaring class and its derived classes, in any project that holds a reference to the declaring project Class/object access Refers to accessing the member through qualification, either with the class name or the name of an object of that class.
Note: If you are looking for good and high quality web space to host and run your java application check Vision java hosting services


declared with the MustInherit keyword. This specifies that

Tuesday, October 31st, 2006

Overloading refers to an item being used in more than one way. Operator names are often overloaded. For instance, the plus sign (+) refers to addition of integers, addition of singles, addition of doubles, and concatenation of strings. Thus, the plus symbol (+) is overloaded. It’s a good thing, too; otherwise, we would need separate symbols for adding integers, singles, and doubles. Function names can also be overloaded. For instance, the absolute value function, Abs, can take an integer parameter, a single parameter, or a double parameter. Because the name Abs represents several different functions, it is overloaded. In fact, if you look at the documentation for the Abs member of the Math class (in the system namespace of the Base Class Library), you will find the following declarations, showing the different functions using the Abs name: Overloads Public Shared Function Abs(Decimal) As Decimal Overloads Public Shared Function Abs(Double) As Double Overloads Public Shared Function Abs(Integer) As Short Overloads Public Shared Function Abs(Integer) As Integer Overloads Public Shared Function Abs(Long) As Long Overloads Public Shared Function Abs(SByte) As SByte Overloads Public Shared Function Abs(Single) As Single Note the use of the Overloads keyword, which tells VB that this function is overloaded. Specifically, a function name is overloaded when two defined functions use the same name but have different argument signatures. For instance, consider a function that retrieves a current account balance. The account could be identified either by the person’s name or by the account number. Thus, we might define two functions, each called GetBalance: Overloads Function GetBalance(sCustName As String) As Decimal Overloads Function GetBalance(sAccountNumber As Long) As Decimal Note also that VB .NET permits function overloading only because the argument signatures of the two functions are different, so that no ambiguity can arise. The function calls: GetBalance(”John Smith”) GetBalance(123456) are resolved by the compiler without difficulty, based on the data type of the argument. This type of overloading is often referred to as overloading the function GetBalance. On the other hand, there are two different functions here, so it seems more appropriate to say that the function name is being overloaded. Overloading is very common and not exclusive to object-oriented programming. 3.6.2 Polymorphism The term polymorphism means having or passing through many different forms. In the .NET Framework, polymorphism is tied directly to inheritance. Again, let us consider our Employee example. The function IncSalary is defined in three classes: the base class CEmployee and the derived classes CExecutive and CSecretary. Thus, the IncSalary function takes on three forms. This is polymorphism, VB .NET style. In case you are interested, many computer scientists would not consider this to be polymorphism. They would argue that the function IncSalary takes on only one form. It is the implementation that differs, not the function. They would refer to the situation described here for IncSalary as function overloading. The main point here is that there is a lot of confusion as to how Microsoft and others use the terms overloading and polymorphism, so you should be on guard when reading documentation.
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services


declared with the MustInherit keyword. This specifies that

Tuesday, October 31st, 2006

3.5.1 Interfaces Revisited We have seen that interfaces can be defined in class modules. VB .NET also supports an additional method of defining an interface, using the Interface keyword. The following example defines the IShape interface: Public Interface IShape Sub Draw( ) Sub Rotate(ByVal sngDegrees As Single) Sub Translate(ByVal x As Integer, ByVal y As Integer) Sub Reflect(ByVal iSlope As Integer, _ ByVal iIntercept As Integer) End Interface Note that we cannot implement any of the members of an interface defined using the Interface keyword, that is, not within the module in which the interface is defined. However, we can implement the interface using an ordinary class module. Note the use of the Implements statement (which was also available in VB 6, but could be applied only to external interfaces): Public Class CRectangle ‘ Implement the interface IShape Implements IShape Public Overridable Sub Draw( ) Implements IShape.Draw ‘ code to implement Draw for rectangles End Sub Public Overridable Sub Spin( ) Implements IShape.Rotate ‘ code to implement Rotate for rectangles End Sub End Class Note also the use of the Implements keyword in each function that implements an interface member. This keyword allows us to give the implementing function any name it does not need to match the name of the method (see the Spin method earlier in this section, which implements the IShape interface’s Rotate method). However, it is probably less confusing (and better programming practice) to use the same name. The main advantage of using the Implements keyword approach to defining an interface is that a single class can implement multiple interfaces, whereas VB .NET does not permit a single class to inherit directly from multiple base classes. On the other hand, the main disadvantage of the Interface keyword approach is that no implementation is possible in the module that defines the interface. Thus, all interface members must be implemented in every class that implements the interface. This can mean code repetition if an interface member has the same implementation in more than one implementing class. 3.6 Polymorphism and Overloading Fortunately, we don’t need to go into the details of polymorphism and overloading, which is just as well, because they tend to be both confusing and ambiguous. For instance, some computer scientists say that overloading is a form of polymorphism, whereas others say it is not. We will discuss only those issues that are directly relevant to the .NET Framework. 3.6.1 Overloading
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services


declared with the MustInherit keyword. This specifies that

Tuesday, October 31st, 2006

declared with the MustInherit keyword. This specifies that we cannot create objects of type CEmployee. In each of the previous cases, the IncSalary member of the base class CEmployee is an abstract member. Any class that contains at least one abstract member is termed an abstract class. (Thus, the CEmployee class as defined earlier is an abstract class.) This terminology comes from the fact that it is not possible to create an object from an abstract class because at least one of the object’s methods would not have an implementation. There are also situations where we might want to define a class in which all members are abstract. In other words, this is a class that only defines an interface. We might refer to such a class as a pure abstract class, although this terminology is not standard. For example, imagine a Shape class called CShape that is designed to model the general properties and actions of geometric shapes (ellipses, rectangles, trapezoids, etc.). All shapes need a Draw method, but the implementation of the method varies depending on the type of shape circles are drawn quite differently than rectangles, for example. Similarly, we want to include methods called Rotate, Translate, and Reflect, but, as with the Draw method, each of these methods require a different implementation based on the type of shape. Thus, we can define the CShape class in either of the following ways: Public Class Class2 Public Overridable Sub Draw( ) End Sub Public Overridable Sub Rotate(ByVal sngDegrees As Single) End Sub Public Overridable Sub Translate(ByVal x As Integer, _ ByVal y As Integer) End Sub Public Overridable Sub Reflect(ByVal iSlope As Integer, _ ByVal iIntercept As Integer) End Sub End Class or: Public MustInherit Class CShape Public MustOverride Sub Draw( ) Public MustOverride Sub Rotate(ByVal sngDegrees As Single) Public MustOverride Sub Translate(ByVal x As Integer, _ ByVal y As Integer) Public MustOverride Sub Reflect(ByVal iSlope As Integer, _ ByVal iIntercept As Integer) End Class Now we can define derived classes such as CRectangle, CEllipse, CPolygon, and so on. Each of these derived classes will (or must, in the latter case) implement the members of the base class CShape. (We won’t go into the details of such an implementation here, since it is not relevant to our discussion.)
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services


NotOverridable Prohibits overriding of the member. This is

Tuesday, October 31st, 2006

Visual Basic looks for the most immediate version in parent classes of the procedure in question. Thus, if Class C derives from Class B, which derives from Class A, a call in Class C to: MyBase.AProc first looks in Class B for a matching procedure named AProc. If none is found, then VB looks in Class A for a matching procedure. (By matching, we mean a method with the same argument signature.) The keyword MyClass provides a reference to the class in which the keyword is used. It is similar to the Me keyword, except when used to call a method. To illustrate the difference, consider a class named Class1 and a derived class named Class1Derived. Note that each class has an IncSalary method: Public Class Class1 Public Overridable Function IncSalary(ByVal sSalary As Single) _ As Single IncSalary = sSalary * CSng(1.1) End Function Public Sub ShowIncSalary(ByVal sSalary As Single) MsgBox(Me.IncSalary(sSalary)) MsgBox(MyClass.IncSalary(sSalary)) End Sub End Class Public Class Class1Derived Inherits Class1 Public Overrides Function IncSalary(ByVal sSalary As Single) _ As Single IncSalary = sSalary * CSng(1.2) End Function End Class Now consider the following code, placed in a form module: Dim c1 As New Class1( ) Dim c2 As New Class1Derived( ) Dim c1var As Class1 c1var = c1 c1var.IncSalary(10000) ‘ Shows 11000, 11000 c1var = c2 c1var.IncSalary(10000) ‘ Shows 12000, 11000 The first call to IncSalary is made using a variable of type Class1 that refers to an object of type Class1. In this case, both of the following calls: Me.IncSalary MyClass.IncSalary return the same value, because they both call IncSalary in the base class Class1.

Hint: If you are looking for high quality and reliable webspace provider to host and run your jsp hosting application check Virtualwebstudio jsp web hosting provider