Understanding business platform

xiaoxiao2021-03-06  39

Microsoft Corporation

Summary: Two parts. The first part is introduced in the experienced J2EE developer's view. Net is what is like. It combines the .NET concept with the principles you have understood, indicating the differences between the two platforms. The second part of this chapter is mirroring, the information provided is the same, but only for experienced .NET developers. To introduce you to J2EE's business characteristics and explain how Java applications work in a distributed environment.

Introduction

This chapter provides a brief introduction to a background of developers who have some platform development experience but have not been exposed to this alternative technology. This is not a training manual, but in connection with other environments you have learned, you can help you understand the basic concepts of some environment.

The competition between the Microsoft platform and the Sun platform is as deep as the competition between the advocator of the Apple user interface and Windows supporters. However, the company's business continues to grow is that the company's implementation components use the platform that best meets their requirements, rather than sticking this or that special ideology.

As a J2EE developer, there is less and less opportunity to get into contact with Microsoft .NET at its career. In fact, for the employer, it is very attractive thing for employers. Net and J2EE. Similarly, if you are a .NET developer, but have not used Java, the second part of this chapter can help you understand the functionality of the J2EE platform. In addition, this is not a reference book, but attempts to associate the concept of J2EE field with the .net concept you already know.

Note If you are an experienced Microsoft .NET developer, go to "J2EE Basic Principle (for .NET Developer)" section.

The summary table of this chapter lists the equivalent components of .NET and J2EE.

Microsoft .NET Basic Principles (for J2EE Developers)

The name of Microsoft .NET reflects Microsoft to re-adjust the operations and distributed applications on the Internet. Microsoft .NET consists of three main parts:

• A application environment-independent application environment that optimizes distributed operation .NET Framework. • A development environment that can be programmed using several Microsoft languages ​​Visual Studio .NET. • Support for distributed environments and .NET Framework's operating system Windows Server System.

Initially, I want to implement a unity of the following characteristics:

• Programming with language. • Enterprise-class scalability and reliability. • Integrate security. • Easy to implement. • Distributed operation. • Support open standards. • Reliable operation and manageability. • Powerful debugging tool.

.NET and J2EE comparison

In the view of Java developers, .NET may be similar to the Java platform, which all provide a structured approach to creating applications, and has a language compiled as an intermediate code, providing an application development. Large API library. Indeed, many Java domain commentators have pointed out that the concept jump from J2EE to .NET seems to be smaller than the concept jump than from Windows DNA to .NET. But in fact, the core of .NET has a set of targets with the Java platform.

Java includes Java platforms (running libraries and APIs) and Java languages. The use of the Java platform is to support applications written in Java language and compiled as Java bytecodes. Although many attempts to compile other languages ​​as Java bytecodes, most of these work are academic activities. The consistent idea of ​​Java is to use a language in a variety of operating systems.

.Net includes a .NET Framework (Running, API) and supported multiple programming languages. The goal of .NET Framework is to support applications written in any language and compiled into a Microsoft Intermediate Language (MSIL). The goal of .NET is "a variety of languages ​​sharing a platform." Research .NET FRAMEWORK

Understand the .NET Framework and its services provided for .NET-based applications.

Note .NET's application or application based on .NET Framework refers to the application of .NET Framework. For simplicity, this book uses some .NET-based applications.

The .NET Framework includes a variety of tasks such as data access, security, file I / O, XML operation, message delivery, class reflection, XML Web services, ASP.NET, and Microsoft Windows services.

Note sometimes compares .NET Framework and Java 2 SDK, but both are not completely equal.

The core part of .NET Framework is to support XML network services. This technology is both a method and a transport layer that transmits information between components of different computers, different networks and components of different operating systems.

Figure 2.1 illustrates the main components of the .NET Framework.

Figure 2. 1 Related to CLR's .NET Framework component

The .NET Framework can be free to re-release as components, including tools, classes, and API support to run .NET-based applications. I want to run the .NET Framework on the computer that is based on the .NET-based application.

Windows XP Service Pack 1 contains .NET Framework version 1.0, Windows? Server 2003 with .NET Framework 1.1, which is part of the operating system. For earlier Windows versions, you can download .NET Framework from the MSDN Web site. NET Framework you can also install .NET Framework.

Note The .NET Framework package is included in the .NET Framework SDK.

There are a variety of ways to install .NET Framework onto the client computer. You can resemble the re-published .NET Framework packets to the .msi file so that you (or your network administrator) can use the Active Directory Group Policy to distribute them. Larger companies can also use the system management server to distribute this package. Smaller companies can select Software Update Services (SUS) to deploy .NET Framework to the Windows 2000 client. Developers can include re-published packages into the compilation output of Visual Studio .NET, add the routine that can detect if there is .NET Framework, if you need to install or update .NET Framework.

Public language runtime

The Public Language Runtime (CLR) is the core components of the .NET Framework. The CLR provides core functions for hosting and running .NET-based applications. The main functions of the CLR are as follows:

• Real-time (JIT) compiled cost machine code. • Interface language integration. • Memory management and garbage recycling. • Managed code operation. • Real-time debugging. • Abnormal processing. • safety. • Runtime Type Security Check. • Thread management.

Note Although there are some differences, CLR can be regarded as a role in implementing Java Virtual Machine (JVM).

Real-time (JIT) compiled cost machine code

When deploying and running an application, the JIT compiler is quickly checking the platform's specifications. For example, the compiler will be checked, including the type and quantity, memory, etc. of the processor. The JIT compiler then compiles the application to generate machine code in the execution environment. This is the JIT compilation process.

Note The JIT process in the .NET Framework is similar to the JVM runtime compiler. Windows version after Windows NT 4.0 supports only x86 environments, which often makes people feel confusing: Why are they worried about compiling the correct steps of MSIL directly on the X86 platform. However, the X86-based computer is not true, MSIL's use provides maximum flexibility for future operating system development.

JIT compiles this fact: An application may not call all program code during execution. During execution, it is not used to convert all MSIL in portable executable (PE) into native code, but in need, and store the obtained native code for preparation. Call can access it. When a type is loaded, the loader creates a STUB for each method of the type. When the method was originally called, the STUB passed control to the JIT compiler, which converts the MSIL of the method to the machine code, and change the STUB to the location of the local code. Then call the JIT compiled method to directly call the previously generated native code, reduce the time spent on the JIT compilation and running code.

The effect of JIT operation is that the time that starts the application takes a little longer when the application is executed. However, the speed of executing the second and subsequent calls of the JIT method will be faster than the pre-compiled application, because the JIT component returns the previously generated native code, and the computer is appropriately optimized. .

The run library provides another compilation mode called the installation time code generation. Like a conventional JIT compiler, the installation time code generation mode converts MSIL to the machine code, but each converted code unit is large, and stores the obtained native code for use when loading and runs the assembly. Using the installation time code generation mode, the installation application converts the full assembly to the machine code, considers information about all of the currently installed assemblies. The resulting file has the speed of the native code that the starter speed is converted with the start-up speed than the standard JIT option.

Cross-language integration

You may be strange when you know that the CLR only supports a type of code. You may say that what is the meaning of the language claimed by the previous page? The answer is that the CLR only supports MSIL. Flexible is that any support .NET programming language can generate MSIL output. This is the reason that is independent of the language. You can create .NET-based applications with one or more languages ​​below:

• Host C (here) • C # (Similar to Java and C Sharp 鈥 _) • Visual Basic .NET • J # (allowed to write Java code for .NET platform J Sharp) • Fortran • Pascal • COBOL • Perl • Python • Eiffel

It turns out that C # has become an experienced Java developer and the universal choice of the .NET platform novice because it is similar to the Java programming language. J # provides a Java language subset that can be compiled into MSIL and run on the CLR. However, no matter which language is used, after writing the code, the compiler turns it into MSIL.

Note If you are an abuse (or only machine code programming), you can write directly with MSIL. However, because MSIL is a pseudo machine code, this is not a fully intuitive method.

Memory management and garbage recycling

The core of the CLR's memory management is the garbage collection process, which is similar to the corresponding process in Java. Garbage Recycling is a background operation that reviews the object submitted to the memory and restores the objects that are no longer needed. Garbage recovery is divided into three generations, which can restore short, medium, long-term objects, called Gen 0, Gen 1 and Gen 2, respectively. All new objects start in Gen 0 heap. The garbage collection algorithm works by checking whether there is any object in the stack.

Note Many classes create temporary objects for their return values, temporary strings, and various other utility classes (such as enumeors, etc.).

If there is not enough free memory allocation to the new object in the heap, the garbage collection loop starts from the Gen 0 object. If the memory is still insufficient, the garbage collection loop reclaims GEN 1 object, then the Gen 2 object. When garbage recycling has been treated with all generations, it is a complete garbage collection cycle.

When the garbage recovery cycle is running, it will increase all surviving objects to the next generation. Survive objects after the garbage recovery cycle is because these objects are still in use (accessible) or waiting to end. Survive Gen 0 objects increased to Gen 1, while surviving Gen 1 objects increased to Gen 2. The garbage recovery process is then compressed and moved any free memory to save the adjacent space, and the number of memory fragments is minimized. Compared with the next generation, the proportion of total garbage recovery cycles is generally 1:10, for example, 10 times Gen 0 recovery is carried out once, 10 Gen 1 recycling is performed.

Note On system resources, higher level garbage recovery, the higher the expenditure - the garbage collector expects to get a higher tip (a joke).

Managed code operation

The fourth largest function of .NET Framework is managed code operation. The definition of the hosted code is very simple - the hosted code uses the CLR, while the non-hosting code is not available. In order to make this definition more strict, it should be said: The hosted code is performed in the internal CLR. The call (service component, COM or DCOM object) is exceeded in the range of CLR. Therefore, CLR garbage collection and other functions do not operate the non-hosting code or unmanaged code components.

Real-time debugging

Real-time debugging (JIT) is a technique for debugging programs that are started outside Visual Studio. If JIT debugging has been enabled, a dialog box will pop up when a fault occurs. The dialog will ask if you want to debug the program and use which debugger to use.

When an exception occurs, JIT debugging can flexibly select the debugger. It is also possible to debug on a computer's replica computer, which helps to find programming problems faster.

Abnormal processing

CLR processes an exception in the .NET Framework application, but also provides some exception management functions. The main one of this is TRY / CATCH / __ FINALLY, using these blocks can capture managed abnormalities and non-hosting exceptions. The basic method is to use a Try clause when it is necessary to perform hazardous operations. If the function in the TRY sentence causes an exception, it is paired with a Catch clause. Whether or not an abnormality occurs? __Finally clause.

safety

The CLR performs security by using an XML format profile or a .NET Framework 1.1 Configuration Tool (Mscorcfg.msc) running security policy node to implement applications. The security profile contains information about the code group hierarchical and the right level associated with the policy level.

The .NET Framework Configuration Tool displays three main security configuration levels: business, machines or users. These levels correspond to three security profiles (EnterpriseC.config, and two separate security.configs of computer and user levels).

The .NET Framework Configuration Tool allows you to manage your rights sets (for example, FullTrust, localintranet, everything, etc., for example, MY_COMPUTER_ZONE, LOCALINTRANET_ZONE, TRUSTED_ZONE, and more. Each code group has a related permissions set, for example, Trusted_zone maps to the Internet authority set. The assembly that meets the code group member conditions receives the permissions related to the permissions. The authority set may include whether the application can access the FILE OPEN dialog that can be printed, or what kind of user interface can be displayed.

Although the security profile can be edited directly, it is highly recommended that you use the .NET Framework configuration tool or code Access Security Policy Tool (Caspol.exe) to modify the security policy. This ensures that the security profile will not undermine when changing the policy.

Runtime type security check

.NET Framework also implements security by runtime type security check. Using type security code, the public language runtime can completely divide each other. Such separation helps ensure that the assembly does not have an adverse effect on each other and improves the reliability of the application. Even if the trust level of type security components is different, they can still be implemented in the same process.

Type Security Codes can only access memory that is authorized to access. For example, the type security code cannot read a value from another object's private field. It can only access the type in a clearly defined, allowed way.

Although type security verification does not require a hosting code, type security plays a very important role in program set isolation and security implementation. If the code type is not safe, undesired side effects are generated. For example, when runtime does not prevent unsafe code from calling this unit (non-hosting) code and performs some malicious operations. When the code type is secure, the runtime security implementation mechanism ensures that it can only be accessed when there is access to this unit.

During the JIT compilation, an optional verification process checks the metadata of the method that is real-time as the method of this codes with MSIL to verify that they are type security.

Thread management

The public language runtime supports multi-threaded applications primarily through the ThreadPool class. ThreadPool can provide automatic thread creation and management mechanisms for most tasks.

Public type system

The Public Type System (CTS) defines how the application and .NET Framework in the run library declare, use and manage types, and is also an important part of the run library to support cross-language integration. It is there is a CTS that enables large developers teams to work to the same application, and each person in the team can program any of a variety of languages ​​supported by .NET Framework.

CTS can perform the following features:

• Create a framework, you can perform a cross-language integration, type security, and high performance code. • Provide an object-oriented model that fully supports multiple programming languages. • Define the rules that language must follow, which helps ensure that objects written in different languages ​​can interact with each other.

The hosted code operation is securely implemented by CTS, so CTS ensures that all .NET-based application components can be described. Then, .NET Framework handles references between hosting code components.

Global assembly cache

Install .NET Framework Create a machine range code cache, called a global assembly cache. The global assembly cache storage specifies the assembly (executable files or library files) shared as several applications on the computer. Combined with strong name tools, it also allows you to run two or more versions of the same name. This is much larger than the selection control of the assembly when running is more than using the ClassPath statement.

There are two version of global assembly cache - Mscorwks is a workstation version, which is running on Windows XP with any desktop operating system that can be installed .NET Framework. Mscorsvr is a part of the Windows 2003 Server family, and it is installed as a component of the .NET Framework on other server operating systems of Microsoft. Mscorwks runs best for single-user-based .NET-based applications, but MSCorsVR is suitable for large, multiprocessor, multi-user environments. Typically, the app's assembly can be placed in the installation directory of the application. However, you may want multiple applications to use the same assembly, then place the assembly in the global program cache, rather than copying them into two different directories.

Note Before placing the assembly to the global assembly cache, you must use the Strong Name Tool to sign the assembly.

There are several ways to deploy assemblies to the global assembly cache:

• Use the installer designed for the global assembly cache design. This is a method recommended. • Developer tools called Global Program Cache Tools (Gacutil.exe), it is part of the .NET Framework SDK. • Use Windows Explorer to drag the assembly into the cache.

For more information on best practices in deploying assemblies to global assembly cache, see MSDN Deploying .NET Framework-based Applications.

Strong name

By using the Strong Name Tool (sn.exe), each code component is digitally signed, .NET Framework improves security. Strong Name The assembly includes the identity of the assembly - its simple text name, version number, and zone information (if any) - along with a public key with a digital signature.

By creating a strong name assembly, you can support multiple DLLs of the same name in the global program cache. Then the application only uses its installed DLL version to solve the universal DLL conflict problem. Using a strong name assembly makes it possible to install the new version of the assembly and the older version of the assembly, without conflicting.

Note In order to avoid dependence on no strong name assembly, strong name assembly can only reference other strong name assemblies.

.NET Remoting

.NET Remoting is a new communication mechanism for Microsoft distributed applications, which are built on .NET Framework. The function of .NET Remoting is similar to the remote method call (RMI) in J2EE.

.NET Remoting makes it possible to easily build a wide range of distributed applications, regardless of the application components in a computer or distributed in different places worldwide. With .NET Remoting, you can build a client application that uses objects of other processes on any other computer that can be accessed on its network. Using .NET Remoting can also communicate with other application domains of the same process.

.NET Remoting provides an abstract method of inter-process communication that separates remote objects from a specific client or server application domain and a particular communication mechanism. Therefore, it is easy, flexible to customize. You can use another communication protocol to replace some kind of communication protocol, replacing a sequence format with another serialization format without recompiling the client or server. In addition, the remote system does not adopt a specific application model. You can communicate from the web application, console application, Windows Server - from almost anything you want to use. Remote servers can also be any type of application domain. Any application can carry a remote object and can provide its service to any client on the computer or on the network.

In order to build such an application in order to use .NET Remoting: The two components can communicate directly with the program domain boundaries, and you only need to build the following:

• A remote object. • A host application domain that listens to the object request. • A client application domain that requests the object. Even in complex multi-client / multi-server applications, you can also look at .NET Remoting. You must also configure the host and client application to connect to a remote infrastructure, you must understand the lifecycle and activation of the remote infrastructure.

Build .NET-based applications

There are several ways to write and build .NET-based applications. The most important methods are as follows:

• Write and build applications with Visual Studio .NET. • Use your favorite development environment and command line compiler. • Using the text editor and command line compiler.

Use Visual Studio .NET 2003

Visual Studio .NET 2003 is the latest version of Microsoft's application development environment, which is installed with MSDN Library for Visual Studio .NET. Visual Studio .NET fully complies with language-neutral methods, making it very easy to create interoperability items in different languages. It provides built-in templates for different projects, depending on the language you want to use. Project types include the following types:

• Applications based on a Windows Form. • ASP.NET web application. • ASP.NET Web Services. • Class library. • Console application. • Windows service.

In addition, Visual Studio can also pack applications to distribute, create a Windows installation package, CAB file, and installation routines.

Use the command line compiler

Creating a .NET-based application with Visual Studio .NET does not require any requirements, you will be very happy after you understand this. Another method is to utilize the command line compiler in the .NET Framework SDK, which is similar to the method created using Javac and J2SE SDK.

You can download the English version of .NET Framework SDK V1.1 from the SDK Web site.

When you install .NET Framework SDK, you will create a% window / versionnumber directory, here VersionNumber is equal to: .NET Framework 1.0 version is V1.0.3705, .NET Framework 1.1 version is V1.1.4322. In this directory, you can find the following command line compiler:

• CSC.exe for C # applications. • VBC.exe for Visual Basic. • JSC.exe for J #.

Run the compiler with the correct command line switch to generate one or more assemblies, and the post CLR can perform these assemblies. Typically, the assembly is .exe or .dll file.

Note You can check the contents of .exe or .dll files using the ILDASM.exe disassemble tools included in .NET Framework (SDK).

The .NET assembly contains descriptive metadata, such as Windows portable executable file headers, program set dependencies, and version information. However, there is no more to match the assembly in Java. The closest comparrential object is the JAR file, which contains classes that store metadata, and can cross-reference information with other JAR files without the ClassPath value.

Use the global assembly cache to find assemblies

.NET Framework does not use variables similar to ClassPath, but use the previously mentioned global assembly cache. Each computer has a global assembly cache, which is both a folder and a registration component database. This folder is located below% Windir% / Assembly and can be registered with Gacutil.exe. Note When you create a installation package in Visual Studio .NET, you want to include registration processing and as part of the installation.

To see a global assembly cache, complete the following steps.

To check global assembly cache

1. Click Start, point to All Programs, point to Administrative Tools, and then click Microsoft .NET Framework 1.1 Configuration (or 1.0). The .NET Configuration 1.1 (or 1.0) management console will appear. 2. Double-click the Assembly Cache node in the left pane. 3. In the pane on the right, click View List of Assemblies in the assembly cache link. The registered assembly list will appear. 4. Right-click an assembly and click Properties. The AssemblyName Properties dialog will appear.

The Version value allows multiple versions to exist at the same time and allows components, such as executables, calling a particular DLL. The format of the version number is as follows:

Majorversion.minorversion.buildNumber.revision

For example, 7.0.5000.0 is a public version number of a Microsoft.vsdesigner assembly.

Public key token is the result obtained after the code signature, which is uniquely identifies each assembly. This ensures that the application can only load the correct assembly to prevent malicious or unintentional replacement applications.

Comprehension characteristics

Features is a feature of most Microsoft software components, such as interface definition language (IDL) interface in COM, so these appears are not surprising in .NET Framework. The current version of Java 2 SDK does not support characteristics, although the proposed Java 2 SDK 1.5 claims to support similar features. For more information, see:

• JSR 175: a metadata facility for the Java Programming Language • New Language Features for Ease of Development In The Java 2 Platform, Standard Edition 1.5: a Conversation with Joshua Bloch

The features of the .NET Framework have both keywords, as well as a similar tag. Type, fields, document classes, and methods are recorded using markers. The metadata of the assembly contains characteristic information. Many of the standard namespaces in .NET Framework include features, if desired, developers can implement their own custom features.

One instance of the property is WebMethod. This feature indicates that the class can be called as an XML web service. If you place the WebMethod tag at the beginning of the method, then the compiler generates additional information to disclose the method as an XML Web service.

The following lines of code simply illustrate this.

[WebMethod]

Public String HelloWorld ()

{

...

}

Features accept parameters, parameters are part of the marker. This is similar to the constructor class.

[WebMethod (Namespace = "http:////////////////////////////////////www.microsoft.com/interoperability")] This specifies the namespace properties of the webMethod feature as the specified URL.

Note CLR supports the characteristics of any language, but the development language format determines the prefix of the tag.

Create a web application

In Java, you can create a web application with JSP pages and servlets. In .NET, you can create ASP.NET with the latest Active Server Pages (ASP) results. Typically, the ASP.NET application will run on the Internet Information Services (IIS), but this is not a very strict requirement. For example, an ASP.NET application can also be run on a platform based on Apache 2.0-based Enterprise Ready Server.

ASP.NET has improved than JSP features, with features such as code hidden and event-driven web controls. To achieve equivalent functions in JSP, you need scripting languages ​​and an additional tool. According to the experience of both Java, familiar with .NET, ASP.NET is more powerful than JSP, which is better than early ASP. The introduction of JavaServer Faces is just to make up for the lack of JSP.

ASP.NET applications often have a graphical front end, so developers often prefer to use Visual Studio .NET to create and edit ASP.NET pages. Another free integrated development environment (IDE) is Web Matrix, you can download from ASP.NET Web Site.

An ASP.NET web application can be created with any language supported by .NET Framework CLR. This provides flexibility in any language programming, and can even create a Web site by combining elements built in different languages.

Carrier assembly

There is no tool directly with EJB peer in .NET Framework. However, there are three main technologies to provide boarding components for enterprise applications:

• Run as a Windows service. • Carry it through IIS. • Using component services.

Run as a Windows service

Windows services (or NT services) are system-level processes running on your computer, which is independent of the logged in user. Typical services include functional, planning procedures, viral scanners, database engines, and network components.

You can use the templates in Visual Studio .NET to get the .NET assembly, and run as a service. This generates an application, as long as the computer is running, the application is running.

Note As a service running application needs to handle its own network configuration. In particular, these applications should run under domain accounts instead of running on the local machine account. This is because the local machine account only has the right to local computers.

Bearing through IIS

The Internet information service provides a framework that can carry a layer and a business layer component. With a configuration file related to the assembly, you can support in IIS as follows:

• Deploy the assembly. • Process the input connection. • supporting agreement. • Implement the connection pool. • Configure security.

Another method is to build its own custom frame to carry assemblies. However, this is a very time consuming and trouble work.

Use component services

The carrier assembly on IIS is very simple and convenient, but it cannot provide all the features of EJB. Component services (or COM ) provide additional features, for example:

• Recycling • Status management • Transaction support • Method level security • Record log • Simulation • Message Queue Support

.NET developers can set COM attributes by component service management tools or using programmable features. Note Although there are many third-party implementation methods, but there is no tool for persistent persistence (CMP), container managed relationship, or EJB-QL peer in .NET. Visual Studio .NET has tools that automatically generate SQL statements and drag and drop database tables to IDE.

Support Web services

Microsoft has spent considerable effort in supporting Web services. ASP.NET Web services are preferred technologies for implementing Web services based on .NET Framework.

In HTTP, ASP.NET Web Services uses SOAP support service requests. ASP.NET Web Services automatically generates WSDL and discovery files (.disco) for Web services. A web service listener can be implemented using an ASP.NET Web service, which can access the business appearance as a COM component or hosted class. The .NET Framework SDK also provides a tool for generating a proxy class, and client applications can use the proxy class to access Web services.

Connection with database

.NET Framework provides ADO.NET (previously known as ActiveX Data Object) as a framework for connectivity to the database. From the perspective of architect, ADO.NET represents abstract design concepts that can build data access in .NET Framework. From a developer's point of view, ADO.NET represents a specific class implemented within .NET Framework, .NET Framework then uses these classes to be accessed.

Note The features provided by ADO.NET are similar to the functions implemented in JDBC and JDO.

For ADO.NET, there are several major design objectives:

• Clearly, Decomposed Object Model - ADO.NET is an easy-to-use object model that developers fully have to determine how to control the connection, command of the command, and data of the data. • Disconnect the Data Cache Model N-layer programming and the XML Web service architecture requires applications to participate in a disconnected, loosely coupled manner. ADO.NET provides a integrated cache data model to block processing data between applications or services, and then optimize the original data source. • XML Support - XML ​​is the key to building interoperable applications and reliable data processing models. XML support is directly included in .NET Framework, ADO.NET is seamlessly interacts with XML through relational or in-unit XML.

You can divide the ADO.NET architecture into two logic segments: commands executes and cache. The functionality required to execute the functionality includes connection, execution, and reading results, etc., .NET data provider supports these features. The DataSet function is a cache for processing results.

Implement collection

A collection is a set of similar types of objects that can be classified together. This is equal to java.util.collections on the J2EE platform.

Any type of object can be divided into the same type of Object set to utilize the structures in the programming language. For example, all objects in the C # foreach statement expectations are all objects in the same type.

However, in the type Object collection, packing and unpacking or transforming such additional processing will affect the performance of the collection. In general, packing and unpacking boxes occur when there is a value type in the collection or recovery type of Object.

Strong type collection, such as StringCollection, if the type of element is a collection expected type (eg, from the StringCollection or recovery string), then these effects can be avoided. In addition, a strong type of collection automatically verifies the type of each element added to the collection.

You can divide the Collectes class into three types:

• General collection - common data set variables, such as hash tables, queues, stacks, directories, and lists. • Bit Collection - Its element is a collection of bit flags. They are slightly different from other collections. • Dedicated Collection - Collection with special purpose, usually handle specific types of elements, such as StringDictionary. Access directory service

The usual meaning of the access directory service in .NET is: Using the Lightweight Directory Access Protocol (LDAP) or Active Directory Service Interface (ADSI), JNDI's peer, connected to Active Directory.

Microsoft implements the LDAP API in WLDAP32.DLL - also known as "LDAP? C" or "C-Binding LDAP". The application written by LDAP is only compatible with the LDAP directory service, although Active Directory also fully supports the LDAP API for directory access.

The API recommended for Active Directory is ADSI. The ADSI is located at the top of the LDAP and can also provide the easiest way to access Active Directory via LDAP. The native ADSI allows access to Active Directory by disclosing an object in a directory in the form of a COM object. Then you can use the method in the COM interface to operate the objects in the directory.

The ADSI Provider contains ADSI object implementations for a particular namespace, the most important one is the Adsi LDAP provider. By implementing the desired interface, the ADSI provider converts these interfaces to the API call for a specific directory service.

The ADSI LDAP provider runs, access Active Directory or other LDAP directory services in the ADSI client. The ADSI LDAP provider works with any LDAP server that supports LDAPv2 or update.

For more information on LDAP API and LDAP programming, see the link on the web resource page Microsoft Platform SDK.

reflection

Reflection allows you to write code to dynamically check the data type or object during runtime. You can get a range of methods, interfaces and even type variables. Reflection can even allow interaction with the object by calling dynamic discovery or to dynamically discovered variables.

Using reflections, you can create an object browser, enumerate applications with record methods, even highly configurable, metadata-driven applications, which create objects and call methods based on instructions in the table or XML file. These are powerful features that can be used in .NET-based applications.

It should be noted that the reflection will also perform potentially dangerous operations. You can use reflection to call the method in the scope is private. You can also assign a variable to the object, and no business logic is called. Reflection provides tools that misuse objects in a very dangerous manner. However, you can use these functions to create a very powerful code, such as the code that loads the data into the object from DataSet based on metadata that matches the number of variable names in the table.

J2EE Basic Principle (for .NET Developer)

If you are a .NET developer and want to know the components and features of the J2EE platform, you can start from here.

Java developed by Sun Microsystems is both a platform and a programming language. At present, there are three versions of the Java platform:

• J2SE (Java 2 Standard Edition) • J2EE (Java 2 Enterprise Edition) • J2ME (Java 2 Micro Edition)

Note "Java" This term usually refers to the function of J2SE. The area where the enterprise version is required to include J2EE.

Java 2 Platform, Enterprise Edition or J2EE is a set of interconnected specifications that allow developers to create a server-based multi-layer application. Therefore, unlike Microsoft .NET, J2EE is a standard rather than a product. The J2EE specification includes a range of Adobe PDF files to illustrate the container structure where the application protocol is running and the application runs. Like .NET, J2EE allows you to focus on writing business logic instead of enterprise frame itself, making it easier to write distributed enterprise applications. J2EE provides an "infrastructure" that allows the application to run applications, otherwise write these will be tedious and time consuming.

Note When publishing, J2EE V1.3 is the latest release version, while V1.4 is still in the final draft phase.

Therefore, the J2EE platform is similar to the viewpoint of Microsoft .NET, the subjects run through the two platforms are the same. But it is very important to understand the essence of both. Java and Microsoft .NET are different from three aspects, they are:

• Operating System Support • Language Support • Execution Method

From the beginning, it is designed to work on a variety of operating systems when designing Java. Therefore, Java code can run in a variety of environments, for example:

• Windows • UNIX • Linux • MacOS • Beos

However, Microsoft .NET can only run on Windows.

Note Rotor is the version of the .NET Framework running on FreeBSD. However, this is more in academic research, not a practical implementation.

Language support includes language, format, and syntax used by creating a program. Write a Java application only uses a Java programming language. For .NET, you can select any language that supports .NET Framework.

Two platforms also have important differences in running applications. When building a project based on the .NET language, the output is the MSIL code, which is the code compiled when the JIT compiler is runtime.

In order to deploy a Java program, build an application to create a Java bytecode. The JVM running over the target operating system explains these bytecodes to generate relevant instructions.

Note Simultaneously, the Java Jit compiler works similar to the .NET Framework component.

Understand the Java platform

The Java platform has two main components. They are:

• Java runtime environment (JRE) • Java Language and Format (API)

The main components of JRE are Java virtual machines, or JVM. The JVM's role is to explain the Java bytecode in the operating machine instruction for the operating system. However, JVM also provides many features similar to .NET CLR. JRE also includes Java class libraries.

Other components developed in the past decade in the J2EE framework. They are:

• Java Server Pages (JSP) • Server side API or servlet • Enterprise Java Beans (EJB) • Java Naming and Directory Interface (JNDI) • Java Message Service (JMS) • Java API for XML-based RPC (JAX-RPC) • J2EE Connector Architecture • J2EE Management Model • J2EE Deployment API • Java Management Extensions (JMX) • J2EE Authorization Contract for Containers • Java API for XML Registries (JAXR) • Java Transaction API (JTA) • Common Object Request Broker Architecture (CORBA) • The JDBC Data Access APIs have most components in .NET Framework or Windows. For example, JMS provides a message based on message-based transaction, which is mapped to System.Messaging namespace.

Since J2EE is a specification, not a product, many suppliers have created their own implementation under Sun's license, including:

• Sun (Sun One Application Server) • IBM (WebSphere) • BEA (WebLogic)

There are several open source implementations, the most famous is JBoss. For more information, see the JBoss Web site http://www.jboss.org/

Implement Java SDK

Like .NET Framework, Java has a software development kit to help you create, compile Java applications. Java SDK has been modified many times, you can download Java 2 SDK, Standard Edition 1.4 from the Sun's Java Web site.

Other suppliers have produced their own Java SDK implementation under the license. As with the J2EE application server, these vendors include IBM and BEA, and some open source implementations. Microsoft has achieved until 1.1.4.

Java 2 SDK contains class libraries that can be used to create your own Java source code and compiler and binary compilers and binarys that build and execute these applications. The SDK's bin directory contains a Javac.exe file that can be used to compile the Java source code (* .java file) into a Java bytecode (* .class file). However, like the .NET application, only the most stubborn and conservative work is completely executed from the command line, and most work uses the GUI-based IDE to create and compile the Java application.

Build a Java application

When compiling Java classes with Java compiler, each class in Java generates a separate .class file, .class file is a standard compilation unit. Then JVM can perform the .class file in the following format:

Java myapp.class

However, the .class file is not completely corresponding to the package in .NET, because the .NET assembly is both a unit that is executed and a distributed unit. Java Developers use the Java Archive (JAR) file to create a published application with multiple .calss files. Although the JAR file can contain any type of file and have an internal directory structure, it is like a ZIP file, but a basic JAR file is a collection of compiled Java class. You can use the jar.exe file in the SDK / bin directory to add, listed .class files or decompress the .class file from the JAR file. You can use the JVM Java.exe file to perform JAR files. The format is:

Java jar myapp.jar

Just use this unit operating system command and the basic tools provided by Java 2 SDK to build a complete J2EE application if you really want to do this. But this method is very tedious and is easily error. Conversely, developers often use build tools, such as Ant, which is part of the Apache Jakarta project. ANT is a built-in build tool that is automatically compiled, packaged, and deployed. It uses XML build files to determine the tasks that need to be completed and deployed.

For more information on more Ant, see the Apache Ant Web site.

Positioning and sharing class

The Java platform does not have something to go with the global assembly. However, applications may still need references or share additional classes. In Java, this work is done using the environment variable named ClassPath. This is similar to the PATH statement in the AutoExec.bat boot file, or the System profile property in Windows.

The default classpath is the current directory. If you like, you can set the environment variable classpath to one or more different directories. When doing this, the path must be explicitly containing the main Java 2 SDK tool JAR and the current directory. Therefore, the simple classpath statement in the Java SDK version 1.3 version running on Windows is as follows:

Set classpath =.;% J2EE_HOME% / lib / j2ee.jar;

If the application needs another class or JAR file, modify the ClassPath variable before running the application. This can be done by reference to the current ClassPath variable as shown below.

Set classpath =% classpath%; C: / intrApp/Resources.jar; C: / OtheRAPP / CLASSES

This adds the new directory to the existing classpath, so when the Java application loads and requests a class, the application also searches all classes in C: / OtheRApp / Classes, or search JAR files C: / Otherapp / Resources.jar.

Both the JavaC.exe compiler and Java.exe execution tools can accept parameters to include or modify the ClassPath variable. Java IDE also allows you to include a ClassPath statement. You can automatically add the library to the class search sequence by setting these libraries as JRE expands.

Note If the Java application generates ClassNotFoundException, it can be determined that this is because there is no required library in the ClassPath statement.

Implement other environment variables

The environment variables used by Java applications are often more than environment variables used based on .NET-based applications. This is because Java applications can run on a variety of operating systems, so they need to handle different environments. Environment variables provide a simple way to ensure consistency between setting and control configuration and application execution path.

Table 2.1: Public Environment Variable Variable Name Rules Java_Home Sun Java SDK installation location J2EE_HOME Sun J2EE SDK installation location Ant_home Ant's primary directory PATH Windows Path statement Using Java integrated design environment

Several vendors have produced IDE bags to assist in creating and editing, ranging from enhanced text editors to a full-featured package similar to Visual Studio .NET. Some is a package that needs to pay, others are free. The examples here include:

• Sun One Studio • JCREATOR • Borland JBuilder • Java GUI Builder • JPAD Pro • CodeGuide • NetBeans • Anyj

Note Although the Visual Secudio .NET can be used to create and edit Java applications, but J # IntelliSense technology is only available for Java SDK 1.1.4 and above, and the Java API class is required to use JavaC.exe from the command line. Compile the application.

All IDE packs allow for compiling applications in an IDE environment. Another way is like Visual Studio, can be compiled from the command line.

Create a web application

For the representation of the layer assembly, Java implements JSP in the .NET architecture where ASP.NET is used. JSP provides server-side technology for developing web applications, and JSP pages are HTML and Java code mixtures.

Java-based web application utilizes dynamic compilation JSP pages with the concept of servlet. The servlet is a Java programming language class that extends the function of the computer that carries the application-response programming model access. Java's servlet can also be regarded as a portable component that provides dynamic content for the user.

The first look, JSP and servlet are very similar, both produce dynamic content. Any script elements can be created in a JSP page or servlet with a Java programming language. In addition, the JVM is compiled into a servlet at runtime JVM, so that both use the same engine. However, developing servlets need to write Java classes, so higher programming techniques are required than developing JSP. You can view servlet as a Java code containing HTML content.

Like the servlet, JSP provides dynamic content for users, but higher than the abstract degree of servlets. JSP can be regarded as a static HTML containing dynamic Java code.

JSP and servlet are hosts in a variety of environments. This includes free environment such as Apache Tomcat, as well as large commercial software and supplier support.

To implement JSP-based applications, you can use Java IDE to design applications. Several IDEs contain tools with real-time editing JSP pages, which can preview any effect after changing graphics or controls.

Note The current version number of the JSP specification is V1.2, the version number of the servlet API is V2.3.

In order to deploy a web application, you will package them into a deployment unit called a web application archive (WAR) file. This is similar to packaging Java applications into JAR. The WAR file can then be easily deployed on the web server.

Carrier assembly

The main feature of the JSP page and servlet is to interact with the user through the browser in the layer. However, components called Enterprise Java Beans (EJB) are required when performing business rules in the business layer. EJB is a peer component of COM components or hosting code components and provides the following services:

• Maintenance status • Transactional support • Method level security • Record log • Simulation • Message Queuing support EJB has three forms:

• Session Bean • Entity Bean • Message Drive Bean.

Session bean management business logic, such as the rules for defining customer relationship management system operations. The session bean may be stateless, or can maintain a state, constraint client on the session bean during the living period of the object. Typically session beans provide some service, such as performing a task (such as authenticating the client).

The entity bean represents an object in a persistent storage area. Each instance of the entity bean corresponds to a line of data in the database table. There are two types of entities Beans: Container Hosting Persistence (CMP) Beans, hosted by container, while Bean managed persistence (BMP) bean management persistence.

For CMP entity beans, the container utilizes mapping between the mapping file hosting the bean and the database field. This mapping file typically stores these mappings as an XML deployment descriptor. Container hosts all communication with the database. Compared with BMP, CMP has the following advantages:

• Easy configuration • Easy maintenance • No database code

Due to the high abstraction, the main disadvantage of CMP is that its performance is poor. However, the J2EE specification has introduced some new features, such as virtual accessors, which increases the performance of BEAN using CMP.

For BMP entity beans, developers are responsible for writing all JDBC code to transfer data between beans and data stores. BMP requires developers to write more code than CMP more than CMP, but there are still a few good reasons for using BMP:

• Greater flexibility • Better performance • Can be connected to multiple database sources

Java developers will use CMP to connect with a standard database (such as ORACLE) or in a small amount of trading per second. It is the use of BMP's land in the case where data access is fast or requires developers, and non-standard databases such as LDAP directory.

Message Drive Bean (MDB) is required to be used in conjunction with the JMS API to asynchronously processing messages. Message Driver Bean is the user of JMS messages. The client does not directly access MDB, and they send JMS messages to the target of the listener MDB. This will be able to re-use MDB, and it also means that developers don't have to worry about getting messages.

The two advantages of using MDB are that MDB can process the user's request, and the response speed is faster than serial calls using non-messaging entity Java beans. Also, the MDB implementation can guarantee the user's response time when searching for multiple data sources.

Building a company Javabean

When building business JavaBean, developers must create the implementation class of the bean and many interfaces. The client accesses sessions and entity beans by developers to access sessions and entity beans in a method defined in the bean interface. These interfaces determine how customers communicate with EJBs. Message-driven Bean and entity and session beans are different because they have no interface, which only contains a bean implementation class.

The interface defined on an entity or session bean depends on a key factor: is a remote access or a local access to this bean?

The situation of the remote client is:

• Applications or components running in JVM with the client (although the application does not require a must be run in a separate JVM.) • Applications or components executing on different computers. • WEB components, such as servlets, client applications, or another EJB. • The client does not know (or need to know) the EJB position.

If the EJB serves the remote client, the developer must create two interfaces: a remote interface with a native interface. Remote interface defines a BEAN-specific business method, such as AuthenticateCustomer. This machine interface defines how to manage bean instances. For example, a session bean has a method of creating a bean instance. The entity bean also includes a method of positioning. The positioning method allows the client to locate the entity bean, for example, FindbyPrimaryKey. If there is a few cases, the local client:

• The client component or application is executed in the same JVM as EJB. • The client can be a web component or EJB. • The location of EJB is opaque for the client.

If EJB is required for the local client service, you also need to create two interfaces, a local interface with a local native interface. The local interface defines the business method of the bean, the method defined is similar to the remote interface. The local native interface is similar to the remote native interface because it defines how the method of operating the bean instance and the method of positioning.

Typically, the local client calls the local interface than the efficiency of remote calls. In a typical J2EE application, session beans provide remote client access, but entity beans are typically provided with local client access. Entity Beans using CMP almost always use local access.

Deploy application

Building and deploying a J2EE application involves many steps to ensure that all the contents needed to work is deployed. In addition to the JAR file containing EJB or other classes, the application may also need a WAR file. The WAR file is a JAR that has the structure of the web application. Finally, the enterprise archive file (EAR) can include WAR and JAR filled with EJB and other content.

The deployment descriptor can be used to configure the deployment setting, which is a .xml file with a defined structure. The deployment descriptor specifies settings, such as security, transactional support, and logging, which tells the application server how to deploy the components in supporting applications. In addition, these settings are associated with settings in the component service. Some deployment descriptor settings are part of the J2EE specification, but others are related to the application server and are vendors.

.NET and J2EE characteristics comparison

Table 2.2 is the comparison of .NET and J2EE characteristics and functions. However, the background composition of each platform is different, so it is directly compared .NET and J2EE sometimes not suitable. For example, MSMQ is a product, while JMS is an API. Therefore, a component cannot be easily removed and the peerless components of other platforms cannot be removed.

Table 2.2: .NET and J2EE Functional Compare Features or Services Microsoft .NET Elements J2EE Elements Remarks Technical Type Product Standards - Middleware Suppliers Microsoft and Partners More 50 Suppliers - Client GUI Windows Forms AWT / SWING Swing / AWT is part of J2SE Web GUI ASP.NET JSP - Web Script ISAPI HTTPHANDLER HTTPMODULE Servlet Filter - Web Applications Host Internet Information Server (depending on supplier implementation) J2EE example includes Apache Tomcat Interpretation CLR JRE - Server-side business logic components .NET class or service component (COM ) EJB session beans - Server-side data component 1 has DB logic service components with bean managed persistence EJB - Server-side data component 2 ADO.NET Data set with container hosting Persistent EJB is just an approximate peer directory Access to implement the Active Directory service interface (ADSI) through LDAP implementation Java Named and Directory Service (JNDI) LDAP compatibility, making it easy to switch between directory services. Remote call .NET Remoting RMI-IIOP - Data Access ADO.NET JDBC, SQL / J, JDO - Message Processing Microsoft Message Queue JMS Microsoft Message Queue is a product. JMS is a specification and therefore requires the underlying implementation. Transactional support Com / distributed transaction controller (DTC) JTA - small knot

This chapter is an overview of Java developers, and is also introduced to Java for .NET developers. The characteristics of each platform are compared, and the peer components in different environments are described. It also describes how different platforms handle common programming issues and solutions used for each platform.

Reference

For information on .NET Framework, see

http://msdn.microsoft.com/netframework/

For information on developing environment-visual studio .NET, please refer to information on any support language programming.

Http://msdn.microsoft.com/vstudio/

For information on supporting distributed environments and .NET Framework, please refer to information about Windows Server System.

http://www.microsoft.com/windowsserversystem/default.mspx

Download .NET Framework 1.1

http://msdn.microsoft.com/netframework/downloads/howtoget.aspx#section3

- or -

Update service Web site from Windows

Http://windowsupdate.microsoft.com/ Download

For more details on the structure of similar features, see JSR 175: a metadata facility for the Java Programming Language

http://www.jcp.org/en/jsr/detail?id=175

- or -

Ease of Development In The Java 2 Platform, Standard? Edition 1.5: a Conversation with Joshua Bloch

http://java.sun.com/features/2003/05/bloch_qa.html

For more information on best practices to deploy assemblies to global assembly cache, see Deploying .NET Framework-based ApplicationShttp: //msdn.microsoft.com/library/default.asp? Url = / library / EN- US / DNBDA / HTML / DALGROADMAP.ASP

Download English .NET Framework SDK V1.1 from SDK Web Sites

Http://www.microsoft.com/downloads/details.aspx?familyid=9b3a2ca6-3647-4070-9f41-a333c6b9181d&displayLANG=EN

Download another free integration development environment from ASP.NET Web Sites Web Matrix

http://www.asp.net/webmatrix

For more information on the LDAP API and programming with LDAP, see the Microsoft Platform SDK on the web resource page

http://windows.microsoft.com/windows2000/reskit/webresources

To download Java 2 SDK, Standard Edition v 1.4, see Sun's Java Web site

http://java.sun.com/

For more information on Ant, see the Web site of Apache Ant

http://ant.apache.org/

Go to the original English page

转载请注明原文地址:https://www.9cbs.com/read-77704.html

New Post(0)