免费论文网 首页

java外文翻译5000字

时间:2016-11-10 12:55:34 来源:免费论文网

篇一:JAVA相关毕业论文外文翻译

Java 堆

Java 堆,每个 Java 对象在其中分配,是您在编写 Java 应用程序时使用最频繁的内存区域。JVM 设计用于将我们与主机的特性隔离,所以将内存当作堆来考虑再正常不过了。您一定遇到过 Java 堆 OutOfMemoryError ,它可能是由于对象泄漏造成的,也可能是因为堆的大小不足以存储所有数据,您也可能了解这些场景的一些调试技巧。但是随着您的 Java 应用程序处理越来越多的数据和越来越多的并发负载,您可能就会遇到无法使用常规技巧进行修复的OutOfMemoryError。在一些场景中,即使 java 堆未满,也会抛出错误。当这类场景发生时,您需要理解 Java 运行时环境(Java Runtime Environment,JRE)内部到底发生了什么。

Java 应用程序在 Java 运行时的虚拟化环境中运行,但是运行时本身是使用

C 之类的语言编写的本机程序,它也会耗用本机资源,包括本机内存。本机内存是可用于运行时进程的内存,它与 Java 应用程序使用的 java 堆内存不同。每种虚拟化资源(包括 Java 堆和 Java 线程)都必须存储在本机内存中,虚拟机在运行时使用的数据也是如此。这意味着主机的硬件和操作系统施加在本机内存上的限制会影响到 Java 应用程序的性能。

硬件限制

本机进程遇到的许多限制都是由硬件造成的,而与操作系统没有关系。每台计算机都有一个处理器和一些随机存取存储器(RAM),后者也称为物理内存。处理器将数据流解释为要执行的指令,它拥有一个或多个处理单元,用于执行整数和浮点运算以及更高级的计算。处理器具有许多寄存器 —— 常快速的内存元素,用作被执行的计算的工作存储,寄存器大小决定了一次计算可使用的最大数值。

处理器通过内存总线连接到物理内存。物理地址(处理器用于索引物理 RAM 的地址)的大小限制了可以寻址的内存。例如,一个 16 位物理地址可以寻址 0x0000 到 0xFFFF 的内存地址,这个地址范围包括 2^16 = 65536 个惟一的内存位置。如果每个地址引用一个存储字节,那么一个 16 位物理地址将允许处理器寻址 64KB 内存。

处理器被描述为特定数量的数据位。这通常指的是寄存器大小,但是也存在例外,比如 32 位 390 指的是物理地址大小。对于桌面和服务器平台,这个数字为 31、32 或 64;对于嵌入式设备和微处理器,这个数字可能小至 4。物理地址大小可以与寄存器带宽一样大,也可以比它大或小。如果在适当的操作系统上运行,大部分 64 位处理器可以运行 32 位程序。

操作系统和虚拟内存

如果您编写无需操作系统,直接在处理器上运行的应用程序,您可以使用处理器可以寻址的所有内存(假设连接到了足够的物理 RAM)。但是要使用多任务和硬件抽象等特性,几乎所有人都会使用某种类型的操作系统来运行他们的程序。

在 Aix 等多任务操作系统中,有多个程序在使用系统资源。需要为每个程序分配物理内存区域来在其中运行。可以设计这样一个操作系统:每个程序直接使用物理内存,并且可以可靠地仅使用分配给它的内存。一些嵌入式操作系统以这种方式工作,但是这在包含多个未经过集中测试的应用程序的环境中是不切实际的,因为任何程序都可能破坏其他程序或者操作系统本身的内存。

虚拟内存 允许多个进程共享物理内存,而且不会破坏彼此的数据。在具有虚拟内存的操作系统(比如 Windows、Linux 和许多其他操作系统)中,每个程序都拥有自己的虚拟地址空间 —— 一个逻辑地址区域,其大小由该系统上的地址大小规定(所以,桌面和服务器平台的虚拟地址空间为 31、32 或 64 位)。进程的虚拟地址空间中的区域可被映射到物理内存、文件或任何其他可寻址存储。操作系统可以将物理内存中的数据移动到未使用的交换区,以便于最充分地利用物理内存。当程序尝试使用虚拟地址访问内存时,操作系统结合片上硬件将该虚拟地址映射到物理位置。该位置可以是物理 RAM、文件或交换区。如果一个内存区域被移动到交换空间,那么它将在被使用之前加载回物理内存中。

在 AIX 上,进程是关于 OS 控制资源(比如文件和套接字信息)、虚拟地址空间以及至少一个执行线程的一系列信息。虽然 32 位地址可以引用 4GB 数据,但程序不能独自使用整个 4GB 地址空间。与其他操作系统一样地址空间分为多个部分,程序只能使用其中的一些部分;其余部分供操作系统使用。与

Windows 和 Linux 相比,AIX 内存模型更加复杂并且可以更加精确地进行优化。AIX 32 位内存模型被分成 16 个 256MB 分段进行管理。

用户程序只能直接控制 16 个分段中的 12 个 — 即 4GB 中的 3GB。最大的限制是,本机堆和所有线程栈都保存在分段 2 中。为了适应对数据需求较高的程序,AIX 提供了一个大内存模型。

大内存模型允许程序员或用户附加一些共享/映射分段作为本机堆使用,通过在构建可执行程序时提供一个链接器选项或者在程序启动之前设置 LDR_CNTRL 环境变量。要在运行时支持大内存模型,需要设置 LDR_CNTRL=MAXDATA=0xN0000000。其中, N 位于 1 和 8 之间。超过此范围的任何值都会造成操作系统使用默认内存模型。在大内存模型中,本机堆从分段 3 开始;分段 2 仅用于原始(初始)线程栈。

当您使用大内存模型时,分段分配是静态的;也就是说,如果你请求 4 个数据分段(1GB 本机堆),但是仅分配 1 个本机堆分段(256MB),则其他 3 个数据分段将不能用于内存映射。

如果您希望本机堆大于 2GB,并且运行的是 AIX 5.1 或更高版本,那么您可以使用 AIX 超大内存模型。与大内存模型类似,可以通过一个链接器选项或在运行时使用 LDR_CNTRL 环境变量来为编译时的可执行程序启用超大内存模型。要在运行时启用超大内存模型,需置 LDR_CNTRL=MAXDATA=0xN0000000@DSA。其中, N 位于 0 和 D 之间(如果您使用 AIX 5.2 或更高版本),或于 1 和 A 之间(如果您使用 AIX 5.1)。 N 值指定可用于本机堆的分段数量,但与大内存模型不同,这些分段可以在必要时用于映射。

通常,IBM Java 运行时使用超大内存模型,除非它被 LDR_CNTRL 环境变量覆盖。

将 N 设置为 1 和 A 之间,这会使用 3 和 C 之间的分段作为本机存储。在 AIX 5.2 中,将 N 设置为 B 或更多会更改内存布局 — 它不再使用 D 和 F 作为共享库,并且允许它们用于本机存储或映射。将 N 设置为 D 可分配最多 13 个分段(3.25GB)的堆。将 N 设置为 0 可允许分段 3 到 F 用于映射 — 本机堆保存在分段 2 中。

本机内存泄漏或本机内存过度使用会造成各种问题,这取决于您是耗尽了地址空间还是用完了物理内存。耗尽地址空间通常只发生在 32 位进程中 — 因为可以轻松地分配最大 4GB 地址空间。64 位进程的用户空间可以达到上千 GB,并且难以用完。如果您确实耗尽了 Java 进程的地址空间,则 Java 运行时会开始出现一些奇怪的症状,本文将在稍后讨论这些情况。在进程地址空间大于物理内存的系统中,内存泄漏或本机内存过度使用会迫使操作系统提供一些虚拟地址空间。访问操作系统提供的内存地址要比读取(物理内存中的)常驻地址慢很多,因为必须硬盘驱动器加载它。

如果您同时尝试使用过多 RAM 虚拟内存,造成数据无法存储在物理内存中,则系统挂起(thrash)— 也就是花费大多数时间在交换空间与内存之间来回复制数据。出现这种情况时,计算机和各应用程序的性能将变得很差,用户会立即觉察到出现了问题。当 JVM 的 Java 堆被换出时,垃圾收集器的性能将变得极差,甚至会造成应用程序挂起。如果多个 Java 运行时在一台机器上同时运行,则物理内存必须满足所有 Java 堆的需要。

Java 运行时如何使用本机内存

Java 运行时是一个 OS 进程,它受上一节所提到的硬件及操作系统限制。运行时环境提供由一些未知用户代码驱动的功能;这使得无法预测运行时环境在各种情况下需要哪些资源。Java 应用程序在托管 Java 环境中采取的每一个措施都有可能影响提供该环境的运行时的资源需求。本节讨论 Java 应用程序消耗本机内存的方式及原因。

Java 堆和垃圾收集

Java 堆是分配给对象的内存区。IBM Developer Kits for Java Standard Edition 拥有一个物理堆,但一些专门的 Java 运行时,比如 IBM WebSphere Real Time,则有多个堆。堆可以分为多个部分,例如 IBM gencon 策略的 nursery 和 tenured 区。大多数 Java 堆都是作为本机内存的相邻 slab 实现的。

控制堆大小的方法是在 Java 命令行中使用 -Xmx 和 -Xms 选项(mx 是堆的最大大小,ms 是初始大小)。虽然逻辑堆(活跃使用的内存区)将根据堆中对象的数量和垃圾收集(CG)所花费的时间增大或缩小,但所使用的本机内存量仍然保持不变,并且将由 -Xmx 值(最大堆大小)决定。内存管理器依赖作为相

邻内存 slab 的堆,因此当堆需要扩展时无法分配更多本机内存;所有堆内存必须预先保留。

保留本机内存与分配它不同。保留本机内存时,它不受物理内存或其他存储的支持。虽然保留地址空间块不会耗尽物理资源,但它确实能防止内存用于其他目的。保留从未使用的内存造成的泄漏与已分配内存的泄漏同样严重。

AIX 上的 IBM 垃圾收集器将最大限度减少物理内存的使用,当使用的堆区域减少时,它会释放堆的备份存储。

对于大多数 Java 应用程序,Java 堆是最大的进程地址空间使用者,因此 Java 启动程序使用 Java 堆大小来确定如何配置地址空间。

即时(Just-in-time,JIT)编译器

JIT 编译器在运行时将 Java 字节码编译为优化的二进制码。这将极大地改善 Java 运行时的速度,并允许 Java 应用程序的运行速度能与本机代码相提并论。

编译字节码将使用本机内存(就像静态编译器一样,比如 gcc,需要内存才能运行),但是 JIT 的输出(可执行代码)也可以存储在本机内存中。包含许多经过 JIT 编译的方法的 Java 应用程序比较小的应用程序使用更多本机内存。

类和类加载器

Java 应用程序由定义对象结构和方法逻辑的类组成。它们还使用 Java 运行时类库中的类(比如 java.lang.String),并且可以使用第三方库。这些类需要在它们的使用期间存储在内存中。

Java 5 之后的 IBM 实现为各类加载器分配本机内存 slab,用于存储类数据。Java 5 中的共享类技术将共享内存中的某个区域映射到存储只读(因此可以共享)类数据的地址空间。当多个 JVM 在同一台机器上运行时,这将减少存储类数据所需的物理内存量。共享类还可以改善 JVM 的启动时间。

共享类系统将固定大小的共享内存区域映射到地址空间。可以不完全占用共享类缓存,并且其中还可以包含当前未使用的类(由其他 JVM 载入),因此使用共享类将比未使用共享类占用更多地址空间(但物理内存较少)。需要重点注

篇二:毕业设计的5000字英文文献翻译

外文及翻译

英语原文 Android Application Fundamentals

Android applications are written in the Java programming language. The Android SDK tools compile the code—along with any data and resource files—into an Android package, an archive file with an .apk suffix. All the code in a single .apk file is considered to be one application and is the file that Android-powered devices use to install the application. Once installed on a device, each Android application lives in its own security sandbox: ? The Android operating system is a multi-user Linux system in which each

application is a different user.

? By default, the system assigns each application a unique Linux user ID (the ID is used only by the system and is unknown to the application). The system sets

permissions for all the files in an application so that only the user ID assigned to that application can access them.

? Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications.

? By default, every application runs in its own Linux process. Android starts the process when any of the application's components need to be executed, then shuts down the process when it's no longer needed or when the system must recover

memory for other applications.

In this way, the Android system implements the principle of least privilege. That is, each application, by default, has access only to the components that it requires to do its work and no more. This creates a very secure environment in which an application cannot access parts of the system for which it is not given permission.

However, there are ways for an application to share data with other applications and for an application to access system services:

? It's possible to arrange for two applications to share the same Linux user ID, in which

case they are able to access each other's files. To conserve system resources,

applications with the same user ID can also arrange to run in the same Linux process

and share the same VM (the applications must also be signed with the same

certificate).

? An application can request permission to access device data such as the user's

contacts, SMS messages, the mountable storage (SD card), camera, Bluetooth, and

more. All application permissions must be granted by the user at install time.

That covers the basics regarding how an Android application exists within the system. The rest of this document introduces you to: ? The core framework components that define your application.

? The manifest file in which you declare components and required device features for

your application.

? Resources that are separate from the application code and allow your application to

gracefully optimize its behavior for a variety of device configurations.

Application Components

Application components are the essential building blocks of an Android application. Each component is a different point through which the system can enter your application. Not all components are actual entry points for the user and some depend on each other, but each one exists as its own entity and plays a specific role—each one is a unique building block that helps define your application's overall behavior.

There are four different types of application components. Each type serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed.

Here are the four types of application components:

Activities

An activity represents a single screen with a user interface. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. Although the activities work together to form a cohesive user experience in the email application, each one is independent of the others. As such, a different application can start any one of these

共 21 页第 1 页

activities (if the email application allows it). For example, a camera application can start the activity in the email application that composes new mail, in order for the user to share a picture.

An activity is implemented as a subclass of Activity and you can learn more about it in the Activities developer guide.

Services

A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity. Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it.

A service is implemented as a subclass of Service and you can learn more about it in the Services developer guide. Content providers

A content provider manages a shared set of application data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. Through the content provider, other applications can query or even modify the data (if the content provider allows it). For example, the Android system provides a content provider that manages the user's contact information. As such, any application with the proper permissions can query part of the content provider (such as ContactsContract.Data) to read and write information about a particular person.

Content providers are also useful for reading and writing data that is private to your application and not shared. For example, the Note Pad sample application uses a content provider to save notes.

A content provider is implemented as a subclass of ContentProvider and must implement a standard set of APIs that enable other applications to perform transactions. For more information, see the Content Providers developer guide.

共 21 页第 2 页

Broadcast receivers

A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. Applications can also initiate broadcasts—for example, to let other applications know that some data has been downloaded to the device and is available for them to use. Although broadcast receivers don't display a user interface, they may create a status bar notification to alert the user when a broadcast event occurs. More commonly, though, a broadcast receiver is just a "gateway" to other components and is intended to do a very minimal amount of work. For instance, it might initiate a service to perform some work based on the event.

A broadcast receiver is implemented as a subclass of BroadcastReceiver and each broadcast is delivered as an Intent object. For more information, see theBroadcastReceiver class.

A unique aspect of the Android system design is that any application can start another application’s component. For example, if you want the user to capture a photo with the device camera, there's probably another application that does that and your application can use it, instead of developing an activity to capture a photo yourself. You don't need to incorporate or even link to the code from the camera application. Instead, you can simply start the activity in the camera application that captures a photo. When complete, the photo is even returned to your application so you can use it. To the user, it seems as if the camera is actually a part of your application.

When the system starts a component, it starts the process for that application (if it's not already running) and instantiates the classes needed for the component. For example, if your application starts the activity in the camera application that captures a photo, that activity runs in the process that belongs to the camera application, not in your application's process.

Therefore, unlike applications on most other systems, Android applications don't have a single entry point (there's no main() function, for example).

Because the system runs each application in a separate process with file permissions that restrict access to other applications, your application cannot directly activate a component from another application. The Android system, however, can. So, to activate a component in

共 21 页第 3 页

another application, you must deliver a message to the system that specifies your intent to start a particular component. The system then activates the component for you.

Activating Components

Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an intent. Intents bind individual components to each other at runtime (you can think of them as the messengers that request an action from other components), whether the component belongs to your application or another.

An intent is created with an Intent object, which defines a message to activate either a specific component or a specific type of component—an intent can be either explicit or implicit, respectively.

For activities and services, an intent defines the action to perform (for example, to "view" or "send" something) and may specify the URI of the data to act on (among other things that the component being started might need to know). For example, an intent might convey a request for an activity to show an image or to open a web page. In some cases, you can start an activity to receive a result, in which case, the activity also returns the result in

an Intent (for example, you can issue an intent to let the user pick a personal contact and have it returned to you—the return intent includes a URI pointing to the chosen contact).

For broadcast receivers, the intent simply defines the announcement being broadcast (for example, a broadcast to indicate the device battery is low includes only a known action string that indicates "battery is low").

The other component type, content provider, is not activated by intents. Rather, it is

activated when targeted by a request from a ContentResolver. The content resolver handles all direct transactions with the content provider so that the component that's performing

transactions with the provider doesn't need to and instead calls methods on

the ContentResolver object. This leaves a layer of abstraction between the content provider and the component requesting information (for security).

There are separate methods for activating each type of component:

共 21 页第 4 页

篇三:java 毕业论文外文文献翻译

Advantages of Managed Code

Microsoft intermediate language shares with Java byte code the idea that it is a low-level language with a simple syntax , which can be very quickly translated into native machine code. Having this

well-defined universal syntax for code has significant advantages.

Platform independence

First, it means that the same file containing byte code instructions can be placed on any platform; at runtime the final stage of compilation can then be easily accomplished so that the code will run on that particular platform. In other words, by compiling to IL we obtain platform independence for .NET, in much the same way as compiling to Java byte code gives Java platform independence.

Performance improvement

IL is actually a bit more ambitious than Java byte code. IL is always Just-In-Time compiled (known as JIT), whereas Java byte code was often interpreted. One of the disadvantages of Java was that, on execution, the process of translating from Java byte code to native executable resulted in a loss of performance.

Instead of compiling the entire application in one go (which could lead to a slow start-up time), the JIT compiler simply compiles each portion of code as it is called (just-in-time). When code has been compiled.once, the resultant native executable is stored until the application exits, so that it does not need to be recompiled the next time that portion of code is run. Microsoft argues that this process is

more efficient than compiling the entire application code at the start, because of the likelihood that large portions of any application code will not actually be executed in any given run. Using the JIT compiler, such code will never be compiled.

This explains why we can expect that execution of managed IL code will be almost as fast as executing native machine code. What it doesn’t explain is why Microsoft expects that we will get a performance improvement. The reason given for this is that, since the final stage of compilation takes place at

runtime, the JIT compiler will know exactly what processor type the program will run on. This means that it can optimize the final executable code to take advantage of any features or particular machine code instructions offered by that particular processor.

实际上,IL比Java字节代码的作用还要大。IL总是即时编译的(简称JIT),而Java字节代码常常是解释型的,Java的一个缺点是,在运行应用程序时,把Java字节代码转换为内部可执行代码的过程可可能导致性能的损失。

JIT编译器并不是把整个应用程序一次编译完(这样会有很长的启动时间),而是只编译它调用的那部分代码。代码编译过一次后,得到的内部可执行代码就存储起来,直到退出该应用程序为止,这样在下次运行这部分代码时,就不需要重新编译了。Microsoft认为这个过程要比一开始就编译整个应用程序代码的效率高得多,因为任何应用程序的大部分代码实际上并不是在每次运行过程中都执行。使用JIT编译器,从来都不会编译这种代码从来都不会被编译。

这解释了为什么托管IL代码的执行几乎和内部机器代码的执行速度一样快,但是并没有说明为什么Microsoft认为这会提高性能。其原因是编译过程的最后一部分是在运行时进行的,JIT编译器确切地知道程序运行在什么类型的处理器上,利用该处理器提供的任何特性或特定的机器代码指令来优化最后的可执行代码。

传统的编译器会优化代码,但它们的优化过程是独立于代码所运行的特定处理器的。这是因为传统的编译

器是在发布软件之前编译为内部机器可执行的代码。即编译器不知道代码所运行的处理器类型,例如该处理器是x86兼容处理器或Alpha处理器,这超出了基本操作的范围。例如Visual Studio 6优化了一台一般的Pentium机器,所以它生成的代码就不能利用Pentium III处理器的硬件特性。相反,JIT编译器不仅可以进行Visual Studio 6所能完成的优化工作,还可以优化代码所运行的特定处理器。

Traditional compilers will optimize the code, but they can only perform optimizations that are

independent of the particular processor that the code will run on. This is because traditional compilers compile to native executable before the software is shipped. This means that the compiler doesn’t know what type of processor the code will run on beyond basic generalities, such as that it will be an

x86-compatible processor or an Alpha processor. Visual Studio 6, for example, optimizes for a generic Pentium machine,

so the code that it generates cannot take advantage of hardware features of Pentium III processors. On the other hand, the JIT compiler can do all the optimizations that Visual Studio 6 can, and in addition it will optimize for the particular processor the code is running on.

Language interoperability

The use of IL not only enables platform independence; it also facilitates language interoperability. Simply put, you can compile to IL from one language, and this compiled code should then be

interoperable with code that has been compiled to IL from another language.

You’re probably now wondering which languages aside from C# are interoperable with .NET, so let’s briefly discuss how some of the other common languages fit into .NET.

Visual Basic .NET

Visual Basic .NET has undergone a complete revamp from Visual Basic 6 to bring it up-to-date with .NET. The way that Visual Basic has evolved over the last few years means that in its previous version, Visual Basic 6, it was not a suitable language for running .NET programs. For example, it is heavily integrated into COM and works by exposing only event handlers as source code to the

developer—most of the background code is not available as source code. Not only that, it does not support implementation inheritance, and the standard data types Visual Basic 6 uses are incompatible with .NET. Visual Basic 6 was upgraded to Visual Basic .NET, and the changes that were made to the language are so extensive you might as well regard Visual Basic .NET as a new language. Existing

Visual Basic 6 code does not compile as Visual Basic .NET code. Converting a Visual Basic 6 program to Visual Basic .NET requires extensive changes to the code. However, Visual Studio .NET (the

upgrade of VS for use with .NET) can do most of the changes for you. If you attempt to read a Visual Basic 6 project into Visual Studio .NET, it will upgrade the project for you, which means that it will

rewrite the Visual Basic 6 source code into Visual Basic .NET source code. Although this means that the work involved for you is heavily cut down, you will need to check through the new Visual Basic .NET code to make sure that the project still works as intended because the conversion might not be perfect. One side effect of this language upgrade is that it is no longer possible to compile Visual Basic .NET to native executable code. Visual Basic .NET compiles only to IL, just as C# does. If you need to continue coding in Visual Basic 6, you may do so, but the executable code produced will completely ignore

the .NET Framework, and you’ll need to keep Visual Studio 6 installed if you want to continue to work in this developer environment.

Visual C++ .NET

Visual C++ 6 already had a large number of Microsoft-specific extensions on Windows. With Visual

C++ .NET, extensions have been added to support the .NET Framework. This means that existing C++ source code will continue to compile to native executable code without modification. It also means, however, that it will run independently of the .NET runtime. If you want your C++ code to run within the .NET Framework, then you can simply add the following line to the beginning of your code: #using <mscorlib.dll>

You can also pass the flag /clr to the compiler, which then assumes that you want to compile to managed code, and will hence emit IL instead of native machine code. The interesting thing about C++ is that when you compile to managed code, the compiler can emit IL that contains an embedded native executable. This means that you can mix managed types and unmanaged types in your C++ code. Thus the managed C++ code:

class MyClass

{

defines a plain C++ class, whereas the code:

__gc class MyClass

{

will give you a managed class, just as if you’d written the class in C# or Visual Basic .NET. The advantage

of using managed C++ over C# code is that we can call unmanaged C++ classes from managed C++ code without having to resort to COM interop.

The compiler raises an error if you attempt to use features that are not supported by .NET on managed types (for example, templates or multiple inheritance of classes). You will also find that you will need to use nonstandard C++ features (such as the __gc keyword shown in the previous code) when using managed classes.

Because of the freedom that C++ allows in terms of low-level pointer manipulation and so on, the C++ compiler is not able to generate code that will pass the CLR’s memory type safety tests. If it’s important that your code is recognized by the CLR as memory type safe, then you’ll need to write your source code

in some other language (such as C# or Visual Basic .NET).

Visual J# .NET

The latest language to be added to the mix is Visual J# .NET. Prior to .NET Framework 1.1, users were able to use J# only after making a separate download. Now the J# language is built into the .NET

Framework. Because of this, J# users are able to take advantage of all the usual features of Visual Studio .NET. Microsoft expects that most J++ users will find it easiest to use J# if they want to work with .NET.

Instead of being targeted at the Java runtime libraries, J# uses the same base class libraries that the rest of the .NET compliant languages use. This means that you can use J# for building ASP.NET Web applications,

Windows Forms, XMLWeb services, and everything else that is possible—just as C# and Visual Basic .NET can.

Scripting languages

Scripting languages are still around, although, in general, their importance is likely to decline with the advent of .NET. JScript, on the other hand, has been upgraded to JScript .NET. We can now write ASP.NET

pages in JScript .NET, run JScript .NET as a compiled rather than an interpreted language, and write

strongly typed JScript .NET code. With ASP.NET there is no reason to use scripting languages in serverside

Web pages. VBA is, however, still used as a language for Microsoft Office and Visual Studio macros. COM and COM+

Technically speaking, COM and COM+ aren’t technologies targeted at .NET, because components based

on them cannot be compiled into IL (although it’s possible to do so to some degree using managed C++, if

the original COM component was written in C++). However, COM+ remains an important tool, because its features are not duplicated in .NET. Also, COM components will still work—and .NET incorporates COM interoperability features that make it possible for managed code to call up COM components and vice versa (this is discussed in Chapter 29). In general, however, you will probably find it more convenient

for most purposes to code new components as .NET components, so that you can take advantage of the .NET base classes as well as the other benefits of running as managed code.

托管代码的优点

Microsoft中间语言与Java字节代码共享一种理念:它们都是一种低级语言,语法很简单,可以非常快速地转换为机器码。对于代码来说,这种精心设计的通用语法,有很大的优点。

1. 平台无关性

首先,这意味着包含字节代码指令的同一个文件可以放在任一个平台中,运行时编译过程的最后阶段可以很容易完成,这样代码就可以运行在该特定的平台上。也就是说编译为中间语言就可以获得.NET平台无关性,这与编译为Java字节代码就会得到Java平台无关性是一样的。

2. 提高性能

实际上,IL比Java字节代码的作用还要大。IL总是即时编译的(简称JIT),而Java字节代码常常是解释型的,Java的一个缺点是,在运行应用程序时,把Java字节代码转换为内部可执行代码的过程可可能导致性能的损失。

JIT编译器并不是把整个应用程序一次编译完(这样会有很长的启动时间),而是只编译它调用的那部分代码(这是其名称由来)。代码编译过一次后,得到的内部可执行代码就存储起来,直到退出该应用程序为止,这样在下次运行这部分代码时,就不需要重新编译了。Microsoft认为这个过程要比一开始就编译整个应用程序代码的效率高得多,因为任何应用程序的大部分代码实际上并不是在每次运行过程中都执行。使用JIT编译器,从来都不会编译这种代码。

这解释了为什么托管IL代码的执行几乎和内部机器代码的执行速度一样快,但是并没有说明为什么Microsoft认为这会提高性能。其原因是编译过程的最后一部分是在运行时进行的,JIT编译器确切地知道程序运行在什么类型的处理器上,利用该处理器提供的任何特性或特定的机器代码指令来优化最后的可执行代码。

传统的编译器会优化代码,但它们的优化过程是独立于代码所运行的特定处理器的。这是因为传统的编译器是在发布软件之前编译为内部机器可执行的代码。即编译器不知道代码所运行的处理器类型,例如该处理器是x86兼容处理器或Alpha处理器,这超出了基本操作的范围。例如Visual Studio 6优化了一台一般的Pentium机器,所以它生成的代码就不能利用Pentium III处理器的硬件特性。相反,JIT编译器不仅可以进行Visual Studio 6所能完成的优化工作,还可以优化代码所运行的特定处理器。

3. 语言的互操作性

使用IL不仅支持平台无关性,还支持语言的互操作性。简言之,就是能将任何一种语言编译为中间代码,编译好的代码可以与从其他语言编译过来的代码进行交互操作。

那么除了C#之外,还有什么语言可以通过.NET进行交互操作呢?下面就简要讨论其他常见语言如何与.NET交互操作。


java外文翻译5000字
由:免费论文网互联网用户整理提供,链接地址:
http://m.csmayi.cn/show/93861.html
转载请保留,谢谢!
相关阅读
最近更新
推荐专题